From 2b5412b0bc55a959cf6553af59e5ea96fd104a1e Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Wed, 26 Jun 2024 10:13:21 +0800 Subject: [PATCH] feat: Add new IDE service endpoints - Implement getDiagnosticsInRange for code diagnostics - Create getCollapsedCode for code collapsing functionality - Add getExtensionToolsPath to retrieve tools directory - Update services.ts with new endpoint handlers --- .../endpoints/documentRangeDiagnostics.ts | 12 ++++++++++++ src/ide_services/endpoints/getCollapsedCode.ts | 11 +++++++++++ src/ide_services/endpoints/getToolsPath.ts | 6 ++++++ src/ide_services/services.ts | 15 +++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 src/ide_services/endpoints/documentRangeDiagnostics.ts create mode 100644 src/ide_services/endpoints/getCollapsedCode.ts create mode 100644 src/ide_services/endpoints/getToolsPath.ts diff --git a/src/ide_services/endpoints/documentRangeDiagnostics.ts b/src/ide_services/endpoints/documentRangeDiagnostics.ts new file mode 100644 index 0000000..7056b58 --- /dev/null +++ b/src/ide_services/endpoints/documentRangeDiagnostics.ts @@ -0,0 +1,12 @@ +import * as vscode from 'vscode'; + +export async function getDiagnosticsInRange(fileName: string, startLine: number, endLine: number): Promise { + const document = await vscode.workspace.openTextDocument(fileName); + const startPosition = new vscode.Position(startLine, 0); + const endPosition = new vscode.Position(endLine, Number.MAX_VALUE); + const range = new vscode.Range(startPosition, endPosition); + const diagnosticsAll = vscode.languages.getDiagnostics(document.uri); + + const diagnostics = diagnosticsAll.filter(diag => range.contains(diag.range)); + return diagnostics.map(diag => { return `${diag.message} <<${diag.source??""}:${diag.code??""}>>`; }); +} \ No newline at end of file diff --git a/src/ide_services/endpoints/getCollapsedCode.ts b/src/ide_services/endpoints/getCollapsedCode.ts new file mode 100644 index 0000000..1b088db --- /dev/null +++ b/src/ide_services/endpoints/getCollapsedCode.ts @@ -0,0 +1,11 @@ +import { collapseFileExculdeSelectRange } from '../../contributes/codecomplete/ast/collapseBlock'; +import * as vscode from 'vscode'; + +export async function getCollapsedCode(fileName: string, startLine: number, endLine: number): Promise { + const document = await vscode.workspace.openTextDocument(fileName); + const startPosition = new vscode.Position(startLine, 0); + const endPosition = new vscode.Position(endLine, Number.MAX_VALUE); + const range = new vscode.Range(startPosition, endPosition); + const code = await collapseFileExculdeSelectRange(document.uri.fsPath, document.getText(), range.start.line, range.end.line); + return code; +} \ No newline at end of file diff --git a/src/ide_services/endpoints/getToolsPath.ts b/src/ide_services/endpoints/getToolsPath.ts new file mode 100644 index 0000000..b27cc9f --- /dev/null +++ b/src/ide_services/endpoints/getToolsPath.ts @@ -0,0 +1,6 @@ +import { UiUtilWrapper } from "../../util/uiUtil"; + + +export async function getExtensionToolsPath(): Promise { + return await UiUtilWrapper.extensionPath() + "/tools/"; +} \ No newline at end of file diff --git a/src/ide_services/services.ts b/src/ide_services/services.ts index 89b83f3..c2c9cc1 100644 --- a/src/ide_services/services.ts +++ b/src/ide_services/services.ts @@ -14,6 +14,9 @@ import { getDocumentSymbols } from "./endpoints/getDocumentSymbols"; import { findTypeDefinitionLocations } from "./endpoints/findTypeDefs"; import { findDefinitionLocations } from "./endpoints/findDefs"; import { getCurrentFileInfo } from "./endpoints/getCurrentFileInfo"; +import { getDiagnosticsInRange } from "./endpoints/documentRangeDiagnostics"; +import { getExtensionToolsPath } from "./endpoints/getToolsPath"; +import { getCollapsedCode } from "./endpoints/getCollapsedCode"; const functionRegistry: any = { /** @@ -89,6 +92,18 @@ const functionRegistry: any = { "/current_file_info": { keys: [], handler: getCurrentFileInfo, + }, + "/get_diagnostics_in_range": { + keys: ["fileName", "startLine", "endLine"], + handler: getDiagnosticsInRange, + }, + "/get_extension_tools_path": { + keys: [], + handler: getExtensionToolsPath, + }, + "/get_collapsed_code": { + keys: ["fileName", "startLine", "endLine"], + handler: getCollapsedCode, } };