Fix breaks introduced in the refactoring merge.

This commit is contained in:
Karl Burtram
2016-07-26 11:43:55 -07:00
parent 7ff6cc34a0
commit 818c9fa47f
4 changed files with 111 additions and 8 deletions

View File

@@ -45,7 +45,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting
// Initialize the shutdown activities // Initialize the shutdown activities
shutdownCallbacks = new List<ShutdownCallback>(); shutdownCallbacks = new List<ShutdownCallback>();
initializeCallbacks = new List<InitializeCallback>(); initializeCallbacks = new List<InitializeCallback>();
}
/// <summary>
/// Provide initialization that must occur after the service host is started
/// </summary>
public void Initialize()
{
// Register the requests that this service host will handle // Register the requests that this service host will handle
this.SetRequestHandler(InitializeRequest.Type, this.HandleInitializeRequest); this.SetRequestHandler(InitializeRequest.Type, this.HandleInitializeRequest);
this.SetRequestHandler(ShutdownRequest.Type, this.HandleShutdownRequest); this.SetRequestHandler(ShutdownRequest.Type, this.HandleShutdownRequest);

View File

@@ -17,6 +17,7 @@ using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts;
using System.Linq; using System.Linq;
using Microsoft.SqlServer.Management.SqlParser.Parser; using Microsoft.SqlServer.Management.SqlParser.Parser;
using Location = Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts.Location; using Location = Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts.Location;
using Microsoft.SqlTools.ServiceLayer.Connection;
namespace Microsoft.SqlTools.ServiceLayer.LanguageServices namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
{ {
@@ -97,6 +98,15 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
// Register the configuration update handler // Register the configuration update handler
WorkspaceService<SqlToolsSettings>.Instance.RegisterConfigChangeCallback(HandleDidChangeConfigurationNotification); WorkspaceService<SqlToolsSettings>.Instance.RegisterConfigChangeCallback(HandleDidChangeConfigurationNotification);
// Register the file change update handler
WorkspaceService<SqlToolsSettings>.Instance.RegisterTextDocChangeCallback(HandleDidChangeTextDocumentNotification);
// Register the file open update handler
WorkspaceService<SqlToolsSettings>.Instance.RegisterTextDocOpenCallback(HandleDidOpenTextDocumentNotification);
// register an OnConnection callback
ConnectionService.Instance.RegisterOnConnectionTask(OnConnection);
// Store the SqlToolsContext for future use // Store the SqlToolsContext for future use
Context = context; Context = context;
} }
@@ -165,8 +175,11 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
TextDocumentPosition textDocumentPosition, TextDocumentPosition textDocumentPosition,
RequestContext<CompletionItem[]> requestContext) RequestContext<CompletionItem[]> requestContext)
{ {
Logger.Write(LogLevel.Verbose, "HandleCompletionRequest"); Logger.Write(LogLevel.Verbose, "HandleCompletionRequest");
await Task.FromResult(true);
// get the current list of completion items and return to client
var completionItems = AutoCompleteService.Instance.GetCompletionItems(textDocumentPosition);
await requestContext.SendResult(completionItems);
} }
private static async Task HandleCompletionResolveRequest( private static async Task HandleCompletionResolveRequest(
@@ -221,6 +234,45 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
#region Handlers for Events from Other Services #region Handlers for Events from Other Services
/// <summary>
/// Handle the file open notification
/// </summary>
/// <param name="scriptFile"></param>
/// <param name="eventContext"></param>
/// <returns></returns>
public async Task HandleDidOpenTextDocumentNotification(
ScriptFile scriptFile,
EventContext eventContext)
{
await this.RunScriptDiagnostics(
new ScriptFile[] { scriptFile },
eventContext);
await Task.FromResult(true);
}
/// <summary>
/// Handles text document change events
/// </summary>
/// <param name="textChangeParams"></param>
/// <param name="eventContext"></param>
/// <returns></returns>
public async Task HandleDidChangeTextDocumentNotification(ScriptFile[] changedFiles, EventContext eventContext)
{
await this.RunScriptDiagnostics(
changedFiles.ToArray(),
eventContext);
await Task.FromResult(true);
}
/// <summary>
/// Handle the file configuration change notification
/// </summary>
/// <param name="newSettings"></param>
/// <param name="oldSettings"></param>
/// <param name="eventContext"></param>
public async Task HandleDidChangeConfigurationNotification( public async Task HandleDidChangeConfigurationNotification(
SqlToolsSettings newSettings, SqlToolsSettings newSettings,
SqlToolsSettings oldSettings, SqlToolsSettings oldSettings,
@@ -251,7 +303,17 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
CurrentSettings.EnableProfileLoading = newSettings.EnableProfileLoading; CurrentSettings.EnableProfileLoading = newSettings.EnableProfileLoading;
CurrentSettings.ScriptAnalysis.Update(newSettings.ScriptAnalysis, CurrentWorkspace.WorkspacePath); CurrentSettings.ScriptAnalysis.Update(newSettings.ScriptAnalysis, CurrentWorkspace.WorkspacePath);
} }
/// <summary>
/// Callback for when a user connection is done processing
/// </summary>
/// <param name="sqlConnection"></param>
public async Task OnConnection(ISqlConnection sqlConnection)
{
await AutoCompleteService.Instance.UpdateAutoCompleteCache(sqlConnection);
await Task.FromResult(true);
}
#endregion #endregion
#region Private Helpers #region Private Helpers

View File

@@ -7,6 +7,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.SqlContext; using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.ServiceLayer.WorkspaceServices; using Microsoft.SqlTools.ServiceLayer.WorkspaceServices;
using Microsoft.SqlTools.ServiceLayer.LanguageServices; using Microsoft.SqlTools.ServiceLayer.LanguageServices;
using Microsoft.SqlTools.ServiceLayer.Connection;
namespace Microsoft.SqlTools.ServiceLayer namespace Microsoft.SqlTools.ServiceLayer
{ {
@@ -37,13 +38,16 @@ namespace Microsoft.SqlTools.ServiceLayer
// Grab the instance of the service host // Grab the instance of the service host
ServiceHost serviceHost = ServiceHost.Instance; ServiceHost serviceHost = ServiceHost.Instance;
// Start the service
serviceHost.Start().Wait();
// Initialize the services that will be hosted here // Initialize the services that will be hosted here
WorkspaceService<SqlToolsSettings>.Instance.InitializeService(serviceHost); WorkspaceService<SqlToolsSettings>.Instance.InitializeService(serviceHost);
AutoCompleteService.Instance.InitializeService(serviceHost); AutoCompleteService.Instance.InitializeService(serviceHost);
LanguageService.Instance.InitializeService(serviceHost, sqlToolsContext); LanguageService.Instance.InitializeService(serviceHost, sqlToolsContext);
ConnectionService.Instance.Initialize(serviceHost);
// Start the service serviceHost.Initialize();
serviceHost.Start().Wait();
serviceHost.WaitForExit(); serviceHost.WaitForExit();
} }
} }

View File

@@ -43,6 +43,7 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
{ {
ConfigChangeCallbacks = new List<ConfigChangeCallback>(); ConfigChangeCallbacks = new List<ConfigChangeCallback>();
TextDocChangeCallbacks = new List<TextDocChangeCallback>(); TextDocChangeCallbacks = new List<TextDocChangeCallback>();
TextDocOpenCallbacks = new List<TextDocOpenCallback>();
} }
#endregion #endregion
@@ -69,6 +70,13 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
/// <param name="eventContext">Context of the event raised for the changed files</param> /// <param name="eventContext">Context of the event raised for the changed files</param>
public delegate Task TextDocChangeCallback(ScriptFile[] changedFiles, EventContext eventContext); public delegate Task TextDocChangeCallback(ScriptFile[] changedFiles, EventContext eventContext);
/// <summary>
/// Delegate for callbacks that occur when a text document is opened
/// </summary>
/// <param name="openFile">File that was opened</param>
/// <param name="eventContext">Context of the event raised for the changed files</param>
public delegate Task TextDocOpenCallback(ScriptFile openFile, EventContext eventContext);
/// <summary> /// <summary>
/// List of callbacks to call when the configuration of the workspace changes /// List of callbacks to call when the configuration of the workspace changes
/// </summary> /// </summary>
@@ -79,6 +87,12 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
/// </summary> /// </summary>
private List<TextDocChangeCallback> TextDocChangeCallbacks { get; set; } private List<TextDocChangeCallback> TextDocChangeCallbacks { get; set; }
/// <summary>
/// List of callbacks to call when a text document is opened
/// </summary>
private List<TextDocOpenCallback> TextDocOpenCallbacks { get; set; }
#endregion #endregion
#region Public Methods #region Public Methods
@@ -140,6 +154,15 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
TextDocChangeCallbacks.Add(task); TextDocChangeCallbacks.Add(task);
} }
/// <summary>
/// Adds a new task to be called when a file is opened
/// </summary>
/// <param name="task">Delegate to call when a document is opened</param>
public void RegisterTextDocOpenCallback(TextDocOpenCallback task)
{
TextDocOpenCallbacks.Add(task);
}
#endregion #endregion
#region Event Handlers #region Event Handlers
@@ -158,7 +181,7 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
// A text change notification can batch multiple change requests // A text change notification can batch multiple change requests
foreach (var textChange in textChangeParams.ContentChanges) foreach (var textChange in textChangeParams.ContentChanges)
{ {
string fileUri = textChangeParams.TextDocument.Uri; string fileUri = textChangeParams.Uri ?? textChangeParams.TextDocument.Uri;
msg.AppendLine(String.Format(" File: {0}", fileUri)); msg.AppendLine(String.Format(" File: {0}", fileUri));
ScriptFile changedFile = Workspace.GetFile(fileUri); ScriptFile changedFile = Workspace.GetFile(fileUri);
@@ -177,12 +200,20 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
return Task.WhenAll(handlers); return Task.WhenAll(handlers);
} }
protected Task HandleDidOpenTextDocumentNotification( protected async Task HandleDidOpenTextDocumentNotification(
DidOpenTextDocumentNotification openParams, DidOpenTextDocumentNotification openParams,
EventContext eventContext) EventContext eventContext)
{ {
Logger.Write(LogLevel.Verbose, "HandleDidOpenTextDocumentNotification"); Logger.Write(LogLevel.Verbose, "HandleDidOpenTextDocumentNotification");
return Task.FromResult(true);
// read the SQL file contents into the ScriptFile
ScriptFile openedFile = Workspace.GetFileBuffer(openParams.Uri, openParams.Text);
// Propagate the changes to the event handlers
var textDocOpenTasks = TextDocOpenCallbacks.Select(
t => t(openedFile, eventContext));
await Task.WhenAll(textDocOpenTasks);
} }
protected Task HandleDidCloseTextDocumentNotification( protected Task HandleDidCloseTextDocumentNotification(