diff --git a/snapshots/output/syntax/src/object-literals.ts b/snapshots/output/syntax/src/object-literals.ts index 0aed7922..30bf69b6 100644 --- a/snapshots/output/syntax/src/object-literals.ts +++ b/snapshots/output/syntax/src/object-literals.ts @@ -75,7 +75,6 @@ export function returnStatement(): Configuration { // ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random(). // ^^^^^^ reference typescript 6.0.3 lib/`lib.es5.d.ts`/Number# // ^^^^^^ reference typescript 6.0.3 lib/`lib.es5.d.ts`/Number. -// ^^^^^^ reference typescript 6.0.3 lib/`lib.es5.d.ts`/Number# // ^^^^^^^^ reference typescript 6.0.3 lib/`lib.es2015.core.d.ts`/NumberConstructor#parseInt(). // ^ reference local 8 return { diff --git a/src/FileIndexer.ts b/src/FileIndexer.ts index 9a7eac1b..4418f10a 100644 --- a/src/FileIndexer.ts +++ b/src/FileIndexer.ts @@ -27,6 +27,7 @@ export class FileIndexer { private localSymbolTable: Map = new Map() private symbolInformation: Map = new Map() + private occurrenceKeys: Set = new Set() private workingDirectoryRegExp: RegExp constructor( public readonly checker: ts.TypeChecker, @@ -398,12 +399,11 @@ export class FileIndexer { } private pushOccurrence(occurrence: scip.scip.Occurrence): void { - const lastOccurrence = this.document.occurrences.at(-1) - if (lastOccurrence) { - if (isEqualOccurrence(lastOccurrence, occurrence)) { - return - } + const key = `${occurrence.range.join(':')} ${occurrence.symbol_roles} ${occurrence.symbol}` + if (this.occurrenceKeys.has(key)) { + return } + this.occurrenceKeys.add(key) this.document.occurrences.push(occurrence) } @@ -1039,29 +1039,6 @@ function bindingElementKind( return Kind.Variable } -function isEqualOccurrence( - a: scip.scip.Occurrence, - b: scip.scip.Occurrence -): boolean { - return ( - a.symbol_roles === b.symbol_roles && - a.symbol === b.symbol && - isEqualArray(a.range, b.range) - ) -} - -function isEqualArray(a: T[], b: T[]): boolean { - if (a.length !== b.length) { - return false - } - for (let index = 0; index < a.length; index++) { - if (a[index] !== b[index]) { - return false - } - } - return true -} - function declarationName(node: ts.Node): ts.Node | undefined { if ( ts.isBindingElement(node) || diff --git a/src/main.test.ts b/src/main.test.ts index 4a563e60..21152e51 100644 --- a/src/main.test.ts +++ b/src/main.test.ts @@ -97,6 +97,20 @@ for (const snapshotDirectory of snapshotDirectories) { [], `${document.relative_path} should not contain duplicate SymbolInformation` ) + const occurrences = new Set() + const duplicateOccurrences: string[] = [] + for (const occurrence of document.occurrences) { + const key = `${occurrence.range.join(':')} ${occurrence.symbol_roles} ${occurrence.symbol}` + if (occurrences.has(key)) { + duplicateOccurrences.push(key) + } + occurrences.add(key) + } + assert.equal( + duplicateOccurrences, + [], + `${document.relative_path} should not contain duplicate occurrences` + ) assert.ok( document.language, `${document.relative_path} should have a SCIP document language`