summaryrefslogtreecommitdiff
path: root/packages/vscode-ide-companion/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/vscode-ide-companion/src')
-rw-r--r--packages/vscode-ide-companion/src/ide-server.ts39
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,