diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs index 171a2647..db02ace3 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs @@ -456,56 +456,73 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices /// Handle the rebuild IntelliSense cache notification /// public async Task HandleRebuildIntelliSenseNotification( - RebuildIntelliSenseParams configChangeParams, + RebuildIntelliSenseParams rebuildParams, EventContext eventContext) { - Logger.Write(LogLevel.Verbose, "HandleRebuildIntelliSenseNotification"); - - // Skip closing this file if the file doesn't exist - var scriptFile = this.CurrentWorkspace.GetFile(configChangeParams.OwnerUri); - if (scriptFile == null) + try { - return; + Logger.Write(LogLevel.Verbose, "HandleRebuildIntelliSenseNotification"); + + // Skip closing this file if the file doesn't exist + var scriptFile = this.CurrentWorkspace.GetFile(rebuildParams.OwnerUri); + if (scriptFile == null) + { + return; + } + + ConnectionInfo connInfo; + LanguageService.ConnectionServiceInstance.TryFindConnection( + scriptFile.ClientFilePath, + out connInfo); + + // check that there is an active connection for the current editor + if (connInfo != null) + { + await Task.Run(() => + { + ScriptParseInfo scriptInfo = GetScriptParseInfo(connInfo.OwnerUri, createIfNotExists: false); + if (scriptInfo != null && scriptInfo.IsConnected && + Monitor.TryEnter(scriptInfo.BuildingMetadataLock, LanguageService.OnConnectionWaitTimeout)) + { + try + { + this.BindingQueue.AddConnectionContext(connInfo, overwrite: true); + } + catch (Exception ex) + { + Logger.Write(LogLevel.Error, "Unknown error " + ex.ToString()); + } + finally + { + // Set Metadata Build event to Signal state. + Monitor.Exit(scriptInfo.BuildingMetadataLock); + } + } + + // if not in the preview window and diagnostics are enabled then run diagnostics + if (!IsPreviewWindow(scriptFile) + && WorkspaceService.Instance.CurrentSettings.IsDiagnositicsEnabled) + { + RunScriptDiagnostics( + new ScriptFile[] { scriptFile }, + eventContext); + } + + // Send a notification to signal that autocomplete is ready + ServiceHost.Instance.SendEvent(IntelliSenseReadyNotification.Type, new IntelliSenseReadyParams() {OwnerUri = connInfo.OwnerUri}); + }); + } + else + { + // Send a notification to signal that autocomplete is ready + await ServiceHost.Instance.SendEvent(IntelliSenseReadyNotification.Type, new IntelliSenseReadyParams() {OwnerUri = rebuildParams.OwnerUri}); + } } - - ConnectionInfo connInfo; - LanguageService.ConnectionServiceInstance.TryFindConnection( - scriptFile.ClientFilePath, - out connInfo); - - await Task.Run(() => + catch (Exception ex) { - ScriptParseInfo scriptInfo = GetScriptParseInfo(connInfo.OwnerUri, createIfNotExists: false); - if (scriptInfo != null && scriptInfo.IsConnected && - Monitor.TryEnter(scriptInfo.BuildingMetadataLock, LanguageService.OnConnectionWaitTimeout)) - { - try - { - this.BindingQueue.AddConnectionContext(connInfo, overwrite: true); - } - catch (Exception ex) - { - Logger.Write(LogLevel.Error, "Unknown error " + ex.ToString()); - } - finally - { - // Set Metadata Build event to Signal state. - Monitor.Exit(scriptInfo.BuildingMetadataLock); - } - } - - // if not in the preview window and diagnostics are enabled then run diagnostics - if (!IsPreviewWindow(scriptFile) - && WorkspaceService.Instance.CurrentSettings.IsDiagnositicsEnabled) - { - RunScriptDiagnostics( - new ScriptFile[] { scriptFile }, - eventContext); - } - - // Send a notification to signal that autocomplete is ready - ServiceHost.Instance.SendEvent(IntelliSenseReadyNotification.Type, new IntelliSenseReadyParams() {OwnerUri = connInfo.OwnerUri}); - }); + Logger.Write(LogLevel.Error, "Unknown error " + ex.ToString()); + await ServiceHost.Instance.SendEvent(IntelliSenseReadyNotification.Type, new IntelliSenseReadyParams() {OwnerUri = rebuildParams.OwnerUri}); + } } ///