add-diagnostic-parser
Skill1.7k starsChanged 7 months agoMITView on GitHub
Use when adding a compiler or tool output parser for the Problems panel. Touches src/diagnostics/<name>.ts, src/diagnostics/build.ts, package.json (cmake.enabledOutputParsers), and package.nls.json. Triggers: "add parser", "new diagnostic parser", "parse compiler output".
Trending
Quiet this year.thin dataabout the whole repository
Who's talking about microsoft/vscode-cmake-tools
- clangd/vscode-clangd“support commands in settings”GitHub · Jun 27, 2020 · 17 reactions
- fredericbonnet/cmake-test-explorer“trigger BuildBeforeRun also by running a test in the testexplorer”GitHub · Mar 12, 2021 · 8 reactions
- twxs/vs.language.cmake“CMake Tools Extension & twxs.cmake extension”GitHub · Jan 29, 2024 · 5 reactions
- disroop/vs-code-conan“configuration provider for cpptools / IntelliSense”GitHub · Jan 14, 2021 · 3 reactions
- microsoft/vscode-cmake-tools-api“Update APIs”GitHub · Aug 1, 2025 · 2 reactions
The biggest 5 of 14 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 14
Talked about on GitHub (14 times).
On GitHub · 14
- Jun 27, 2020support commands in settings — clangd/vscode-clangd17 reactions · 8 comments
- Mar 12, 2021trigger BuildBeforeRun also by running a test in the testexplorer — fredericbonnet/cmake-test-explorer8 reactions
- Jan 29, 2024CMake Tools Extension & twxs.cmake extension — twxs/vs.language.cmake5 reactions · 1 comment
- Jan 14, 2021configuration provider for cpptools / IntelliSense — disroop/vs-code-conan3 reactions · 5 comments
- Aug 1, 2025Update APIs — microsoft/vscode-cmake-tools-api2 reactions · 4 comments
9 more on GitHub
- Nov 15, 2024Add C++26 support (setting values only) — microsoft/vscode-cpptools2 reactions · 3 comments
- Oct 25, 2024cmake-kits.json incorrect CXX compiler — raspberrypi/pico-vscode2 reactions · 3 comments
- Oct 24, 2024Add support for `${command:<name-of-command>}` in c_cpp_properties.json — microsoft/vscode-cpptools2 reactions · 7 comments
- Feb 28, 2022Add support for resolving commands — microsoft/vscode-cpptools2 reactions · 4 comments
- Jun 19, 2025Cleanup standard version handling. — microsoft/vscode-makefile-tools1 reaction
- Mar 5, 2025Pixi builds / VSCode / CMake issues and differences — FreeCAD/FreeCAD1 reaction · 15 comments
- Jan 31, 2025Feature request: Improved variable and command substitution for build directories setting — JacquesLucke/gcov-viewer1 reaction
- Sep 26, 2024Replace CMake grammar — github-linguist/linguist1 reaction
- Sep 16, 2024Newest macos-latest environment update not working for VS Code tests — actions/runner-images1 reaction · 2 comments
In this repository7 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- add-commandSkill
- add-settingSkill
- backend-testsSkill
- presets-vs-kitsSkill
- pr-readinessSkill
- validation-projectSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 29
Create src/diagnostics/<name>.ts.
- Very specific: line 149
Import the new parser module and add an instance to the Compilers class.
- Very specific: line 178
Add the parser name to the cmake.enabledOutputParsers enum.
- Very specific: line 214
If any user-visible setting descriptions changed, update the localization key in package.nls.json.
- Very specific: line 220
Add tests in test/unit-tests/diagnostics.test.ts.
- Distinctive: line 242
Add an entry under the current version:
- Distinctive: line 271
Use opt-in for parsers with aggressive regexes that might false-positive on common output, or for niche toolchains.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Adding a New Diagnostic / Output Parser
Recipe for adding a new compiler or tool output parser to CMake Tools. A parser extracts diagnostics (errors, warnings, notes) from build output and surfaces them in the VS Code Problems panel.
Overview
Adding a parser touches 4 files (plus tests and changelog):
| File | What to do |
src/diagnostics/<name>.ts | Create the parser class |
src/diagnostics/build.ts | Register the parser in Compilers |
package.json | Add to cmake.enabledOutputParsers enum |
package.nls.json | Update description if user-visible text changes |
Step 1: Create the parser file
Create src/diagnostics/<name>.ts. Every parser extends RawDiagnosticParser (defined in src/diagnostics/util.ts) and exports a class named Parser.
Base class contract
// src/diagnostics/util.ts (simplified)
export abstract class RawDiagnosticParser {
get diagnostics(): readonly RawDiagnostic[] { /* accumulated results */ }
/** Called by the build consumer for every line of output. */
handleLine(line: string): boolean {
const result = this.doHandleLine(line);
if (result === FeedLineResult.Ok) return true; // line consumed, no new diagnostic
if (result === FeedLineResult.NotMine) return false; // line not recognized
// Otherwise result is a RawDiagnostic — it gets stored automatically
this._diagnostics.push(result);
return true;
}
/** Implement this. Return a RawDiagnostic to emit, or a FeedLineResult. */
protected abstract doHandleLine(line: string): RawDiagnostic | FeedLineResult;
}Minimal single-regex parser (like MSVC)
/**
* Module for parsing <ToolName> diagnostics
*/ /** */
import * as vscode from 'vscode';
import { oneLess, RawDiagnosticParser, FeedLineResult } from '@cmt/diagnostics/util';
// Regex that captures: file, line, severity, code (optional), message
export const REGEX = /^(.+):(\d+):\s+(error|warning|info)\s+(\w+):\s+(.*)$/;
export class Parser extends RawDiagnosticParser {
doHandleLine(line: string) {
const mat = REGEX.exec(line);
if (!mat) {
return FeedLineResult.NotMine;
}
const [full, file, lineStr, severity, code, message] = mat;
const lineno = oneLess(lineStr); // convert 1-based to 0-based
return {
full,
file,
location: new vscode.Range(lineno, 0, lineno, 999),
severity,
message,
code,
related: []
};
}
}Multi-line / stateful parser (like IAR)
For tools whose diagnostics span multiple lines, use internal state:
import { RawDiagnosticParser, RawDiagnostic, FeedLineResult, oneLess } from '@cmt/diagnostics/util';
enum ParserState { init, pending_message }
export class Parser extends RawDiagnosticParser {
private state = ParserState.init;
private pending: RawDiagnostic | null = null;
doHandleLine(line: string): RawDiagnostic | FeedLineResult {
switch (this.state) {
case ParserState.init: {
const mat = FIRST_LINE_REGEX.exec(line);
if (!mat) return FeedLineResult.NotMine;
this.pending = { /* ... build partial diagnostic ... */ };
this.state = ParserState.pending_message;
return FeedLineResult.Ok; // consumed, but not complete yet
}
case ParserState.pending_message: {
if (/* line completes the diagnostic */) {
const diag = this.pending!;
this.reset();
return diag; // emits the diagnostic
}
return FeedLineResult.Ok; // still accumulating
}
}
return FeedLineResult.NotMine;
}
}Key types
// src/diagnostics/util.ts
interface RawDiagnostic {
full: string; // the full matched line(s)
file: string; // source file path
location: vscode.Range; // 0-based range (use oneLess() for 1-based input)
severity: string; // 'error' | 'warning' | 'note' | 'info' | 'fatal error' | 'remark'
message: string;
code?: string; // optional diagnostic code (e.g. 'C4996', 'LNK2019')
related: RawRelated[]; // related diagnostics (notes, template backtraces)
}
enum FeedLineResult {
Ok, // line was consumed (but no new diagnostic produced yet)
NotMine, // line not recognized by this parser
}diagnosticSeverity() in util.ts maps the severity string to vscode.DiagnosticSeverity. Recognized values: 'error', 'fatal error', 'catastrophic error', 'warning', 'note', 'info', 'remark'.
Step 2: Register in src/diagnostics/build.ts
Import the new parser module and add an instance to the Compilers class. The property name becomes the parser identifier used in cmake.enabledOutputParsers.
// At the top — add import
import * as myparser from '@cmt/diagnostics/myparser';
// Inside the Compilers class — add property
export class Compilers {
[compiler: string]: RawDiagnosticParser;
gcc = new gcc.Parser();
gnuld = new gnu_ld.Parser();
ghs = new ghs.Parser();
diab = new diab.Parser();
msvc = new mvsc.Parser();
iar = new iar.Parser();
iwyu = new iwyu.Parser();
myparser = new myparser.Parser(); // ← new parser
}The CompileOutputConsumer.error() method iterates over all Compilers properties in declaration order, calling parser.handleLine(line). The first parser to return true claims the line — order matters if your parser's regex could match lines from another compiler.
The resolveDiagnostics() method filters diagnostics by config.enableOutputParsers — only parsers whose name appears in that array will have their diagnostics shown in the Problems panel.
Step 3: Update package.json
Add the parser name to the cmake.enabledOutputParsers enum. Decide whether it should be default-enabled or opt-in.
// package.json → contributes.configuration → cmake.enabledOutputParsers
"cmake.enabledOutputParsers": {
"type": "array",
"items": {
"type": "string",
"enum": [
"cmake",
"gcc",
"gnuld",
"msvc",
"ghs",
"diab",
"iar",
"iwyu",
"myparser" // ← add to enum
]
},
"default": [
"cmake",
"gcc",
"gnuld",
"msvc",
"ghs",
"diab"
// only add here if default-enabled
]
}Step 4: Update package.nls.json
If any user-visible setting descriptions changed, update the localization key in package.nls.json. The cmake.enabledOutputParsers description uses the key cmake-tools.configuration.cmake.enabledOutputParsers.description.
Step 5: Write tests
Add tests in test/unit-tests/diagnostics.test.ts. The test pattern:
test('Parse <tool> error', () => {
const build_consumer = new diags.CompileOutputConsumer(
new ConfigurationReader({} as ExtensionConfigurationSettings)
);
// Feed real compiler output lines
build_consumer.error('<tool-specific output line>');
// Verify diagnostics
const parser = build_consumer.compilers.myparser;
expect(parser.diagnostics).to.have.length(1);
expect(parser.diagnostics[0].severity).to.eq('error');
expect(parser.diagnostics[0].file).to.eq('expected/file.cpp');
});Step 6: CHANGELOG.md
Add an entry under the current version:
Features:
- Add `myparser` diagnostic parser for <ToolName> compiler output. [PR #XXXX](https://github.com/microsoft/vscode-cmake-tools/pull/XXXX)Currently registered parsers
Property in Compilers | Module file | Default-enabled |
gcc | src/diagnostics/gcc.ts | ✅ |
gnuld | src/diagnostics/gnu-ld.ts | ✅ |
ghs | src/diagnostics/ghs.ts | ✅ |
diab | src/diagnostics/diab.ts | ✅ |
msvc | src/diagnostics/msvc.ts | ✅ |
iar | src/diagnostics/iar.ts | ❌ opt-in |
iwyu | src/diagnostics/iwyu.ts | ❌ opt-in |
The cmake parser (in src/diagnostics/cmake.ts) is separate — it handles CMake's own configure/generate output via CMakeOutputConsumer, not build compiler output. It is listed in the enabledOutputParsers default array but is not part of the Compilers class.
Default-enabled vs opt-in
- Default-enabled parsers (
cmake,gcc,gnuld,msvc,ghs,diab) are included in the"default"array inpackage.json. Users get them automatically. - Opt-in parsers (
iar,iwyu) are in the"enum"but not in"default". Users must add them to theircmake.enabledOutputParserssetting. - Use opt-in for parsers with aggressive regexes that might false-positive on common output, or for niche toolchains.
Verification checklist
- Parser class extends
RawDiagnosticParserand exports asParser doHandleLine()returnsFeedLineResult.NotMinefor unrecognized linesdoHandleLine()returns aRawDiagnostic(notFeedLineResult.Ok) when a diagnostic is complete- Line/column numbers converted from 1-based to 0-based with
oneLess() - Registered in
Compilersclass insrc/diagnostics/build.ts - Added to
cmake.enabledOutputParsersenum inpackage.json - Default array updated (or deliberately left opt-in)
- Unit tests in
test/unit-tests/diagnostics.test.tspass yarn compilesucceedsCHANGELOG.mdentry added
See also: .github/copilot-instructions.md for project-wide conventions.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

