Skip to content

Commit 8426cba

Browse files
committed
1 parent b94eed8 commit 8426cba

3 files changed

Lines changed: 19 additions & 29 deletions

File tree

snapshots/output/syntax/src/object-literals.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export function returnStatement(): Configuration {
7575
// ^^^^^^ reference syntax 1.0.0 src/`object-literals.ts`/random().
7676
// ^^^^^^ reference typescript 6.0.3 lib/`lib.es5.d.ts`/Number#
7777
// ^^^^^^ reference typescript 6.0.3 lib/`lib.es5.d.ts`/Number.
78-
// ^^^^^^ reference typescript 6.0.3 lib/`lib.es5.d.ts`/Number#
7978
// ^^^^^^^^ reference typescript 6.0.3 lib/`lib.es2015.core.d.ts`/NumberConstructor#parseInt().
8079
// ^ reference local 8
8180
return {

src/FileIndexer.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class FileIndexer {
2727
private localSymbolTable: Map<ts.Node, ScipSymbol> = new Map()
2828
private symbolInformation: Map<string, scip.scip.SymbolInformation> =
2929
new Map()
30+
private occurrenceKeys: Set<string> = new Set()
3031
private workingDirectoryRegExp: RegExp
3132
constructor(
3233
public readonly checker: ts.TypeChecker,
@@ -395,12 +396,11 @@ export class FileIndexer {
395396
}
396397

397398
private pushOccurrence(occurrence: scip.scip.Occurrence): void {
398-
const lastOccurrence = this.document.occurrences.at(-1)
399-
if (lastOccurrence) {
400-
if (isEqualOccurrence(lastOccurrence, occurrence)) {
401-
return
402-
}
399+
const key = `${occurrence.range.join(':')} ${occurrence.symbol_roles} ${occurrence.symbol}`
400+
if (this.occurrenceKeys.has(key)) {
401+
return
403402
}
403+
this.occurrenceKeys.add(key)
404404
this.document.occurrences.push(occurrence)
405405
}
406406

@@ -1020,29 +1020,6 @@ function bindingElementKind(
10201020
return Kind.Variable
10211021
}
10221022

1023-
function isEqualOccurrence(
1024-
a: scip.scip.Occurrence,
1025-
b: scip.scip.Occurrence
1026-
): boolean {
1027-
return (
1028-
a.symbol_roles === b.symbol_roles &&
1029-
a.symbol === b.symbol &&
1030-
isEqualArray(a.range, b.range)
1031-
)
1032-
}
1033-
1034-
function isEqualArray<T>(a: T[], b: T[]): boolean {
1035-
if (a.length !== b.length) {
1036-
return false
1037-
}
1038-
for (let index = 0; index < a.length; index++) {
1039-
if (a[index] !== b[index]) {
1040-
return false
1041-
}
1042-
}
1043-
return true
1044-
}
1045-
10461023
function declarationName(node: ts.Node): ts.Node | undefined {
10471024
if (
10481025
ts.isBindingElement(node) ||

src/main.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ for (const snapshotDirectory of snapshotDirectories) {
9797
[],
9898
`${document.relative_path} should not contain duplicate SymbolInformation`
9999
)
100+
const occurrences = new Set<string>()
101+
const duplicateOccurrences: string[] = []
102+
for (const occurrence of document.occurrences) {
103+
const key = `${occurrence.range.join(':')} ${occurrence.symbol_roles} ${occurrence.symbol}`
104+
if (occurrences.has(key)) {
105+
duplicateOccurrences.push(key)
106+
}
107+
occurrences.add(key)
108+
}
109+
assert.equal(
110+
duplicateOccurrences,
111+
[],
112+
`${document.relative_path} should not contain duplicate occurrences`
113+
)
100114
assert.ok(
101115
document.language,
102116
`${document.relative_path} should have a SCIP document language`

0 commit comments

Comments
 (0)