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
2 changes: 2 additions & 0 deletions snapshots/input/react/src/LoaderInput.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// format-options: showExternalSymbols

import React from 'react'

/** Takes loading prop, input component as child */
Expand Down
10 changes: 10 additions & 0 deletions snapshots/output/react/src/LoaderInput.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// language TypeScriptReact
// < definition react-example 1.0.0 src/`LoaderInput.tsx`/

// format-options: showExternalSymbols

import React from 'react'
// ^^^^^ reference @types/react 19.2.18 `index.d.ts`/React/
// external SymbolInformation @types/react 19.2.18 `index.d.ts`/React/
// ^^^^^^^ reference @types/react 19.2.18 `index.d.ts`/
// external SymbolInformation @types/react 19.2.18 `index.d.ts`/

/** Takes loading prop, input component as child */
interface Props {
Expand All @@ -14,12 +18,14 @@ interface Props {
//^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
// ^^^^^ reference @types/react 19.2.18 `index.d.ts`/React/
// ^^^^^^^^^ reference @types/react 19.2.18 `index.d.ts`/React/ReactNode#
// external SymbolInformation @types/react 19.2.18 `index.d.ts`/React/ReactNode#
}

export const LoaderInput: React.FunctionComponent<Props> = ({
// ^^^^^^^^^^^ definition react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput.
// ^^^^^ reference @types/react 19.2.18 `index.d.ts`/React/
// ^^^^^^^^^^^^^^^^^ reference @types/react 19.2.18 `index.d.ts`/React/FunctionComponent#
// external SymbolInformation @types/react 19.2.18 `index.d.ts`/React/FunctionComponent#
// ^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#
loading,
//^^^^^^^ definition local 3
Expand All @@ -30,12 +36,15 @@ export const LoaderInput: React.FunctionComponent<Props> = ({
}) => (
<div className="hello">
// ^^^ reference @types/react 19.2.18 `index.d.ts`/React/JSX/IntrinsicElements#div.
// external SymbolInformation @types/react 19.2.18 `index.d.ts`/React/JSX/IntrinsicElements#div.
// ^^^^^^^^^ reference @types/react 19.2.18 `index.d.ts`/React/HTMLAttributes#className.
// external SymbolInformation @types/react 19.2.18 `index.d.ts`/React/HTMLAttributes#className.
{children}
// ^^^^^^^^ reference local 4
{loading && <p>spinner</p>}
// ^^^^^^^ reference local 3
// ^ reference @types/react 19.2.18 `index.d.ts`/React/JSX/IntrinsicElements#p.
// external SymbolInformation @types/react 19.2.18 `index.d.ts`/React/JSX/IntrinsicElements#p.
// ^ reference @types/react 19.2.18 `index.d.ts`/React/JSX/IntrinsicElements#p.
</div>
// ^^^ reference @types/react 19.2.18 `index.d.ts`/React/JSX/IntrinsicElements#div.
Expand All @@ -51,6 +60,7 @@ export const LoaderInput2: React.FunctionComponent<Props> = props => {
// ^^^^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/LoaderInput.
// ^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#loading.
// ^^^ reference @types/react 19.2.18 `index.d.ts`/React/Attributes#key.
// external SymbolInformation @types/react 19.2.18 `index.d.ts`/React/Attributes#key.
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
// ^^^^^ reference local 6
// ^^^^^^^^ reference react-example 1.0.0 src/`LoaderInput.tsx`/Props#children.
Expand Down
6 changes: 6 additions & 0 deletions src/SnapshotTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ function getSymbolTable(

function parseOptions(lines: string[]): {
showDocs: boolean
showExternalSymbols: boolean
showKinds: boolean
showRanges: boolean
} {
const formatOptions = {
showDocs: false,
showExternalSymbols: false,
showKinds: false,
showRanges: false,
}
Expand Down Expand Up @@ -184,6 +186,10 @@ export function formatSnapshot(

const externalSymbol = externalSymbolTable.get(symbol)
if (externalSymbol) {
if (formatOptions.showExternalSymbols) {
out.push(prefix)
out.push(`external SymbolInformation ${symbolNameForSnapshot(symbol)}`)
}
pushKind(externalSymbol.kind)
pushOneDoc(externalSymbol.documentation, true)
pushOneRelationship(externalSymbol.relationships)
Expand Down
34 changes: 33 additions & 1 deletion src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ for (const snapshotDirectory of snapshotDirectories) {
document.symbols.map(symbol => symbol.symbol)
)
)
const externalSymbolInformation = new Set(
index.external_symbols.map(symbol => symbol.symbol)
)
assert.equal(
externalSymbolInformation.size,
index.external_symbols.length,
'external SymbolInformation should be unique'
)
assert.equal(
index.external_symbols
.map(symbol => symbol.symbol)
.filter(symbol => symbolInformation.has(symbol)),
[],
'symbols should not be both internal and external'
)
const availableSymbols = new Set([
...symbolInformation,
...externalSymbolInformation,
])
const indexedPackages = new Set(
[...symbolInformation]
.filter(symbol => !symbol.startsWith('local '))
Expand Down Expand Up @@ -121,6 +140,19 @@ for (const snapshotDirectory of snapshotDirectories) {
[],
`${document.relative_path} should not contain duplicate occurrences`
)
const missingOccurrenceSymbols = document.occurrences
.map(occurrence => occurrence.symbol)
.filter(
symbol =>
symbol &&
!symbol.startsWith('local ') &&
!availableSymbols.has(symbol)
)
assert.equal(
missingOccurrenceSymbols,
[],
`${document.relative_path} global occurrences should have SymbolInformation`
)
const missingInternalSymbols = document.occurrences
.map(occurrence => occurrence.symbol)
.filter(
Expand Down Expand Up @@ -157,7 +189,7 @@ for (const snapshotDirectory of snapshotDirectories) {
? fs.readFileSync(outputPath).toString()
: ''
const input = Input.fromFile(inputPath)
const obtained = formatSnapshot(input, document)
const obtained = formatSnapshot(input, document, index.external_symbols)
if (obtained === expected) {
// Test passed
continue
Expand Down
19 changes: 19 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,20 @@ export function indexCommand(
}
const output = fs.openSync(options.output, 'w')
let documentCount = 0
const definedSymbols = new Set<string>()
const occurrenceSymbols = new Set<string>()
const writeIndex = (index: scip.scip.Index): void => {
documentCount += index.documents.length
for (const document of index.documents) {
for (const symbol of document.symbols) {
definedSymbols.add(symbol.symbol)
}
for (const occurrence of document.occurrences) {
if (occurrence.symbol && !occurrence.symbol.startsWith('local ')) {
occurrenceSymbols.add(occurrence.symbol)
}
}
}
fs.writeSync(output, index.serializeBinary())
}

Expand Down Expand Up @@ -85,6 +97,13 @@ export function indexCommand(
cache
)
}
writeIndex(
new scip.scip.Index({
external_symbols: [...occurrenceSymbols]
.filter(symbol => !definedSymbols.has(symbol))
.map(symbol => new scip.scip.SymbolInformation({ symbol })),
})
)
} finally {
fs.close(output)
if (documentCount > 0) {
Expand Down
Loading