mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Updates schema, UX and prompt for IDE context (#5046)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user