@@ -8,7 +8,7 @@ const ts = TS();
8
8
9
9
import { CodeSnippetBuilder } from './code' ;
10
10
import {
11
- AbstractContextRunnable , CacheScopes , ComputeCost , ContextProvider , type ComputeContextSession ,
11
+ AbstractContextRunnable , CacheScopes , ComputeCost , ContextProvider , SnippetLocation , type ComputeContextSession ,
12
12
type ContextResult ,
13
13
type ContextRunnableCollector ,
14
14
type ProviderComputeContext , type RequestContext , type RunnableResult ,
@@ -38,7 +38,7 @@ export class CompilerOptionsRunnable extends AbstractContextRunnable {
38
38
private readonly sourceFile : tt . SourceFile ;
39
39
40
40
constructor ( session : ComputeContextSession , languageService : tt . LanguageService , context : RequestContext , sourceFile : tt . SourceFile ) {
41
- super ( session , languageService , context , 'CompilerOptionsRunnable' , Priorities . Traits , ComputeCost . Low ) ;
41
+ super ( session , languageService , context , 'CompilerOptionsRunnable' , SnippetLocation . Primary , Priorities . Traits , ComputeCost . Low ) ;
42
42
this . sourceFile = sourceFile ;
43
43
}
44
44
@@ -83,7 +83,7 @@ export abstract class FunctionLikeContextRunnable<T extends tt.FunctionLikeDecla
83
83
protected readonly sourceFile : tt . SourceFile ;
84
84
85
85
constructor ( session : ComputeContextSession , languageService : tt . LanguageService , context : RequestContext , id : string , declaration : T , priority : number , cost : ComputeCost ) {
86
- super ( session , languageService , context , id , priority , cost ) ;
86
+ super ( session , languageService , context , id , SnippetLocation . Primary , priority , cost ) ;
87
87
this . declaration = declaration ;
88
88
this . sourceFile = declaration . getSourceFile ( ) ;
89
89
}
@@ -168,7 +168,7 @@ export class TypeOfLocalsRunnable extends AbstractContextRunnable {
168
168
private runnableResult : RunnableResult | undefined ;
169
169
170
170
constructor ( session : ComputeContextSession , languageService : tt . LanguageService , context : RequestContext , tokenInfo : tss . TokenInfo , excludes : Set < tt . Symbol > , cacheScope : CacheScope | undefined , priority : number = Priorities . Locals ) {
171
- super ( session , languageService , context , 'TypeOfLocalsRunnable' , priority , ComputeCost . Medium ) ;
171
+ super ( session , languageService , context , 'TypeOfLocalsRunnable' , SnippetLocation . Primary , priority , ComputeCost . Medium ) ;
172
172
this . tokenInfo = tokenInfo ;
173
173
this . excludes = excludes ;
174
174
this . cacheScope = cacheScope ;
@@ -239,8 +239,10 @@ export class TypesOfNeighborFilesRunnable extends AbstractContextRunnable {
239
239
240
240
private readonly tokenInfo : tss . TokenInfo ;
241
241
242
+ private static SymbolsToInclude : number = ts . SymbolFlags . Class | ts . SymbolFlags . Interface | ts . SymbolFlags . TypeAlias | ts . SymbolFlags . Enum | ts . SymbolFlags . Function ;
243
+
242
244
constructor ( session : ComputeContextSession , languageService : tt . LanguageService , context : RequestContext , tokenInfo : tss . TokenInfo , priority : number = Priorities . NeighborFiles ) {
243
- super ( session , languageService , context , 'TypesOfNeighborFilesRunnable' , priority , ComputeCost . Medium ) ;
245
+ super ( session , languageService , context , 'TypesOfNeighborFilesRunnable' , SnippetLocation . Secondary , priority , ComputeCost . Medium ) ;
244
246
this . tokenInfo = tokenInfo ;
245
247
}
246
248
@@ -257,7 +259,7 @@ export class TypesOfNeighborFilesRunnable extends AbstractContextRunnable {
257
259
const symbols = this . symbols ;
258
260
for ( const neighborFile of this . context . neighborFiles ) {
259
261
cancellationToken . throwIfCancellationRequested ( ) ;
260
- if ( result . isTokenBudgetExhausted ( ) ) {
262
+ if ( result . isSecondaryBudgetExhausted ( ) ) {
261
263
return ;
262
264
}
263
265
const neighborSourceFile = this . getProgram ( ) . getSourceFile ( neighborFile ) ;
@@ -273,7 +275,7 @@ export class TypesOfNeighborFilesRunnable extends AbstractContextRunnable {
273
275
for ( const member of sourceFileSymbol . exports ) {
274
276
cancellationToken . throwIfCancellationRequested ( ) ;
275
277
const memberSymbol = member [ 1 ] ;
276
- if ( ( memberSymbol . flags & ( ts . SymbolFlags . Class | ts . SymbolFlags . Interface | ts . SymbolFlags . TypeAlias | ts . SymbolFlags . Enum | ts . SymbolFlags . Function ) ) === 0 ) {
278
+ if ( ( memberSymbol . flags & TypesOfNeighborFilesRunnable . SymbolsToInclude ) === 0 ) {
277
279
continue ;
278
280
}
279
281
if ( ! this . handleSymbol ( memberSymbol , member [ 0 ] as string , true ) ) {
@@ -304,7 +306,7 @@ export class ImportsRunnable extends AbstractContextRunnable {
304
306
] ) ;
305
307
306
308
constructor ( session : ComputeContextSession , languageService : tt . LanguageService , context : RequestContext , tokenInfo : tss . TokenInfo , excludes : Set < tt . Symbol > , priority : number = Priorities . Imports ) {
307
- super ( session , languageService , context , 'ImportsRunnable' , priority , ComputeCost . Medium ) ;
309
+ super ( session , languageService , context , 'ImportsRunnable' , SnippetLocation . Secondary , priority , ComputeCost . Medium ) ;
308
310
this . tokenInfo = tokenInfo ;
309
311
this . excludes = excludes ;
310
312
this . runnableResult = undefined ;
@@ -459,8 +461,8 @@ export class TypeOfExpressionRunnable extends AbstractContextRunnable {
459
461
460
462
private readonly expression : tt . Expression ;
461
463
462
- constructor ( session : ComputeContextSession , languageService : tt . LanguageService , context : RequestContext , expression : tt . Expression , priority : number = Priorities . Locals ) {
463
- super ( session , languageService , context , 'TypeOfExpressionRunnable' , priority , ComputeCost . Low ) ;
464
+ constructor ( session : ComputeContextSession , languageService : tt . LanguageService , context : RequestContext , expression : tt . Expression , priority : number = Priorities . Expression ) {
465
+ super ( session , languageService , context , 'TypeOfExpressionRunnable' , SnippetLocation . Primary , priority , ComputeCost . Low ) ;
464
466
this . expression = expression ;
465
467
}
466
468
@@ -523,15 +525,15 @@ export class TypeOfExpressionRunnable extends AbstractContextRunnable {
523
525
}
524
526
const snippetBuilder = new CodeSnippetBuilder ( this . session , this . symbols , sourceFile ) ;
525
527
snippetBuilder . addTypeSymbol ( returnTypeSymbol , returnTypeSymbol . name ) ;
526
- result . addSnippet ( snippetBuilder , undefined ) ;
528
+ result . addSnippet ( snippetBuilder , this . location , undefined ) ;
527
529
}
528
530
const typeSymbol = type . getSymbol ( ) ;
529
531
if ( typeSymbol === undefined ) {
530
532
return ;
531
533
}
532
534
const snippetBuilder = new CodeSnippetBuilder ( this . session , this . symbols , sourceFile ) ;
533
535
snippetBuilder . addTypeSymbol ( typeSymbol , typeSymbol . name ) ;
534
- result . addSnippet ( snippetBuilder , undefined ) ;
536
+ result . addSnippet ( snippetBuilder , this . location , undefined ) ;
535
537
}
536
538
}
537
539
0 commit comments