@@ -14,27 +14,23 @@ import {
14
14
typeParameterDescriptor ,
15
15
} from './Descriptor'
16
16
import { Input } from './Input'
17
- import * as lsif from './lsif'
18
- import { LsifSymbol } from './LsifSymbol'
19
- import { lsiftyped } from './main'
20
17
import { Packages } from './Packages'
21
18
import { Range } from './Range'
19
+ import * as scip from './scip'
20
+ import { ScipSymbol } from './ScipSymbol'
22
21
import * as ts_inline from './TypeScriptInternal'
23
22
24
- type Descriptor = lsif . lib . codeintel . lsiftyped . Descriptor
25
- type Relationship = lsif . lib . codeintel . lsiftyped . Relationship
26
-
27
23
export class FileIndexer {
28
24
private localCounter = new Counter ( )
29
25
private propertyCounters : Map < string , Counter > = new Map ( )
30
- private localSymbolTable : Map < ts . Node , LsifSymbol > = new Map ( )
26
+ private localSymbolTable : Map < ts . Node , ScipSymbol > = new Map ( )
31
27
private workingDirectoryRegExp : RegExp
32
28
constructor (
33
29
public readonly checker : ts . TypeChecker ,
34
30
public readonly options : ProjectOptions ,
35
31
public readonly input : Input ,
36
- public readonly document : lsif . lib . codeintel . lsiftyped . Document ,
37
- public readonly globalSymbolTable : Map < ts . Node , LsifSymbol > ,
32
+ public readonly document : scip . scip . Document ,
33
+ public readonly globalSymbolTable : Map < ts . Node , ScipSymbol > ,
38
34
public readonly packages : Packages ,
39
35
public readonly sourceFile : ts . SourceFile
40
36
) {
@@ -45,21 +41,21 @@ export class FileIndexer {
45
41
this . visit ( this . sourceFile )
46
42
}
47
43
private emitSourceFileOccurrence ( ) : void {
48
- const symbol = this . lsifSymbol ( this . sourceFile )
44
+ const symbol = this . scipSymbol ( this . sourceFile )
49
45
if ( symbol . isEmpty ( ) ) {
50
46
return
51
47
}
52
48
this . document . occurrences . push (
53
- new lsif . lib . codeintel . lsiftyped . Occurrence ( {
49
+ new scip . scip . Occurrence ( {
54
50
range : [ 0 , 0 , 0 ] ,
55
51
symbol : symbol . value ,
56
- symbol_roles : lsiftyped . SymbolRole . Definition ,
52
+ symbol_roles : scip . scip . SymbolRole . Definition ,
57
53
} )
58
54
)
59
55
const moduleName =
60
56
this . sourceFile . moduleName || path . basename ( this . sourceFile . fileName )
61
57
this . document . symbols . push (
62
- new lsiftyped . SymbolInformation ( {
58
+ new scip . scip . SymbolInformation ( {
63
59
symbol : symbol . value ,
64
60
documentation : [ '```ts\nmodule "' + moduleName + '"\n```' ] ,
65
61
} )
@@ -106,24 +102,24 @@ export class FileIndexer {
106
102
let role = 0
107
103
const isDefinition = this . declarationName ( node . parent ) === node
108
104
if ( isDefinition ) {
109
- role |= lsiftyped . SymbolRole . Definition
105
+ role |= scip . scip . SymbolRole . Definition
110
106
}
111
107
for ( const declaration of sym ?. declarations || [ ] ) {
112
- const lsifSymbol = this . lsifSymbol ( declaration )
108
+ const scipSymbol = this . scipSymbol ( declaration )
113
109
114
- if ( lsifSymbol . isEmpty ( ) ) {
110
+ if ( scipSymbol . isEmpty ( ) ) {
115
111
// Skip empty symbols
116
112
continue
117
113
}
118
114
this . document . occurrences . push (
119
- new lsif . lib . codeintel . lsiftyped . Occurrence ( {
115
+ new scip . scip . Occurrence ( {
120
116
range,
121
- symbol : lsifSymbol . value ,
117
+ symbol : scipSymbol . value ,
122
118
symbol_roles : role ,
123
119
} )
124
120
)
125
121
if ( isDefinition ) {
126
- this . addSymbolInformation ( node , sym , declaration , lsifSymbol )
122
+ this . addSymbolInformation ( node , sym , declaration , scipSymbol )
127
123
this . handleShorthandPropertyDefinition ( declaration , range )
128
124
this . handleObjectBindingPattern ( node , range )
129
125
// Only emit one symbol for definitions sites, see https://github.com/sourcegraph/lsif-typescript/issues/45
@@ -153,14 +149,14 @@ export class FileIndexer {
153
149
const tpe = this . checker . getTypeAtLocation ( node . parent . parent )
154
150
const property = tpe . getProperty ( node . getText ( ) )
155
151
for ( const declaration of property ?. declarations || [ ] ) {
156
- const lsifSymbol = this . lsifSymbol ( declaration )
157
- if ( lsifSymbol . isEmpty ( ) ) {
152
+ const scipSymbol = this . scipSymbol ( declaration )
153
+ if ( scipSymbol . isEmpty ( ) ) {
158
154
continue
159
155
}
160
156
this . document . occurrences . push (
161
- new lsif . lib . codeintel . lsiftyped . Occurrence ( {
157
+ new scip . scip . Occurrence ( {
162
158
range,
163
- symbol : lsifSymbol . value ,
159
+ symbol : scipSymbol . value ,
164
160
} )
165
161
)
166
162
}
@@ -190,14 +186,14 @@ export class FileIndexer {
190
186
return
191
187
}
192
188
for ( const symbol of valueSymbol ?. declarations || [ ] ) {
193
- const lsifSymbol = this . lsifSymbol ( symbol )
194
- if ( lsifSymbol . isEmpty ( ) ) {
189
+ const scipSymbol = this . scipSymbol ( symbol )
190
+ if ( scipSymbol . isEmpty ( ) ) {
195
191
continue
196
192
}
197
193
this . document . occurrences . push (
198
- new lsif . lib . codeintel . lsiftyped . Occurrence ( {
194
+ new scip . scip . Occurrence ( {
199
195
range,
200
- symbol : lsifSymbol . value ,
196
+ symbol : scipSymbol . value ,
201
197
} )
202
198
)
203
199
}
@@ -210,7 +206,7 @@ export class FileIndexer {
210
206
node : ts . Node ,
211
207
sym : ts . Symbol ,
212
208
declaration : ts . Node ,
213
- symbol : LsifSymbol
209
+ symbol : ScipSymbol
214
210
) : void {
215
211
const documentation = [
216
212
'```ts\n' +
@@ -223,7 +219,7 @@ export class FileIndexer {
223
219
}
224
220
225
221
this . document . symbols . push (
226
- new lsiftyped . SymbolInformation ( {
222
+ new scip . scip . SymbolInformation ( {
227
223
symbol : symbol . value ,
228
224
documentation,
229
225
relationships : this . relationships ( declaration , symbol ) ,
@@ -233,15 +229,15 @@ export class FileIndexer {
233
229
234
230
private relationships (
235
231
declaration : ts . Node ,
236
- declarationSymbol : LsifSymbol
237
- ) : Relationship [ ] {
238
- const relationships : Relationship [ ] = [ ]
232
+ declarationSymbol : ScipSymbol
233
+ ) : scip . scip . Relationship [ ] {
234
+ const relationships : scip . scip . Relationship [ ] = [ ]
239
235
const isAddedSymbol = new Set < string > ( )
240
236
const pushImplementation = (
241
237
node : ts . NamedDeclaration ,
242
238
isReferences : boolean
243
239
) : void => {
244
- const symbol = this . lsifSymbol ( node )
240
+ const symbol = this . scipSymbol ( node )
245
241
if ( symbol . isEmpty ( ) ) {
246
242
return
247
243
}
@@ -255,7 +251,7 @@ export class FileIndexer {
255
251
}
256
252
isAddedSymbol . add ( symbol . value )
257
253
relationships . push (
258
- new lsiftyped . Relationship ( {
254
+ new scip . scip . Relationship ( {
259
255
symbol : symbol . value ,
260
256
is_implementation : true ,
261
257
is_reference : isReferences ,
@@ -309,19 +305,19 @@ export class FileIndexer {
309
305
return undefined
310
306
}
311
307
312
- private lsifSymbol ( node : ts . Node ) : LsifSymbol {
313
- const fromCache : LsifSymbol | undefined =
308
+ private scipSymbol ( node : ts . Node ) : ScipSymbol {
309
+ const fromCache : ScipSymbol | undefined =
314
310
this . globalSymbolTable . get ( node ) || this . localSymbolTable . get ( node )
315
311
if ( fromCache ) {
316
312
return fromCache
317
313
}
318
314
if ( ts . isBlock ( node ) ) {
319
- return LsifSymbol . empty ( )
315
+ return ScipSymbol . empty ( )
320
316
}
321
317
if ( ts . isSourceFile ( node ) ) {
322
318
const package_ = this . packages . symbol ( node . fileName )
323
319
if ( ! package_ ) {
324
- return this . cached ( node , LsifSymbol . empty ( ) )
320
+ return this . cached ( node , ScipSymbol . empty ( ) )
325
321
}
326
322
return this . cached ( node , package_ )
327
323
}
@@ -337,8 +333,8 @@ export class FileIndexer {
337
333
}
338
334
return this . cached (
339
335
node ,
340
- LsifSymbol . global (
341
- this . lsifSymbol ( node . getSourceFile ( ) ) ,
336
+ ScipSymbol . global (
337
+ this . scipSymbol ( node . getSourceFile ( ) ) ,
342
338
metaDescriptor ( `${ node . name . getText ( ) } ${ counter . next ( ) } ` )
343
339
)
344
340
)
@@ -362,7 +358,7 @@ export class FileIndexer {
362
358
const tpe = this . checker . getTypeOfSymbolAtLocation ( props , node )
363
359
const property = tpe . getProperty ( node . name . text )
364
360
for ( const decl of property ?. declarations || [ ] ) {
365
- return this . lsifSymbol ( decl )
361
+ return this . scipSymbol ( decl )
366
362
}
367
363
} catch {
368
364
// TODO: https://github.com/sourcegraph/lsif-typescript/issues/34
@@ -373,25 +369,25 @@ export class FileIndexer {
373
369
}
374
370
}
375
371
376
- const owner = this . lsifSymbol ( node . parent )
372
+ const owner = this . scipSymbol ( node . parent )
377
373
if ( owner . isEmpty ( ) || owner . isLocal ( ) ) {
378
374
return this . newLocalSymbol ( node )
379
375
}
380
376
381
377
if ( isAnonymousContainerOfSymbols ( node ) ) {
382
- return this . cached ( node , this . lsifSymbol ( node . parent ) )
378
+ return this . cached ( node , this . scipSymbol ( node . parent ) )
383
379
}
384
380
385
381
if ( ts . isImportSpecifier ( node ) || ts . isImportClause ( node ) ) {
386
382
const tpe = this . checker . getTypeAtLocation ( node )
387
383
for ( const declaration of tpe . symbol ?. declarations || [ ] ) {
388
- return this . lsifSymbol ( declaration )
384
+ return this . scipSymbol ( declaration )
389
385
}
390
386
}
391
387
392
388
const desc = this . descriptor ( node )
393
389
if ( desc ) {
394
- return this . cached ( node , LsifSymbol . global ( owner , desc ) )
390
+ return this . cached ( node , ScipSymbol . global ( owner , desc ) )
395
391
}
396
392
397
393
// Fallback case: generate a local symbol. It's not a bug when this case
@@ -401,16 +397,16 @@ export class FileIndexer {
401
397
return this . newLocalSymbol ( node )
402
398
}
403
399
404
- private newLocalSymbol ( node : ts . Node ) : LsifSymbol {
405
- const symbol = LsifSymbol . local ( this . localCounter . next ( ) )
400
+ private newLocalSymbol ( node : ts . Node ) : ScipSymbol {
401
+ const symbol = ScipSymbol . local ( this . localCounter . next ( ) )
406
402
this . localSymbolTable . set ( node , symbol )
407
403
return symbol
408
404
}
409
- private cached ( node : ts . Node , symbol : LsifSymbol ) : LsifSymbol {
405
+ private cached ( node : ts . Node , symbol : ScipSymbol ) : ScipSymbol {
410
406
this . globalSymbolTable . set ( node , symbol )
411
407
return symbol
412
408
}
413
- private descriptor ( node : ts . Node ) : Descriptor | undefined {
409
+ private descriptor ( node : ts . Node ) : scip . scip . Descriptor | undefined {
414
410
if (
415
411
ts . isInterfaceDeclaration ( node ) ||
416
412
ts . isEnumDeclaration ( node ) ||
0 commit comments