mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Renaming callbacks to be more sane
This commit is contained in:
@@ -4,9 +4,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.SqlTools.EditorServices.Utility;
|
using Microsoft.SqlTools.EditorServices.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||||
@@ -27,12 +27,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting
|
|||||||
private static readonly Lazy<ServiceHost> instance = new Lazy<ServiceHost>(() => new ServiceHost());
|
private static readonly Lazy<ServiceHost> instance = new Lazy<ServiceHost>(() => new ServiceHost());
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates or retrieves the current instance of the ServiceHost
|
/// Current instance of the ServiceHost
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Instance of the service host</returns>
|
public static ServiceHost Instance
|
||||||
public static ServiceHost Create()
|
|
||||||
{
|
{
|
||||||
return instance.Value;
|
get { return instance.Value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -42,8 +41,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting
|
|||||||
private ServiceHost() : base(new StdioServerChannel())
|
private ServiceHost() : base(new StdioServerChannel())
|
||||||
{
|
{
|
||||||
// Initialize the shutdown activities
|
// Initialize the shutdown activities
|
||||||
shutdownActivities = new List<ShutdownHandler>();
|
shutdownCallbacks = new List<ShutdownCallback>();
|
||||||
initializeActivities = new List<InitializeHandler>();
|
initializeCallbacks = new List<InitializeCallback>();
|
||||||
|
|
||||||
// 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);
|
||||||
@@ -54,34 +53,34 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting
|
|||||||
|
|
||||||
#region Member Variables
|
#region Member Variables
|
||||||
|
|
||||||
public delegate Task ShutdownHandler(object shutdownParams, RequestContext<object> shutdownRequestContext);
|
public delegate Task ShutdownCallback(object shutdownParams, RequestContext<object> shutdownRequestContext);
|
||||||
|
|
||||||
public delegate Task InitializeHandler(InitializeRequest startupParams, RequestContext<InitializeResult> requestContext);
|
public delegate Task InitializeCallback(InitializeRequest startupParams, RequestContext<InitializeResult> requestContext);
|
||||||
|
|
||||||
private readonly List<ShutdownHandler> shutdownActivities;
|
private readonly List<ShutdownCallback> shutdownCallbacks;
|
||||||
|
|
||||||
private readonly List<InitializeHandler> initializeActivities;
|
private readonly List<InitializeCallback> initializeCallbacks;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a new method to be called when the shutdown request is submitted
|
/// Adds a new callback to be called when the shutdown request is submitted
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="activity"></param>
|
/// <param name="callback">Callback to perform when a shutdown request is submitted</param>
|
||||||
public void RegisterShutdownTask(ShutdownHandler activity)
|
public void RegisterShutdownTask(ShutdownCallback callback)
|
||||||
{
|
{
|
||||||
shutdownActivities.Add(activity);
|
shutdownCallbacks.Add(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a new method to be called when the initialize request is submitted
|
/// Add a new method to be called when the initialize request is submitted
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="activity"></param>
|
/// <param name="callback">Callback to perform when an initialize request is submitted</param>
|
||||||
public void RegisterInitializeTask(InitializeHandler activity)
|
public void RegisterInitializeTask(InitializeCallback callback)
|
||||||
{
|
{
|
||||||
initializeActivities.Add(activity);
|
initializeCallbacks.Add(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -96,7 +95,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting
|
|||||||
Logger.Write(LogLevel.Normal, "Service host is shutting down...");
|
Logger.Write(LogLevel.Normal, "Service host is shutting down...");
|
||||||
|
|
||||||
// Call all the shutdown methods provided by the service components
|
// Call all the shutdown methods provided by the service components
|
||||||
Task[] shutdownTasks = shutdownActivities.Select(t => t(shutdownParams, requestContext)).ToArray();
|
Task[] shutdownTasks = shutdownCallbacks.Select(t => t(shutdownParams, requestContext)).ToArray();
|
||||||
await Task.WhenAll(shutdownTasks);
|
await Task.WhenAll(shutdownTasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +110,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting
|
|||||||
Logger.Write(LogLevel.Verbose, "HandleInitializationRequest");
|
Logger.Write(LogLevel.Verbose, "HandleInitializationRequest");
|
||||||
|
|
||||||
// Call all tasks that registered on the initialize request
|
// Call all tasks that registered on the initialize request
|
||||||
var initializeTasks = initializeActivities.Select(t => t(initializeParams, requestContext));
|
var initializeTasks = initializeCallbacks.Select(t => t(initializeParams, requestContext));
|
||||||
await Task.WhenAll(initializeTasks);
|
await Task.WhenAll(initializeTasks);
|
||||||
|
|
||||||
// TODO: Figure out where this needs to go to be agnostic of the language
|
// TODO: Figure out where this needs to go to be agnostic of the language
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Register the configuration update handler
|
// Register the configuration update handler
|
||||||
WorkspaceService<SqlToolsSettings>.Instance.RegisterDidChangeConfigurationNotificationTask(HandleDidChangeConfigurationNotification);
|
WorkspaceService<SqlToolsSettings>.Instance.RegisterConfigChangeCallback(HandleDidChangeConfigurationNotification);
|
||||||
|
|
||||||
// Store the SqlToolsContext for future use
|
// Store the SqlToolsContext for future use
|
||||||
Context = context;
|
Context = context;
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ namespace Microsoft.SqlTools.ServiceLayer
|
|||||||
var profilePaths = new ProfilePaths(hostProfileId, "baseAllUsersPath", "baseCurrentUserPath");
|
var profilePaths = new ProfilePaths(hostProfileId, "baseAllUsersPath", "baseCurrentUserPath");
|
||||||
SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails, profilePaths);
|
SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails, profilePaths);
|
||||||
|
|
||||||
// Create the service host
|
// Grab the instance of the service host
|
||||||
ServiceHost serviceHost = ServiceHost.Create();
|
ServiceHost serviceHost = ServiceHost.Instance;
|
||||||
|
|
||||||
// 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);
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlTools.EditorServices.Utility;
|
using Microsoft.SqlTools.EditorServices.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
|
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
|
||||||
{
|
{
|
||||||
@@ -29,8 +29,8 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
|
|||||||
|
|
||||||
private WorkspaceService()
|
private WorkspaceService()
|
||||||
{
|
{
|
||||||
ConfigurationNotificationHandlers = new List<DidChangeConfigurationNotificationHandler>();
|
ConfigChangeCallbacks = new List<ConfigChangeCallback>();
|
||||||
TextDocumentChangeHandlers = new List<DidChangeTextDocumentNotificationTask>();
|
TextDocChangeCallbacks = new List<TextDocChangeCallback>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -41,12 +41,31 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
|
|||||||
|
|
||||||
public TConfig CurrentSettings { get; private set; }
|
public TConfig CurrentSettings { get; private set; }
|
||||||
|
|
||||||
public delegate Task DidChangeConfigurationNotificationHandler(TConfig newSettings, TConfig oldSettings, EventContext eventContext);
|
/// <summary>
|
||||||
|
/// Delegate for callbacks that occur when the configuration for the workspace changes
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newSettings">The settings that were just set</param>
|
||||||
|
/// <param name="oldSettings">The settings before they were changed</param>
|
||||||
|
/// <param name="eventContext">Context of the event that triggered the callback</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public delegate Task ConfigChangeCallback(TConfig newSettings, TConfig oldSettings, EventContext eventContext);
|
||||||
|
|
||||||
public delegate Task DidChangeTextDocumentNotificationTask(ScriptFile[] changedFiles, EventContext eventContext);
|
/// <summary>
|
||||||
|
/// Delegate for callbacks that occur when the current text document changes
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="changedFiles">Array of files that changed</param>
|
||||||
|
/// <param name="eventContext">Context of the event raised for the changed files</param>
|
||||||
|
public delegate Task TextDocChangeCallback(ScriptFile[] changedFiles, EventContext eventContext);
|
||||||
|
|
||||||
private List<DidChangeConfigurationNotificationHandler> ConfigurationNotificationHandlers { get; set; }
|
/// <summary>
|
||||||
private List<DidChangeTextDocumentNotificationTask> TextDocumentChangeHandlers { get; set; }
|
/// List of callbacks to call when the configuration of the workspace changes
|
||||||
|
/// </summary>
|
||||||
|
private List<ConfigChangeCallback> ConfigChangeCallbacks { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List of callbacks to call when the current text document changes
|
||||||
|
/// </summary>
|
||||||
|
private List<TextDocChangeCallback> TextDocChangeCallbacks { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -95,18 +114,18 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
|
|||||||
/// handle changing configuration and changing the current configuration.
|
/// handle changing configuration and changing the current configuration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="task">Task to handle the request</param>
|
/// <param name="task">Task to handle the request</param>
|
||||||
public void RegisterDidChangeConfigurationNotificationTask(DidChangeConfigurationNotificationHandler task)
|
public void RegisterConfigChangeCallback(ConfigChangeCallback task)
|
||||||
{
|
{
|
||||||
ConfigurationNotificationHandlers.Add(task);
|
ConfigChangeCallbacks.Add(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a new task to be called when the text of a document changes.
|
/// Adds a new task to be called when the text of a document changes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="task">Delegate to call when the document changes</param>
|
/// <param name="task">Delegate to call when the document changes</param>
|
||||||
public void RegisterDidChangeTextDocumentNotificationTask(DidChangeTextDocumentNotificationTask task)
|
public void RegisterTextDocChangeCallback(TextDocChangeCallback task)
|
||||||
{
|
{
|
||||||
TextDocumentChangeHandlers.Add(task);
|
TextDocChangeCallbacks.Add(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -145,7 +164,7 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
|
|||||||
|
|
||||||
Logger.Write(LogLevel.Verbose, msg.ToString());
|
Logger.Write(LogLevel.Verbose, msg.ToString());
|
||||||
|
|
||||||
var handlers = TextDocumentChangeHandlers.Select(t => t(changedFiles.ToArray(), eventContext));
|
var handlers = TextDocChangeCallbacks.Select(t => t(changedFiles.ToArray(), eventContext));
|
||||||
return Task.WhenAll(handlers);
|
return Task.WhenAll(handlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +196,7 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
|
|||||||
Logger.Write(LogLevel.Verbose, "HandleDidChangeConfigurationNotification");
|
Logger.Write(LogLevel.Verbose, "HandleDidChangeConfigurationNotification");
|
||||||
|
|
||||||
// Propagate the changes to the event handlers
|
// Propagate the changes to the event handlers
|
||||||
var configUpdateTasks = ConfigurationNotificationHandlers.Select(
|
var configUpdateTasks = ConfigChangeCallbacks.Select(
|
||||||
t => t(configChangeParams.Settings, CurrentSettings, eventContext));
|
t => t(configChangeParams.Settings, CurrentSettings, eventContext));
|
||||||
await Task.WhenAll(configUpdateTasks);
|
await Task.WhenAll(configUpdateTasks);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user