Skip to content

Commit dd5c24c

Browse files
Updates to Copilot CLI prompt resolver (#2401)
* Updates to Copilot CLI prompt resolver * Update src/extension/chatSessions/vscode-node/copilotPromptReferences.ts Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 0997dc6 commit dd5c24c

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/extension/agents/copilotcli/node/copilotcliPromptResolver.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ export class CopilotCLIPromptResolver {
3030

3131
/**
3232
* Generates the final prompt for the Copilot CLI agent, resolving variables and preparing attachments.
33-
* @param request
3433
* @param prompt Provide a prompt to override the request prompt
35-
* @param additionalReferences
36-
* @param token
37-
* @returns
3834
*/
3935
public async resolvePrompt(request: vscode.ChatRequest, prompt: string | undefined, additionalReferences: vscode.ChatPromptReference[], isIsolationEnabled: boolean, token: vscode.CancellationToken): Promise<{ prompt: string; attachments: Attachment[]; references: vscode.ChatPromptReference[] }> {
4036
const allReferences = request.references.concat(additionalReferences.filter(ref => !request.references.includes(ref)));
@@ -44,7 +40,7 @@ export class CopilotCLIPromptResolver {
4440
}
4541
const [variables, attachments] = await this.constructChatVariablesAndAttachments(new ChatVariablesCollection(allReferences), isIsolationEnabled, token);
4642
if (token.isCancellationRequested) {
47-
return { prompt, attachments: [], references: allReferences };
43+
return { prompt, attachments: [], references: [] };
4844
}
4945
prompt = await raceCancellation(generateUserPrompt(request, prompt, variables, this.instantiationService), token);
5046
const references = Array.from(variables).map(v => v.reference);

src/extension/chatSessions/vscode-node/copilotPromptReferences.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { Attachment } from '@github/copilot/sdk';
67
import * as l10n from '@vscode/l10n';
78
import type { ChatPromptReference } from 'vscode';
89
import { isLocation } from '../../../util/common/types';
910
import { coalesce } from '../../../util/vs/base/common/arrays';
1011
import { Codicon } from '../../../util/vs/base/common/codicons';
12+
import { ResourceSet } from '../../../util/vs/base/common/map';
1113
import { basename } from '../../../util/vs/base/common/resources';
1214
import { isNumber, isString } from '../../../util/vs/base/common/types';
1315
import { URI } from '../../../util/vs/base/common/uri';
1416
import { Range as InternalRange } from '../../../util/vs/editor/common/core/range';
1517
import { SymbolKind } from '../../../util/vs/workbench/api/common/extHostTypes/symbolInformation';
1618
import { ChatReferenceDiagnostic, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, Range, Uri } from '../../../vscodeTypes';
17-
import { Attachment } from '@github/copilot/sdk';
18-
import { ResourceSet } from '../../../util/vs/base/common/map';
1919

20+
/**
21+
* Converts a ChatPromptReference into a PromptVariable entry that is used in VS code.
22+
*/
2023
export function convertReferenceToVariable(ref: ChatPromptReference, attachments: readonly Attachment[]) {
2124
const value = ref.value;
2225
const range = ref.range ? { start: ref.range[0], endExclusive: ref.range[1] } : undefined;
@@ -63,8 +66,8 @@ export function convertReferenceToVariable(ref: ChatPromptReference, attachments
6366
}
6467

6568
const folders = new ResourceSet(attachments.filter(att => att.type === 'directory').map(att => URI.file(att.path)));
66-
const isFile = URI.isUri(value) || (value && typeof value === 'object' && 'uri' in value);
67-
const isFolder = isFile && URI.isUri(value) && (value.path.endsWith('/') || folders.has(value));
69+
const isFile = URI.isUri(value) || isLocation(value);
70+
const isFolder = URI.isUri(value) && (value.path.endsWith('/') || folders.has(value));
6871
return {
6972
id: ref.id,
7073
name: ref.name,
@@ -204,7 +207,7 @@ namespace DiagnosticConverter {
204207
message: value.message,
205208
source: value.source,
206209
code,
207-
severity: DiagnosticSeverityConveter.from(value.severity),
210+
severity: DiagnosticSeverityConverter.from(value.severity),
208211
relatedInformation: value.relatedInformation && value.relatedInformation.map(DiagnosticRelatedInformationConverter.from),
209212
tags: Array.isArray(value.tags) ? coalesce(value.tags.map(DiagnosticTagConverter.from)) : undefined,
210213
};
@@ -221,7 +224,7 @@ namespace DiagnosticRelatedInformationConverter {
221224
}
222225
}
223226

224-
namespace DiagnosticSeverityConveter {
227+
namespace DiagnosticSeverityConverter {
225228
export enum MarkerSeverity {
226229
Hint = 1,
227230
Info = 2,

0 commit comments

Comments
 (0)