Skip to content

Commit ed05df2

Browse files
authored
Merge pull request #322 from PowerShell/kapilmb/clear-problems-window
Clear diagnostic markers after file is closed
2 parents 2dafaff + 30b0b9f commit ed05df2

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

+13-10
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ protected Task HandleDidOpenTextDocumentNotification(
413413
return Task.FromResult(true);
414414
}
415415

416-
protected Task HandleDidCloseTextDocumentNotification(
416+
protected async Task HandleDidCloseTextDocumentNotification(
417417
TextDocumentIdentifier closeParams,
418418
EventContext eventContext)
419419
{
@@ -423,11 +423,10 @@ protected Task HandleDidCloseTextDocumentNotification(
423423
if (fileToClose != null)
424424
{
425425
editorSession.Workspace.CloseFile(fileToClose);
426+
await ClearMarkers(fileToClose, eventContext);
426427
}
427428

428429
Logger.Write(LogLevel.Verbose, "Finished closing document.");
429-
430-
return Task.FromResult(true);
431430
}
432431

433432
protected Task HandleDidChangeTextDocumentNotification(
@@ -496,15 +495,9 @@ protected async Task HandleDidChangeConfigurationNotification(
496495
// event to clear the analysis markers that they already have.
497496
if (!this.currentSettings.ScriptAnalysis.Enable.Value || settingsPathChanged)
498497
{
499-
ScriptFileMarker[] emptyAnalysisDiagnostics = new ScriptFileMarker[0];
500-
501498
foreach (var scriptFile in editorSession.Workspace.GetOpenedFiles())
502499
{
503-
await PublishScriptDiagnostics(
504-
scriptFile,
505-
emptyAnalysisDiagnostics,
506-
this.codeActionsPerFile,
507-
eventContext);
500+
await ClearMarkers(scriptFile, eventContext);
508501
}
509502
}
510503

@@ -1215,6 +1208,16 @@ await PublishScriptDiagnostics(
12151208
}
12161209
}
12171210

1211+
private async Task ClearMarkers(ScriptFile scriptFile, EventContext eventContext)
1212+
{
1213+
// send empty diagnostic markers to clear any markers associated with the given file
1214+
await PublishScriptDiagnostics(
1215+
scriptFile,
1216+
new ScriptFileMarker[0],
1217+
this.codeActionsPerFile,
1218+
eventContext);
1219+
}
1220+
12181221
private static async Task PublishScriptDiagnostics(
12191222
ScriptFile scriptFile,
12201223
ScriptFileMarker[] semanticMarkers,

0 commit comments

Comments
 (0)