diff --git a/client/src/extension.ts b/client/src/extension.ts index a56e63ac..a25146d2 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -127,7 +127,17 @@ export async function activate(context: ExtensionContext) { } ); - context.subscriptions.push(previewDisposable); + let clearAllDiagnostics = commands.registerCommand( + "extension.clearAllDiagnostics", + () => { + languageClient.sendNotification("cfn/clearAllDiagnostics"); + } + ); + + context.subscriptions.push( + previewDisposable, + clearAllDiagnostics + ); } function reloadSidePreview(file: string, languageClient: LanguageClient) { diff --git a/package.json b/package.json index 5598ef69..9cb119d0 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,7 @@ "main": "./client/out/extension", "activationEvents": [ "onLanguage:yaml", - "onLanguage:json", - "onCommand:extension.sidePreview" + "onLanguage:json" ], "extensionDependencies": [], "homepage": "https://github.com/awslabs/aws-cfn-lint-visual-studio-code/blob/main/README.md", @@ -85,6 +84,10 @@ "dark": "./resources/open-preview-dark.svg", "light": "./resources/open-preview-light.svg" } + }, + { + "command": "extension.clearAllDiagnostics", + "title": "Clear CloudFormation template issues" } ], "menus": { diff --git a/server/src/requestTypes.ts b/server/src/requestTypes.ts index bedd3678..f4acd633 100644 --- a/server/src/requestTypes.ts +++ b/server/src/requestTypes.ts @@ -39,3 +39,9 @@ export namespace ValidateCfnLintVersion { "cfn/validateCfnLintVersion" ); } + +export namespace ClearAllDiagnostics { + export const type: NotificationType<{}> = new NotificationType( + "cfn/clearAllDiagnostics" + ); +} diff --git a/server/src/server/handlers/notificationHandler.ts b/server/src/server/handlers/notificationHandler.ts index ec2f2367..bb16057e 100644 --- a/server/src/server/handlers/notificationHandler.ts +++ b/server/src/server/handlers/notificationHandler.ts @@ -18,6 +18,7 @@ import { RequestPreview, PreviewClosed, ValidateCfnLintVersion, + ClearAllDiagnostics, } from "../../requestTypes"; import { SettingsState } from "../../cfnSettings"; import { ValidationHandler } from "./validationHandler"; @@ -49,6 +50,11 @@ export class NotificationHandler { this.connection.onNotification(ValidateCfnLintVersion.type, () => this.validateCfnLintVersion() ); + this.connection.onNotification(ClearAllDiagnostics.type, () => { + this.cfnSettings.documents.all().forEach((document) => { + this.connection.sendDiagnostics({ uri: document.uri, diagnostics: [] }); + }); + }); } private requestPreview(uri: string): void {