summaryrefslogtreecommitdiff
path: root/packages/vscode-ide-companion/src/ide-server.ts
diff options
context:
space:
mode:
authorShreya Keshive <[email protected]>2025-07-28 14:20:56 -0400
committerGitHub <[email protected]>2025-07-28 18:20:56 +0000
commitcfe3753d4c956ffcf13e227c0619069db672adbf (patch)
tree5d0b1ad9bfe3950861aff072e9cec91b5c20570e /packages/vscode-ide-companion/src/ide-server.ts
parent9aef0a8e6c133d3bf1ff43f80119664c154ffdf2 (diff)
Refactors companion VS Code extension to import & use notification schema defined in gemini-cli (#5059)
Diffstat (limited to 'packages/vscode-ide-companion/src/ide-server.ts')
-rw-r--r--packages/vscode-ide-companion/src/ide-server.ts53
1 files changed, 8 insertions, 45 deletions
diff --git a/packages/vscode-ide-companion/src/ide-server.ts b/packages/vscode-ide-companion/src/ide-server.ts
index df8e160b..8296c64c 100644
--- a/packages/vscode-ide-companion/src/ide-server.ts
+++ b/packages/vscode-ide-companion/src/ide-server.ts
@@ -14,59 +14,22 @@ import {
type JSONRPCNotification,
} from '@modelcontextprotocol/sdk/types.js';
import { Server as HTTPServer } from 'node:http';
-import { RecentFilesManager } from './recent-files-manager.js';
+import { OpenFilesManager } from './open-files-manager.js';
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 sendIdeContextUpdateNotification(
transport: StreamableHTTPServerTransport,
log: (message: string) => void,
- recentFilesManager: RecentFilesManager,
+ openFilesManager: OpenFilesManager,
) {
- const editor = vscode.window.activeTextEditor;
- const activeFile =
- editor && editor.document.uri.scheme === 'file'
- ? editor.document.uri.fsPath
- : undefined;
-
- const selection = editor?.selection;
- const cursor = selection
- ? {
- // This value is a zero-based index, but the vscode IDE is one-based.
- line: selection.active.line + 1,
- 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 ideContext = openFilesManager.state;
const notification: JSONRPCNotification = {
jsonrpc: '2.0',
method: 'ide/contextUpdate',
- params: {
- workspaceState: {
- openFiles,
- },
- },
+ params: ideContext,
};
log(
`Sending IDE context update notification: ${JSON.stringify(
@@ -97,13 +60,13 @@ export class IDEServer {
app.use(express.json());
const mcpServer = createMcpServer();
- const recentFilesManager = new RecentFilesManager(context);
- const onDidChangeSubscription = recentFilesManager.onDidChange(() => {
+ const openFilesManager = new OpenFilesManager(context);
+ const onDidChangeSubscription = openFilesManager.onDidChange(() => {
for (const transport of Object.values(transports)) {
sendIdeContextUpdateNotification(
transport,
this.log.bind(this),
- recentFilesManager,
+ openFilesManager,
);
}
});
@@ -207,7 +170,7 @@ export class IDEServer {
sendIdeContextUpdateNotification(
transport,
this.log.bind(this),
- recentFilesManager,
+ openFilesManager,
);
sessionsWithInitialNotification.add(sessionId);
}