Skip to content

Commit 108abe1

Browse files
committed
Resolve SCIP relationship targets
Amp-Thread-ID: https://ampcode.com/threads/T-01a029e2-5095-710a-9cce-0c6d8645c173
1 parent 3242e33 commit 108abe1

4 files changed

Lines changed: 37 additions & 3 deletions

File tree

snapshots/input/syntax/src/inheritance.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export abstract class IntermediateSuperclass extends Superclass {
1313
}
1414
public abstract intermediateOverrideMethod(): string
1515
}
16+
export class ExternalSubclass extends Error {
17+
public override name = 'ExternalSubclass'
18+
}
1619
export class Subclass
1720
extends IntermediateSuperclass
1821
implements IntermediateSuperinterface, Overloader

snapshots/output/syntax/src/inheritance.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ export abstract class IntermediateSuperclass extends Superclass {
3131
public abstract intermediateOverrideMethod(): string
3232
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperclass#intermediateOverrideMethod().
3333
}
34+
export class ExternalSubclass extends Error {
35+
// ^^^^^^^^^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/ExternalSubclass#
36+
// relationship implementation typescript 6.0.3 lib/`lib.es5.d.ts`/Error#
37+
// ^^^^^ reference typescript 6.0.3 lib/`lib.es5.d.ts`/Error#
38+
// ^^^^^ reference typescript 6.0.3 lib/`lib.es5.d.ts`/Error.
39+
public override name = 'ExternalSubclass'
40+
// ^^^^ definition syntax 1.0.0 src/`inheritance.ts`/ExternalSubclass#name.
41+
// relationship implementation reference typescript 6.0.3 lib/`lib.es5.d.ts`/Error#name.
42+
}
3443
export class Subclass
3544
// ^^^^^^^^ definition syntax 1.0.0 src/`inheritance.ts`/Subclass#
3645
// relationship implementation syntax 1.0.0 src/`inheritance.ts`/IntermediateSuperclass#

src/main.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ for (const snapshotDirectory of snapshotDirectories) {
153153
[],
154154
`${document.relative_path} global occurrences should have SymbolInformation`
155155
)
156+
const missingRelationshipSymbols = document.symbols
157+
.flatMap(symbol => symbol.relationships)
158+
.map(relationship => relationship.symbol)
159+
.filter(
160+
symbol =>
161+
symbol &&
162+
!symbol.startsWith('local ') &&
163+
!availableSymbols.has(symbol)
164+
)
165+
assert.equal(
166+
missingRelationshipSymbols,
167+
[],
168+
`${document.relative_path} relationship targets should have SymbolInformation`
169+
)
156170
const missingInternalSymbols = document.occurrences
157171
.map(occurrence => occurrence.symbol)
158172
.filter(

src/main.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,24 @@ export function indexCommand(
4747
const output = fs.openSync(options.output, 'w')
4848
let documentCount = 0
4949
const definedSymbols = new Set<string>()
50-
const occurrenceSymbols = new Set<string>()
50+
const referencedSymbols = new Set<string>()
5151
const writeIndex = (index: scip.scip.Index): void => {
5252
documentCount += index.documents.length
5353
for (const document of index.documents) {
5454
for (const symbol of document.symbols) {
5555
definedSymbols.add(symbol.symbol)
56+
for (const relationship of symbol.relationships) {
57+
if (
58+
relationship.symbol &&
59+
!relationship.symbol.startsWith('local ')
60+
) {
61+
referencedSymbols.add(relationship.symbol)
62+
}
63+
}
5664
}
5765
for (const occurrence of document.occurrences) {
5866
if (occurrence.symbol && !occurrence.symbol.startsWith('local ')) {
59-
occurrenceSymbols.add(occurrence.symbol)
67+
referencedSymbols.add(occurrence.symbol)
6068
}
6169
}
6270
}
@@ -99,7 +107,7 @@ export function indexCommand(
99107
}
100108
writeIndex(
101109
new scip.scip.Index({
102-
external_symbols: [...occurrenceSymbols]
110+
external_symbols: [...referencedSymbols]
103111
.filter(symbol => !definedSymbols.has(symbol))
104112
.map(symbol => new scip.scip.SymbolInformation({ symbol })),
105113
})

0 commit comments

Comments
 (0)