Skip to content

Commit 8d7f430

Browse files
committed
Drop dangling local symbol occurrences
Amp-Thread-ID: https://ampcode.com/threads/T-01a029e2-5095-710a-9cce-0c6d8645c173
1 parent 6bafc40 commit 8d7f430

7 files changed

Lines changed: 48 additions & 8 deletions

File tree

snapshots/input/multi-project/packages/a/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@
33
export function a(): string {
44
return ''
55
}
6+
7+
export function localResult() {
8+
interface LocalResult {
9+
value: string
10+
}
11+
return { value: '' } as LocalResult
12+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { a } from '@example/a/src'
1+
import { a, localResult } from '@example/a/src'
22

33
export function b() {
4+
localResult().value
45
return a()
56
}

snapshots/output/multi-project/packages/a/src/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,24 @@ export function a(): string {
1414
return ''
1515
}
1616

17+
export function localResult() {
18+
// ^^^^^^^^^^^ definition @example/a 1.0.0 src/`index.ts`/localResult().
19+
// documentation ```ts
20+
// > function localResult(): LocalResult
21+
// > ```
22+
interface LocalResult {
23+
// ^^^^^^^^^^^ definition local 0
24+
// documentation ```ts
25+
// > interface LocalResult
26+
// > ```
27+
value: string
28+
// ^^^^^ definition local 1
29+
// documentation ```ts
30+
// > (property) value: string
31+
// > ```
32+
}
33+
return { value: '' } as LocalResult
34+
// ^^^^^ reference local 1
35+
// ^^^^^^^^^^^ reference local 0
36+
}
37+

snapshots/output/multi-project/packages/b/src/b.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// language TypeScript
22
// < definition @example/b 1.0.0 src/`b.ts`/
33

4-
import { a } from '@example/a/src'
4+
import { a, localResult } from '@example/a/src'
55
// ^ reference @example/a 1.0.0 src/`index.ts`/a().
6-
// ^^^^^^^^^^^^^^^^ reference @example/a 1.0.0 src/`index.ts`/
6+
// ^^^^^^^^^^^ reference @example/a 1.0.0 src/`index.ts`/localResult().
7+
// ^^^^^^^^^^^^^^^^ reference @example/a 1.0.0 src/`index.ts`/
78

89
export function b() {
910
// ^ definition @example/b 1.0.0 src/`b.ts`/b().
11+
localResult().value
12+
//^^^^^^^^^^^ reference @example/a 1.0.0 src/`index.ts`/localResult().
1013
return a()
1114
// ^ reference @example/a 1.0.0 src/`index.ts`/a().
1215
}

snapshots/output/prototype-members/src/connection.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ export function Connection() {}
66

77
Connection.prototype = {
88
//^^^^^^^^^ reference prototype-members 1.0.0 src/`connection.mjs`/Connection().
9-
//^^^^^^^^^ reference local 3
10-
// ^^^^^^^^^ reference local 2
119
getSchemaVersion() {
1210
//^^^^^^^^^^^^^^^^ definition prototype-members 1.0.0 src/`connection.mjs`/Connection().getSchemaVersion().
1311
return 0

src/FileIndexer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ export class FileIndexer {
6565

6666
this.emitSourceFileOccurrence()
6767
this.visit(this.sourceFile)
68+
// A SCIP local symbol is owned by one document. TypeScript can report
69+
// synthetic or cross-file declaration candidates that the symbol algorithm
70+
// cannot represent as locals in this document, so discard those unusable
71+
// occurrences instead of emitting dangling local identities.
72+
this.document.occurrences = this.document.occurrences.filter(
73+
occurrence =>
74+
!occurrence.symbol.startsWith('local ') ||
75+
this.symbolInformation.has(occurrence.symbol)
76+
)
6877
}
6978
private emitSourceFileOccurrence(): void {
7079
const symbol = this.scipSymbol(this.sourceFile)

src/main.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,14 @@ for (const snapshotDirectory of snapshotDirectories) {
145145
.filter(
146146
symbol =>
147147
symbol &&
148-
!symbol.startsWith('local ') &&
149-
!availableSymbols.has(symbol)
148+
(symbol.startsWith('local ')
149+
? !symbols.has(symbol)
150+
: !availableSymbols.has(symbol))
150151
)
151152
assert.equal(
152153
missingOccurrenceSymbols,
153154
[],
154-
`${document.relative_path} global occurrences should have SymbolInformation`
155+
`${document.relative_path} occurrences should have SymbolInformation`
155156
)
156157
const missingRelationshipSymbols = document.symbols
157158
.flatMap(symbol => symbol.relationships)

0 commit comments

Comments
 (0)