diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs
index 0bbdf45f..97ed65a2 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs
@@ -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
}
}
+ ///
+ /// Handle the file close notification
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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
+ }
+ }
+
///
/// Handle the rebuild IntelliSense cache notification
///