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:
Benjamin Russell
2016-07-22 11:49:50 -07:00
parent 5d776863d8
commit 85668cb3de
38 changed files with 296 additions and 197 deletions

View File

@@ -4,9 +4,10 @@
// //
using System.Diagnostics; 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 public class CompletionRequest
{ {

View File

@@ -3,9 +3,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 public class DefinitionRequest
{ {

View File

@@ -3,9 +3,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 public class PublishDiagnosticsNotification
{ {

View File

@@ -3,9 +3,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 public enum DocumentHighlightKind
{ {

View File

@@ -3,9 +3,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 public class ExpandAliasRequest
{ {

View File

@@ -3,10 +3,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 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 public class FindModuleRequest
{ {

View File

@@ -3,9 +3,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 public class MarkedString
{ {

View File

@@ -3,9 +3,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 class InstallModuleRequest
{ {

View File

@@ -3,9 +3,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 public class ReferencesRequest
{ {

View File

@@ -3,9 +3,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 public class ShowOnlineHelpRequest
{ {

View File

@@ -3,9 +3,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 public class SignatureHelpRequest
{ {

View File

@@ -3,31 +3,160 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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.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> /// <summary>
/// Main class for Language Service functionality /// Main class for Language Service functionality
/// </summary> /// </summary>
public class LanguageService 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> /// <summary>
/// Gets or sets the current SQL Tools context /// Gets or sets the current SQL Tools context
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private SqlToolsContext Context { get; set; } private SqlToolsContext Context { get; set; }
/// <summary> public void InitializeService(ServiceHost.ServiceHost serviceHost)
/// Constructor for the Language Service class
/// </summary>
/// <param name="context"></param>
public LanguageService(SqlToolsContext context)
{ {
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> /// <summary>
/// Gets a list of semantic diagnostic marks for the provided script file /// Gets a list of semantic diagnostic marks for the provided script file
/// </summary> /// </summary>

View File

@@ -2,11 +2,10 @@
// Copyright (c) Microsoft. All rights reserved. // Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System; using System;
using Microsoft.SqlTools.EditorServices.Protocol.Server;
using Microsoft.SqlTools.EditorServices.Session; using Microsoft.SqlTools.EditorServices.Session;
using Microsoft.SqlTools.EditorServices.Utility; using Microsoft.SqlTools.EditorServices.Utility;
namespace Microsoft.SqlTools.ServiceHost namespace Microsoft.SqlTools.ServiceLayer
{ {
/// <summary> /// <summary>
/// Main application class for SQL Tools API Service Host executable /// 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 hostDetails = new HostDetails(hostName, hostProfileId, hostVersion);
var profilePaths = new ProfilePaths(hostProfileId, "baseAllUsersPath", "baseCurrentUserPath"); var profilePaths = new ProfilePaths(hostProfileId, "baseAllUsersPath", "baseCurrentUserPath");
// create and run the language server // Create the service host
var languageServer = new LanguageServer(hostDetails, profilePaths); ServiceHost.ServiceHost serviceHost = ServiceHost.ServiceHost.Create(hostDetails, profilePaths);
languageServer.Start().Wait();
languageServer.WaitForExit(); // Initialize the services that will be hosted here
LanguageService.LanguageService.Instance.InitializeService(serviceHost);
// Start the service
serviceHost.Start().Wait();
serviceHost.WaitForExit();
} }
} }
} }

View File

@@ -4,7 +4,7 @@
// //
namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts
{ {
/// <summary> /// <summary>
/// Defines a class that describes the capabilities of a language /// Defines a class that describes the capabilities of a language

View File

@@ -3,9 +3,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 public class InitializeRequest
{ {

View File

@@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 public class ServerCapabilities
{ {

View File

@@ -3,9 +3,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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> /// <summary>
/// Defines a message that is sent from the client to request /// Defines a message that is sent from the client to request

View File

@@ -3,8 +3,8 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers;
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel
{ {

View File

@@ -7,6 +7,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers;
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel
{ {

View File

@@ -6,6 +6,7 @@
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers;
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel
{ {

View File

@@ -10,6 +10,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel; using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel;
using Microsoft.SqlTools.EditorServices.Utility; using Microsoft.SqlTools.EditorServices.Utility;
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol
{ {

View File

@@ -3,6 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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; using Newtonsoft.Json.Linq;
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers

View File

@@ -3,6 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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; using Newtonsoft.Json.Linq;
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers

View File

@@ -5,6 +5,7 @@
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers
{ {

View File

@@ -10,11 +10,13 @@ using System.Threading;
using System.Linq; using System.Linq;
using System; using System;
using Microsoft.SqlTools.EditorServices; using Microsoft.SqlTools.EditorServices;
using Microsoft.SqlTools.EditorServices.Protocol.LanguageServer;
using Microsoft.SqlTools.EditorServices.Session; using Microsoft.SqlTools.EditorServices.Session;
using Microsoft.SqlTools.EditorServices.Utility; 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;
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel; using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel;
using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.ServiceHost namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
{ {
@@ -23,59 +25,115 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
/// </summary> /// </summary>
public class ServiceHost : ServiceHostBase 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 static CancellationTokenSource existingRequestCancellation;
private ServiceHostSettings currentSettings = new ServiceHostSettings(); private ServiceHostSettings currentSettings = new ServiceHostSettings();
private EditorSession editorSession; private EditorSession editorSession;
/// <param name="hostDetails"> public delegate Task ShutdownHandler(object shutdownParams, RequestContext<object> shutdownRequestContext);
/// Provides details about the host application.
/// </param> private readonly List<ShutdownHandler> shutdownActivities;
public ServiceHost(HostDetails hostDetails, ProfilePaths profilePaths)
: base(new StdioServerChannel()) #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(); shutdownActivities.Add(activity);
this.editorSession.StartSession(hostDetails, profilePaths);
} }
#endregion
#region Private Methods
/// <summary> /// <summary>
/// Initialize the VS Code request/response callbacks /// Initialize the VS Code request/response callbacks
/// </summary> /// </summary>
protected override void Initialize() private void Initialize()
{ {
// Register all supported message types // Register all supported message types
this.SetRequestHandler(InitializeRequest.Type, this.HandleInitializeRequest);
this.SetEventHandler(DidChangeTextDocumentNotification.Type, this.HandleDidChangeTextDocumentNotification); this.SetEventHandler(DidChangeTextDocumentNotification.Type, this.HandleDidChangeTextDocumentNotification);
this.SetEventHandler(DidOpenTextDocumentNotification.Type, this.HandleDidOpenTextDocumentNotification); this.SetEventHandler(DidOpenTextDocumentNotification.Type, this.HandleDidOpenTextDocumentNotification);
this.SetEventHandler(DidCloseTextDocumentNotification.Type, this.HandleDidCloseTextDocumentNotification); this.SetEventHandler(DidCloseTextDocumentNotification.Type, this.HandleDidCloseTextDocumentNotification);
this.SetEventHandler(DidChangeConfigurationNotification<LanguageServerSettingsWrapper>.Type, this.HandleDidChangeConfigurationNotification); 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> /// <summary>
/// Handles the shutdown event for the Language Server /// Handles the shutdown event for the Language Server
/// </summary> /// </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) if (this.editorSession != null)
{ {
this.editorSession.Dispose(); this.editorSession.Dispose();
this.editorSession = null; this.editorSession = null;
} }
await Task.FromResult(true);
} }
/// <summary> /// <summary>
@@ -84,11 +142,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
/// <param name="initializeParams"></param> /// <param name="initializeParams"></param>
/// <param name="requestContext"></param> /// <param name="requestContext"></param>
/// <returns></returns> /// <returns></returns>
protected async Task HandleInitializeRequest( private async Task HandleInitializeRequest(InitializeRequest initializeParams, RequestContext<InitializeResult> requestContext)
InitializeRequest initializeParams,
RequestContext<InitializeResult> requestContext)
{ {
Logger.Write(LogLevel.Verbose, "HandleDidChangeTextDocumentNotification"); Logger.Write(LogLevel.Verbose, "HandleInitializationRequest");
// Grab the workspace path from the parameters // Grab the workspace path from the parameters
editorSession.Workspace.WorkspacePath = initializeParams.RootPath; editorSession.Workspace.WorkspacePath = initializeParams.RootPath;
@@ -118,6 +174,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
}); });
} }
#endregion
///////////////////////////////////////////////
/// <summary> /// <summary>
/// Handles text document change events /// Handles text document change events
/// </summary> /// </summary>
@@ -226,78 +287,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
await Task.FromResult(true); 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> /// <summary>
/// Runs script diagnostics on changed files /// Runs script diagnostics on changed files
/// </summary> /// </summary>
@@ -333,7 +322,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
{ {
Logger.Write( Logger.Write(
LogLevel.Error, LogLevel.Error,
string.Format( String.Format(
"Exception while cancelling analysis task:\n\n{0}", "Exception while cancelling analysis task:\n\n{0}",
e.ToString())); e.ToString()));

View File

@@ -4,7 +4,7 @@
// //
using System.Threading.Tasks; 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;
using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel; using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel;
@@ -13,59 +13,22 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost
public abstract class ServiceHostBase : ProtocolEndpoint public abstract class ServiceHostBase : ProtocolEndpoint
{ {
private bool isStarted; private bool isStarted;
private ChannelBase serverChannel;
private TaskCompletionSource<bool> serverExitedTask; private TaskCompletionSource<bool> serverExitedTask;
public ServiceHostBase(ChannelBase serverChannel) : public ServiceHostBase(ChannelBase serverChannel) :
base(serverChannel, MessageProtocolType.LanguageServer) base(serverChannel, MessageProtocolType.LanguageServer)
{ {
this.serverChannel = serverChannel;
} }
protected override Task OnStart() protected override Task OnStart()
{ {
// Register handlers for server lifetime messages // Register handlers for server lifetime messages
this.SetRequestHandler(ShutdownRequest.Type, this.HandleShutdownRequest);
this.SetEventHandler(ExitNotification.Type, this.HandleExitNotification); this.SetEventHandler(ExitNotification.Type, this.HandleExitNotification);
// Initialize the implementation class
this.Initialize();
return Task.FromResult(true); 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( private async Task HandleExitNotification(
object exitParams, object exitParams,
EventContext eventContext) EventContext eventContext)

View File

@@ -5,7 +5,8 @@
using System; using System;
using Microsoft.SqlTools.EditorServices.Session; using Microsoft.SqlTools.EditorServices.Session;
using Microsoft.SqlTools.LanguageSupport; using Microsoft.SqlTools.ServiceLayer.LanguageService;
using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts;
namespace Microsoft.SqlTools.EditorServices namespace Microsoft.SqlTools.EditorServices
{ {

View File

@@ -5,7 +5,7 @@
using System.Diagnostics; using System.Diagnostics;
namespace Microsoft.SqlTools.EditorServices namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
{ {
/// <summary> /// <summary>
/// Provides details about a position in a file buffer. All /// Provides details about a position in a file buffer. All

View File

@@ -6,7 +6,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
namespace Microsoft.SqlTools.EditorServices namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
{ {
/// <summary> /// <summary>
/// Provides details about a range between two positions in /// Provides details about a range between two positions in

View File

@@ -3,9 +3,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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> public class DidChangeConfigurationNotification<TConfig>
{ {

View File

@@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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> /// <summary>
/// Contains details relating to a content change in an open file. /// Contains details relating to a content change in an open file.

View File

@@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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> /// <summary>
/// Provides details and operations for a buffer position in a /// Provides details and operations for a buffer position in a

View File

@@ -9,7 +9,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
namespace Microsoft.SqlTools.EditorServices namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
{ {
/// <summary> /// <summary>
/// Contains the details and contents of an open script file. /// Contains the details and contents of an open script file.

View File

@@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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> /// <summary>
/// Defines the message level of a script file marker. /// Defines the message level of a script file marker.

View File

@@ -5,7 +5,7 @@
//using System.Management.Automation.Language; //using System.Management.Automation.Language;
namespace Microsoft.SqlTools.EditorServices namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
{ {
/// <summary> /// <summary>
/// Contains details about a specific region of text in script file. /// Contains details about a specific region of text in script file.

View File

@@ -4,9 +4,9 @@
// //
using System.Diagnostics; 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> /// <summary>
/// Defines a base parameter class for identifying a text document. /// Defines a base parameter class for identifying a text document.

View File

@@ -11,7 +11,7 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Linq; using System.Linq;
namespace Microsoft.SqlTools.EditorServices namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts
{ {
/// <summary> /// <summary>
/// Manages a "workspace" of script files that are open for a particular /// Manages a "workspace" of script files that are open for a particular

View File

@@ -3,9 +3,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // 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 public enum SymbolKind
{ {