Clear and rebuild IntelliSense cache (#238)

* Stage changes to other machine

* IntelliSense cache rebuild command

* Move to other machine

* Add a test for overwriting binding queue.

* Move event handler into lanaguageservice.cs
This commit is contained in:
Karl Burtram
2017-02-16 12:23:26 -08:00
committed by GitHub
parent 6f8fc51d6f
commit 5d0c187684
8 changed files with 148 additions and 8 deletions

View File

@@ -212,6 +212,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
serviceHost.SetRequestHandler(HoverRequest.Type, HandleHoverRequest);
serviceHost.SetRequestHandler(CompletionRequest.Type, HandleCompletionRequest);
serviceHost.SetRequestHandler(DefinitionRequest.Type, HandleDefinitionRequest);
serviceHost.SetEventHandler(RebuildIntelliSenseNotification.Type, HandleRebuildIntelliSenseNotification);
// Register a no-op shutdown task for validation of the shutdown logic
serviceHost.RegisterShutdownTask(async (shutdownParams, shutdownRequestContext) =>
@@ -442,6 +443,62 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
await Task.FromResult(true);
}
/// <summary>
/// Handle the rebuild IntelliSense cache notification
/// </summary>
public async Task HandleRebuildIntelliSenseNotification(
RebuildIntelliSenseParams configChangeParams,
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)
{
return;
}
ConnectionInfo connInfo;
LanguageService.ConnectionServiceInstance.TryFindConnection(
scriptFile.ClientFilePath,
out connInfo);
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});
});
}
/// <summary>
/// Handle the file configuration change notification
/// </summary>