Skip to content

FAR cleanup and isDefinition definition #48211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,119 @@ namespace ts {
return createMultiMap() as UnderscoreEscapedMultiMap<T>;
}

export function createSet<TElement, THash = number>(getHashCode: (element: TElement) => THash, equals: EqualityComparer<TElement>): Set<TElement> {
const multiMap = new Map<THash, TElement[]>();
let size = 0;

function getElementIterator(): Iterator<TElement> {
const valueIt = multiMap.values();
let arrayIt: Iterator<TElement> | undefined;
return {
next: () => {
while (true) {
if (arrayIt) {
const n = arrayIt.next();
if (!n.done) {
return { value: n.value };
}
arrayIt = undefined;
}
else {
const n = valueIt.next();
if (n.done) {
return { value: undefined, done: true };
}
arrayIt = arrayIterator(n.value);
}
}
}
};
}

const set: Set<TElement> = {
has(element: TElement): boolean {
const hash = getHashCode(element);
const candidates = multiMap.get(hash);
if (candidates) {
for (const candidate of candidates) {
if (equals(candidate, element)) {
return true;
}
}
}

return false;
},
add(element: TElement): Set<TElement> {
const hash = getHashCode(element);
const values = multiMap.get(hash);
if (values) {
if (!contains(values, element, equals)) {
values.push(element);
size++;
}
}
else {
multiMap.set(hash, [ element ]);
size++;
}

return this;
},
delete(element: TElement): boolean {
const hash = getHashCode(element);
const candidates = multiMap.get(hash);
if (candidates) {
for (let i = 0; i < candidates.length; i++) {
if (equals(candidates[i], element)) {
if (candidates.length === 1) {
multiMap.delete(hash);
}
else {
unorderedRemoveItemAt(candidates, i);
}
size--;
return true;
}
}
}

return false;
},
clear(): void {
multiMap.clear();
size = 0;
},
get size() {
return size;
},
forEach(action: (value: TElement, key: TElement) => void): void {
for (const elements of arrayFrom(multiMap.values())) {
for (const element of elements) {
action(element, element);
}
}
},
keys(): Iterator<TElement> {
return getElementIterator();
},
values(): Iterator<TElement> {
return getElementIterator();
},
entries(): Iterator<[TElement, TElement]> {
const it = getElementIterator();
return {
next: () => {
const n = it.next();
return n.done ? n : { value: [ n.value, n.value ] };
}
};
},
};

return set;
}

/**
* Tests whether a value is an array.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/harness/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,10 @@ namespace ts.server {
throw new Error("Program objects are not serializable through the server protocol.");
}

updateIsDefinitionOfReferencedSymbols(_referencedSymbols: readonly ReferencedSymbol[], _knownSymbolSpans: Set<DocumentSpan>): boolean {
return notImplemented();
}

getNonBoundSourceFile(_fileName: string): SourceFile {
throw new Error("SourceFile objects are not serializable through the server protocol.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ namespace FourSlash {
const text = definition.displayParts.map(d => d.text).join("");
return {
definition: fullExpected.length > i && typeof fullExpected[i].definition === "string" ? text : { text, range: definition.textSpan },
references,
references: references.map(r => ({ ...r, isStartingPoint: undefined })), // TODO (acasey): fix up?
};
});
this.assertObjectsEqual(fullActual, fullExpected);
Expand Down
3 changes: 3 additions & 0 deletions src/harness/harnessLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@ namespace Harness.LanguageService {
getAutoImportProvider(): ts.Program | undefined {
throw new Error("Program can not be marshaled across the shim layer.");
}
updateIsDefinitionOfReferencedSymbols(_referencedSymbols: readonly ts.ReferencedSymbol[], _knownSymbolSpans: ts.Set<ts.DocumentSpan>): boolean {
return ts.notImplemented();
}
getNonBoundSourceFile(): ts.SourceFile {
throw new Error("SourceFile can not be marshaled across the shim layer.");
}
Expand Down
Loading