Skip to content

Commit 582f523

Browse files
authored
Add Exp setting to control the amount of emitted context items (#1183)
* WIP * WIP * WIP * Add usage mode * Add ExP setting to control the amount of emitted context items * Revert completionsCoreContribution.ts
1 parent fb5d23c commit 582f523

File tree

17 files changed

+502
-172
lines changed

17 files changed

+502
-172
lines changed

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,6 +2811,22 @@
28112811
],
28122812
"markdownDescription": "%github.copilot.chat.languageContext.typescript.enabled%"
28132813
},
2814+
"github.copilot.chat.languageContext.typescript.items": {
2815+
"type": "string",
2816+
"enum": [
2817+
"minimal",
2818+
"double",
2819+
"fillHalf",
2820+
"fill"
2821+
],
2822+
"default": "minimal",
2823+
"scope": "resource",
2824+
"tags": [
2825+
"experimental",
2826+
"onExP"
2827+
],
2828+
"markdownDescription": "%github.copilot.chat.languageContext.typescript.items%"
2829+
},
28142830
"github.copilot.chat.languageContext.typescript.cacheTimeout": {
28152831
"type": "number",
28162832
"default": 500,

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@
228228
"github.copilot.walkthrough.sparkle.media.altText": "The video shows the sparkle icon in the source control input box being clicked, triggering GitHub Copilot to generate a commit message automatically",
229229
"github.copilot.chat.completionContext.typescript.mode": "The execution mode of the TypeScript Copilot context provider.",
230230
"github.copilot.chat.languageContext.typescript.enabled": "Enables the TypeScript language context provider for inline completions",
231+
"github.copilot.chat.languageContext.typescript.items": "Controls which kind of items are included in the TypeScript language context provider.",
231232
"github.copilot.chat.languageContext.typescript.cacheTimeout": "The cache population timeout for the TypeScript language context provider in milliseconds. The default is 500 milliseconds.",
232233
"github.copilot.chat.languageContext.fix.typescript.enabled": "Enables the TypeScript language context provider for /fix commands",
233234
"github.copilot.chat.languageContext.inline.typescript.enabled": "Enables the TypeScript language context provider for inline chats (both generate and edit)",

src/extension/completions/vscode-node/completionsCoreContribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ export class CompletionsCoreContribution extends Disposable {
1010
constructor(@IInstantiationService instantiationService: IInstantiationService) {
1111
super();
1212
}
13-
}
13+
}

src/extension/typescriptContext/common/serverProtocol.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,15 @@ export namespace ContextItemReference {
104104
}
105105

106106
export enum Priorities {
107-
Locals = 1,
108-
Inherited = 0.9,
109-
Properties = 0.8,
110-
Blueprints = 0.7,
111-
Imports = 0.6,
112-
NeighborFiles = 0.55,
113-
Globals = 0.5,
114-
Traits = 0.4,
107+
Expression = 1.0,
108+
Locals = 0.9,
109+
Inherited = 0.8,
110+
Traits = 0.7,
111+
Blueprints = 0.6,
112+
Properties = 0.5,
113+
Imports = 0.4,
114+
NeighborFiles = 0.3,
115+
Globals = 0.2
115116
}
116117

117118
export enum SpeculativeKind {
@@ -395,10 +396,11 @@ export type ContextRequestResult = {
395396

396397
export interface ComputeContextRequestArgs extends tt.server.protocol.FileLocationRequestArgs {
397398
startTime: number;
398-
timeBudget?: number;
399-
tokenBudget?: number;
400-
neighborFiles?: FilePath[];
401-
clientSideRunnableResults?: CachedContextRunnableResult[];
399+
timeBudget: number;
400+
primaryCharacterBudget: number;
401+
secondaryCharacterBudget: number;
402+
neighborFiles?: readonly FilePath[];
403+
clientSideRunnableResults?: readonly CachedContextRunnableResult[];
402404
}
403405

404406
export interface ComputeContextRequest extends tt.server.protocol.Request {

src/extension/typescriptContext/serverPlugin/src/common/baseContextProviders.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const ts = TS();
88

99
import { CodeSnippetBuilder } from './code';
1010
import {
11-
AbstractContextRunnable, CacheScopes, ComputeCost, ContextProvider, type ComputeContextSession,
11+
AbstractContextRunnable, CacheScopes, ComputeCost, ContextProvider, SnippetLocation, type ComputeContextSession,
1212
type ContextResult,
1313
type ContextRunnableCollector,
1414
type ProviderComputeContext, type RequestContext, type RunnableResult,
@@ -38,7 +38,7 @@ export class CompilerOptionsRunnable extends AbstractContextRunnable {
3838
private readonly sourceFile: tt.SourceFile;
3939

4040
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);
4242
this.sourceFile = sourceFile;
4343
}
4444

@@ -83,7 +83,7 @@ export abstract class FunctionLikeContextRunnable<T extends tt.FunctionLikeDecla
8383
protected readonly sourceFile: tt.SourceFile;
8484

8585
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);
8787
this.declaration = declaration;
8888
this.sourceFile = declaration.getSourceFile();
8989
}
@@ -168,7 +168,7 @@ export class TypeOfLocalsRunnable extends AbstractContextRunnable {
168168
private runnableResult: RunnableResult | undefined;
169169

170170
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);
172172
this.tokenInfo = tokenInfo;
173173
this.excludes = excludes;
174174
this.cacheScope = cacheScope;
@@ -239,8 +239,10 @@ export class TypesOfNeighborFilesRunnable extends AbstractContextRunnable {
239239

240240
private readonly tokenInfo: tss.TokenInfo;
241241

242+
private static SymbolsToInclude: number = ts.SymbolFlags.Class | ts.SymbolFlags.Interface | ts.SymbolFlags.TypeAlias | ts.SymbolFlags.Enum | ts.SymbolFlags.Function;
243+
242244
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);
244246
this.tokenInfo = tokenInfo;
245247
}
246248

@@ -257,7 +259,7 @@ export class TypesOfNeighborFilesRunnable extends AbstractContextRunnable {
257259
const symbols = this.symbols;
258260
for (const neighborFile of this.context.neighborFiles) {
259261
cancellationToken.throwIfCancellationRequested();
260-
if (result.isTokenBudgetExhausted()) {
262+
if (result.isSecondaryBudgetExhausted()) {
261263
return;
262264
}
263265
const neighborSourceFile = this.getProgram().getSourceFile(neighborFile);
@@ -273,7 +275,7 @@ export class TypesOfNeighborFilesRunnable extends AbstractContextRunnable {
273275
for (const member of sourceFileSymbol.exports) {
274276
cancellationToken.throwIfCancellationRequested();
275277
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) {
277279
continue;
278280
}
279281
if (!this.handleSymbol(memberSymbol, member[0] as string, true)) {
@@ -304,7 +306,7 @@ export class ImportsRunnable extends AbstractContextRunnable {
304306
]);
305307

306308
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);
308310
this.tokenInfo = tokenInfo;
309311
this.excludes = excludes;
310312
this.runnableResult = undefined;
@@ -459,8 +461,8 @@ export class TypeOfExpressionRunnable extends AbstractContextRunnable {
459461

460462
private readonly expression: tt.Expression;
461463

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);
464466
this.expression = expression;
465467
}
466468

@@ -523,15 +525,15 @@ export class TypeOfExpressionRunnable extends AbstractContextRunnable {
523525
}
524526
const snippetBuilder = new CodeSnippetBuilder(this.session, this.symbols, sourceFile);
525527
snippetBuilder.addTypeSymbol(returnTypeSymbol, returnTypeSymbol.name);
526-
result.addSnippet(snippetBuilder, undefined);
528+
result.addSnippet(snippetBuilder, this.location, undefined);
527529
}
528530
const typeSymbol = type.getSymbol();
529531
if (typeSymbol === undefined) {
530532
return;
531533
}
532534
const snippetBuilder = new CodeSnippetBuilder(this.session, this.symbols, sourceFile);
533535
snippetBuilder.addTypeSymbol(typeSymbol, typeSymbol.name);
534-
result.addSnippet(snippetBuilder, undefined);
536+
result.addSnippet(snippetBuilder, this.location, undefined);
535537
}
536538
}
537539

src/extension/typescriptContext/serverPlugin/src/common/classContextProvider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import TS from './typescript';
77
const ts = TS();
88

99
import { CodeSnippetBuilder } from './code';
10-
import { AbstractContextRunnable, ComputeCost, ContextProvider, ContextResult, Search, type ComputeContextSession, type ContextRunnableCollector, type RequestContext, type RunnableResult } from './contextProvider';
10+
import { AbstractContextRunnable, ComputeCost, ContextProvider, ContextResult, Search, SnippetLocation, type ComputeContextSession, type ContextRunnableCollector, type RequestContext, type RunnableResult } from './contextProvider';
1111
import { EmitMode, Priorities, SpeculativeKind } from './protocol';
1212
import tss, { ClassDeclarations, ReferencedByVisitor, Symbols } from './typescripts';
1313

@@ -264,7 +264,7 @@ export class SuperClassRunnable extends AbstractContextRunnable {
264264
private readonly classDeclaration: tt.ClassDeclaration;
265265

266266
constructor(session: ComputeContextSession, languageService: tt.LanguageService, context: RequestContext, classDeclaration: tt.ClassDeclaration, priority: number = Priorities.Inherited) {
267-
super(session, languageService, context, 'SuperClassRunnable', priority, ComputeCost.Medium);
267+
super(session, languageService, context, 'SuperClassRunnable', SnippetLocation.Primary, priority, ComputeCost.Medium);
268268
this.classDeclaration = classDeclaration;
269269
}
270270

@@ -296,7 +296,7 @@ class SimilarClassRunnable extends AbstractContextRunnable {
296296
private readonly classDeclaration: tt.ClassDeclaration;
297297

298298
constructor(session: ComputeContextSession, languageService: tt.LanguageService, context: RequestContext, classDeclaration: tt.ClassDeclaration, priority: number = Priorities.Blueprints) {
299-
super(session, languageService, context, 'SimilarClassRunnable', priority, ComputeCost.High);
299+
super(session, languageService, context, 'SimilarClassRunnable', SnippetLocation.Primary, priority, ComputeCost.High);
300300
this.classDeclaration = classDeclaration;
301301
}
302302

@@ -325,7 +325,7 @@ class SimilarClassRunnable extends AbstractContextRunnable {
325325
}
326326
const code = new CodeSnippetBuilder(this.session, this.context.getSymbols(foundInProgram), classDeclaration.getSourceFile());
327327
code.addDeclaration(similarClass.declaration);
328-
result.addSnippet(code, undefined);
328+
result.addSnippet(code, this.location, undefined);
329329
}
330330
}
331331

0 commit comments

Comments
 (0)