Skip to content
Open
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
1 change: 0 additions & 1 deletion snapshots/output/syntax/src/object-literals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
33 changes: 5 additions & 28 deletions src/FileIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class FileIndexer {
private localSymbolTable: Map<ts.Node, ScipSymbol> = new Map()
private symbolInformation: Map<string, scip.scip.SymbolInformation> =
new Map()
private occurrenceKeys: Set<string> = new Set()
private workingDirectoryRegExp: RegExp
constructor(
public readonly checker: ts.TypeChecker,
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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<T>(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) ||
Expand Down
14 changes: 14 additions & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ for (const snapshotDirectory of snapshotDirectories) {
[],
`${document.relative_path} should not contain duplicate SymbolInformation`
)
const occurrences = new Set<string>()
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`
Expand Down
Loading