Skip to content

Clear diagnostic markers after file is closed #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ protected Task HandleDidOpenTextDocumentNotification(
return Task.FromResult(true);
}

protected Task HandleDidCloseTextDocumentNotification(
protected async Task HandleDidCloseTextDocumentNotification(
TextDocumentIdentifier closeParams,
EventContext eventContext)
{
Expand All @@ -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(
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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,
Expand Down