added task to clear diagnostics when file closed (#1050)

* added task to clear diagnostics when file closed

* remove unnecessary return statement
This commit is contained in:
Lucy Zhang
2020-08-17 08:04:09 -07:00
committed by GitHub
parent 148b6e398d
commit 6c24f72f48

View File

@@ -288,6 +288,9 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
// Register the file open update handler
WorkspaceServiceInstance.RegisterTextDocOpenCallback(HandleDidOpenTextDocumentNotification);
// Register the file open update handler
WorkspaceServiceInstance.RegisterTextDocCloseCallback(HandleDidCloseTextDocumentNotification);
// Register a callback for when a connection is created
ConnectionServiceInstance.RegisterOnConnectionTask(UpdateLanguageServiceOnConnection);
@@ -701,6 +704,34 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
}
}
/// <summary>
/// Handle the file close notification
/// </summary>
/// <param name="uri"></param>
/// <param name="scriptFile"></param>
/// <param name="eventContext"></param>
/// <returns></returns>
public async Task HandleDidCloseTextDocumentNotification(
string uri,
ScriptFile scriptFile,
EventContext eventContext)
{
try
{
// if not in the preview window and diagnostics are enabled then clear diagnostics
if (!IsPreviewWindow(scriptFile)
&& CurrentWorkspaceSettings.IsDiagnosticsEnabled)
{
await DiagnosticsHelper.ClearScriptDiagnostics(uri, eventContext);
}
}
catch (Exception ex)
{
Logger.Write(TraceEventType.Error, "Unknown error " + ex.ToString());
// TODO: need mechanism return errors from event handlers
}
}
/// <summary>
/// Handle the rebuild IntelliSense cache notification
/// </summary>