From 30b0b9f44d6e1b287ea4a8f23fd5eaf5fb41a07b Mon Sep 17 00:00:00 2001 From: Kapil Borle Date: Fri, 16 Dec 2016 20:58:35 -0800 Subject: [PATCH] Clear diagnostic markers after file is closed When a user closes a file in a workspace, the extension did not clear the diagnostic markers corresponding to the closed file from the Problems window. --- .../Server/LanguageServer.cs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 8da5988b6..745cdecba 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -413,7 +413,7 @@ protected Task HandleDidOpenTextDocumentNotification( return Task.FromResult(true); } - protected Task HandleDidCloseTextDocumentNotification( + protected async Task HandleDidCloseTextDocumentNotification( TextDocumentIdentifier closeParams, EventContext eventContext) { @@ -423,11 +423,10 @@ protected Task HandleDidCloseTextDocumentNotification( if (fileToClose != null) { editorSession.Workspace.CloseFile(fileToClose); + await ClearMarkers(fileToClose, eventContext); } Logger.Write(LogLevel.Verbose, "Finished closing document."); - - return Task.FromResult(true); } protected Task HandleDidChangeTextDocumentNotification( @@ -496,15 +495,9 @@ protected async Task HandleDidChangeConfigurationNotification( // event to clear the analysis markers that they already have. if (!this.currentSettings.ScriptAnalysis.Enable.Value || settingsPathChanged) { - ScriptFileMarker[] emptyAnalysisDiagnostics = new ScriptFileMarker[0]; - foreach (var scriptFile in editorSession.Workspace.GetOpenedFiles()) { - await PublishScriptDiagnostics( - scriptFile, - emptyAnalysisDiagnostics, - this.codeActionsPerFile, - eventContext); + await ClearMarkers(scriptFile, eventContext); } } @@ -1215,6 +1208,16 @@ await PublishScriptDiagnostics( } } + private async Task ClearMarkers(ScriptFile scriptFile, EventContext eventContext) + { + // send empty diagnostic markers to clear any markers associated with the given file + await PublishScriptDiagnostics( + scriptFile, + new ScriptFileMarker[0], + this.codeActionsPerFile, + eventContext); + } + private static async Task PublishScriptDiagnostics( ScriptFile scriptFile, ScriptFileMarker[] semanticMarkers,