Skip to content

Commit 3242e33

Browse files
committed
Emit external symbol information
Amp-Thread-ID: https://ampcode.com/threads/T-01a029e2-5095-710a-9cce-0c6d8645c173
1 parent 3521d13 commit 3242e33

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/main.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ for (const snapshotDirectory of snapshotDirectories) {
8888
document.symbols.map(symbol => symbol.symbol)
8989
)
9090
)
91+
const externalSymbolInformation = new Set(
92+
index.external_symbols.map(symbol => symbol.symbol)
93+
)
94+
assert.equal(
95+
externalSymbolInformation.size,
96+
index.external_symbols.length,
97+
'external SymbolInformation should be unique'
98+
)
99+
assert.equal(
100+
index.external_symbols
101+
.map(symbol => symbol.symbol)
102+
.filter(symbol => symbolInformation.has(symbol)),
103+
[],
104+
'symbols should not be both internal and external'
105+
)
106+
const availableSymbols = new Set([
107+
...symbolInformation,
108+
...externalSymbolInformation,
109+
])
91110
const indexedPackages = new Set(
92111
[...symbolInformation]
93112
.filter(symbol => !symbol.startsWith('local '))
@@ -121,6 +140,19 @@ for (const snapshotDirectory of snapshotDirectories) {
121140
[],
122141
`${document.relative_path} should not contain duplicate occurrences`
123142
)
143+
const missingOccurrenceSymbols = document.occurrences
144+
.map(occurrence => occurrence.symbol)
145+
.filter(
146+
symbol =>
147+
symbol &&
148+
!symbol.startsWith('local ') &&
149+
!availableSymbols.has(symbol)
150+
)
151+
assert.equal(
152+
missingOccurrenceSymbols,
153+
[],
154+
`${document.relative_path} global occurrences should have SymbolInformation`
155+
)
124156
const missingInternalSymbols = document.occurrences
125157
.map(occurrence => occurrence.symbol)
126158
.filter(
@@ -157,7 +189,7 @@ for (const snapshotDirectory of snapshotDirectories) {
157189
? fs.readFileSync(outputPath).toString()
158190
: ''
159191
const input = Input.fromFile(inputPath)
160-
const obtained = formatSnapshot(input, document)
192+
const obtained = formatSnapshot(input, document, index.external_symbols)
161193
if (obtained === expected) {
162194
// Test passed
163195
continue

src/main.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,20 @@ export function indexCommand(
4646
}
4747
const output = fs.openSync(options.output, 'w')
4848
let documentCount = 0
49+
const definedSymbols = new Set<string>()
50+
const occurrenceSymbols = new Set<string>()
4951
const writeIndex = (index: scip.scip.Index): void => {
5052
documentCount += index.documents.length
53+
for (const document of index.documents) {
54+
for (const symbol of document.symbols) {
55+
definedSymbols.add(symbol.symbol)
56+
}
57+
for (const occurrence of document.occurrences) {
58+
if (occurrence.symbol && !occurrence.symbol.startsWith('local ')) {
59+
occurrenceSymbols.add(occurrence.symbol)
60+
}
61+
}
62+
}
5163
fs.writeSync(output, index.serializeBinary())
5264
}
5365

@@ -85,6 +97,13 @@ export function indexCommand(
8597
cache
8698
)
8799
}
100+
writeIndex(
101+
new scip.scip.Index({
102+
external_symbols: [...occurrenceSymbols]
103+
.filter(symbol => !definedSymbols.has(symbol))
104+
.map(symbol => new scip.scip.SymbolInformation({ symbol })),
105+
})
106+
)
88107
} finally {
89108
fs.close(output)
90109
if (documentCount > 0) {

0 commit comments

Comments
 (0)