Skip to content

Commit aca01d1

Browse files
Fix diagnostics where no command is passed (#4765)
* fix diagnostics where no command is passed * update changelog
1 parent 3b8fe87 commit aca01d1

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Bug Fixes:
4141
- Fix `$comment` not being accepted inside a cacheVariable object in CMake presets. [#4600](https://github.com/microsoft/vscode-cmake-tools/issues/4600)
4242
- Fix kits from `cmake.additionalKits` not being shown when `cmake.showSystemKits` is `false`. [#4651](https://github.com/microsoft/vscode-cmake-tools/issues/4651)
4343
- Fix how `jobs` is handled in build presets. Also update how `cmake.parallelJobs` is handled as a fallback when a build preset does not define `jobs`. [#4176](https://github.com/microsoft/vscode-cmake-tools/issues/4176)
44+
- Fix diagnostics to handle when there isn't a command in the error output. [PR #4765](https://github.com/microsoft/vscode-cmake-tools/pull/4765)
4445

4546
## 1.22.28
4647

src/diagnostics/cmake.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ export class CMakeOutputConsumer extends CommandConsumer {
106106
// Switch on the state to implement our crude FSM
107107
switch (this._errorState.state) {
108108
case 'init': {
109-
const re = /CMake (.*?)(?: \(dev\))? at (.*?):(\d+) \((.*?)\):/;
109+
const re = /CMake (.*?)(?: \(dev\))? at (.*?):(\d+)(?: \((.*?)\))?:/;
110110
const result = re.exec(line);
111111
if (result) {
112-
// We have encountered and error
112+
// We have encountered an error
113113
const [full, level, filename, linestr, command] = result;
114114
const lineno = oneLess(linestr);
115115
const diagmap: { [k: string]: vscode.DiagnosticSeverity } = {
@@ -118,7 +118,7 @@ export class CMakeOutputConsumer extends CommandConsumer {
118118
Error: vscode.DiagnosticSeverity.Error
119119
};
120120
const vsdiag = new vscode.Diagnostic(new vscode.Range(lineno, 0, lineno, 9999), full, diagmap[level]);
121-
vsdiag.source = `CMake (${command})`;
121+
vsdiag.source = command ? `CMake (${command})` : 'CMake';
122122
vsdiag.relatedInformation = [];
123123
const filepath = util.resolvePath(filename, this.sourceDir);
124124
this._errorState.diag = {

test/unit-tests/diagnostics.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,23 @@ suite('Diagnostics', () => {
165165
expect(warning.diag.range.start.line).to.eq(14);
166166
expect(warning.diag.source).to.eq('CMake (message)');
167167
});
168+
test('Parse error without command name', () => {
169+
const error_output = [
170+
'CMake Error at CMakeLists.txt:5:',
171+
' Parse error. Expected "(", got newline with text "',
172+
'',
173+
' ".',
174+
'',
175+
''
176+
];
177+
feedLines(consumer, [], error_output);
178+
expect(consumer.diagnostics.length).to.eq(1);
179+
const diag = consumer.diagnostics[0];
180+
expect(diag.filepath).to.eq('dummyPath/CMakeLists.txt');
181+
expect(diag.diag.severity).to.eq(vscode.DiagnosticSeverity.Error);
182+
expect(diag.diag.source).to.eq('CMake');
183+
expect(diag.diag.range.start.line).to.eq(4);
184+
});
168185
test('Populate a diagnostic collection', () => {
169186
const error_output = [
170187
'CMake Warning at CMakeLists.txt:14 (message):',

0 commit comments

Comments
 (0)