getDiagnostics
Retrieve diagnostic information (errors, warnings, hints) from all workspace files to enable intelligent code analysis and suggestions.
Instructions
获取当前工作区所有文件的诊断信息(错误/警告/提示)。返回完整的诊断列表,包含所有文件的详细错误信息。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:129-146 (handler)Handler function for the 'getDiagnostics' tool. Fetches all diagnostics from VSCodeDiagnosticsClient and returns formatted JSON response.private async handleGetDiagnostics() { try { const diagnostics = await this.diagnosticsClient.getDiagnostics(); return { content: [ { type: 'text', text: JSON.stringify(diagnostics, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `[handleGetDiagnostics] ${error instanceof Error ? error.message : String(error)}` ); } }
- src/vscode.ts:44-66 (helper)Core helper method in VSCodeDiagnosticsClient that performs HTTP fetch to retrieve all diagnostics from the local VS Code extension server.async getDiagnostics(): Promise<FileDiagnostic[]> { try { // 使用 fetch API 请求本地服务器 const response = await fetch(this.diagnosticsUrl); // 检查响应是否成功 if (!response.ok) { // 如果HTTP状态码表示错误,则抛出错误 throw new Error(`HTTP error! status: ${response.status}`); } // 解析 JSON 数据 const data = await response.json(); return data as FileDiagnostic[]; } catch (error: any) { // 捕获并记录错误,例如服务器未运行或网络问题 // 捕获并记录错误,然后重新抛出一个更明确的错误 const errorMessage = `获取诊断失败: ${error.message}. 请确保配套的 "Diagnostics Server" VS Code 扩展已安装、已启用,并且 VS Code 正在运行中。`; console.error(errorMessage); throw new Error(errorMessage); } }
- src/index.ts:46-54 (registration)Tool registration in the ListTools response, defining name, description, and input schema for 'getDiagnostics'.{ name: 'getDiagnostics', description: '获取当前工作区所有文件的诊断信息(错误/警告/提示)。返回完整的诊断列表,包含所有文件的详细错误信息。', inputSchema: { type: 'object', properties: {}, additionalProperties: false, }, },
- src/index.ts:49-53 (schema)Input schema for the 'getDiagnostics' tool (no parameters required).inputSchema: { type: 'object', properties: {}, additionalProperties: false, },
- src/index.ts:105-106 (handler)Dispatch handler in CallToolRequestSchema switch statement routing to the specific getDiagnostics handler.case 'getDiagnostics': return await this.handleGetDiagnostics();