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
This commit is contained in:
bobo.yang 2024-06-26 10:13:21 +08:00
parent a308d09dc8
commit 2b5412b0bc
4 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,12 @@
import * as vscode from 'vscode';
export async function getDiagnosticsInRange(fileName: string, startLine: number, endLine: number): Promise<string[]> {
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??""}>>`; });
}

View File

@ -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<string> {
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;
}

View File

@ -0,0 +1,6 @@
import { UiUtilWrapper } from "../../util/uiUtil";
export async function getExtensionToolsPath(): Promise<string> {
return await UiUtilWrapper.extensionPath() + "/tools/";
}

View File

@ -14,6 +14,9 @@ import { getDocumentSymbols } from "./endpoints/getDocumentSymbols";
import { findTypeDefinitionLocations } from "./endpoints/findTypeDefs"; import { findTypeDefinitionLocations } from "./endpoints/findTypeDefs";
import { findDefinitionLocations } from "./endpoints/findDefs"; import { findDefinitionLocations } from "./endpoints/findDefs";
import { getCurrentFileInfo } from "./endpoints/getCurrentFileInfo"; import { getCurrentFileInfo } from "./endpoints/getCurrentFileInfo";
import { getDiagnosticsInRange } from "./endpoints/documentRangeDiagnostics";
import { getExtensionToolsPath } from "./endpoints/getToolsPath";
import { getCollapsedCode } from "./endpoints/getCollapsedCode";
const functionRegistry: any = { const functionRegistry: any = {
/** /**
@ -89,6 +92,18 @@ const functionRegistry: any = {
"/current_file_info": { "/current_file_info": {
keys: [], keys: [],
handler: getCurrentFileInfo, 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,
} }
}; };