Skip to content

Commit 3d2e56e

Browse files
authored
nes: fix: respect priority scale of [0, 1] (#400)
by converting importance that can be in [0, 100] to priority scale of [0, 1]
1 parent 5be1bf5 commit 3d2e56e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/extension/languageContextProvider/vscode-node/languageContextProviderService.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ export class LanguageContextProviderService extends Disposable implements ILangu
6767
const ctx = item.context as Copilot.CodeSnippet;
6868
return {
6969
kind: ContextKind.Snippet,
70-
priority: ctx.importance ? ctx.importance : 0,
70+
priority: this.convertImportanceToPriority(ctx.importance),
7171
uri: URI.parse(ctx.uri),
7272
value: ctx.value
7373
} satisfies SnippetContext;
7474
} else {
7575
const ctx = item.context as Copilot.Trait;
7676
return {
7777
kind: ContextKind.Trait,
78-
priority: ctx.importance ? ctx.importance : 0,
78+
priority: this.convertImportanceToPriority(ctx.importance),
7979
name: ctx.name,
8080
value: ctx.value,
8181
} satisfies TraitContext;
@@ -85,6 +85,17 @@ export class LanguageContextProviderService extends Disposable implements ILangu
8585
return contextItems;
8686
}
8787

88+
// importance is coined by the copilot extension and must be an integer in [0, 100], while priority is by the chat extension and spans [0, 1]
89+
private convertImportanceToPriority(importance: number | undefined): number {
90+
if (importance === undefined || importance < 0) {
91+
return 0;
92+
}
93+
if (importance > 100) {
94+
return 1;
95+
}
96+
return importance / 100;
97+
}
98+
8899
public getContextItemsOnTimeout(doc: TextDocument, request: Copilot.ResolveRequest): ContextItem[] {
89100
return [];
90101
}

0 commit comments

Comments
 (0)