Skip to content

Commit e65715e

Browse files
Copilotsnehara99
andauthored
Add command to clear build diagnostics from Problems pane (#4691)
* Initial plan * Add command to clear build diagnostics from Problems pane Co-authored-by: snehara99 <[email protected]> * Add unit test for clearAll diagnostic collections Co-authored-by: snehara99 <[email protected]> * Update changelog to link PR #4691 instead of issue for feature Co-authored-by: snehara99 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: snehara99 <[email protected]>
1 parent 265af0d commit e65715e

6 files changed

Lines changed: 62 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
Features:
66
- triple: Add riscv32be riscv64be support. [#4648](https://github.com/microsoft/vscode-cmake-tools/pull/4648) [@lygstate](https://github.com/lygstate)
7+
- Add command to clear build diagnostics from the Problems pane. [#4691](https://github.com/microsoft/vscode-cmake-tools/pull/4691)
78

89
Bug Fixes:
910

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@
289289
"when": "cmake:enableFullFeatureSet",
290290
"category": "CMake"
291291
},
292+
{
293+
"command": "cmake.clearBuildDiagnostics",
294+
"title": "%cmake-tools.command.cmake.clearBuildDiagnostics.title%",
295+
"when": "cmake:enableFullFeatureSet",
296+
"category": "CMake"
297+
},
292298
{
293299
"command": "cmake.selectActiveFolder",
294300
"title": "%cmake-tools.command.cmake.selectActiveFolder.title%",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
]
2222
},
2323
"cmake-tools.command.cmake.logDiagnostics.title": "Log Diagnostics",
24+
"cmake-tools.command.cmake.clearBuildDiagnostics.title": "Clear Build Diagnostics",
2425
"cmake-tools.command.cmake.editKits.title": "Edit User-Local CMake Kits",
2526
"cmake-tools.command.cmake.scanForKits.title": "Scan for Kits",
2627
"cmake-tools.command.cmake.scanForCompilers.title": "Scan for Compilers",

src/diagnostics/collections.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ class LazyCollection implements vscode.Disposable {
3030
}
3131
this._collection = undefined;
3232
}
33+
34+
/**
35+
* Clear the diagnostics in the collection
36+
*/
37+
clear() {
38+
if (this._collection) {
39+
this._collection.clear();
40+
}
41+
}
3342
}
3443

3544
/**
@@ -66,6 +75,15 @@ class Collections {
6675
this._build.dispose();
6776
this._presets.dispose();
6877
}
78+
79+
/**
80+
* Clear all diagnostics from all collections
81+
*/
82+
clearAll() {
83+
this._cmake.clear();
84+
this._build.clear();
85+
this._presets.clear();
86+
}
6987
}
7088

7189
export const collections = new Collections();

src/extension.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { getCMakeExecutableInformation } from '@cmt/cmakeExecutable';
5050
import { DebuggerInformation, getDebuggerPipeName } from '@cmt/debug/cmakeDebugger/debuggerConfigureDriver';
5151
import { DebugConfigurationProvider, DynamicDebugConfigurationProvider } from '@cmt/debug/cmakeDebugger/debugConfigurationProvider';
5252
import { deIntegrateTestExplorer } from "@cmt/ctest";
53+
import collections from '@cmt/diagnostics/collections';
5354
import { LanguageServiceData } from './languageServices/languageServiceData';
5455

5556
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
@@ -1905,6 +1906,11 @@ export class ExtensionManager implements vscode.Disposable {
19051906
output.show();
19061907
}
19071908

1909+
async clearBuildDiagnostics() {
1910+
telemetry.logEvent("clearBuildDiagnostics");
1911+
collections.clearAll();
1912+
}
1913+
19081914
activeCMakeWorkspaceFolder(): vscode.WorkspaceFolder | undefined {
19091915
return this.getActiveProject()?.workspaceFolder;
19101916
}
@@ -2411,6 +2417,7 @@ async function setup(context: vscode.ExtensionContext, progress?: ProgressHandle
24112417
'openSettings',
24122418
'viewLog',
24132419
'logDiagnostics',
2420+
'clearBuildDiagnostics',
24142421
'compileFile',
24152422
'selectWorkspace',
24162423
'tasksBuildCommand',

test/unit-tests/diagnostics.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ExtensionConfigurationSettings, ConfigurationReader } from '../../src/c
1313
import { platformPathEquivalent, resolvePath } from '@cmt/util';
1414
import { CMakeOutputConsumer } from '@cmt/diagnostics/cmake';
1515
import { populateCollection } from '@cmt/diagnostics/util';
16+
import collections from '@cmt/diagnostics/collections';
1617
import { getTestResourceFilePath } from '@test/util';
1718

1819
function feedLines(consumer: OutputConsumer, output: string[], error: string[]) {
@@ -975,4 +976,32 @@ suite('Diagnostics', () => {
975976
expect(all2.message).to.eq('The full include-list:\n#include "array.h" // for ARRAY_SIZE');
976977
expect(all2.severity).to.eq('note');
977978
});
979+
980+
test('clearAll clears all diagnostic collections', () => {
981+
// Add some diagnostics to each collection
982+
const testUri = vscode.Uri.file('/test/file.cpp');
983+
const testDiagnostic = new vscode.Diagnostic(
984+
new vscode.Range(0, 0, 0, 10),
985+
'Test diagnostic',
986+
vscode.DiagnosticSeverity.Error
987+
);
988+
989+
// Populate the collections
990+
collections.cmake.set(testUri, [testDiagnostic]);
991+
collections.build.set(testUri, [testDiagnostic]);
992+
collections.presets.set(testUri, [testDiagnostic]);
993+
994+
// Verify diagnostics were added
995+
expect(collections.cmake.has(testUri)).to.be.true;
996+
expect(collections.build.has(testUri)).to.be.true;
997+
expect(collections.presets.has(testUri)).to.be.true;
998+
999+
// Clear all collections
1000+
collections.clearAll();
1001+
1002+
// Verify all collections are cleared
1003+
expect(collections.cmake.has(testUri)).to.be.false;
1004+
expect(collections.build.has(testUri)).to.be.false;
1005+
expect(collections.presets.has(testUri)).to.be.false;
1006+
});
9781007
});

0 commit comments

Comments
 (0)