Skip to content

Commit 0d58c5b

Browse files
committed
Also update vscode run command
1 parent 27e46b1 commit 0d58c5b

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/extension/context/node/resolvers/vscodeContext.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ export async function parseSettingsAndCommands(workbenchService: IWorkbenchServi
109109
return parsedMetadata;
110110
}
111111
else {
112-
const allcommands = (await workbenchService.getAllCommands(/* filterByPreCondition */true));
113-
const commandItem = allcommands.find(commandItem => commandItem.command === item.details?.key);
112+
// Get all commands regardless of preconditions, because there are some commands that a user may meet the preconditions for,
113+
// but Copilot not, so we still will show the command in the palette for the user to run.
114+
const allCommandsNoFilter = (await workbenchService.getAllCommands(/* filterByPreCondition */false));
115+
const commandItem = allCommandsNoFilter.find(commandItem => commandItem.command === item.details?.key);
114116
if (!commandItem) {
115117
// If we can't find the command on the list, just open the command palette without any pre-filled filter
116118
parsedMetadata.push({

src/extension/tools/node/vscodeCmdTool.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,25 @@ class VSCodeCmdTool implements vscode.LanguageModelTool<IVSCodeCmdToolToolInput>
3333
const command = options.input.commandId;
3434
const args = options.input.args ?? [];
3535

36-
const allcommands = (await this._workbenchService.getAllCommands(/* filterByPreCondition */true));
37-
const commandItem = allcommands.find(commandItem => commandItem.command === command);
36+
const allCommands = (await this._workbenchService.getAllCommands(/* filterByPreCondition */true));
37+
const commandItem = allCommands.find(commandItem => commandItem.command === command);
3838
if (!commandItem) {
39-
return new LanguageModelToolResult([new LanguageModelTextPart(`Failed to find ${options.input.name} command.`)]);
39+
// Try again but without filtering by preconditions to see if the command exists at all
40+
const allCommandsNoFilter = (await this._workbenchService.getAllCommands(/* filterByPreCondition */false));
41+
const commandItemNoFilter = allCommandsNoFilter.find(commandItem => commandItem.command === command);
42+
if (commandItemNoFilter) {
43+
return new LanguageModelToolResult([new LanguageModelTextPart(`Command \`${options.input.name}\` exists, but its preconditions are not currently met. Ask the user to try running it manually via the command palette.`)]);
44+
} else {
45+
return new LanguageModelToolResult([new LanguageModelTextPart(`Failed to find command \`${options.input.name}\`.`)]);
46+
}
4047
}
4148

4249
try {
4350
await this._commandService.executeCommand(command, ...args);
44-
return new LanguageModelToolResult([new LanguageModelTextPart(`Finished running ${options.input.name} command`)]);
51+
return new LanguageModelToolResult([new LanguageModelTextPart(`Finished running command \`${options.input.name}\`.`)]);
4552
} catch (error) {
4653
this._logService.error(`[VSCodeCmdTool] ${error}`);
47-
return new LanguageModelToolResult([new LanguageModelTextPart(`Failed to run ${options.input.name} command.`)]);
54+
return new LanguageModelToolResult([new LanguageModelTextPart(`Failed to run command \`${options.input.name}\`.`)]);
4855
}
4956
}
5057

0 commit comments

Comments
 (0)