Skip to content

Commit 16c7ece

Browse files
authored
Add an icon to clear the copilot chat (#2236)
This add a "Clear chat" icon (see below on the right) to the Quantum Copilot chat panel, and wires up the pre-existing clear chat functioality to it <img width="396" alt="image" src="https://github.com/user-attachments/assets/a22dfa83-d613-42d0-9b64-13c3d213e824" />
1 parent 403ac55 commit 16c7ece

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Diff for: vscode/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@
240240
"command": "qsharp-vscode.workspacesAdd",
241241
"when": "view == quantum-workspaces",
242242
"group": "navigation"
243+
},
244+
{
245+
"command": "qsharp-vscode.copilotClear",
246+
"when": "view == quantum-copilot",
247+
"group": "navigation"
243248
}
244249
],
245250
"view/item/context": [
@@ -386,6 +391,13 @@
386391
"title": "Remove workspace connection",
387392
"icon": "$(remove)"
388393
},
394+
{
395+
"command": "qsharp-vscode.copilotClear",
396+
"category": "Q#",
397+
"title": "Clear Quantum Copilot chat",
398+
"enablement": "!qdkCopilotIsBusy",
399+
"icon": "$(clear-all)"
400+
},
389401
{
390402
"command": "qsharp-vscode.workspacePythonCode",
391403
"category": "Q#",

Diff for: vscode/src/copilot/copilot.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { OpenAIChatService } from "./openAiChatService";
2121
import { getRandomGuid } from "../utils";
2222
import { EventType, sendTelemetryEvent, UserFlowStatus } from "../telemetry";
2323
import { knownToolNameOrDefault } from "./azqTools";
24+
import { commands } from "vscode";
2425

2526
export class Copilot {
2627
private service: IChatService;
@@ -59,7 +60,14 @@ export class Copilot {
5960
}
6061
this.messages.push({ role: "user", content: userMessage });
6162

62-
await this.completeChat();
63+
// Set the context so the 'clear' command is disabled when processing a response.
64+
await commands.executeCommand("setContext", `qdkCopilotIsBusy`, true);
65+
try {
66+
await this.completeChat();
67+
} finally {
68+
// Reset the busy context when the chat is done.
69+
await commands.executeCommand("setContext", `qdkCopilotIsBusy`, false);
70+
}
6371
}
6472

6573
/**

Diff for: vscode/src/copilot/webviewViewProvider.ts

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { log } from "qsharp-lang";
55
import {
6+
commands,
67
CancellationToken,
78
ExtensionContext,
89
Uri,
@@ -13,6 +14,7 @@ import {
1314
} from "vscode";
1415
import { Copilot, CopilotUpdateHandler } from "./copilot";
1516
import { CopilotCommand } from "./shared";
17+
import { qsharpExtensionId } from "../common";
1618

1719
export function registerCopilotPanel(context: ExtensionContext): void {
1820
const provider = new CopilotWebviewViewProvider(context.extensionUri);
@@ -25,6 +27,11 @@ export function registerCopilotPanel(context: ExtensionContext): void {
2527
},
2628
),
2729
);
30+
context.subscriptions.push(
31+
commands.registerCommand(`${qsharpExtensionId}.copilotClear`, async () => {
32+
provider.clearChat();
33+
}),
34+
);
2835
}
2936

3037
class CopilotWebviewViewProvider implements WebviewViewProvider {
@@ -99,6 +106,10 @@ class CopilotWebviewViewProvider implements WebviewViewProvider {
99106
}
100107
}
101108

109+
clearChat() {
110+
this.copilot?.restartChat([]);
111+
}
112+
102113
handleMessageFromWebview(message: CopilotCommand) {
103114
if (!this.copilot) {
104115
return;

0 commit comments

Comments
 (0)