@@ -65,6 +65,34 @@ export class FileIndexer {
6565
6666 this . emitSourceFileOccurrence ( )
6767 this . visit ( this . sourceFile )
68+ const missingLocalDefinition = this . document . occurrences . find (
69+ occurrence =>
70+ occurrence . symbol . startsWith ( 'local ' ) &&
71+ ( occurrence . symbol_roles & scip . scip . SymbolRole . Definition ) !== 0 &&
72+ ! this . symbolInformation . has ( occurrence . symbol )
73+ )
74+ if ( missingLocalDefinition ) {
75+ throw new Error (
76+ `local definition '${ missingLocalDefinition . symbol } ' has no SymbolInformation in '${ this . document . relative_path } '`
77+ )
78+ }
79+ // A SCIP local symbol is owned by one document. TypeScript can report
80+ // synthetic or cross-file declaration candidates that the symbol algorithm
81+ // cannot represent as locals in this document, so discard those unusable
82+ // occurrences instead of emitting dangling local identities.
83+ this . document . occurrences = this . document . occurrences . filter (
84+ occurrence =>
85+ ! occurrence . symbol . startsWith ( 'local ' ) ||
86+ this . symbolInformation . has ( occurrence . symbol )
87+ )
88+ // Relationships to locals have the same document-local ownership rule.
89+ for ( const symbol of this . document . symbols ) {
90+ symbol . relationships = symbol . relationships . filter (
91+ relationship =>
92+ ! relationship . symbol . startsWith ( 'local ' ) ||
93+ this . symbolInformation . has ( relationship . symbol )
94+ )
95+ }
6896 }
6997 private emitSourceFileOccurrence ( ) : void {
7098 const symbol = this . scipSymbol ( this . sourceFile )
0 commit comments