File tree 3 files changed +32
-1
lines changed
3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 240
240
"command" : " qsharp-vscode.workspacesAdd" ,
241
241
"when" : " view == quantum-workspaces" ,
242
242
"group" : " navigation"
243
+ },
244
+ {
245
+ "command" : " qsharp-vscode.copilotClear" ,
246
+ "when" : " view == quantum-copilot" ,
247
+ "group" : " navigation"
243
248
}
244
249
],
245
250
"view/item/context" : [
386
391
"title" : " Remove workspace connection" ,
387
392
"icon" : " $(remove)"
388
393
},
394
+ {
395
+ "command" : " qsharp-vscode.copilotClear" ,
396
+ "category" : " Q#" ,
397
+ "title" : " Clear Quantum Copilot chat" ,
398
+ "enablement" : " !qdkCopilotIsBusy" ,
399
+ "icon" : " $(clear-all)"
400
+ },
389
401
{
390
402
"command" : " qsharp-vscode.workspacePythonCode" ,
391
403
"category" : " Q#" ,
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import { OpenAIChatService } from "./openAiChatService";
21
21
import { getRandomGuid } from "../utils" ;
22
22
import { EventType , sendTelemetryEvent , UserFlowStatus } from "../telemetry" ;
23
23
import { knownToolNameOrDefault } from "./azqTools" ;
24
+ import { commands } from "vscode" ;
24
25
25
26
export class Copilot {
26
27
private service : IChatService ;
@@ -59,7 +60,14 @@ export class Copilot {
59
60
}
60
61
this . messages . push ( { role : "user" , content : userMessage } ) ;
61
62
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
+ }
63
71
}
64
72
65
73
/**
Original file line number Diff line number Diff line change 3
3
4
4
import { log } from "qsharp-lang" ;
5
5
import {
6
+ commands ,
6
7
CancellationToken ,
7
8
ExtensionContext ,
8
9
Uri ,
@@ -13,6 +14,7 @@ import {
13
14
} from "vscode" ;
14
15
import { Copilot , CopilotUpdateHandler } from "./copilot" ;
15
16
import { CopilotCommand } from "./shared" ;
17
+ import { qsharpExtensionId } from "../common" ;
16
18
17
19
export function registerCopilotPanel ( context : ExtensionContext ) : void {
18
20
const provider = new CopilotWebviewViewProvider ( context . extensionUri ) ;
@@ -25,6 +27,11 @@ export function registerCopilotPanel(context: ExtensionContext): void {
25
27
} ,
26
28
) ,
27
29
) ;
30
+ context . subscriptions . push (
31
+ commands . registerCommand ( `${ qsharpExtensionId } .copilotClear` , async ( ) => {
32
+ provider . clearChat ( ) ;
33
+ } ) ,
34
+ ) ;
28
35
}
29
36
30
37
class CopilotWebviewViewProvider implements WebviewViewProvider {
@@ -99,6 +106,10 @@ class CopilotWebviewViewProvider implements WebviewViewProvider {
99
106
}
100
107
}
101
108
109
+ clearChat ( ) {
110
+ this . copilot ?. restartChat ( [ ] ) ;
111
+ }
112
+
102
113
handleMessageFromWebview ( message : CopilotCommand ) {
103
114
if ( ! this . copilot ) {
104
115
return ;
You can’t perform that action at this time.
0 commit comments