Skip to content

Commit b69f08d

Browse files
Prepend cmake to our diagnostics (#4766)
* prepend 'cmake' in diagnostics source to make it more obvious where the diagnostic is coming from * update changelog * prepend 'cmake' in diagnostics source to make it more obvious where the diagnostic is coming from * update changelog * fix tests * fix test
1 parent e32a469 commit b69f08d

5 files changed

Lines changed: 19 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Improvements:
2121
- Use environment variables from `cmake.environment` and `cmake.configureEnvironment` when expanding `$penv{}` macros in CMake Presets `include` paths. [#3578](https://github.com/microsoft/vscode-cmake-tools/issues/3578)
2222
- Allow preset modification commands to target CMakeUserPresets.json. The target file is determined by the focused editor, or by prompting the user when both files exist. [#4564](https://github.com/microsoft/vscode-cmake-tools/issues/4564)
2323
- Display info tooltip when hovering over CMake policy identifiers (e.g., `CMP0177`), showing the CMake version that introduced the policy, a short description, and a link to the official documentation. [#4544](https://github.com/microsoft/vscode-cmake-tools/issues/4544)
24+
- Append `cmake` to diagnostics that this extension contributes to the Problems Pane. [PR #4766](https://github.com/microsoft/vscode-cmake-tools/pull/4766)
2425

2526
Bug Fixes:
2627
- Fix configure/build sometimes using stale preset values when unsaved changes to included preset files are auto-saved before configure. The extension now explicitly refreshes presets from disk after saving, instead of relying solely on the asynchronous file watcher. [#4502](https://github.com/microsoft/vscode-cmake-tools/issues/4502)

src/diagnostics/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class CompileOutputConsumer implements OutputConsumer {
134134
}
135135

136136
const diag = new vscode.Diagnostic(raw_diag.location, raw_diag.message, severity);
137-
diag.source = source;
137+
diag.source = `cmake ${source}`;
138138
if (raw_diag.code) {
139139
diag.code = raw_diag.code;
140140
}
@@ -167,7 +167,7 @@ export class CompileOutputConsumer implements OutputConsumer {
167167
}
168168

169169
const diag = new vscode.Diagnostic(raw_diag.location, raw_diag.message, severity);
170-
diag.source = name;
170+
diag.source = `cmake ${name}`;
171171
if (raw_diag.code) {
172172
diag.code = raw_diag.code;
173173
}

src/diagnostics/cmake.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ export class CMakeOutputConsumer extends CommandConsumer {
139139
Error: vscode.DiagnosticSeverity.Error
140140
};
141141
const vsdiag = new vscode.Diagnostic(new vscode.Range(lineno, 0, lineno, 9999), full, diagmap[level]);
142-
vsdiag.source = command ? `CMake (${command})` : 'CMake';
142+
vsdiag.source = 'cmake';
143+
vsdiag.code = command ? command : undefined;
143144
vsdiag.relatedInformation = [];
144145
const filepath = util.resolvePath(filename, this.sourceDir);
145146
this._errorState.diag = {

src/presets/presetsController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ export class PresetsController implements vscode.Disposable {
15661566
const diagnostic: Diagnostic = {
15671567
severity: DiagnosticSeverity.Error,
15681568
message: error[0],
1569-
source: error[1],
1569+
source: `cmake ${error[1]}`,
15701570
range: new Range(new Position(0, 0), new Position(0, 0)) // TODO in the future we can add the range of the error - parse originalPresetsFile
15711571
};
15721572
// avoid duplicate diagnostics

test/unit-tests/diagnostics.test.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ suite('Diagnostics', () => {
8080
const diag = consumer.diagnostics[0];
8181
expect(diag.filepath).to.eq('dummyPath/CMakeLists.txt');
8282
expect(diag.diag.severity).to.eq(vscode.DiagnosticSeverity.Warning);
83-
expect(diag.diag.source).to.eq('CMake (message)');
83+
expect(diag.diag.source).to.eq('cmake');
84+
expect(diag.diag.code).to.eq('message');
8485
expect(diag.diag.message).to.match(/I am a warning!$/);
8586
expect(diag.diag.range.start.line).to.eq(13); // Line numbers are one-based
8687
});
@@ -96,7 +97,8 @@ suite('Diagnostics', () => {
9697
const diag = consumer.diagnostics[0];
9798
expect(diag.filepath).to.eq('dummyPath/CMakeLists.txt');
9899
expect(diag.diag.severity).to.eq(vscode.DiagnosticSeverity.Warning);
99-
expect(diag.diag.source).to.eq('CMake (message)');
100+
expect(diag.diag.source).to.eq('cmake');
101+
expect(diag.diag.code).to.eq('message');
100102
expect(diag.diag.message).to.match(/I am deprecated!$/);
101103
expect(diag.diag.range.start.line).to.eq(13); // Line numbers are one-based
102104
});
@@ -122,8 +124,10 @@ suite('Diagnostics', () => {
122124
expect(error.diag.severity).to.eq(vscode.DiagnosticSeverity.Error);
123125
expect(warning.diag.range.start.line).to.eq(13);
124126
expect(error.diag.range.start.line).to.eq(12);
125-
expect(warning.diag.source).to.eq('CMake (message)');
126-
expect(error.diag.source).to.eq('CMake (some_error_function)');
127+
expect(warning.diag.source).to.eq('cmake');
128+
expect(warning.diag.code).to.eq('message');
129+
expect(error.diag.source).to.eq('cmake');
130+
expect(error.diag.code).to.eq('some_error_function');
127131
expect(warning.diag.message).to.match(/I am a warning!$/);
128132
expect(error.diag.message).to.match(/I am an error!$/);
129133
});
@@ -144,7 +148,8 @@ suite('Diagnostics', () => {
144148
expect(warning.diag.severity).to.eq(vscode.DiagnosticSeverity.Warning);
145149
expect(warning.diag.message).to.match(/I'm an inner warning$/);
146150
expect(warning.diag.range.start.line).to.eq(14);
147-
expect(warning.diag.source).to.eq('CMake (message)');
151+
expect(warning.diag.source).to.eq('cmake');
152+
expect(warning.diag.code).to.eq('message');
148153
});
149154
test('Parse Author Warnings', () => {
150155
const error_output = [
@@ -163,7 +168,8 @@ suite('Diagnostics', () => {
163168
expect(warning.diag.severity).to.eq(vscode.DiagnosticSeverity.Warning);
164169
expect(warning.diag.message).to.match(/I'm an inner warning$/);
165170
expect(warning.diag.range.start.line).to.eq(14);
166-
expect(warning.diag.source).to.eq('CMake (message)');
171+
expect(warning.diag.source).to.eq('cmake');
172+
expect(warning.diag.code).to.eq('message');
167173
});
168174
test('Parse error without command name', () => {
169175
const error_output = [
@@ -179,7 +185,7 @@ suite('Diagnostics', () => {
179185
const diag = consumer.diagnostics[0];
180186
expect(diag.filepath).to.eq('dummyPath/CMakeLists.txt');
181187
expect(diag.diag.severity).to.eq(vscode.DiagnosticSeverity.Error);
182-
expect(diag.diag.source).to.eq('CMake');
188+
expect(diag.diag.source).to.eq('cmake');
183189
expect(diag.diag.range.start.line).to.eq(4);
184190
});
185191
test('Populate a diagnostic collection', () => {

0 commit comments

Comments
 (0)