getDiagnosticsSummary
Generate a summary of code quality metrics including file counts, errors, and warnings to assess project diagnostics.
Instructions
获取诊断统计摘要,快速了解项目整体代码质量。返回文件总数、错误数量、警告数量的统计信息。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:221-266 (handler)The primary handler function for the 'getDiagnosticsSummary' MCP tool. It fetches all diagnostics from the VSCodeDiagnosticsClient, counts errors and warnings by iterating over the diagnostics, constructs a summary object, and returns it as JSON-formatted text content.private async handleGetDiagnosticsSummary() { try { const diagnostics = await this.diagnosticsClient.getDiagnostics(); let errorCount = 0; let warningCount = 0; diagnostics.forEach((fileDiagnosticTuple) => { // fileDiagnosticTuple is a tuple [uri: any, diagnostics: Diagnostic[]] if (Array.isArray(fileDiagnosticTuple) && fileDiagnosticTuple.length === 2) { const diagnosticList = fileDiagnosticTuple[1]; if (Array.isArray(diagnosticList)) { diagnosticList.forEach((d) => { if (d && typeof d.severity === 'number') { // severity: 0=Error, 1=Warning in VS Code if (d.severity === 0) { errorCount++; } else if (d.severity === 1) { warningCount++; } } }); } } }); const summary = { fileCount: diagnostics.length, errorCount, warningCount, }; return { content: [ { type: 'text', text: JSON.stringify(summary, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `[handleGetDiagnosticsSummary] ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:85-93 (registration)The tool registration entry in the ListToolsRequestSchema handler, defining the name, description, and empty inputSchema for 'getDiagnosticsSummary'.{ name: 'getDiagnosticsSummary', description: '获取诊断统计摘要,快速了解项目整体代码质量。返回文件总数、错误数量、警告数量的统计信息。', inputSchema: { type: 'object', properties: {}, additionalProperties: false, }, },
- src/index.ts:88-92 (schema)The input schema for the 'getDiagnosticsSummary' tool, which accepts no parameters.inputSchema: { type: 'object', properties: {}, additionalProperties: false, },
- src/vscode.ts:160-170 (helper)A helper method in VSCodeDiagnosticsClient that computes the diagnostics summary (though not directly used by the MCP tool handler). It uses standard VS Code severity codes (1=Error, 2=Warning).async getDiagnosticsSummary(): Promise<DiagnosticSummary> { const allDiagnostics = await this.getDiagnostics(); const totalFiles = allDiagnostics.length; const allDiagnosticItems = allDiagnostics.flatMap(f => f.diagnostics); const errors = allDiagnosticItems.filter(d => d.severity === 1).length; const warnings = allDiagnosticItems.filter(d => d.severity === 2).length; return { totalFiles, errors, warnings }; }
- src/vscode.ts:20-24 (helper)Type definition for the DiagnosticSummary returned by the helper method.export interface DiagnosticSummary { totalFiles: number; errors: number; warnings: number; }