From 826516581b8f6855c9661a2ee99d4a3b98e9b159 Mon Sep 17 00:00:00 2001 From: yiliang114 <1204183885@qq.com> Date: Sun, 23 Nov 2025 21:45:44 +0800 Subject: [PATCH] feat(vscode-ide-companion): send initial active editor state to WebView on initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Send activeEditorChanged message with initial editor state when WebView is created - Include fileName, filePath, and selection info if available - Applied in both side panel and editor panel initialization This ensures the WebView displays the current file context immediately on load. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../src/WebViewProvider.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/packages/vscode-ide-companion/src/WebViewProvider.ts b/packages/vscode-ide-companion/src/WebViewProvider.ts index 5a9c288f..af7282a7 100644 --- a/packages/vscode-ide-companion/src/WebViewProvider.ts +++ b/packages/vscode-ide-companion/src/WebViewProvider.ts @@ -231,6 +231,27 @@ export class WebViewProvider { }); this.disposables.push(selectionChangeDisposable); + // Send initial active editor state to WebView + const initialEditor = vscode.window.activeTextEditor; + if (initialEditor) { + const filePath = initialEditor.document.uri.fsPath || null; + const fileName = filePath ? getFileName(filePath) : null; + + let selectionInfo = null; + if (!initialEditor.selection.isEmpty) { + const selection = initialEditor.selection; + selectionInfo = { + startLine: selection.start.line + 1, + endLine: selection.end.line + 1, + }; + } + + this.sendMessageToWebView({ + type: 'activeEditorChanged', + data: { fileName, filePath, selection: selectionInfo }, + }); + } + // Check if we have valid auth cache and auto-reconnect if (!this.agentInitialized) { const workspaceFolder = vscode.workspace.workspaceFolders?.[0]; @@ -520,6 +541,27 @@ export class WebViewProvider { ); this.disposables.push(editorChangeDisposable); + // Send initial active editor state to WebView + const initialEditor = vscode.window.activeTextEditor; + if (initialEditor) { + const filePath = initialEditor.document.uri.fsPath || null; + const fileName = filePath ? getFileName(filePath) : null; + + let selectionInfo = null; + if (!initialEditor.selection.isEmpty) { + const selection = initialEditor.selection; + selectionInfo = { + startLine: selection.start.line + 1, + endLine: selection.end.line + 1, + }; + } + + this.sendMessageToWebView({ + type: 'activeEditorChanged', + data: { fileName, filePath, selection: selectionInfo }, + }); + } + // Capture the tab reference on restore this.panelManager.captureTab();