diff --git a/snapshots/output/pure-js/src/main.js b/snapshots/output/pure-js/src/main.js index 91bdebfd..22568ae9 100644 --- a/snapshots/output/pure-js/src/main.js +++ b/snapshots/output/pure-js/src/main.js @@ -67,7 +67,6 @@ // documentation ```ts\nvar a: number\n``` print_fib(a) //^^^^^^^^^ reference pure-js 1.0.0 src/`main.js`/print_fib(). -// ^ reference pure-js 1.0.0 src/`main.js`/a. // ^ reference pure-js 1.0.0 src/`main.js`/a. function forever() { diff --git a/snapshots/output/syntax/src/local.ts b/snapshots/output/syntax/src/local.ts index 98ad7f61..472f5d73 100644 --- a/snapshots/output/syntax/src/local.ts +++ b/snapshots/output/syntax/src/local.ts @@ -37,8 +37,6 @@ // ^ reference local 8 // ^^ reference local 9 // ^^^^^^ reference typescript 4.8.4 lib/`lib.es5.d.ts`/Array#reduce(). -// ^^^^^^ reference typescript 4.8.4 lib/`lib.es5.d.ts`/Array#reduce(). -// ^^^^^^ reference typescript 4.8.4 lib/`lib.es5.d.ts`/Array#reduce(). // ^^^^^^^^^^^^^ definition local 16 // documentation ```ts\n(parameter) previousValue: string\n``` // ^^^^^^^^^^^^ definition local 17 diff --git a/snapshots/output/syntax/src/structural-type.ts b/snapshots/output/syntax/src/structural-type.ts index 6d7cf25a..b061b836 100644 --- a/snapshots/output/syntax/src/structural-type.ts +++ b/snapshots/output/syntax/src/structural-type.ts @@ -17,7 +17,6 @@ // ^^^^^^^ reference typescript 4.8.4 lib/`lib.es2015.symbol.wellknown.d.ts`/Promise# // ^^^^^^^ reference typescript 4.8.4 lib/`lib.es2018.promise.d.ts`/Promise# // ^^^^^^^ reference typescript 4.8.4 lib/`lib.es2015.promise.d.ts`/PromiseConstructor#resolve(). -// ^^^^^^^ reference typescript 4.8.4 lib/`lib.es2015.promise.d.ts`/PromiseConstructor#resolve(). // ^^^^^^ definition syntax 1.0.0 src/`structural-type.ts`/member0: // documentation ```ts\n(property) member: number\n``` } diff --git a/src/FileIndexer.ts b/src/FileIndexer.ts index 615efd75..27f6a52b 100644 --- a/src/FileIndexer.ts +++ b/src/FileIndexer.ts @@ -45,7 +45,7 @@ export class FileIndexer { if (symbol.isEmpty()) { return } - this.document.occurrences.push( + this.pushOccurrence( new scip.scip.Occurrence({ range: [0, 0, 0], symbol: symbol.value, @@ -111,7 +111,7 @@ export class FileIndexer { // Skip empty symbols continue } - this.document.occurrences.push( + this.pushOccurrence( new scip.scip.Occurrence({ range, symbol: scipSymbol.value, @@ -153,7 +153,7 @@ export class FileIndexer { if (scipSymbol.isEmpty()) { continue } - this.document.occurrences.push( + this.pushOccurrence( new scip.scip.Occurrence({ range, symbol: scipSymbol.value, @@ -190,7 +190,7 @@ export class FileIndexer { if (scipSymbol.isEmpty()) { continue } - this.document.occurrences.push( + this.pushOccurrence( new scip.scip.Occurrence({ range, symbol: scipSymbol.value, @@ -227,6 +227,17 @@ export class FileIndexer { ) } + private pushOccurrence(occurrence: scip.scip.Occurrence): void { + if (this.document.occurrences.length > 0) { + const lastOccurrence = + this.document.occurrences[this.document.occurrences.length - 1] + if (isEqualOccurrence(lastOccurrence, occurrence)) { + return + } + } + this.document.occurrences.push(occurrence) + } + private relationships( declaration: ts.Node, declarationSymbol: ScipSymbol @@ -673,3 +684,26 @@ function scriptElementKind( } return ts.ScriptElementKind.unknown } + +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 +}