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
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function genericArrow2(): Foobar[] {
return [1].map(n => ({ foobar: n + 1 }))
// ^^^ reference typescript 6.0.3 lib/`lib.es5.d.ts`/Array#map().
// ^ definition local 26
// ^^^^^^ reference syntax 1.0.0 src/`object-literals-arrow-function.ts`/foobar1:
// ^^^^^^ definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/foobar1:
// ^ reference local 26
}

2 changes: 1 addition & 1 deletion snapshots/output/syntax/src/structural-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function foo(): Promise<{ member: number }> {
// ^^^^^^^ reference typescript 6.0.3 lib/`lib.es2015.promise.d.ts`/Promise.
// ^^^^^^^ reference typescript 6.0.3 lib/`lib.es2015.symbol.wellknown.d.ts`/Promise#
// ^^^^^^^ reference typescript 6.0.3 lib/`lib.es2015.promise.d.ts`/PromiseConstructor#resolve().
// ^^^^^^ reference syntax 1.0.0 src/`structural-type.ts`/member0:
// ^^^^^^ definition syntax 1.0.0 src/`structural-type.ts`/member0:
}
export function bar(): Promise<number> {
// ^^^ definition syntax 1.0.0 src/`structural-type.ts`/bar().
Expand Down
6 changes: 5 additions & 1 deletion src/FileIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ export class FileIndexer {
objectElement,
contextualType
)
return symbol?.getDeclarations()
const declarations = symbol?.getDeclarations()
// Inferred object types can contextually resolve a property back to its
// own declaration. Treat that circular result as a definition instead of
// emitting a reference to a symbol that never gets SymbolInformation.
return declarations?.includes(objectElement) ? undefined : declarations
}

private visitSymbolOccurrence(node: ts.Node, sym: ts.Symbol): void {
Expand Down
27 changes: 27 additions & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ for (const snapshotDirectory of snapshotDirectories) {
documentPaths.add(document.relative_path)
}
assert.equal(duplicateDocuments, [], 'SCIP document paths should be unique')
const symbolInformation = new Set(
index.documents.flatMap(document =>
document.symbols.map(symbol => symbol.symbol)
)
)
const indexedPackages = new Set(
[...symbolInformation]
.filter(symbol => !symbol.startsWith('local '))
.map(symbolPackage)
)
for (const document of index.documents) {
const symbols = new Set<string>()
const duplicateSymbols: string[] = []
Expand Down Expand Up @@ -111,6 +121,19 @@ for (const snapshotDirectory of snapshotDirectories) {
[],
`${document.relative_path} should not contain duplicate occurrences`
)
const missingInternalSymbols = document.occurrences
.map(occurrence => occurrence.symbol)
.filter(
symbol =>
symbol &&
indexedPackages.has(symbolPackage(symbol)) &&
!symbolInformation.has(symbol)
)
assert.equal(
missingInternalSymbols,
[],
`${document.relative_path} occurrences in indexed packages should have SymbolInformation`
)
assert.ok(
document.language,
`${document.relative_path} should have a SCIP document language`
Expand Down Expand Up @@ -162,4 +185,8 @@ for (const snapshotDirectory of snapshotDirectories) {
})
}

function symbolPackage(symbol: string): string {
return symbol.split(' ', 4).join(' ')
}

test.run()
Loading