mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
First major portion of refactor 90%
The overall architecture of the service host is completed here. However, this doesn't build because the EditorSession dependencies haven't been worked out just yet.
This commit is contained in:
@@ -4,9 +4,10 @@
|
||||
//
|
||||
|
||||
using System.Diagnostics;
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts
|
||||
{
|
||||
public class CompletionRequest
|
||||
{
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts
|
||||
{
|
||||
public class DefinitionRequest
|
||||
{
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts
|
||||
{
|
||||
public class PublishDiagnosticsNotification
|
||||
{
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts
|
||||
{
|
||||
public enum DocumentHighlightKind
|
||||
{
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts
|
||||
{
|
||||
public class ExpandAliasRequest
|
||||
{
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts
|
||||
{
|
||||
public class FindModuleRequest
|
||||
{
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts
|
||||
{
|
||||
public class MarkedString
|
||||
{
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts
|
||||
{
|
||||
class InstallModuleRequest
|
||||
{
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts
|
||||
{
|
||||
public class ReferencesRequest
|
||||
{
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts
|
||||
{
|
||||
public class ShowOnlineHelpRequest
|
||||
{
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts
|
||||
{
|
||||
public class SignatureHelpRequest
|
||||
{
|
||||
|
||||
@@ -3,31 +3,160 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.EditorServices.Session;
|
||||
using Microsoft.SqlTools.EditorServices.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.LanguageSupport
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageService
|
||||
{
|
||||
/// <summary>
|
||||
/// Main class for Language Service functionality
|
||||
/// </summary>
|
||||
public class LanguageService
|
||||
{
|
||||
|
||||
#region Singleton Instance Implementation
|
||||
|
||||
private static LanguageService instance;
|
||||
|
||||
public static LanguageService Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new LanguageService();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the Language Service class
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
private LanguageService(SqlToolsContext context)
|
||||
{
|
||||
this.Context = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default, parameterless contstructor.
|
||||
/// TODO: Remove once the SqlToolsContext stuff is sorted out
|
||||
/// </summary>
|
||||
private LanguageService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current SQL Tools context
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private SqlToolsContext Context { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the Language Service class
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public LanguageService(SqlToolsContext context)
|
||||
public void InitializeService(ServiceHost.ServiceHost serviceHost)
|
||||
{
|
||||
this.Context = context;
|
||||
// Register the requests that this service will handle
|
||||
serviceHost.SetRequestHandler(DefinitionRequest.Type, HandleDefinitionRequest);
|
||||
serviceHost.SetRequestHandler(ReferencesRequest.Type, HandleReferencesRequest);
|
||||
serviceHost.SetRequestHandler(CompletionRequest.Type, HandleCompletionRequest);
|
||||
serviceHost.SetRequestHandler(CompletionResolveRequest.Type, HandleCompletionResolveRequest);
|
||||
serviceHost.SetRequestHandler(SignatureHelpRequest.Type, HandleSignatureHelpRequest);
|
||||
serviceHost.SetRequestHandler(DocumentHighlightRequest.Type, HandleDocumentHighlightRequest);
|
||||
serviceHost.SetRequestHandler(HoverRequest.Type, HandleHoverRequest);
|
||||
serviceHost.SetRequestHandler(DocumentSymbolRequest.Type, HandleDocumentSymbolRequest);
|
||||
serviceHost.SetRequestHandler(WorkspaceSymbolRequest.Type, HandleWorkspaceSymbolRequest);
|
||||
|
||||
// Register a no-op shutdown task for validation of the shutdown logic
|
||||
serviceHost.RegisterShutdownTask(async (shutdownParams, shutdownRequestContext) =>
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "Shutting down language service");
|
||||
await Task.FromResult(0);
|
||||
});
|
||||
}
|
||||
|
||||
#region Request Handlers
|
||||
|
||||
private static async Task HandleDefinitionRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<Location[]> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleDefinitionRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static async Task HandleReferencesRequest(
|
||||
ReferencesParams referencesParams,
|
||||
RequestContext<Location[]> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleReferencesRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static async Task HandleCompletionRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<CompletionItem[]> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleCompletionRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static async Task HandleCompletionResolveRequest(
|
||||
CompletionItem completionItem,
|
||||
RequestContext<CompletionItem> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleCompletionResolveRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static async Task HandleSignatureHelpRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<SignatureHelp> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleSignatureHelpRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static async Task HandleDocumentHighlightRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<DocumentHighlight[]> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleDocumentHighlightRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static async Task HandleHoverRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<Hover> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleHoverRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static async Task HandleDocumentSymbolRequest(
|
||||
TextDocumentIdentifier textDocumentIdentifier,
|
||||
RequestContext<SymbolInformation[]> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleDocumentSymbolRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static async Task HandleWorkspaceSymbolRequest(
|
||||
WorkspaceSymbolParams workspaceSymbolParams,
|
||||
RequestContext<SymbolInformation[]> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleWorkspaceSymbolRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of semantic diagnostic marks for the provided script file
|
||||
/// </summary>
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
using System;
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.Server;
|
||||
using Microsoft.SqlTools.EditorServices.Session;
|
||||
using Microsoft.SqlTools.EditorServices.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceHost
|
||||
namespace Microsoft.SqlTools.ServiceLayer
|
||||
{
|
||||
/// <summary>
|
||||
/// Main application class for SQL Tools API Service Host executable
|
||||
@@ -31,10 +30,15 @@ namespace Microsoft.SqlTools.ServiceHost
|
||||
var hostDetails = new HostDetails(hostName, hostProfileId, hostVersion);
|
||||
var profilePaths = new ProfilePaths(hostProfileId, "baseAllUsersPath", "baseCurrentUserPath");
|
||||
|
||||
// create and run the language server
|
||||
var languageServer = new LanguageServer(hostDetails, profilePaths);
|
||||
languageServer.Start().Wait();
|
||||
languageServer.WaitForExit();
|
||||
// Create the service host
|
||||
ServiceHost.ServiceHost serviceHost = ServiceHost.ServiceHost.Create(hostDetails, profilePaths);
|
||||
|
||||
// Initialize the services that will be hosted here
|
||||
LanguageService.LanguageService.Instance.InitializeService(serviceHost);
|
||||
|
||||
// Start the service
|
||||
serviceHost.Start().Wait();
|
||||
serviceHost.WaitForExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//
|
||||
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a class that describes the capabilities of a language
|
||||
@@ -3,9 +3,9 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts
|
||||
{
|
||||
public class InitializeRequest
|
||||
{
|
||||
@@ -3,7 +3,7 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts
|
||||
{
|
||||
public class ServerCapabilities
|
||||
{
|
||||
@@ -3,9 +3,9 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a message that is sent from the client to request
|
||||
@@ -3,8 +3,8 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Serializers;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel;
|
||||
using Microsoft.SqlTools.EditorServices.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers
|
||||
{
|
||||
|
||||
@@ -10,11 +10,13 @@ using System.Threading;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using Microsoft.SqlTools.EditorServices;
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.LanguageServer;
|
||||
using Microsoft.SqlTools.EditorServices.Session;
|
||||
using Microsoft.SqlTools.EditorServices.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
|
||||
{
|
||||
@@ -23,59 +25,115 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
|
||||
/// </summary>
|
||||
public class ServiceHost : ServiceHostBase
|
||||
{
|
||||
#region Singleton Instance Code
|
||||
|
||||
/// <summary>
|
||||
/// Singleton instance of the instance
|
||||
/// </summary>
|
||||
private static ServiceHost instance;
|
||||
|
||||
/// <summary>
|
||||
/// Creates or retrieves the current instance of the ServiceHost
|
||||
/// </summary>
|
||||
/// <param name="hostDetails">Details about the host application</param>
|
||||
/// <param name="profilePaths">Details about the profile</param>
|
||||
/// <returns>Instance of the service host</returns>
|
||||
public static ServiceHost Create(HostDetails hostDetails, ProfilePaths profilePaths)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new ServiceHost(hostDetails, profilePaths);
|
||||
}
|
||||
// TODO: hostDetails and profilePaths are thrown out in SqlDataToolsContext,
|
||||
// so we don't need to keep track of whether these have changed for now.
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs new instance of ServiceHost using the host and profile details provided.
|
||||
/// Access is private to ensure only one instance exists at a time.
|
||||
/// </summary>
|
||||
/// <param name="hostDetails">Details about the host application</param>
|
||||
/// <param name="profilePaths">Details about the profile</param>
|
||||
private ServiceHost(HostDetails hostDetails, ProfilePaths profilePaths)
|
||||
: base(new StdioServerChannel())
|
||||
{
|
||||
// Initialize the shutdown activities
|
||||
shutdownActivities = new List<ShutdownHandler>();
|
||||
|
||||
// Create an editor session that we'll use for keeping track of state
|
||||
this.editorSession = new EditorSession();
|
||||
this.editorSession.StartSession(hostDetails, profilePaths);
|
||||
|
||||
// Register the requests that this service host will handle
|
||||
this.SetRequestHandler(InitializeRequest.Type, this.HandleInitializeRequest);
|
||||
this.SetRequestHandler(ShutdownRequest.Type, this.HandleShutdownRequest);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Member Variables
|
||||
|
||||
private static CancellationTokenSource existingRequestCancellation;
|
||||
|
||||
private ServiceHostSettings currentSettings = new ServiceHostSettings();
|
||||
|
||||
private EditorSession editorSession;
|
||||
|
||||
/// <param name="hostDetails">
|
||||
/// Provides details about the host application.
|
||||
/// </param>
|
||||
public ServiceHost(HostDetails hostDetails, ProfilePaths profilePaths)
|
||||
: base(new StdioServerChannel())
|
||||
public delegate Task ShutdownHandler(object shutdownParams, RequestContext<object> shutdownRequestContext);
|
||||
|
||||
private readonly List<ShutdownHandler> shutdownActivities;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new method to be called when the shutdown request is submitted
|
||||
/// </summary>
|
||||
/// <param name="activity"></param>
|
||||
public void RegisterShutdownTask(ShutdownHandler activity)
|
||||
{
|
||||
this.editorSession = new EditorSession();
|
||||
this.editorSession.StartSession(hostDetails, profilePaths);
|
||||
shutdownActivities.Add(activity);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the VS Code request/response callbacks
|
||||
/// </summary>
|
||||
protected override void Initialize()
|
||||
private void Initialize()
|
||||
{
|
||||
// Register all supported message types
|
||||
this.SetRequestHandler(InitializeRequest.Type, this.HandleInitializeRequest);
|
||||
|
||||
this.SetEventHandler(DidChangeTextDocumentNotification.Type, this.HandleDidChangeTextDocumentNotification);
|
||||
this.SetEventHandler(DidOpenTextDocumentNotification.Type, this.HandleDidOpenTextDocumentNotification);
|
||||
this.SetEventHandler(DidCloseTextDocumentNotification.Type, this.HandleDidCloseTextDocumentNotification);
|
||||
this.SetEventHandler(DidChangeConfigurationNotification<LanguageServerSettingsWrapper>.Type, this.HandleDidChangeConfigurationNotification);
|
||||
|
||||
this.SetRequestHandler(DefinitionRequest.Type, this.HandleDefinitionRequest);
|
||||
this.SetRequestHandler(ReferencesRequest.Type, this.HandleReferencesRequest);
|
||||
this.SetRequestHandler(CompletionRequest.Type, this.HandleCompletionRequest);
|
||||
this.SetRequestHandler(CompletionResolveRequest.Type, this.HandleCompletionResolveRequest);
|
||||
this.SetRequestHandler(SignatureHelpRequest.Type, this.HandleSignatureHelpRequest);
|
||||
this.SetRequestHandler(DocumentHighlightRequest.Type, this.HandleDocumentHighlightRequest);
|
||||
this.SetRequestHandler(HoverRequest.Type, this.HandleHoverRequest);
|
||||
this.SetRequestHandler(DocumentSymbolRequest.Type, this.HandleDocumentSymbolRequest);
|
||||
this.SetRequestHandler(WorkspaceSymbolRequest.Type, this.HandleWorkspaceSymbolRequest);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the shutdown event for the Language Server
|
||||
/// </summary>
|
||||
protected override async Task Shutdown()
|
||||
private async Task HandleShutdownRequest(object shutdownParams, RequestContext<object> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Normal, "Language service is shutting down...");
|
||||
Logger.Write(LogLevel.Normal, "Service host is shutting down...");
|
||||
|
||||
// Call all the shutdown methods provided by the service components
|
||||
Task[] shutdownTasks = shutdownActivities.Select(t => t(shutdownParams, requestContext)).ToArray();
|
||||
await Task.WhenAll(shutdownTasks);
|
||||
|
||||
// Shutdown the editor session
|
||||
if (this.editorSession != null)
|
||||
{
|
||||
this.editorSession.Dispose();
|
||||
this.editorSession = null;
|
||||
}
|
||||
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -84,11 +142,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
|
||||
/// <param name="initializeParams"></param>
|
||||
/// <param name="requestContext"></param>
|
||||
/// <returns></returns>
|
||||
protected async Task HandleInitializeRequest(
|
||||
InitializeRequest initializeParams,
|
||||
RequestContext<InitializeResult> requestContext)
|
||||
private async Task HandleInitializeRequest(InitializeRequest initializeParams, RequestContext<InitializeResult> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleDidChangeTextDocumentNotification");
|
||||
Logger.Write(LogLevel.Verbose, "HandleInitializationRequest");
|
||||
|
||||
// Grab the workspace path from the parameters
|
||||
editorSession.Workspace.WorkspacePath = initializeParams.RootPath;
|
||||
@@ -118,6 +174,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
///////////////////////////////////////////////
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handles text document change events
|
||||
/// </summary>
|
||||
@@ -226,78 +287,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
protected async Task HandleDefinitionRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<Location[]> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleDefinitionRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
protected async Task HandleReferencesRequest(
|
||||
ReferencesParams referencesParams,
|
||||
RequestContext<Location[]> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleReferencesRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
protected async Task HandleCompletionRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<CompletionItem[]> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleCompletionRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
protected async Task HandleCompletionResolveRequest(
|
||||
CompletionItem completionItem,
|
||||
RequestContext<CompletionItem> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleCompletionResolveRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
protected async Task HandleSignatureHelpRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<SignatureHelp> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleSignatureHelpRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
protected async Task HandleDocumentHighlightRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<DocumentHighlight[]> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleDocumentHighlightRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
protected async Task HandleHoverRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<Hover> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleHoverRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
protected async Task HandleDocumentSymbolRequest(
|
||||
TextDocumentIdentifier textDocumentIdentifier,
|
||||
RequestContext<SymbolInformation[]> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleDocumentSymbolRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
protected async Task HandleWorkspaceSymbolRequest(
|
||||
WorkspaceSymbolParams workspaceSymbolParams,
|
||||
RequestContext<SymbolInformation[]> requestContext)
|
||||
{
|
||||
Logger.Write(LogLevel.Verbose, "HandleWorkspaceSymbolRequest");
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs script diagnostics on changed files
|
||||
/// </summary>
|
||||
@@ -333,7 +322,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
|
||||
{
|
||||
Logger.Write(
|
||||
LogLevel.Error,
|
||||
string.Format(
|
||||
String.Format(
|
||||
"Exception while cancelling analysis task:\n\n{0}",
|
||||
e.ToString()));
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.LanguageServer;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel;
|
||||
|
||||
@@ -13,59 +13,22 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
|
||||
public abstract class ServiceHostBase : ProtocolEndpoint
|
||||
{
|
||||
private bool isStarted;
|
||||
private ChannelBase serverChannel;
|
||||
private TaskCompletionSource<bool> serverExitedTask;
|
||||
|
||||
public ServiceHostBase(ChannelBase serverChannel) :
|
||||
base(serverChannel, MessageProtocolType.LanguageServer)
|
||||
{
|
||||
this.serverChannel = serverChannel;
|
||||
}
|
||||
|
||||
protected override Task OnStart()
|
||||
{
|
||||
// Register handlers for server lifetime messages
|
||||
this.SetRequestHandler(ShutdownRequest.Type, this.HandleShutdownRequest);
|
||||
|
||||
this.SetEventHandler(ExitNotification.Type, this.HandleExitNotification);
|
||||
|
||||
// Initialize the implementation class
|
||||
this.Initialize();
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
protected override async Task OnStop()
|
||||
{
|
||||
await this.Shutdown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overridden by the subclass to provide initialization
|
||||
/// logic after the server channel is started.
|
||||
/// </summary>
|
||||
protected abstract void Initialize();
|
||||
|
||||
/// <summary>
|
||||
/// Can be overridden by the subclass to provide shutdown
|
||||
/// logic before the server exits. Subclasses do not need
|
||||
/// to invoke or return the value of the base implementation.
|
||||
/// </summary>
|
||||
protected virtual Task Shutdown()
|
||||
{
|
||||
// No default implementation yet.
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
private async Task HandleShutdownRequest(
|
||||
object shutdownParams,
|
||||
RequestContext<object> requestContext)
|
||||
{
|
||||
// Allow the implementor to shut down gracefully
|
||||
await this.Shutdown();
|
||||
|
||||
await requestContext.SendResult(new object());
|
||||
}
|
||||
|
||||
private async Task HandleExitNotification(
|
||||
object exitParams,
|
||||
EventContext eventContext)
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
|
||||
using System;
|
||||
using Microsoft.SqlTools.EditorServices.Session;
|
||||
using Microsoft.SqlTools.LanguageSupport;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageService;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices
|
||||
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides details about a position in a file buffer. All
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices
|
||||
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides details about a range between two positions in
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
|
||||
{
|
||||
public class DidChangeConfigurationNotification<TConfig>
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices
|
||||
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains details relating to a content change in an open file.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices
|
||||
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides details and operations for a buffer position in a
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices
|
||||
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the details and contents of an open script file.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices
|
||||
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the message level of a script file marker.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
//using System.Management.Automation.Language;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices
|
||||
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains details about a specific region of text in script file.
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
//
|
||||
|
||||
using System.Diagnostics;
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a base parameter class for identifying a text document.
|
||||
|
||||
@@ -11,7 +11,7 @@ using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices
|
||||
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages a "workspace" of script files that are open for a particular
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer
|
||||
namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
|
||||
{
|
||||
public enum SymbolKind
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user