feat: Add getCurrentFileInfo and getIDEServicePort handlers

- Added getCurrentFileInfo handler to retrieve the absolute path of the current file
- Added getIDEServicePort handler to retrieve the IDE service port
- Updated fileHandler.ts and handlerRegister.ts to include the new handlers
- Created getCurrentFileInfo.ts in ide_services/endpoints to implement the getCurrentFileInfo handler
- Updated services.ts in ide_services to include the getCurrentFileInfo handler
This commit is contained in:
bobo.yang 2024-06-16 22:06:27 +08:00
parent 2a1da12004
commit 2bdf9d01eb
4 changed files with 43 additions and 1 deletions

View File

@ -30,3 +30,30 @@ export async function readFile(message: any, panel: vscode.WebviewPanel | vscode
logger.channel()?.error(`Error reading file ${message.file}: ${error}`);
}
}
regInMessage({ command: 'getCurrentFileInfo'});
regOutMessage({ command: 'getCurrentFileInfo', result: '' });
// Read content from specified file and return it
export async function getCurrentFileInfo(message: any, panel: vscode.WebviewPanel | vscode.WebviewView): Promise<void> {
try {
// 获取当前文件的绝对路径
const fileUri = vscode.window.activeTextEditor?.document.uri;
const filePath = fileUri?.fsPath;
MessageHandler.sendMessage(panel, { command: 'getCurrentFileInfo', result: filePath ?? "" });
} catch (error) {
logger.channel()?.error(`Error getting current file info: ${error}`);
}
}
regInMessage({ command: 'getIDEServicePort'});
regOutMessage({ command: 'getIDEServicePort', result: 8090 });
// Read content from specified file and return it
export async function getIDEServicePort(message: any, panel: vscode.WebviewPanel | vscode.WebviewView): Promise<void> {
try {
// Get IDE service port
const port = process.env.DEVCHAT_IDE_SERVICE_PORT;
MessageHandler.sendMessage(panel, { command: 'getIDEServicePort', result: port ?? 0 });
} catch (error) {
logger.channel()?.error(`Error getting IDE service port: ${error}`);
}
}

View File

@ -13,7 +13,7 @@ import {createAndOpenFile} from './codeBlockHandler';
import { listAllMessages } from './listMessages';
import { doVscodeCommand } from './vscodeCommandHandler';
import { featureToggle, getFeatureToggles } from './featureToggleHandler';
import { readFile, writeFile } from './fileHandler';
import { readFile, writeFile, getIDEServicePort, getCurrentFileInfo } from './fileHandler';
import { getTopics, deleteTopic } from './topicHandler';
import { readConfig, writeConfig, readServerConfigBase, writeServerConfigBase } from './configHandler';
import { getSetting, getUserAccessKey, getValidLlmModelList, updateSetting } from './removehandler';
@ -86,6 +86,9 @@ messageHandler.registerHandler('deleteTopic', deleteTopic);
messageHandler.registerHandler('readConfig', readConfig);
messageHandler.registerHandler('writeConfig', writeConfig);
messageHandler.registerHandler('getCurrentFileInfo', getCurrentFileInfo);
messageHandler.registerHandler('getIDEServicePort', getIDEServicePort);
messageHandler.registerHandler('readServerConfigBase', readServerConfigBase);
messageHandler.registerHandler('writeServerConfigBase', writeServerConfigBase);

View File

@ -0,0 +1,7 @@
import * as vscode from 'vscode';
export async function getCurrentFileInfo() {
const fileUri = vscode.window.activeTextEditor?.document.uri;
const filePath = fileUri?.fsPath;
return {"path": filePath ?? ""};
}

View File

@ -13,6 +13,7 @@ import { UnofficialEndpoints } from "./endpoints/unofficial";
import { getDocumentSymbols } from "./endpoints/getDocumentSymbols";
import { findTypeDefinitionLocations } from "./endpoints/findTypeDefs";
import { findDefinitionLocations } from "./endpoints/findDefs";
import { getCurrentFileInfo } from "./endpoints/getCurrentFileInfo";
const functionRegistry: any = {
/**
@ -85,6 +86,10 @@ const functionRegistry: any = {
keys: ["code"],
handler: UnofficialEndpoints.runCode,
},
"/getCurrentFileInfo": {
keys: [],
handler: getCurrentFileInfo,
}
};
let server: http.Server | null = null;