diff options
| author | Shreya Keshive <[email protected]> | 2025-07-28 11:03:22 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-28 15:03:22 +0000 |
| commit | e2754416516edb8c27e63cee5b249f41c3e0fffc (patch) | |
| tree | e00ee188509ce7f0b4f353cf6e08d0422490fe72 /packages/vscode-ide-companion/src | |
| parent | f2e006179d27af34c35b58b1df3032e351e61eaf (diff) | |
Updates schema, UX and prompt for IDE context (#5046)
Diffstat (limited to 'packages/vscode-ide-companion/src')
| -rw-r--r-- | packages/vscode-ide-companion/src/ide-server.ts | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/packages/vscode-ide-companion/src/ide-server.ts b/packages/vscode-ide-companion/src/ide-server.ts index f47463ba..df8e160b 100644 --- a/packages/vscode-ide-companion/src/ide-server.ts +++ b/packages/vscode-ide-companion/src/ide-server.ts @@ -20,16 +20,17 @@ const MCP_SESSION_ID_HEADER = 'mcp-session-id'; const IDE_SERVER_PORT_ENV_VAR = 'GEMINI_CLI_IDE_SERVER_PORT'; const MAX_SELECTED_TEXT_LENGTH = 16384; // 16 KiB limit -function sendOpenFilesChangedNotification( +function sendIdeContextUpdateNotification( transport: StreamableHTTPServerTransport, log: (message: string) => void, recentFilesManager: RecentFilesManager, ) { const editor = vscode.window.activeTextEditor; - const filePath = + const activeFile = editor && editor.document.uri.scheme === 'file' ? editor.document.uri.fsPath - : ''; + : undefined; + const selection = editor?.selection; const cursor = selection ? { @@ -38,25 +39,37 @@ function sendOpenFilesChangedNotification( character: selection.active.character, } : undefined; + let selectedText = editor?.document.getText(selection) ?? undefined; if (selectedText && selectedText.length > MAX_SELECTED_TEXT_LENGTH) { selectedText = selectedText.substring(0, MAX_SELECTED_TEXT_LENGTH) + '... [TRUNCATED]'; } + + const openFiles = recentFilesManager.recentFiles.map((file) => { + const isActive = file.filePath === activeFile; + return { + path: file.filePath, + timestamp: file.timestamp, + isActive, + ...(isActive && { + cursor, + selectedText, + }), + }; + }); + const notification: JSONRPCNotification = { jsonrpc: '2.0', - method: 'ide/openFilesChanged', + method: 'ide/contextUpdate', params: { - activeFile: filePath, - recentOpenFiles: recentFilesManager.recentFiles.filter( - (file) => file.filePath !== filePath, - ), - cursor, - selectedText, + workspaceState: { + openFiles, + }, }, }; log( - `Sending active file changed notification: ${JSON.stringify( + `Sending IDE context update notification: ${JSON.stringify( notification, null, 2, @@ -87,7 +100,7 @@ export class IDEServer { const recentFilesManager = new RecentFilesManager(context); const onDidChangeSubscription = recentFilesManager.onDidChange(() => { for (const transport of Object.values(transports)) { - sendOpenFilesChangedNotification( + sendIdeContextUpdateNotification( transport, this.log.bind(this), recentFilesManager, @@ -191,7 +204,7 @@ export class IDEServer { } if (!sessionsWithInitialNotification.has(sessionId)) { - sendOpenFilesChangedNotification( + sendIdeContextUpdateNotification( transport, this.log.bind(this), recentFilesManager, |
