Skip to content

Commit 584207b

Browse files
authored
feat: add watcher for user prompts (#24)
1 parent 8c41430 commit 584207b

File tree

1 file changed

+17
-1
lines changed
  • packages/core/src/codewhispererChat/controllers/chat

1 file changed

+17
-1
lines changed

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export class ChatController {
140140
private readonly promptGenerator: PromptsGenerator
141141
private readonly userIntentRecognizer: UserIntentRecognizer
142142
private readonly telemetryHelper: CWCTelemetryHelper
143+
private userPromptsWatcher: vscode.FileSystemWatcher | undefined
143144

144145
public constructor(
145146
private readonly chatControllerMessageListeners: ChatControllerMessageListeners,
@@ -263,6 +264,21 @@ export class ChatController {
263264
})
264265
}
265266

267+
private registerUserPromptsWatcher() {
268+
if (this.userPromptsWatcher) {
269+
return
270+
}
271+
this.userPromptsWatcher = vscode.workspace.createFileSystemWatcher(
272+
new vscode.RelativePattern(vscode.Uri.file(getUserPromptsDirectory()), `*${promptFileExtension}`),
273+
false,
274+
true,
275+
false
276+
)
277+
this.userPromptsWatcher.onDidCreate(() => this.processContextCommandUpdateMessage())
278+
this.userPromptsWatcher.onDidDelete(() => this.processContextCommandUpdateMessage())
279+
globals.context.subscriptions.push(this.userPromptsWatcher)
280+
}
281+
266282
private processFooterInfoLinkClick(click: FooterInfoLinkClick) {
267283
this.openLinkInExternalBrowser(click)
268284
}
@@ -403,6 +419,7 @@ export class ChatController {
403419

404420
private async processContextCommandUpdateMessage() {
405421
// when UI is ready, refresh the context commands
422+
this.registerUserPromptsWatcher()
406423
const contextCommand: MynahUIDataModel['contextCommands'] = [
407424
{
408425
commands: [
@@ -555,7 +572,6 @@ export class ChatController {
555572
await fs.writeFile(newFilePath, newFileContent)
556573
const newFileDoc = await vscode.workspace.openTextDocument(newFilePath)
557574
await vscode.window.showTextDocument(newFileDoc)
558-
await this.processContextCommandUpdateMessage()
559575
}
560576
}
561577
}

0 commit comments

Comments
 (0)