mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Don't crash when refreshing IntelliSense cache disconnected (#260)
* Prevent null ref exception in refresh cache handler * Send refresh complete event when disconnected * Wrap handler in global try/catch
This commit is contained in:
committed by
Kevin Cunnane
parent
74ba68053b
commit
0d99b36cc1
@@ -456,56 +456,73 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
/// Handle the rebuild IntelliSense cache notification
|
/// Handle the rebuild IntelliSense cache notification
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task HandleRebuildIntelliSenseNotification(
|
public async Task HandleRebuildIntelliSenseNotification(
|
||||||
RebuildIntelliSenseParams configChangeParams,
|
RebuildIntelliSenseParams rebuildParams,
|
||||||
EventContext eventContext)
|
EventContext eventContext)
|
||||||
{
|
{
|
||||||
Logger.Write(LogLevel.Verbose, "HandleRebuildIntelliSenseNotification");
|
try
|
||||||
|
|
||||||
// Skip closing this file if the file doesn't exist
|
|
||||||
var scriptFile = this.CurrentWorkspace.GetFile(configChangeParams.OwnerUri);
|
|
||||||
if (scriptFile == null)
|
|
||||||
{
|
{
|
||||||
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<SqlToolsSettings>.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});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
ConnectionInfo connInfo;
|
|
||||||
LanguageService.ConnectionServiceInstance.TryFindConnection(
|
|
||||||
scriptFile.ClientFilePath,
|
|
||||||
out connInfo);
|
|
||||||
|
|
||||||
await Task.Run(() =>
|
|
||||||
{
|
{
|
||||||
ScriptParseInfo scriptInfo = GetScriptParseInfo(connInfo.OwnerUri, createIfNotExists: false);
|
Logger.Write(LogLevel.Error, "Unknown error " + ex.ToString());
|
||||||
if (scriptInfo != null && scriptInfo.IsConnected &&
|
await ServiceHost.Instance.SendEvent(IntelliSenseReadyNotification.Type, new IntelliSenseReadyParams() {OwnerUri = rebuildParams.OwnerUri});
|
||||||
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<SqlToolsSettings>.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});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user