From 1a08e1cb634c488c6e5f589b258561d3dc893b24 Mon Sep 17 00:00:00 2001 From: Bender-0 Date: Sun, 14 Sep 2025 20:06:17 +0200 Subject: [PATCH] feature: Implement logic for 'Add Context' button This commit wires up the 'Add Context' button in the chat interface. - The button in ChatInterface.tsx now sends a 'addContext' message to the extension. - The chatSidebarProvider.ts now handles this message by opening a file selection dialog, allowing users to select a file to add as context to the conversation. --- src/providers/chatSidebarProvider.ts | 20 +++++++++++++++++++ src/webview/components/Chat/ChatInterface.tsx | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/providers/chatSidebarProvider.ts b/src/providers/chatSidebarProvider.ts index d045426e..f6a11f49 100644 --- a/src/providers/chatSidebarProvider.ts +++ b/src/providers/chatSidebarProvider.ts @@ -90,6 +90,26 @@ export class ChatSidebarProvider implements vscode.WebviewViewProvider { case 'changeProvider': await this.handleChangeProvider(message.model, webviewView.webview); break; + case 'addContext': + const options: vscode.OpenDialogOptions = { + canSelectMany: false, + openLabel: 'Select File', + canSelectFiles: true, + canSelectFolders: false + }; + + vscode.window.showOpenDialog(options).then(fileUri => { + if (fileUri && fileUri[0]) { + webviewView.webview.postMessage({ + command: 'contextFromCanvas', + data: { + fileName: fileUri[0].fsPath, + type: 'file' + } + }); + } + }); + break; } } ); diff --git a/src/webview/components/Chat/ChatInterface.tsx b/src/webview/components/Chat/ChatInterface.tsx index 1ede6e68..5612bb36 100644 --- a/src/webview/components/Chat/ChatInterface.tsx +++ b/src/webview/components/Chat/ChatInterface.tsx @@ -352,8 +352,9 @@ const ChatInterface: React.FC = ({ layout, vscode }) => { }, [inputMessage]); const handleAddContext = () => { - // TODO: Implement context addition functionality - console.log('Add Context clicked'); + vscode.postMessage({ + command: 'addContext' + }); }; const handleNewConversation = () => {