From 1b592aeaefdd0def515aec8848ebe7061189fa65 Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Thu, 21 Jul 2016 11:36:38 -0700 Subject: [PATCH 01/15] Moving LanguageServer to ServiceHost NOTE: This is a WIP commit --- .../{Server/LanguageServer.cs => ServiceHost/ServiceHost.cs} | 0 .../LanguageServerBase.cs => ServiceHost/ServiceHostBase.cs} | 0 .../ServiceHostEditorOperations.cs} | 0 .../ServiceHostSettings.cs} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/ServiceHost/{Server/LanguageServer.cs => ServiceHost/ServiceHost.cs} (100%) rename src/ServiceHost/{Server/LanguageServerBase.cs => ServiceHost/ServiceHostBase.cs} (100%) rename src/ServiceHost/{Server/LanguageServerEditorOperations.cs => ServiceHost/ServiceHostEditorOperations.cs} (100%) rename src/ServiceHost/{Server/LanguageServerSettings.cs => ServiceHost/ServiceHostSettings.cs} (100%) diff --git a/src/ServiceHost/Server/LanguageServer.cs b/src/ServiceHost/ServiceHost/ServiceHost.cs similarity index 100% rename from src/ServiceHost/Server/LanguageServer.cs rename to src/ServiceHost/ServiceHost/ServiceHost.cs diff --git a/src/ServiceHost/Server/LanguageServerBase.cs b/src/ServiceHost/ServiceHost/ServiceHostBase.cs similarity index 100% rename from src/ServiceHost/Server/LanguageServerBase.cs rename to src/ServiceHost/ServiceHost/ServiceHostBase.cs diff --git a/src/ServiceHost/Server/LanguageServerEditorOperations.cs b/src/ServiceHost/ServiceHost/ServiceHostEditorOperations.cs similarity index 100% rename from src/ServiceHost/Server/LanguageServerEditorOperations.cs rename to src/ServiceHost/ServiceHost/ServiceHostEditorOperations.cs diff --git a/src/ServiceHost/Server/LanguageServerSettings.cs b/src/ServiceHost/ServiceHost/ServiceHostSettings.cs similarity index 100% rename from src/ServiceHost/Server/LanguageServerSettings.cs rename to src/ServiceHost/ServiceHost/ServiceHostSettings.cs From 9edeb199461da98b07b1456578596dde6ad366ea Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Thu, 21 Jul 2016 12:00:53 -0700 Subject: [PATCH 02/15] Renaming the classes for the ServiceHost NOTE: This is a WIP commit, it will not build --- src/ServiceHost/ServiceHost/ServiceHost.cs | 9 +++++---- src/ServiceHost/ServiceHost/ServiceHostBase.cs | 6 +++--- src/ServiceHost/ServiceHost/ServiceHostSettings.cs | 10 +++++----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/ServiceHost/ServiceHost/ServiceHost.cs b/src/ServiceHost/ServiceHost/ServiceHost.cs index d6719141..e3e47d72 100644 --- a/src/ServiceHost/ServiceHost/ServiceHost.cs +++ b/src/ServiceHost/ServiceHost/ServiceHost.cs @@ -13,24 +13,25 @@ using System.Text; using System.Threading; using System.Linq; using System; +using Microsoft.SqlTools.EditorServices; -namespace Microsoft.SqlTools.EditorServices.Protocol.Server +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost { /// /// SQL Tools VS Code Language Server request handler /// - public class LanguageServer : LanguageServerBase + public class ServiceHost : ServiceHostBase { private static CancellationTokenSource existingRequestCancellation; - private LanguageServerSettings currentSettings = new LanguageServerSettings(); + private ServiceHostSettings currentSettings = new ServiceHostSettings(); private EditorSession editorSession; /// /// Provides details about the host application. /// - public LanguageServer(HostDetails hostDetails, ProfilePaths profilePaths) + public ServiceHost(HostDetails hostDetails, ProfilePaths profilePaths) : base(new StdioServerChannel()) { this.editorSession = new EditorSession(); diff --git a/src/ServiceHost/ServiceHost/ServiceHostBase.cs b/src/ServiceHost/ServiceHost/ServiceHostBase.cs index 0128484b..f1bc2e73 100644 --- a/src/ServiceHost/ServiceHost/ServiceHostBase.cs +++ b/src/ServiceHost/ServiceHost/ServiceHostBase.cs @@ -8,15 +8,15 @@ using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol; using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Channel; using System.Threading.Tasks; -namespace Microsoft.SqlTools.EditorServices.Protocol.Server +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost { - public abstract class LanguageServerBase : ProtocolEndpoint + public abstract class ServiceHostBase : ProtocolEndpoint { private bool isStarted; private ChannelBase serverChannel; private TaskCompletionSource serverExitedTask; - public LanguageServerBase(ChannelBase serverChannel) : + public ServiceHostBase(ChannelBase serverChannel) : base(serverChannel, MessageProtocolType.LanguageServer) { this.serverChannel = serverChannel; diff --git a/src/ServiceHost/ServiceHost/ServiceHostSettings.cs b/src/ServiceHost/ServiceHost/ServiceHostSettings.cs index be09984a..53d99647 100644 --- a/src/ServiceHost/ServiceHost/ServiceHostSettings.cs +++ b/src/ServiceHost/ServiceHost/ServiceHostSettings.cs @@ -6,20 +6,20 @@ using System.IO; using Microsoft.SqlTools.EditorServices.Utility; -namespace Microsoft.SqlTools.EditorServices.Protocol.Server +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost { - public class LanguageServerSettings + public class ServiceHostSettings { public bool EnableProfileLoading { get; set; } public ScriptAnalysisSettings ScriptAnalysis { get; set; } - public LanguageServerSettings() + public ServiceHostSettings() { this.ScriptAnalysis = new ScriptAnalysisSettings(); } - public void Update(LanguageServerSettings settings, string workspaceRootPath) + public void Update(ServiceHostSettings settings, string workspaceRootPath) { if (settings != null) { @@ -85,6 +85,6 @@ namespace Microsoft.SqlTools.EditorServices.Protocol.Server // mode name sent from the client is written as 'SqlTools' and // JSON.net is using camelCasing. - public LanguageServerSettings SqlTools { get; set; } + public ServiceHostSettings SqlTools { get; set; } } } From a7eb53cc06b4ce7b15eb8025e1c1314a5f27133a Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Thu, 21 Jul 2016 12:15:22 -0700 Subject: [PATCH 03/15] Moving the MessageProtocol files into ServiceHost/Protocol The contracts for the basic protocol have been moved into their own /Protocol/Contracts folder. No code changes have been made to change the namespaces or class names --- .../Protocol}/Channel/ChannelBase.cs | 0 .../Protocol}/Channel/StdioClientChannel.cs | 0 .../Protocol}/Channel/StdioServerChannel.cs | 0 .../{MessageProtocol => ServiceHost/Protocol}/Constants.cs | 0 .../Protocol/Contracts}/EventType.cs | 0 .../Protocol/Contracts}/Message.cs | 0 .../Protocol/Contracts}/RequestType.cs | 0 .../{MessageProtocol => ServiceHost/Protocol}/EventContext.cs | 0 .../{MessageProtocol => ServiceHost/Protocol}/IMessageSender.cs | 0 .../Protocol}/MessageDispatcher.cs | 0 .../Protocol}/MessageParseException.cs | 0 .../Protocol}/MessageProtocolType.cs | 0 .../{MessageProtocol => ServiceHost/Protocol}/MessageReader.cs | 0 .../{MessageProtocol => ServiceHost/Protocol}/MessageWriter.cs | 0 .../{MessageProtocol => ServiceHost/Protocol}/ProtocolEndpoint.cs | 0 .../{MessageProtocol => ServiceHost/Protocol}/RequestContext.cs | 0 .../Protocol/Serializers}/IMessageSerializer.cs | 0 .../Protocol}/Serializers/JsonRpcMessageSerializer.cs | 0 .../Protocol}/Serializers/V8MessageSerializer.cs | 0 19 files changed, 0 insertions(+), 0 deletions(-) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/Channel/ChannelBase.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/Channel/StdioClientChannel.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/Channel/StdioServerChannel.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/Constants.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol/Contracts}/EventType.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol/Contracts}/Message.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol/Contracts}/RequestType.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/EventContext.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/IMessageSender.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/MessageDispatcher.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/MessageParseException.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/MessageProtocolType.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/MessageReader.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/MessageWriter.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/ProtocolEndpoint.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/RequestContext.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol/Serializers}/IMessageSerializer.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/Serializers/JsonRpcMessageSerializer.cs (100%) rename src/ServiceHost/{MessageProtocol => ServiceHost/Protocol}/Serializers/V8MessageSerializer.cs (100%) diff --git a/src/ServiceHost/MessageProtocol/Channel/ChannelBase.cs b/src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/Channel/ChannelBase.cs rename to src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs diff --git a/src/ServiceHost/MessageProtocol/Channel/StdioClientChannel.cs b/src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/Channel/StdioClientChannel.cs rename to src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs diff --git a/src/ServiceHost/MessageProtocol/Channel/StdioServerChannel.cs b/src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/Channel/StdioServerChannel.cs rename to src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs diff --git a/src/ServiceHost/MessageProtocol/Constants.cs b/src/ServiceHost/ServiceHost/Protocol/Constants.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/Constants.cs rename to src/ServiceHost/ServiceHost/Protocol/Constants.cs diff --git a/src/ServiceHost/MessageProtocol/EventType.cs b/src/ServiceHost/ServiceHost/Protocol/Contracts/EventType.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/EventType.cs rename to src/ServiceHost/ServiceHost/Protocol/Contracts/EventType.cs diff --git a/src/ServiceHost/MessageProtocol/Message.cs b/src/ServiceHost/ServiceHost/Protocol/Contracts/Message.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/Message.cs rename to src/ServiceHost/ServiceHost/Protocol/Contracts/Message.cs diff --git a/src/ServiceHost/MessageProtocol/RequestType.cs b/src/ServiceHost/ServiceHost/Protocol/Contracts/RequestType.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/RequestType.cs rename to src/ServiceHost/ServiceHost/Protocol/Contracts/RequestType.cs diff --git a/src/ServiceHost/MessageProtocol/EventContext.cs b/src/ServiceHost/ServiceHost/Protocol/EventContext.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/EventContext.cs rename to src/ServiceHost/ServiceHost/Protocol/EventContext.cs diff --git a/src/ServiceHost/MessageProtocol/IMessageSender.cs b/src/ServiceHost/ServiceHost/Protocol/IMessageSender.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/IMessageSender.cs rename to src/ServiceHost/ServiceHost/Protocol/IMessageSender.cs diff --git a/src/ServiceHost/MessageProtocol/MessageDispatcher.cs b/src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/MessageDispatcher.cs rename to src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs diff --git a/src/ServiceHost/MessageProtocol/MessageParseException.cs b/src/ServiceHost/ServiceHost/Protocol/MessageParseException.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/MessageParseException.cs rename to src/ServiceHost/ServiceHost/Protocol/MessageParseException.cs diff --git a/src/ServiceHost/MessageProtocol/MessageProtocolType.cs b/src/ServiceHost/ServiceHost/Protocol/MessageProtocolType.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/MessageProtocolType.cs rename to src/ServiceHost/ServiceHost/Protocol/MessageProtocolType.cs diff --git a/src/ServiceHost/MessageProtocol/MessageReader.cs b/src/ServiceHost/ServiceHost/Protocol/MessageReader.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/MessageReader.cs rename to src/ServiceHost/ServiceHost/Protocol/MessageReader.cs diff --git a/src/ServiceHost/MessageProtocol/MessageWriter.cs b/src/ServiceHost/ServiceHost/Protocol/MessageWriter.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/MessageWriter.cs rename to src/ServiceHost/ServiceHost/Protocol/MessageWriter.cs diff --git a/src/ServiceHost/MessageProtocol/ProtocolEndpoint.cs b/src/ServiceHost/ServiceHost/Protocol/ProtocolEndpoint.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/ProtocolEndpoint.cs rename to src/ServiceHost/ServiceHost/Protocol/ProtocolEndpoint.cs diff --git a/src/ServiceHost/MessageProtocol/RequestContext.cs b/src/ServiceHost/ServiceHost/Protocol/RequestContext.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/RequestContext.cs rename to src/ServiceHost/ServiceHost/Protocol/RequestContext.cs diff --git a/src/ServiceHost/MessageProtocol/IMessageSerializer.cs b/src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/IMessageSerializer.cs rename to src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs diff --git a/src/ServiceHost/MessageProtocol/Serializers/JsonRpcMessageSerializer.cs b/src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/Serializers/JsonRpcMessageSerializer.cs rename to src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs diff --git a/src/ServiceHost/MessageProtocol/Serializers/V8MessageSerializer.cs b/src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs similarity index 100% rename from src/ServiceHost/MessageProtocol/Serializers/V8MessageSerializer.cs rename to src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs From f1e6b8a4e4c06d51a2375b3033ee17f12e3a023d Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Thu, 21 Jul 2016 12:17:53 -0700 Subject: [PATCH 04/15] Changing the default namespace ... to better match the nomenclature we're using internally for the difference between the UX and the Service Layer. --- src/ServiceHost/ServiceHost.xproj | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ServiceHost/ServiceHost.xproj b/src/ServiceHost/ServiceHost.xproj index ac743bab..358bb7c3 100644 --- a/src/ServiceHost/ServiceHost.xproj +++ b/src/ServiceHost/ServiceHost.xproj @@ -1,4 +1,4 @@ - + 14.0 @@ -7,14 +7,13 @@ {0D61DC2B-DA66-441D-B9D0-F76C98F780F9} - Microsoft.SqlTools.ServiceHost + Microsoft.SqlTools.ServiceLayer .\obj .\bin\ v4.5.2 - 2.0 - + \ No newline at end of file From eb25f56e6411b43c361effe5c93e8ac8a3e48981 Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Thu, 21 Jul 2016 13:39:01 -0700 Subject: [PATCH 05/15] Renaming all the namespaces for ServiceHost Also wiring up the namespace changes to make the servicehost component build. NOTE: This will not build --- .../ServiceHost/Protocol/Channel/ChannelBase.cs | 2 +- .../Protocol/Channel/StdioClientChannel.cs | 2 +- .../Protocol/Channel/StdioServerChannel.cs | 2 +- src/ServiceHost/ServiceHost/Protocol/Constants.cs | 2 +- .../ServiceHost/Protocol/Contracts/EventType.cs | 2 +- .../ServiceHost/Protocol/Contracts/Message.cs | 2 +- .../ServiceHost/Protocol/Contracts/RequestType.cs | 2 +- src/ServiceHost/ServiceHost/Protocol/EventContext.cs | 3 ++- .../ServiceHost/Protocol/IMessageSender.cs | 3 ++- .../ServiceHost/Protocol/MessageDispatcher.cs | 6 +++--- .../ServiceHost/Protocol/MessageParseException.cs | 2 +- .../ServiceHost/Protocol/MessageProtocolType.cs | 2 +- src/ServiceHost/ServiceHost/Protocol/MessageReader.cs | 10 ++++++---- src/ServiceHost/ServiceHost/Protocol/MessageWriter.cs | 10 ++++++---- .../ServiceHost/Protocol/ProtocolEndpoint.cs | 5 +++-- .../ServiceHost/Protocol/RequestContext.cs | 5 +++-- .../Protocol/Serializers/IMessageSerializer.cs | 2 +- .../Protocol/Serializers/JsonRpcMessageSerializer.cs | 2 +- .../Protocol/Serializers/V8MessageSerializer.cs | 2 +- src/ServiceHost/ServiceHost/ServiceHost.cs | 11 ++++++----- src/ServiceHost/ServiceHost/ServiceHostBase.cs | 6 +++--- 21 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs b/src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs index 848da39f..622e5826 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs @@ -6,7 +6,7 @@ using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Serializers; using System.Threading.Tasks; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Channel +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel { /// /// Defines a base implementation for servers and their clients over a diff --git a/src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs b/src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs index 5390f52d..e8645d38 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs @@ -8,7 +8,7 @@ using System.IO; using System.Text; using System.Threading.Tasks; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Channel +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel { /// /// Provides a client implementation for the standard I/O channel. diff --git a/src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs b/src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs index 0b9376d4..46fd5d0f 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs @@ -7,7 +7,7 @@ using System.IO; using System.Text; using System.Threading.Tasks; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Channel +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel { /// /// Provides a server implementation for the standard I/O channel. diff --git a/src/ServiceHost/ServiceHost/Protocol/Constants.cs b/src/ServiceHost/ServiceHost/Protocol/Constants.cs index 0fae5d8d..81dd58ea 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Constants.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Constants.cs @@ -6,7 +6,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol { public static class Constants { diff --git a/src/ServiceHost/ServiceHost/Protocol/Contracts/EventType.cs b/src/ServiceHost/ServiceHost/Protocol/Contracts/EventType.cs index dd460817..94612af8 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Contracts/EventType.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Contracts/EventType.cs @@ -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.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts { /// /// Defines an event type with a particular method name. diff --git a/src/ServiceHost/ServiceHost/Protocol/Contracts/Message.cs b/src/ServiceHost/ServiceHost/Protocol/Contracts/Message.cs index 75dab5cd..2474b094 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Contracts/Message.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Contracts/Message.cs @@ -6,7 +6,7 @@ using System.Diagnostics; using Newtonsoft.Json.Linq; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts { /// /// Defines all possible message types. diff --git a/src/ServiceHost/ServiceHost/Protocol/Contracts/RequestType.cs b/src/ServiceHost/ServiceHost/Protocol/Contracts/RequestType.cs index 29fc11c5..9206cb66 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Contracts/RequestType.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Contracts/RequestType.cs @@ -5,7 +5,7 @@ using System.Diagnostics; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts { [DebuggerDisplay("RequestType MethodName = {MethodName}")] public class RequestType diff --git a/src/ServiceHost/ServiceHost/Protocol/EventContext.cs b/src/ServiceHost/ServiceHost/Protocol/EventContext.cs index eb42ebbb..8754351c 100644 --- a/src/ServiceHost/ServiceHost/Protocol/EventContext.cs +++ b/src/ServiceHost/ServiceHost/Protocol/EventContext.cs @@ -4,8 +4,9 @@ // using System.Threading.Tasks; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol { /// /// Provides context for a received event so that handlers diff --git a/src/ServiceHost/ServiceHost/Protocol/IMessageSender.cs b/src/ServiceHost/ServiceHost/Protocol/IMessageSender.cs index 7f331eed..2e0e461e 100644 --- a/src/ServiceHost/ServiceHost/Protocol/IMessageSender.cs +++ b/src/ServiceHost/ServiceHost/Protocol/IMessageSender.cs @@ -4,8 +4,9 @@ // using System.Threading.Tasks; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol { internal interface IMessageSender { diff --git a/src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs b/src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs index 21c179e2..58f541d2 100644 --- a/src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs +++ b/src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs @@ -3,15 +3,15 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Channel; -using Microsoft.SqlTools.EditorServices.Utility; using System; using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel; +using Microsoft.SqlTools.EditorServices.Utility; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol { public class MessageDispatcher { diff --git a/src/ServiceHost/ServiceHost/Protocol/MessageParseException.cs b/src/ServiceHost/ServiceHost/Protocol/MessageParseException.cs index 98a17c20..76db24d3 100644 --- a/src/ServiceHost/ServiceHost/Protocol/MessageParseException.cs +++ b/src/ServiceHost/ServiceHost/Protocol/MessageParseException.cs @@ -5,7 +5,7 @@ using System; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol { public class MessageParseException : Exception { diff --git a/src/ServiceHost/ServiceHost/Protocol/MessageProtocolType.cs b/src/ServiceHost/ServiceHost/Protocol/MessageProtocolType.cs index 5484ae3c..09655481 100644 --- a/src/ServiceHost/ServiceHost/Protocol/MessageProtocolType.cs +++ b/src/ServiceHost/ServiceHost/Protocol/MessageProtocolType.cs @@ -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.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol { /// /// Defines the possible message protocol types. diff --git a/src/ServiceHost/ServiceHost/Protocol/MessageReader.cs b/src/ServiceHost/ServiceHost/Protocol/MessageReader.cs index a2df43ba..7722a426 100644 --- a/src/ServiceHost/ServiceHost/Protocol/MessageReader.cs +++ b/src/ServiceHost/ServiceHost/Protocol/MessageReader.cs @@ -3,16 +3,18 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.EditorServices.Utility; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Threading.Tasks; +using Microsoft.SqlTools.EditorServices.Utility; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol { public class MessageReader { diff --git a/src/ServiceHost/ServiceHost/Protocol/MessageWriter.cs b/src/ServiceHost/ServiceHost/Protocol/MessageWriter.cs index 96e13bcd..4098d181 100644 --- a/src/ServiceHost/ServiceHost/Protocol/MessageWriter.cs +++ b/src/ServiceHost/ServiceHost/Protocol/MessageWriter.cs @@ -3,14 +3,16 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.EditorServices.Utility; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using System.IO; using System.Text; using System.Threading.Tasks; +using Microsoft.SqlTools.EditorServices.Utility; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol { public class MessageWriter { diff --git a/src/ServiceHost/ServiceHost/Protocol/ProtocolEndpoint.cs b/src/ServiceHost/ServiceHost/Protocol/ProtocolEndpoint.cs index daead186..27601412 100644 --- a/src/ServiceHost/ServiceHost/Protocol/ProtocolEndpoint.cs +++ b/src/ServiceHost/ServiceHost/Protocol/ProtocolEndpoint.cs @@ -3,13 +3,14 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Channel; using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol { /// /// Provides behavior for a client or server endpoint that diff --git a/src/ServiceHost/ServiceHost/Protocol/RequestContext.cs b/src/ServiceHost/ServiceHost/Protocol/RequestContext.cs index a35bb136..6d09294e 100644 --- a/src/ServiceHost/ServiceHost/Protocol/RequestContext.cs +++ b/src/ServiceHost/ServiceHost/Protocol/RequestContext.cs @@ -3,10 +3,11 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Newtonsoft.Json.Linq; using System.Threading.Tasks; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Newtonsoft.Json.Linq; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol { public class RequestContext { diff --git a/src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs b/src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs index 81b23fa6..318955fd 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs @@ -5,7 +5,7 @@ using Newtonsoft.Json.Linq; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers { /// /// Defines a common interface for message serializers. diff --git a/src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs b/src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs index fa1d1518..194f270d 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs @@ -5,7 +5,7 @@ using Newtonsoft.Json.Linq; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Serializers +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers { /// /// Serializes messages in the JSON RPC format. Used primarily diff --git a/src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs b/src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs index 941e249a..81af48f5 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs @@ -6,7 +6,7 @@ using Newtonsoft.Json.Linq; using System; -namespace Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Serializers +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers { /// /// Serializes messages in the V8 format. Used primarily for debug adapters. diff --git a/src/ServiceHost/ServiceHost/ServiceHost.cs b/src/ServiceHost/ServiceHost/ServiceHost.cs index e3e47d72..53337392 100644 --- a/src/ServiceHost/ServiceHost/ServiceHost.cs +++ b/src/ServiceHost/ServiceHost/ServiceHost.cs @@ -2,18 +2,19 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.EditorServices.Protocol.LanguageServer; -using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol; -using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Channel; -using Microsoft.SqlTools.EditorServices.Session; + using System.Threading.Tasks; -using Microsoft.SqlTools.EditorServices.Utility; using System.Collections.Generic; using System.Text; 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.ServiceHost.Protocol; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel; namespace Microsoft.SqlTools.ServiceLayer.ServiceHost { diff --git a/src/ServiceHost/ServiceHost/ServiceHostBase.cs b/src/ServiceHost/ServiceHost/ServiceHostBase.cs index f1bc2e73..b89c90eb 100644 --- a/src/ServiceHost/ServiceHost/ServiceHostBase.cs +++ b/src/ServiceHost/ServiceHost/ServiceHostBase.cs @@ -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.LanguageServer; -using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol; -using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Channel; using System.Threading.Tasks; +using Microsoft.SqlTools.EditorServices.Protocol.LanguageServer; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel; namespace Microsoft.SqlTools.ServiceLayer.ServiceHost { From 9ec6265602c47b9a90ddf81730f866440baa919d Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Thu, 21 Jul 2016 14:29:41 -0700 Subject: [PATCH 06/15] Separated LanguageServer into different components LanguageServer -> LanguageService - for any functionality that deals with parsing SQL ServerService - for any functionality that is required to manage the service layer WorkspaceService - for any functionality that deals with managing the state of the workspace, session, or text document Namespace changes have not been applied yet, so this doesn't build yet. --- .../{LanguageServer => LanguageService/Contracts}/Completion.cs | 0 .../{LanguageServer => LanguageService/Contracts}/Definition.cs | 0 .../{LanguageServer => LanguageService/Contracts}/Diagnostics.cs | 0 .../Contracts}/DocumentHighlight.cs | 0 .../Contracts}/ExpandAliasRequest.cs | 0 .../Contracts}/FindModuleRequest.cs | 0 .../{LanguageServer => LanguageService/Contracts}/Hover.cs | 0 .../Contracts}/InstallModuleRequest.cs | 0 .../{LanguageServer => LanguageService/Contracts}/References.cs | 0 .../Contracts}/ShowOnlineHelpRequest.cs | 0 .../Contracts}/SignatureHelp.cs | 0 .../{LanguageSupport => LanguageService}/LanguageService.cs | 0 .../Contracts}/ClientCapabilities.cs | 0 .../{LanguageServer => ServerService/Contracts}/Initialize.cs | 0 .../Contracts}/ServerCapabilities.cs | 0 .../{LanguageServer => ServerService/Contracts}/Shutdown.cs | 0 src/ServiceHost/{Workspace => WorkspaceService}/BufferPosition.cs | 0 src/ServiceHost/{Workspace => WorkspaceService}/BufferRange.cs | 0 .../{LanguageServer => WorkspaceService}/Configuration.cs | 0 src/ServiceHost/{Workspace => WorkspaceService}/FileChange.cs | 0 src/ServiceHost/{Workspace => WorkspaceService}/FilePosition.cs | 0 src/ServiceHost/{Workspace => WorkspaceService}/ScriptFile.cs | 0 .../{Workspace => WorkspaceService}/ScriptFileMarker.cs | 0 src/ServiceHost/{Workspace => WorkspaceService}/ScriptRegion.cs | 0 .../{LanguageServer => WorkspaceService}/TextDocument.cs | 0 src/ServiceHost/{Workspace => WorkspaceService}/Workspace.cs | 0 .../{LanguageServer => WorkspaceService}/WorkspaceSymbols.cs | 0 27 files changed, 0 insertions(+), 0 deletions(-) rename src/ServiceHost/{LanguageServer => LanguageService/Contracts}/Completion.cs (100%) rename src/ServiceHost/{LanguageServer => LanguageService/Contracts}/Definition.cs (100%) rename src/ServiceHost/{LanguageServer => LanguageService/Contracts}/Diagnostics.cs (100%) rename src/ServiceHost/{LanguageServer => LanguageService/Contracts}/DocumentHighlight.cs (100%) rename src/ServiceHost/{LanguageServer => LanguageService/Contracts}/ExpandAliasRequest.cs (100%) rename src/ServiceHost/{LanguageServer => LanguageService/Contracts}/FindModuleRequest.cs (100%) rename src/ServiceHost/{LanguageServer => LanguageService/Contracts}/Hover.cs (100%) rename src/ServiceHost/{LanguageServer => LanguageService/Contracts}/InstallModuleRequest.cs (100%) rename src/ServiceHost/{LanguageServer => LanguageService/Contracts}/References.cs (100%) rename src/ServiceHost/{LanguageServer => LanguageService/Contracts}/ShowOnlineHelpRequest.cs (100%) rename src/ServiceHost/{LanguageServer => LanguageService/Contracts}/SignatureHelp.cs (100%) rename src/ServiceHost/{LanguageSupport => LanguageService}/LanguageService.cs (100%) rename src/ServiceHost/{LanguageServer => ServerService/Contracts}/ClientCapabilities.cs (100%) rename src/ServiceHost/{LanguageServer => ServerService/Contracts}/Initialize.cs (100%) rename src/ServiceHost/{LanguageServer => ServerService/Contracts}/ServerCapabilities.cs (100%) rename src/ServiceHost/{LanguageServer => ServerService/Contracts}/Shutdown.cs (100%) rename src/ServiceHost/{Workspace => WorkspaceService}/BufferPosition.cs (100%) rename src/ServiceHost/{Workspace => WorkspaceService}/BufferRange.cs (100%) rename src/ServiceHost/{LanguageServer => WorkspaceService}/Configuration.cs (100%) rename src/ServiceHost/{Workspace => WorkspaceService}/FileChange.cs (100%) rename src/ServiceHost/{Workspace => WorkspaceService}/FilePosition.cs (100%) rename src/ServiceHost/{Workspace => WorkspaceService}/ScriptFile.cs (100%) rename src/ServiceHost/{Workspace => WorkspaceService}/ScriptFileMarker.cs (100%) rename src/ServiceHost/{Workspace => WorkspaceService}/ScriptRegion.cs (100%) rename src/ServiceHost/{LanguageServer => WorkspaceService}/TextDocument.cs (100%) rename src/ServiceHost/{Workspace => WorkspaceService}/Workspace.cs (100%) rename src/ServiceHost/{LanguageServer => WorkspaceService}/WorkspaceSymbols.cs (100%) diff --git a/src/ServiceHost/LanguageServer/Completion.cs b/src/ServiceHost/LanguageService/Contracts/Completion.cs similarity index 100% rename from src/ServiceHost/LanguageServer/Completion.cs rename to src/ServiceHost/LanguageService/Contracts/Completion.cs diff --git a/src/ServiceHost/LanguageServer/Definition.cs b/src/ServiceHost/LanguageService/Contracts/Definition.cs similarity index 100% rename from src/ServiceHost/LanguageServer/Definition.cs rename to src/ServiceHost/LanguageService/Contracts/Definition.cs diff --git a/src/ServiceHost/LanguageServer/Diagnostics.cs b/src/ServiceHost/LanguageService/Contracts/Diagnostics.cs similarity index 100% rename from src/ServiceHost/LanguageServer/Diagnostics.cs rename to src/ServiceHost/LanguageService/Contracts/Diagnostics.cs diff --git a/src/ServiceHost/LanguageServer/DocumentHighlight.cs b/src/ServiceHost/LanguageService/Contracts/DocumentHighlight.cs similarity index 100% rename from src/ServiceHost/LanguageServer/DocumentHighlight.cs rename to src/ServiceHost/LanguageService/Contracts/DocumentHighlight.cs diff --git a/src/ServiceHost/LanguageServer/ExpandAliasRequest.cs b/src/ServiceHost/LanguageService/Contracts/ExpandAliasRequest.cs similarity index 100% rename from src/ServiceHost/LanguageServer/ExpandAliasRequest.cs rename to src/ServiceHost/LanguageService/Contracts/ExpandAliasRequest.cs diff --git a/src/ServiceHost/LanguageServer/FindModuleRequest.cs b/src/ServiceHost/LanguageService/Contracts/FindModuleRequest.cs similarity index 100% rename from src/ServiceHost/LanguageServer/FindModuleRequest.cs rename to src/ServiceHost/LanguageService/Contracts/FindModuleRequest.cs diff --git a/src/ServiceHost/LanguageServer/Hover.cs b/src/ServiceHost/LanguageService/Contracts/Hover.cs similarity index 100% rename from src/ServiceHost/LanguageServer/Hover.cs rename to src/ServiceHost/LanguageService/Contracts/Hover.cs diff --git a/src/ServiceHost/LanguageServer/InstallModuleRequest.cs b/src/ServiceHost/LanguageService/Contracts/InstallModuleRequest.cs similarity index 100% rename from src/ServiceHost/LanguageServer/InstallModuleRequest.cs rename to src/ServiceHost/LanguageService/Contracts/InstallModuleRequest.cs diff --git a/src/ServiceHost/LanguageServer/References.cs b/src/ServiceHost/LanguageService/Contracts/References.cs similarity index 100% rename from src/ServiceHost/LanguageServer/References.cs rename to src/ServiceHost/LanguageService/Contracts/References.cs diff --git a/src/ServiceHost/LanguageServer/ShowOnlineHelpRequest.cs b/src/ServiceHost/LanguageService/Contracts/ShowOnlineHelpRequest.cs similarity index 100% rename from src/ServiceHost/LanguageServer/ShowOnlineHelpRequest.cs rename to src/ServiceHost/LanguageService/Contracts/ShowOnlineHelpRequest.cs diff --git a/src/ServiceHost/LanguageServer/SignatureHelp.cs b/src/ServiceHost/LanguageService/Contracts/SignatureHelp.cs similarity index 100% rename from src/ServiceHost/LanguageServer/SignatureHelp.cs rename to src/ServiceHost/LanguageService/Contracts/SignatureHelp.cs diff --git a/src/ServiceHost/LanguageSupport/LanguageService.cs b/src/ServiceHost/LanguageService/LanguageService.cs similarity index 100% rename from src/ServiceHost/LanguageSupport/LanguageService.cs rename to src/ServiceHost/LanguageService/LanguageService.cs diff --git a/src/ServiceHost/LanguageServer/ClientCapabilities.cs b/src/ServiceHost/ServerService/Contracts/ClientCapabilities.cs similarity index 100% rename from src/ServiceHost/LanguageServer/ClientCapabilities.cs rename to src/ServiceHost/ServerService/Contracts/ClientCapabilities.cs diff --git a/src/ServiceHost/LanguageServer/Initialize.cs b/src/ServiceHost/ServerService/Contracts/Initialize.cs similarity index 100% rename from src/ServiceHost/LanguageServer/Initialize.cs rename to src/ServiceHost/ServerService/Contracts/Initialize.cs diff --git a/src/ServiceHost/LanguageServer/ServerCapabilities.cs b/src/ServiceHost/ServerService/Contracts/ServerCapabilities.cs similarity index 100% rename from src/ServiceHost/LanguageServer/ServerCapabilities.cs rename to src/ServiceHost/ServerService/Contracts/ServerCapabilities.cs diff --git a/src/ServiceHost/LanguageServer/Shutdown.cs b/src/ServiceHost/ServerService/Contracts/Shutdown.cs similarity index 100% rename from src/ServiceHost/LanguageServer/Shutdown.cs rename to src/ServiceHost/ServerService/Contracts/Shutdown.cs diff --git a/src/ServiceHost/Workspace/BufferPosition.cs b/src/ServiceHost/WorkspaceService/BufferPosition.cs similarity index 100% rename from src/ServiceHost/Workspace/BufferPosition.cs rename to src/ServiceHost/WorkspaceService/BufferPosition.cs diff --git a/src/ServiceHost/Workspace/BufferRange.cs b/src/ServiceHost/WorkspaceService/BufferRange.cs similarity index 100% rename from src/ServiceHost/Workspace/BufferRange.cs rename to src/ServiceHost/WorkspaceService/BufferRange.cs diff --git a/src/ServiceHost/LanguageServer/Configuration.cs b/src/ServiceHost/WorkspaceService/Configuration.cs similarity index 100% rename from src/ServiceHost/LanguageServer/Configuration.cs rename to src/ServiceHost/WorkspaceService/Configuration.cs diff --git a/src/ServiceHost/Workspace/FileChange.cs b/src/ServiceHost/WorkspaceService/FileChange.cs similarity index 100% rename from src/ServiceHost/Workspace/FileChange.cs rename to src/ServiceHost/WorkspaceService/FileChange.cs diff --git a/src/ServiceHost/Workspace/FilePosition.cs b/src/ServiceHost/WorkspaceService/FilePosition.cs similarity index 100% rename from src/ServiceHost/Workspace/FilePosition.cs rename to src/ServiceHost/WorkspaceService/FilePosition.cs diff --git a/src/ServiceHost/Workspace/ScriptFile.cs b/src/ServiceHost/WorkspaceService/ScriptFile.cs similarity index 100% rename from src/ServiceHost/Workspace/ScriptFile.cs rename to src/ServiceHost/WorkspaceService/ScriptFile.cs diff --git a/src/ServiceHost/Workspace/ScriptFileMarker.cs b/src/ServiceHost/WorkspaceService/ScriptFileMarker.cs similarity index 100% rename from src/ServiceHost/Workspace/ScriptFileMarker.cs rename to src/ServiceHost/WorkspaceService/ScriptFileMarker.cs diff --git a/src/ServiceHost/Workspace/ScriptRegion.cs b/src/ServiceHost/WorkspaceService/ScriptRegion.cs similarity index 100% rename from src/ServiceHost/Workspace/ScriptRegion.cs rename to src/ServiceHost/WorkspaceService/ScriptRegion.cs diff --git a/src/ServiceHost/LanguageServer/TextDocument.cs b/src/ServiceHost/WorkspaceService/TextDocument.cs similarity index 100% rename from src/ServiceHost/LanguageServer/TextDocument.cs rename to src/ServiceHost/WorkspaceService/TextDocument.cs diff --git a/src/ServiceHost/Workspace/Workspace.cs b/src/ServiceHost/WorkspaceService/Workspace.cs similarity index 100% rename from src/ServiceHost/Workspace/Workspace.cs rename to src/ServiceHost/WorkspaceService/Workspace.cs diff --git a/src/ServiceHost/LanguageServer/WorkspaceSymbols.cs b/src/ServiceHost/WorkspaceService/WorkspaceSymbols.cs similarity index 100% rename from src/ServiceHost/LanguageServer/WorkspaceSymbols.cs rename to src/ServiceHost/WorkspaceService/WorkspaceSymbols.cs From 5d776863d88b64c6d185abf9c9e6ba1b8a85d28d Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Thu, 21 Jul 2016 16:53:53 -0700 Subject: [PATCH 07/15] Moving the WorkspaceService contracts into a contract folder I'm not convinced yet that this is the best place for these files, but it will be ok for now. This doesn't build --- .../WorkspaceService/{ => Contracts}/BufferPosition.cs | 0 src/ServiceHost/WorkspaceService/{ => Contracts}/BufferRange.cs | 0 src/ServiceHost/WorkspaceService/{ => Contracts}/Configuration.cs | 0 src/ServiceHost/WorkspaceService/{ => Contracts}/FileChange.cs | 0 src/ServiceHost/WorkspaceService/{ => Contracts}/FilePosition.cs | 0 src/ServiceHost/WorkspaceService/{ => Contracts}/ScriptFile.cs | 0 .../WorkspaceService/{ => Contracts}/ScriptFileMarker.cs | 0 src/ServiceHost/WorkspaceService/{ => Contracts}/ScriptRegion.cs | 0 src/ServiceHost/WorkspaceService/{ => Contracts}/TextDocument.cs | 0 src/ServiceHost/WorkspaceService/{ => Contracts}/Workspace.cs | 0 .../WorkspaceService/{ => Contracts}/WorkspaceSymbols.cs | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename src/ServiceHost/WorkspaceService/{ => Contracts}/BufferPosition.cs (100%) rename src/ServiceHost/WorkspaceService/{ => Contracts}/BufferRange.cs (100%) rename src/ServiceHost/WorkspaceService/{ => Contracts}/Configuration.cs (100%) rename src/ServiceHost/WorkspaceService/{ => Contracts}/FileChange.cs (100%) rename src/ServiceHost/WorkspaceService/{ => Contracts}/FilePosition.cs (100%) rename src/ServiceHost/WorkspaceService/{ => Contracts}/ScriptFile.cs (100%) rename src/ServiceHost/WorkspaceService/{ => Contracts}/ScriptFileMarker.cs (100%) rename src/ServiceHost/WorkspaceService/{ => Contracts}/ScriptRegion.cs (100%) rename src/ServiceHost/WorkspaceService/{ => Contracts}/TextDocument.cs (100%) rename src/ServiceHost/WorkspaceService/{ => Contracts}/Workspace.cs (100%) rename src/ServiceHost/WorkspaceService/{ => Contracts}/WorkspaceSymbols.cs (100%) diff --git a/src/ServiceHost/WorkspaceService/BufferPosition.cs b/src/ServiceHost/WorkspaceService/Contracts/BufferPosition.cs similarity index 100% rename from src/ServiceHost/WorkspaceService/BufferPosition.cs rename to src/ServiceHost/WorkspaceService/Contracts/BufferPosition.cs diff --git a/src/ServiceHost/WorkspaceService/BufferRange.cs b/src/ServiceHost/WorkspaceService/Contracts/BufferRange.cs similarity index 100% rename from src/ServiceHost/WorkspaceService/BufferRange.cs rename to src/ServiceHost/WorkspaceService/Contracts/BufferRange.cs diff --git a/src/ServiceHost/WorkspaceService/Configuration.cs b/src/ServiceHost/WorkspaceService/Contracts/Configuration.cs similarity index 100% rename from src/ServiceHost/WorkspaceService/Configuration.cs rename to src/ServiceHost/WorkspaceService/Contracts/Configuration.cs diff --git a/src/ServiceHost/WorkspaceService/FileChange.cs b/src/ServiceHost/WorkspaceService/Contracts/FileChange.cs similarity index 100% rename from src/ServiceHost/WorkspaceService/FileChange.cs rename to src/ServiceHost/WorkspaceService/Contracts/FileChange.cs diff --git a/src/ServiceHost/WorkspaceService/FilePosition.cs b/src/ServiceHost/WorkspaceService/Contracts/FilePosition.cs similarity index 100% rename from src/ServiceHost/WorkspaceService/FilePosition.cs rename to src/ServiceHost/WorkspaceService/Contracts/FilePosition.cs diff --git a/src/ServiceHost/WorkspaceService/ScriptFile.cs b/src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs similarity index 100% rename from src/ServiceHost/WorkspaceService/ScriptFile.cs rename to src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs diff --git a/src/ServiceHost/WorkspaceService/ScriptFileMarker.cs b/src/ServiceHost/WorkspaceService/Contracts/ScriptFileMarker.cs similarity index 100% rename from src/ServiceHost/WorkspaceService/ScriptFileMarker.cs rename to src/ServiceHost/WorkspaceService/Contracts/ScriptFileMarker.cs diff --git a/src/ServiceHost/WorkspaceService/ScriptRegion.cs b/src/ServiceHost/WorkspaceService/Contracts/ScriptRegion.cs similarity index 100% rename from src/ServiceHost/WorkspaceService/ScriptRegion.cs rename to src/ServiceHost/WorkspaceService/Contracts/ScriptRegion.cs diff --git a/src/ServiceHost/WorkspaceService/TextDocument.cs b/src/ServiceHost/WorkspaceService/Contracts/TextDocument.cs similarity index 100% rename from src/ServiceHost/WorkspaceService/TextDocument.cs rename to src/ServiceHost/WorkspaceService/Contracts/TextDocument.cs diff --git a/src/ServiceHost/WorkspaceService/Workspace.cs b/src/ServiceHost/WorkspaceService/Contracts/Workspace.cs similarity index 100% rename from src/ServiceHost/WorkspaceService/Workspace.cs rename to src/ServiceHost/WorkspaceService/Contracts/Workspace.cs diff --git a/src/ServiceHost/WorkspaceService/WorkspaceSymbols.cs b/src/ServiceHost/WorkspaceService/Contracts/WorkspaceSymbols.cs similarity index 100% rename from src/ServiceHost/WorkspaceService/WorkspaceSymbols.cs rename to src/ServiceHost/WorkspaceService/Contracts/WorkspaceSymbols.cs From 85668cb3deb45f650717fbfffc0e38c9c250e8fc Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Fri, 22 Jul 2016 11:49:50 -0700 Subject: [PATCH 08/15] 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. --- .../LanguageService/Contracts/Completion.cs | 5 +- .../LanguageService/Contracts/Definition.cs | 5 +- .../LanguageService/Contracts/Diagnostics.cs | 5 +- .../Contracts/DocumentHighlight.cs | 5 +- .../Contracts/ExpandAliasRequest.cs | 4 +- .../Contracts/FindModuleRequest.cs | 4 +- .../LanguageService/Contracts/Hover.cs | 5 +- .../Contracts/InstallModuleRequest.cs | 4 +- .../LanguageService/Contracts/References.cs | 5 +- .../Contracts/ShowOnlineHelpRequest.cs | 4 +- .../Contracts/SignatureHelp.cs | 5 +- .../LanguageService/LanguageService.cs | 145 +++++++++++++- src/ServiceHost/Program.cs | 16 +- .../Contracts/ClientCapabilities.cs | 2 +- .../Contracts/Initialize.cs | 4 +- .../Contracts/ServerCapabilities.cs | 2 +- .../Contracts/Shutdown.cs | 4 +- .../Protocol/Channel/ChannelBase.cs | 2 +- .../Protocol/Channel/StdioClientChannel.cs | 1 + .../Protocol/Channel/StdioServerChannel.cs | 1 + .../ServiceHost/Protocol/MessageDispatcher.cs | 1 + .../Serializers/IMessageSerializer.cs | 1 + .../Serializers/JsonRpcMessageSerializer.cs | 1 + .../Serializers/V8MessageSerializer.cs | 1 + src/ServiceHost/ServiceHost/ServiceHost.cs | 189 +++++++++--------- .../ServiceHost/ServiceHostBase.cs | 41 +--- src/ServiceHost/Session/EditorSession.cs | 3 +- .../Contracts/BufferPosition.cs | 2 +- .../WorkspaceService/Contracts/BufferRange.cs | 2 +- .../Contracts/Configuration.cs | 4 +- .../WorkspaceService/Contracts/FileChange.cs | 2 +- .../Contracts/FilePosition.cs | 2 +- .../WorkspaceService/Contracts/ScriptFile.cs | 2 +- .../Contracts/ScriptFileMarker.cs | 2 +- .../Contracts/ScriptRegion.cs | 2 +- .../Contracts/TextDocument.cs | 4 +- .../WorkspaceService/Contracts/Workspace.cs | 2 +- .../Contracts/WorkspaceSymbols.cs | 4 +- 38 files changed, 296 insertions(+), 197 deletions(-) rename src/ServiceHost/{ServerService => ServiceHost}/Contracts/ClientCapabilities.cs (85%) rename src/ServiceHost/{ServerService => ServiceHost}/Contracts/Initialize.cs (91%) rename src/ServiceHost/{ServerService => ServiceHost}/Contracts/ServerCapabilities.cs (96%) rename src/ServiceHost/{ServerService => ServiceHost}/Contracts/Shutdown.cs (85%) diff --git a/src/ServiceHost/LanguageService/Contracts/Completion.cs b/src/ServiceHost/LanguageService/Contracts/Completion.cs index 5f26ea96..ef78330d 100644 --- a/src/ServiceHost/LanguageService/Contracts/Completion.cs +++ b/src/ServiceHost/LanguageService/Contracts/Completion.cs @@ -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 { diff --git a/src/ServiceHost/LanguageService/Contracts/Definition.cs b/src/ServiceHost/LanguageService/Contracts/Definition.cs index b18845c3..b6a211e6 100644 --- a/src/ServiceHost/LanguageService/Contracts/Definition.cs +++ b/src/ServiceHost/LanguageService/Contracts/Definition.cs @@ -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 { diff --git a/src/ServiceHost/LanguageService/Contracts/Diagnostics.cs b/src/ServiceHost/LanguageService/Contracts/Diagnostics.cs index a5472607..c1895bdf 100644 --- a/src/ServiceHost/LanguageService/Contracts/Diagnostics.cs +++ b/src/ServiceHost/LanguageService/Contracts/Diagnostics.cs @@ -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 { diff --git a/src/ServiceHost/LanguageService/Contracts/DocumentHighlight.cs b/src/ServiceHost/LanguageService/Contracts/DocumentHighlight.cs index 6849ddfb..db459eb4 100644 --- a/src/ServiceHost/LanguageService/Contracts/DocumentHighlight.cs +++ b/src/ServiceHost/LanguageService/Contracts/DocumentHighlight.cs @@ -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 { diff --git a/src/ServiceHost/LanguageService/Contracts/ExpandAliasRequest.cs b/src/ServiceHost/LanguageService/Contracts/ExpandAliasRequest.cs index d7f9fde4..7a970db5 100644 --- a/src/ServiceHost/LanguageService/Contracts/ExpandAliasRequest.cs +++ b/src/ServiceHost/LanguageService/Contracts/ExpandAliasRequest.cs @@ -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 { diff --git a/src/ServiceHost/LanguageService/Contracts/FindModuleRequest.cs b/src/ServiceHost/LanguageService/Contracts/FindModuleRequest.cs index ab78a158..dff3939c 100644 --- a/src/ServiceHost/LanguageService/Contracts/FindModuleRequest.cs +++ b/src/ServiceHost/LanguageService/Contracts/FindModuleRequest.cs @@ -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 { diff --git a/src/ServiceHost/LanguageService/Contracts/Hover.cs b/src/ServiceHost/LanguageService/Contracts/Hover.cs index 2e196fba..dd7f05c0 100644 --- a/src/ServiceHost/LanguageService/Contracts/Hover.cs +++ b/src/ServiceHost/LanguageService/Contracts/Hover.cs @@ -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 { diff --git a/src/ServiceHost/LanguageService/Contracts/InstallModuleRequest.cs b/src/ServiceHost/LanguageService/Contracts/InstallModuleRequest.cs index b03b8864..361bb60f 100644 --- a/src/ServiceHost/LanguageService/Contracts/InstallModuleRequest.cs +++ b/src/ServiceHost/LanguageService/Contracts/InstallModuleRequest.cs @@ -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 { diff --git a/src/ServiceHost/LanguageService/Contracts/References.cs b/src/ServiceHost/LanguageService/Contracts/References.cs index 25a92b12..d2e12ccd 100644 --- a/src/ServiceHost/LanguageService/Contracts/References.cs +++ b/src/ServiceHost/LanguageService/Contracts/References.cs @@ -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 { diff --git a/src/ServiceHost/LanguageService/Contracts/ShowOnlineHelpRequest.cs b/src/ServiceHost/LanguageService/Contracts/ShowOnlineHelpRequest.cs index 8f21fb1b..d77eeafa 100644 --- a/src/ServiceHost/LanguageService/Contracts/ShowOnlineHelpRequest.cs +++ b/src/ServiceHost/LanguageService/Contracts/ShowOnlineHelpRequest.cs @@ -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 { diff --git a/src/ServiceHost/LanguageService/Contracts/SignatureHelp.cs b/src/ServiceHost/LanguageService/Contracts/SignatureHelp.cs index 5d4233e3..26e62b21 100644 --- a/src/ServiceHost/LanguageService/Contracts/SignatureHelp.cs +++ b/src/ServiceHost/LanguageService/Contracts/SignatureHelp.cs @@ -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 { diff --git a/src/ServiceHost/LanguageService/LanguageService.cs b/src/ServiceHost/LanguageService/LanguageService.cs index 3ab77697..51665fbd 100644 --- a/src/ServiceHost/LanguageService/LanguageService.cs +++ b/src/ServiceHost/LanguageService/LanguageService.cs @@ -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 { /// /// Main class for Language Service functionality /// public class LanguageService { + + #region Singleton Instance Implementation + + private static LanguageService instance; + + public static LanguageService Instance + { + get + { + if (instance == null) + { + instance = new LanguageService(); + } + return instance; + } + } + + /// + /// Constructor for the Language Service class + /// + /// + private LanguageService(SqlToolsContext context) + { + this.Context = context; + } + + /// + /// Default, parameterless contstructor. + /// TODO: Remove once the SqlToolsContext stuff is sorted out + /// + private LanguageService() + { + + } + + #endregion + /// /// Gets or sets the current SQL Tools context /// /// private SqlToolsContext Context { get; set; } - /// - /// Constructor for the Language Service class - /// - /// - 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 requestContext) + { + Logger.Write(LogLevel.Verbose, "HandleDefinitionRequest"); + await Task.FromResult(true); + } + + private static async Task HandleReferencesRequest( + ReferencesParams referencesParams, + RequestContext requestContext) + { + Logger.Write(LogLevel.Verbose, "HandleReferencesRequest"); + await Task.FromResult(true); + } + + private static async Task HandleCompletionRequest( + TextDocumentPosition textDocumentPosition, + RequestContext requestContext) + { + Logger.Write(LogLevel.Verbose, "HandleCompletionRequest"); + await Task.FromResult(true); + } + + private static async Task HandleCompletionResolveRequest( + CompletionItem completionItem, + RequestContext requestContext) + { + Logger.Write(LogLevel.Verbose, "HandleCompletionResolveRequest"); + await Task.FromResult(true); + } + + private static async Task HandleSignatureHelpRequest( + TextDocumentPosition textDocumentPosition, + RequestContext requestContext) + { + Logger.Write(LogLevel.Verbose, "HandleSignatureHelpRequest"); + await Task.FromResult(true); + } + + private static async Task HandleDocumentHighlightRequest( + TextDocumentPosition textDocumentPosition, + RequestContext requestContext) + { + Logger.Write(LogLevel.Verbose, "HandleDocumentHighlightRequest"); + await Task.FromResult(true); + } + + private static async Task HandleHoverRequest( + TextDocumentPosition textDocumentPosition, + RequestContext requestContext) + { + Logger.Write(LogLevel.Verbose, "HandleHoverRequest"); + await Task.FromResult(true); + } + + private static async Task HandleDocumentSymbolRequest( + TextDocumentIdentifier textDocumentIdentifier, + RequestContext requestContext) + { + Logger.Write(LogLevel.Verbose, "HandleDocumentSymbolRequest"); + await Task.FromResult(true); + } + + private static async Task HandleWorkspaceSymbolRequest( + WorkspaceSymbolParams workspaceSymbolParams, + RequestContext requestContext) + { + Logger.Write(LogLevel.Verbose, "HandleWorkspaceSymbolRequest"); + await Task.FromResult(true); + } + + #endregion + /// /// Gets a list of semantic diagnostic marks for the provided script file /// diff --git a/src/ServiceHost/Program.cs b/src/ServiceHost/Program.cs index 6bfd0f24..fda85c74 100644 --- a/src/ServiceHost/Program.cs +++ b/src/ServiceHost/Program.cs @@ -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 { /// /// 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(); } } } diff --git a/src/ServiceHost/ServerService/Contracts/ClientCapabilities.cs b/src/ServiceHost/ServiceHost/Contracts/ClientCapabilities.cs similarity index 85% rename from src/ServiceHost/ServerService/Contracts/ClientCapabilities.cs rename to src/ServiceHost/ServiceHost/Contracts/ClientCapabilities.cs index 70e2d068..e8b084e7 100644 --- a/src/ServiceHost/ServerService/Contracts/ClientCapabilities.cs +++ b/src/ServiceHost/ServiceHost/Contracts/ClientCapabilities.cs @@ -4,7 +4,7 @@ // -namespace Microsoft.SqlTools.EditorServices.Protocol.LanguageServer +namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts { /// /// Defines a class that describes the capabilities of a language diff --git a/src/ServiceHost/ServerService/Contracts/Initialize.cs b/src/ServiceHost/ServiceHost/Contracts/Initialize.cs similarity index 91% rename from src/ServiceHost/ServerService/Contracts/Initialize.cs rename to src/ServiceHost/ServiceHost/Contracts/Initialize.cs index 7551835e..a5dc1eff 100644 --- a/src/ServiceHost/ServerService/Contracts/Initialize.cs +++ b/src/ServiceHost/ServiceHost/Contracts/Initialize.cs @@ -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 { diff --git a/src/ServiceHost/ServerService/Contracts/ServerCapabilities.cs b/src/ServiceHost/ServiceHost/Contracts/ServerCapabilities.cs similarity index 96% rename from src/ServiceHost/ServerService/Contracts/ServerCapabilities.cs rename to src/ServiceHost/ServiceHost/Contracts/ServerCapabilities.cs index 2f7404d9..f378aa9e 100644 --- a/src/ServiceHost/ServerService/Contracts/ServerCapabilities.cs +++ b/src/ServiceHost/ServiceHost/Contracts/ServerCapabilities.cs @@ -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 { diff --git a/src/ServiceHost/ServerService/Contracts/Shutdown.cs b/src/ServiceHost/ServiceHost/Contracts/Shutdown.cs similarity index 85% rename from src/ServiceHost/ServerService/Contracts/Shutdown.cs rename to src/ServiceHost/ServiceHost/Contracts/Shutdown.cs index f0a7bbd2..395aaef0 100644 --- a/src/ServiceHost/ServerService/Contracts/Shutdown.cs +++ b/src/ServiceHost/ServiceHost/Contracts/Shutdown.cs @@ -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 { /// /// Defines a message that is sent from the client to request diff --git a/src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs b/src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs index 622e5826..3d55ace4 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs @@ -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 { diff --git a/src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs b/src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs index e8645d38..83bf5c38 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs @@ -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 { diff --git a/src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs b/src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs index 46fd5d0f..9aa164e2 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs @@ -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 { diff --git a/src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs b/src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs index 58f541d2..fe4ccdff 100644 --- a/src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs +++ b/src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs @@ -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 { diff --git a/src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs b/src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs index 318955fd..de537b1d 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs @@ -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 diff --git a/src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs b/src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs index 194f270d..bf29a530 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs @@ -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 diff --git a/src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs b/src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs index 81af48f5..7ac68143 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs +++ b/src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs @@ -5,6 +5,7 @@ using Newtonsoft.Json.Linq; using System; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers { diff --git a/src/ServiceHost/ServiceHost/ServiceHost.cs b/src/ServiceHost/ServiceHost/ServiceHost.cs index 53337392..0b393e3f 100644 --- a/src/ServiceHost/ServiceHost/ServiceHost.cs +++ b/src/ServiceHost/ServiceHost/ServiceHost.cs @@ -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 /// public class ServiceHost : ServiceHostBase { + #region Singleton Instance Code + + /// + /// Singleton instance of the instance + /// + private static ServiceHost instance; + + /// + /// Creates or retrieves the current instance of the ServiceHost + /// + /// Details about the host application + /// Details about the profile + /// Instance of the service host + 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; + } + + /// + /// Constructs new instance of ServiceHost using the host and profile details provided. + /// Access is private to ensure only one instance exists at a time. + /// + /// Details about the host application + /// Details about the profile + private ServiceHost(HostDetails hostDetails, ProfilePaths profilePaths) + : base(new StdioServerChannel()) + { + // Initialize the shutdown activities + shutdownActivities = new List(); + + // 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; - /// - /// Provides details about the host application. - /// - public ServiceHost(HostDetails hostDetails, ProfilePaths profilePaths) - : base(new StdioServerChannel()) + public delegate Task ShutdownHandler(object shutdownParams, RequestContext shutdownRequestContext); + + private readonly List shutdownActivities; + + #endregion + + #region Public Methods + + /// + /// Adds a new method to be called when the shutdown request is submitted + /// + /// + public void RegisterShutdownTask(ShutdownHandler activity) { - this.editorSession = new EditorSession(); - this.editorSession.StartSession(hostDetails, profilePaths); + shutdownActivities.Add(activity); } + #endregion + + #region Private Methods + /// /// Initialize the VS Code request/response callbacks /// - 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.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); + } /// /// Handles the shutdown event for the Language Server /// - protected override async Task Shutdown() + private async Task HandleShutdownRequest(object shutdownParams, RequestContext 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); } /// @@ -84,11 +142,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost /// /// /// - protected async Task HandleInitializeRequest( - InitializeRequest initializeParams, - RequestContext requestContext) + private async Task HandleInitializeRequest(InitializeRequest initializeParams, RequestContext 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 + + /////////////////////////////////////////////// + + /// /// Handles text document change events /// @@ -226,78 +287,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost await Task.FromResult(true); } - protected async Task HandleDefinitionRequest( - TextDocumentPosition textDocumentPosition, - RequestContext requestContext) - { - Logger.Write(LogLevel.Verbose, "HandleDefinitionRequest"); - await Task.FromResult(true); - } - - protected async Task HandleReferencesRequest( - ReferencesParams referencesParams, - RequestContext requestContext) - { - Logger.Write(LogLevel.Verbose, "HandleReferencesRequest"); - await Task.FromResult(true); - } - - protected async Task HandleCompletionRequest( - TextDocumentPosition textDocumentPosition, - RequestContext requestContext) - { - Logger.Write(LogLevel.Verbose, "HandleCompletionRequest"); - await Task.FromResult(true); - } - - protected async Task HandleCompletionResolveRequest( - CompletionItem completionItem, - RequestContext requestContext) - { - Logger.Write(LogLevel.Verbose, "HandleCompletionResolveRequest"); - await Task.FromResult(true); - } - - protected async Task HandleSignatureHelpRequest( - TextDocumentPosition textDocumentPosition, - RequestContext requestContext) - { - Logger.Write(LogLevel.Verbose, "HandleSignatureHelpRequest"); - await Task.FromResult(true); - } - - protected async Task HandleDocumentHighlightRequest( - TextDocumentPosition textDocumentPosition, - RequestContext requestContext) - { - Logger.Write(LogLevel.Verbose, "HandleDocumentHighlightRequest"); - await Task.FromResult(true); - } - - protected async Task HandleHoverRequest( - TextDocumentPosition textDocumentPosition, - RequestContext requestContext) - { - Logger.Write(LogLevel.Verbose, "HandleHoverRequest"); - await Task.FromResult(true); - } - - protected async Task HandleDocumentSymbolRequest( - TextDocumentIdentifier textDocumentIdentifier, - RequestContext requestContext) - { - Logger.Write(LogLevel.Verbose, "HandleDocumentSymbolRequest"); - await Task.FromResult(true); - } - - protected async Task HandleWorkspaceSymbolRequest( - WorkspaceSymbolParams workspaceSymbolParams, - RequestContext requestContext) - { - Logger.Write(LogLevel.Verbose, "HandleWorkspaceSymbolRequest"); - await Task.FromResult(true); - } - /// /// Runs script diagnostics on changed files /// @@ -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())); diff --git a/src/ServiceHost/ServiceHost/ServiceHostBase.cs b/src/ServiceHost/ServiceHost/ServiceHostBase.cs index b89c90eb..eb6ec946 100644 --- a/src/ServiceHost/ServiceHost/ServiceHostBase.cs +++ b/src/ServiceHost/ServiceHost/ServiceHostBase.cs @@ -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 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(); - } - - /// - /// Overridden by the subclass to provide initialization - /// logic after the server channel is started. - /// - protected abstract void Initialize(); - - /// - /// 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. - /// - protected virtual Task Shutdown() - { - // No default implementation yet. - return Task.FromResult(true); - } - - private async Task HandleShutdownRequest( - object shutdownParams, - RequestContext requestContext) - { - // Allow the implementor to shut down gracefully - await this.Shutdown(); - - await requestContext.SendResult(new object()); - } - private async Task HandleExitNotification( object exitParams, EventContext eventContext) diff --git a/src/ServiceHost/Session/EditorSession.cs b/src/ServiceHost/Session/EditorSession.cs index 3c592a8f..7b3dcc46 100644 --- a/src/ServiceHost/Session/EditorSession.cs +++ b/src/ServiceHost/Session/EditorSession.cs @@ -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 { diff --git a/src/ServiceHost/WorkspaceService/Contracts/BufferPosition.cs b/src/ServiceHost/WorkspaceService/Contracts/BufferPosition.cs index 8f790d85..020548f6 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/BufferPosition.cs +++ b/src/ServiceHost/WorkspaceService/Contracts/BufferPosition.cs @@ -5,7 +5,7 @@ using System.Diagnostics; -namespace Microsoft.SqlTools.EditorServices +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts { /// /// Provides details about a position in a file buffer. All diff --git a/src/ServiceHost/WorkspaceService/Contracts/BufferRange.cs b/src/ServiceHost/WorkspaceService/Contracts/BufferRange.cs index 5d20598f..f46abb96 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/BufferRange.cs +++ b/src/ServiceHost/WorkspaceService/Contracts/BufferRange.cs @@ -6,7 +6,7 @@ using System; using System.Diagnostics; -namespace Microsoft.SqlTools.EditorServices +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts { /// /// Provides details about a range between two positions in diff --git a/src/ServiceHost/WorkspaceService/Contracts/Configuration.cs b/src/ServiceHost/WorkspaceService/Contracts/Configuration.cs index b9ad87db..45697554 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/Configuration.cs +++ b/src/ServiceHost/WorkspaceService/Contracts/Configuration.cs @@ -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 { diff --git a/src/ServiceHost/WorkspaceService/Contracts/FileChange.cs b/src/ServiceHost/WorkspaceService/Contracts/FileChange.cs index 2f6efdf8..a4398afe 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/FileChange.cs +++ b/src/ServiceHost/WorkspaceService/Contracts/FileChange.cs @@ -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 { /// /// Contains details relating to a content change in an open file. diff --git a/src/ServiceHost/WorkspaceService/Contracts/FilePosition.cs b/src/ServiceHost/WorkspaceService/Contracts/FilePosition.cs index 2cb58745..13e205ca 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/FilePosition.cs +++ b/src/ServiceHost/WorkspaceService/Contracts/FilePosition.cs @@ -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 { /// /// Provides details and operations for a buffer position in a diff --git a/src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs b/src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs index 90d66244..4e30b840 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs +++ b/src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs @@ -9,7 +9,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; -namespace Microsoft.SqlTools.EditorServices +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts { /// /// Contains the details and contents of an open script file. diff --git a/src/ServiceHost/WorkspaceService/Contracts/ScriptFileMarker.cs b/src/ServiceHost/WorkspaceService/Contracts/ScriptFileMarker.cs index 87c2576c..a43de169 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/ScriptFileMarker.cs +++ b/src/ServiceHost/WorkspaceService/Contracts/ScriptFileMarker.cs @@ -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 { /// /// Defines the message level of a script file marker. diff --git a/src/ServiceHost/WorkspaceService/Contracts/ScriptRegion.cs b/src/ServiceHost/WorkspaceService/Contracts/ScriptRegion.cs index f2fa4ac8..943e2252 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/ScriptRegion.cs +++ b/src/ServiceHost/WorkspaceService/Contracts/ScriptRegion.cs @@ -5,7 +5,7 @@ //using System.Management.Automation.Language; -namespace Microsoft.SqlTools.EditorServices +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts { /// /// Contains details about a specific region of text in script file. diff --git a/src/ServiceHost/WorkspaceService/Contracts/TextDocument.cs b/src/ServiceHost/WorkspaceService/Contracts/TextDocument.cs index 9f477374..e091b315 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/TextDocument.cs +++ b/src/ServiceHost/WorkspaceService/Contracts/TextDocument.cs @@ -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 { /// /// Defines a base parameter class for identifying a text document. diff --git a/src/ServiceHost/WorkspaceService/Contracts/Workspace.cs b/src/ServiceHost/WorkspaceService/Contracts/Workspace.cs index 39e1d70f..83b655fd 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/Workspace.cs +++ b/src/ServiceHost/WorkspaceService/Contracts/Workspace.cs @@ -11,7 +11,7 @@ using System.Text; using System.Text.RegularExpressions; using System.Linq; -namespace Microsoft.SqlTools.EditorServices +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts { /// /// Manages a "workspace" of script files that are open for a particular diff --git a/src/ServiceHost/WorkspaceService/Contracts/WorkspaceSymbols.cs b/src/ServiceHost/WorkspaceService/Contracts/WorkspaceSymbols.cs index 25a554b5..347a9468 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/WorkspaceSymbols.cs +++ b/src/ServiceHost/WorkspaceService/Contracts/WorkspaceSymbols.cs @@ -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 { From b9f041cdf47b64188e6b8bac5eafb81de09d1f47 Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Fri, 22 Jul 2016 16:41:23 -0700 Subject: [PATCH 09/15] The last 10% of the refactor This will build successfully --- .../LanguageService/LanguageService.cs | 260 ++++++++++- src/ServiceHost/Program.cs | 10 +- src/ServiceHost/ServiceHost/ServiceHost.cs | 406 ++---------------- src/ServiceHost/Session/EditorSession.cs | 76 ---- .../{Session => SqlContext}/HostDetails.cs | 2 +- .../{Session => SqlContext}/ProfilePaths.cs | 3 +- .../SqlToolsContext.cs | 2 +- .../SqlToolsSettings.cs} | 38 +- .../WorkspaceService/Contracts/ScriptFile.cs | 16 +- .../{Contracts => }/Workspace.cs | 40 +- .../WorkspaceService/WorkspaceService.cs | 216 ++++++++++ 11 files changed, 533 insertions(+), 536 deletions(-) delete mode 100644 src/ServiceHost/Session/EditorSession.cs rename src/ServiceHost/{Session => SqlContext}/HostDetails.cs (98%) rename src/ServiceHost/{Session => SqlContext}/ProfilePaths.cs (98%) rename src/ServiceHost/{Session => SqlContext}/SqlToolsContext.cs (91%) rename src/ServiceHost/{ServiceHost/ServiceHostSettings.cs => SqlContext/SqlToolsSettings.cs} (82%) rename src/ServiceHost/WorkspaceService/{Contracts => }/Workspace.cs (90%) create mode 100644 src/ServiceHost/WorkspaceService/WorkspaceService.cs diff --git a/src/ServiceHost/LanguageService/LanguageService.cs b/src/ServiceHost/LanguageService/LanguageService.cs index 51665fbd..05cc90c5 100644 --- a/src/ServiceHost/LanguageService/LanguageService.cs +++ b/src/ServiceHost/LanguageService/LanguageService.cs @@ -3,12 +3,16 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // +using System; +using System.Threading; 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.SqlContext; +using Microsoft.SqlTools.ServiceLayer.WorkspaceService; using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; +using System.Linq; namespace Microsoft.SqlTools.ServiceLayer.LanguageService { @@ -34,15 +38,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageService } } - /// - /// Constructor for the Language Service class - /// - /// - private LanguageService(SqlToolsContext context) - { - this.Context = context; - } - /// /// Default, parameterless contstructor. /// TODO: Remove once the SqlToolsContext stuff is sorted out @@ -54,13 +49,29 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageService #endregion + #region Properties + + private static CancellationTokenSource ExistingRequestCancellation { get; set; } + + private SqlToolsSettings CurrentSettings + { + get { return WorkspaceService.Instance.CurrentSettings; } + } + + private Workspace CurrentWorkspace + { + get { return WorkspaceService.Instance.Workspace; } + } + /// /// Gets or sets the current SQL Tools context /// /// private SqlToolsContext Context { get; set; } - public void InitializeService(ServiceHost.ServiceHost serviceHost) + #endregion + + public void InitializeService(ServiceHost.ServiceHost serviceHost, SqlToolsContext context) { // Register the requests that this service will handle serviceHost.SetRequestHandler(DefinitionRequest.Type, HandleDefinitionRequest); @@ -79,6 +90,12 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageService Logger.Write(LogLevel.Verbose, "Shutting down language service"); await Task.FromResult(0); }); + + // Register the configuration update handler + WorkspaceService.Instance.RegisterDidChangeConfigurationNotificationTask(HandleDidChangeConfigurationNotification); + + // Store the SqlToolsContext for future use + Context = context; } #region Request Handlers @@ -157,11 +174,48 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageService #endregion + #region Handlers for Events from Other Services + + public async Task HandleDidChangeConfigurationNotification( + SqlToolsSettings newSettings, + SqlToolsSettings oldSettings, + EventContext eventContext) + { + // If script analysis settings have changed we need to clear & possibly update the current diagnostic records. + bool oldScriptAnalysisEnabled = oldSettings.ScriptAnalysis.Enable.HasValue; + if ((oldScriptAnalysisEnabled != newSettings.ScriptAnalysis.Enable)) + { + // If the user just turned off script analysis or changed the settings path, send a diagnostics + // event to clear the analysis markers that they already have. + if (!newSettings.ScriptAnalysis.Enable.Value) + { + ScriptFileMarker[] emptyAnalysisDiagnostics = new ScriptFileMarker[0]; + + foreach (var scriptFile in WorkspaceService.Instance.Workspace.GetOpenedFiles()) + { + await PublishScriptDiagnostics(scriptFile, emptyAnalysisDiagnostics, eventContext); + } + } + else + { + await this.RunScriptDiagnostics(CurrentWorkspace.GetOpenedFiles(), eventContext); + } + } + + // Update the settings in the current + CurrentSettings.EnableProfileLoading = newSettings.EnableProfileLoading; + CurrentSettings.ScriptAnalysis.Update(newSettings.ScriptAnalysis, CurrentWorkspace.WorkspacePath); + } + + #endregion + + #region Private Helpers + /// /// Gets a list of semantic diagnostic marks for the provided script file /// /// - public ScriptFileMarker[] GetSemanticMarkers(ScriptFile scriptFile) + private ScriptFileMarker[] GetSemanticMarkers(ScriptFile scriptFile) { // the commented out snippet is an example of how to create a error marker // semanticMarkers = new ScriptFileMarker[1]; @@ -182,5 +236,187 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageService // }; return new ScriptFileMarker[0]; } + + /// + /// Runs script diagnostics on changed files + /// + /// + /// + private Task RunScriptDiagnostics(ScriptFile[] filesToAnalyze, EventContext eventContext) + { + if (!CurrentSettings.ScriptAnalysis.Enable.Value) + { + // If the user has disabled script analysis, skip it entirely + return Task.FromResult(true); + } + + // If there's an existing task, attempt to cancel it + try + { + if (ExistingRequestCancellation != null) + { + // Try to cancel the request + ExistingRequestCancellation.Cancel(); + + // If cancellation didn't throw an exception, + // clean up the existing token + ExistingRequestCancellation.Dispose(); + ExistingRequestCancellation = null; + } + } + catch (Exception e) + { + Logger.Write( + LogLevel.Error, + String.Format( + "Exception while cancelling analysis task:\n\n{0}", + e.ToString())); + + TaskCompletionSource cancelTask = new TaskCompletionSource(); + cancelTask.SetCanceled(); + return cancelTask.Task; + } + + // Create a fresh cancellation token and then start the task. + // We create this on a different TaskScheduler so that we + // don't block the main message loop thread. + ExistingRequestCancellation = new CancellationTokenSource(); + Task.Factory.StartNew( + () => + DelayThenInvokeDiagnostics( + 750, + filesToAnalyze, + eventContext, + ExistingRequestCancellation.Token), + CancellationToken.None, + TaskCreationOptions.None, + TaskScheduler.Default); + + return Task.FromResult(true); + } + + /// + /// Actually run the script diagnostics after waiting for some small delay + /// + /// + /// + /// + /// + private async Task DelayThenInvokeDiagnostics( + int delayMilliseconds, + ScriptFile[] filesToAnalyze, + EventContext eventContext, + CancellationToken cancellationToken) + { + // First of all, wait for the desired delay period before + // analyzing the provided list of files + try + { + await Task.Delay(delayMilliseconds, cancellationToken); + } + catch (TaskCanceledException) + { + // If the task is cancelled, exit directly + return; + } + + // If we've made it past the delay period then we don't care + // about the cancellation token anymore. This could happen + // when the user stops typing for long enough that the delay + // period ends but then starts typing while analysis is going + // on. It makes sense to send back the results from the first + // delay period while the second one is ticking away. + + // Get the requested files + foreach (ScriptFile scriptFile in filesToAnalyze) + { + Logger.Write(LogLevel.Verbose, "Analyzing script file: " + scriptFile.FilePath); + ScriptFileMarker[] semanticMarkers = GetSemanticMarkers(scriptFile); + Logger.Write(LogLevel.Verbose, "Analysis complete."); + + await PublishScriptDiagnostics(scriptFile, semanticMarkers, eventContext); + } + } + + /// + /// Send the diagnostic results back to the host application + /// + /// + /// + /// + private static async Task PublishScriptDiagnostics( + ScriptFile scriptFile, + ScriptFileMarker[] semanticMarkers, + EventContext eventContext) + { + var allMarkers = scriptFile.SyntaxMarkers != null + ? scriptFile.SyntaxMarkers.Concat(semanticMarkers) + : semanticMarkers; + + // Always send syntax and semantic errors. We want to + // make sure no out-of-date markers are being displayed. + await eventContext.SendEvent( + PublishDiagnosticsNotification.Type, + new PublishDiagnosticsNotification + { + Uri = scriptFile.ClientFilePath, + Diagnostics = + allMarkers + .Select(GetDiagnosticFromMarker) + .ToArray() + }); + } + + /// + /// Convert a ScriptFileMarker to a Diagnostic that is Language Service compatible + /// + /// + /// + private static Diagnostic GetDiagnosticFromMarker(ScriptFileMarker scriptFileMarker) + { + return new Diagnostic + { + Severity = MapDiagnosticSeverity(scriptFileMarker.Level), + Message = scriptFileMarker.Message, + Range = new Range + { + // TODO: What offsets should I use? + Start = new Position + { + Line = scriptFileMarker.ScriptRegion.StartLineNumber - 1, + Character = scriptFileMarker.ScriptRegion.StartColumnNumber - 1 + }, + End = new Position + { + Line = scriptFileMarker.ScriptRegion.EndLineNumber - 1, + Character = scriptFileMarker.ScriptRegion.EndColumnNumber - 1 + } + } + }; + } + + /// + /// Map ScriptFileMarker severity to Diagnostic severity + /// + /// + private static DiagnosticSeverity MapDiagnosticSeverity(ScriptFileMarkerLevel markerLevel) + { + switch (markerLevel) + { + case ScriptFileMarkerLevel.Error: + return DiagnosticSeverity.Error; + + case ScriptFileMarkerLevel.Warning: + return DiagnosticSeverity.Warning; + + case ScriptFileMarkerLevel.Information: + return DiagnosticSeverity.Information; + + default: + return DiagnosticSeverity.Error; + } + } + + #endregion } } diff --git a/src/ServiceHost/Program.cs b/src/ServiceHost/Program.cs index fda85c74..9717feb3 100644 --- a/src/ServiceHost/Program.cs +++ b/src/ServiceHost/Program.cs @@ -2,8 +2,8 @@ // 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.Session; using Microsoft.SqlTools.EditorServices.Utility; +using Microsoft.SqlTools.ServiceLayer.SqlContext; namespace Microsoft.SqlTools.ServiceLayer { @@ -24,17 +24,19 @@ namespace Microsoft.SqlTools.ServiceLayer const string hostName = "SQL Tools Service Host"; const string hostProfileId = "SQLToolsService"; - Version hostVersion = new Version(1,0); + Version hostVersion = new Version(1,0); // set up the host details and profile paths var hostDetails = new HostDetails(hostName, hostProfileId, hostVersion); var profilePaths = new ProfilePaths(hostProfileId, "baseAllUsersPath", "baseCurrentUserPath"); + SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails, profilePaths); // Create the service host - ServiceHost.ServiceHost serviceHost = ServiceHost.ServiceHost.Create(hostDetails, profilePaths); + ServiceHost.ServiceHost serviceHost = ServiceHost.ServiceHost.Create(); // Initialize the services that will be hosted here - LanguageService.LanguageService.Instance.InitializeService(serviceHost); + WorkspaceService.WorkspaceService.Instance.InitializeService(serviceHost); + LanguageService.LanguageService.Instance.InitializeService(serviceHost, sqlToolsContext); // Start the service serviceHost.Start().Wait(); diff --git a/src/ServiceHost/ServiceHost/ServiceHost.cs b/src/ServiceHost/ServiceHost/ServiceHost.cs index 0b393e3f..1e433b91 100644 --- a/src/ServiceHost/ServiceHost/ServiceHost.cs +++ b/src/ServiceHost/ServiceHost/ServiceHost.cs @@ -5,18 +5,11 @@ using System.Threading.Tasks; using System.Collections.Generic; -using System.Text; -using System.Threading; using System.Linq; -using System; -using Microsoft.SqlTools.EditorServices; -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 { @@ -35,18 +28,13 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost /// /// Creates or retrieves the current instance of the ServiceHost /// - /// Details about the host application - /// Details about the profile /// Instance of the service host - public static ServiceHost Create(HostDetails hostDetails, ProfilePaths profilePaths) + public static ServiceHost Create() { if (instance == null) { - instance = new ServiceHost(hostDetails, profilePaths); + instance = new ServiceHost(); } - // 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; } @@ -54,17 +42,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost /// Constructs new instance of ServiceHost using the host and profile details provided. /// Access is private to ensure only one instance exists at a time. /// - /// Details about the host application - /// Details about the profile - private ServiceHost(HostDetails hostDetails, ProfilePaths profilePaths) - : base(new StdioServerChannel()) + private ServiceHost() : base(new StdioServerChannel()) { // Initialize the shutdown activities shutdownActivities = new List(); - - // Create an editor session that we'll use for keeping track of state - this.editorSession = new EditorSession(); - this.editorSession.StartSession(hostDetails, profilePaths); + initializeActivities = new List(); // Register the requests that this service host will handle this.SetRequestHandler(InitializeRequest.Type, this.HandleInitializeRequest); @@ -75,16 +57,14 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost #region Member Variables - private static CancellationTokenSource existingRequestCancellation; - - private ServiceHostSettings currentSettings = new ServiceHostSettings(); - - private EditorSession editorSession; - public delegate Task ShutdownHandler(object shutdownParams, RequestContext shutdownRequestContext); + public delegate Task InitializeHandler(InitializeRequest startupParams, RequestContext requestContext); + private readonly List shutdownActivities; + private readonly List initializeActivities; + #endregion #region Public Methods @@ -98,24 +78,18 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost shutdownActivities.Add(activity); } + /// + /// Add a new method to be called when the initialize request is submitted + /// + /// + public void RegisterInitializeTask(InitializeHandler activity) + { + initializeActivities.Add(activity); + } + #endregion - #region Private Methods - - /// - /// Initialize the VS Code request/response callbacks - /// - private void Initialize() - { - // Register all supported message types - - this.SetEventHandler(DidChangeTextDocumentNotification.Type, this.HandleDidChangeTextDocumentNotification); - this.SetEventHandler(DidOpenTextDocumentNotification.Type, this.HandleDidOpenTextDocumentNotification); - this.SetEventHandler(DidCloseTextDocumentNotification.Type, this.HandleDidCloseTextDocumentNotification); - this.SetEventHandler(DidChangeConfigurationNotification.Type, this.HandleDidChangeConfigurationNotification); - - - } + #region Request Handlers /// /// Handles the shutdown event for the Language Server @@ -127,13 +101,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost // 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; - } } /// @@ -146,9 +113,13 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost { Logger.Write(LogLevel.Verbose, "HandleInitializationRequest"); - // Grab the workspace path from the parameters - editorSession.Workspace.WorkspacePath = initializeParams.RootPath; + // Call all tasks that registered on the initialize request + var initializeTasks = initializeActivities.Select(t => t(initializeParams, requestContext)); + await Task.WhenAll(initializeTasks); + // TODO: Figure out where this needs to go to be agnostic of the language + + // Send back what this server can do await requestContext.SendResult( new InitializeResult { @@ -175,334 +146,5 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost } #endregion - - /////////////////////////////////////////////// - - - /// - /// Handles text document change events - /// - /// - /// - /// - protected Task HandleDidChangeTextDocumentNotification( - DidChangeTextDocumentParams textChangeParams, - EventContext eventContext) - { - StringBuilder msg = new StringBuilder(); - msg.Append("HandleDidChangeTextDocumentNotification"); - List changedFiles = new List(); - - // A text change notification can batch multiple change requests - foreach (var textChange in textChangeParams.ContentChanges) - { - string fileUri = textChangeParams.TextDocument.Uri; - msg.AppendLine(); - msg.Append(" File: "); - msg.Append(fileUri); - - ScriptFile changedFile = editorSession.Workspace.GetFile(fileUri); - - changedFile.ApplyChange( - GetFileChangeDetails( - textChange.Range.Value, - textChange.Text)); - - changedFiles.Add(changedFile); - } - - Logger.Write(LogLevel.Verbose, msg.ToString()); - - this.RunScriptDiagnostics( - changedFiles.ToArray(), - editorSession, - eventContext); - - return Task.FromResult(true); - } - - protected Task HandleDidOpenTextDocumentNotification( - DidOpenTextDocumentNotification openParams, - EventContext eventContext) - { - Logger.Write(LogLevel.Verbose, "HandleDidOpenTextDocumentNotification"); - return Task.FromResult(true); - } - - protected Task HandleDidCloseTextDocumentNotification( - TextDocumentIdentifier closeParams, - EventContext eventContext) - { - Logger.Write(LogLevel.Verbose, "HandleDidCloseTextDocumentNotification"); - return Task.FromResult(true); - } - - /// - /// Handles the configuration change event - /// - /// - /// - protected async Task HandleDidChangeConfigurationNotification( - DidChangeConfigurationParams configChangeParams, - EventContext eventContext) - { - Logger.Write(LogLevel.Verbose, "HandleDidChangeConfigurationNotification"); - - bool oldLoadProfiles = this.currentSettings.EnableProfileLoading; - bool oldScriptAnalysisEnabled = - this.currentSettings.ScriptAnalysis.Enable.HasValue; - string oldScriptAnalysisSettingsPath = - this.currentSettings.ScriptAnalysis.SettingsPath; - - this.currentSettings.Update( - configChangeParams.Settings.SqlTools, - this.editorSession.Workspace.WorkspacePath); - - // If script analysis settings have changed we need to clear & possibly update the current diagnostic records. - if ((oldScriptAnalysisEnabled != this.currentSettings.ScriptAnalysis.Enable)) - { - // If the user just turned off script analysis or changed the settings path, send a diagnostics - // event to clear the analysis markers that they already have. - if (!this.currentSettings.ScriptAnalysis.Enable.Value) - { - ScriptFileMarker[] emptyAnalysisDiagnostics = new ScriptFileMarker[0]; - - foreach (var scriptFile in editorSession.Workspace.GetOpenedFiles()) - { - await PublishScriptDiagnostics( - scriptFile, - emptyAnalysisDiagnostics, - eventContext); - } - } - else - { - await this.RunScriptDiagnostics( - this.editorSession.Workspace.GetOpenedFiles(), - this.editorSession, - eventContext); - } - } - - await Task.FromResult(true); - } - - /// - /// Runs script diagnostics on changed files - /// - /// - /// - /// - private Task RunScriptDiagnostics( - ScriptFile[] filesToAnalyze, - EditorSession editorSession, - EventContext eventContext) - { - if (!this.currentSettings.ScriptAnalysis.Enable.Value) - { - // If the user has disabled script analysis, skip it entirely - return Task.FromResult(true); - } - - // If there's an existing task, attempt to cancel it - try - { - if (existingRequestCancellation != null) - { - // Try to cancel the request - existingRequestCancellation.Cancel(); - - // If cancellation didn't throw an exception, - // clean up the existing token - existingRequestCancellation.Dispose(); - existingRequestCancellation = null; - } - } - catch (Exception e) - { - Logger.Write( - LogLevel.Error, - String.Format( - "Exception while cancelling analysis task:\n\n{0}", - e.ToString())); - - TaskCompletionSource cancelTask = new TaskCompletionSource(); - cancelTask.SetCanceled(); - return cancelTask.Task; - } - - // Create a fresh cancellation token and then start the task. - // We create this on a different TaskScheduler so that we - // don't block the main message loop thread. - existingRequestCancellation = new CancellationTokenSource(); - Task.Factory.StartNew( - () => - DelayThenInvokeDiagnostics( - 750, - filesToAnalyze, - editorSession, - eventContext, - existingRequestCancellation.Token), - CancellationToken.None, - TaskCreationOptions.None, - TaskScheduler.Default); - - return Task.FromResult(true); - } - - /// - /// Actually run the script diagnostics after waiting for some small delay - /// - /// - /// - /// - /// - /// - private static async Task DelayThenInvokeDiagnostics( - int delayMilliseconds, - ScriptFile[] filesToAnalyze, - EditorSession editorSession, - EventContext eventContext, - CancellationToken cancellationToken) - { - // First of all, wait for the desired delay period before - // analyzing the provided list of files - try - { - await Task.Delay(delayMilliseconds, cancellationToken); - } - catch (TaskCanceledException) - { - // If the task is cancelled, exit directly - return; - } - - // If we've made it past the delay period then we don't care - // about the cancellation token anymore. This could happen - // when the user stops typing for long enough that the delay - // period ends but then starts typing while analysis is going - // on. It makes sense to send back the results from the first - // delay period while the second one is ticking away. - - // Get the requested files - foreach (ScriptFile scriptFile in filesToAnalyze) - { - ScriptFileMarker[] semanticMarkers = null; - if (editorSession.LanguageService != null) - { - Logger.Write(LogLevel.Verbose, "Analyzing script file: " + scriptFile.FilePath); - semanticMarkers = editorSession.LanguageService.GetSemanticMarkers(scriptFile); - Logger.Write(LogLevel.Verbose, "Analysis complete."); - } - else - { - // Semantic markers aren't available if the AnalysisService - // isn't available - semanticMarkers = new ScriptFileMarker[0]; - } - - await PublishScriptDiagnostics( - scriptFile, - semanticMarkers, - eventContext); - } - } - - /// - /// Send the diagnostic results back to the host application - /// - /// - /// - /// - private static async Task PublishScriptDiagnostics( - ScriptFile scriptFile, - ScriptFileMarker[] semanticMarkers, - EventContext eventContext) - { - var allMarkers = scriptFile.SyntaxMarkers != null - ? scriptFile.SyntaxMarkers.Concat(semanticMarkers) - : semanticMarkers; - - // Always send syntax and semantic errors. We want to - // make sure no out-of-date markers are being displayed. - await eventContext.SendEvent( - PublishDiagnosticsNotification.Type, - new PublishDiagnosticsNotification - { - Uri = scriptFile.ClientFilePath, - Diagnostics = - allMarkers - .Select(GetDiagnosticFromMarker) - .ToArray() - }); - } - - /// - /// Convert a ScriptFileMarker to a Diagnostic that is Language Service compatible - /// - /// - /// - private static Diagnostic GetDiagnosticFromMarker(ScriptFileMarker scriptFileMarker) - { - return new Diagnostic - { - Severity = MapDiagnosticSeverity(scriptFileMarker.Level), - Message = scriptFileMarker.Message, - Range = new Range - { - // TODO: What offsets should I use? - Start = new Position - { - Line = scriptFileMarker.ScriptRegion.StartLineNumber - 1, - Character = scriptFileMarker.ScriptRegion.StartColumnNumber - 1 - }, - End = new Position - { - Line = scriptFileMarker.ScriptRegion.EndLineNumber - 1, - Character = scriptFileMarker.ScriptRegion.EndColumnNumber - 1 - } - } - }; - } - - /// - /// Map ScriptFileMarker severity to Diagnostic severity - /// - /// - private static DiagnosticSeverity MapDiagnosticSeverity(ScriptFileMarkerLevel markerLevel) - { - switch (markerLevel) - { - case ScriptFileMarkerLevel.Error: - return DiagnosticSeverity.Error; - - case ScriptFileMarkerLevel.Warning: - return DiagnosticSeverity.Warning; - - case ScriptFileMarkerLevel.Information: - return DiagnosticSeverity.Information; - - default: - return DiagnosticSeverity.Error; - } - } - - /// - /// Switch from 0-based offsets to 1 based offsets - /// - /// - /// - private static FileChange GetFileChangeDetails(Range changeRange, string insertString) - { - // The protocol's positions are zero-based so add 1 to all offsets - return new FileChange - { - InsertString = insertString, - Line = changeRange.Start.Line + 1, - Offset = changeRange.Start.Character + 1, - EndLine = changeRange.End.Line + 1, - EndOffset = changeRange.End.Character + 1 - }; - } } } diff --git a/src/ServiceHost/Session/EditorSession.cs b/src/ServiceHost/Session/EditorSession.cs deleted file mode 100644 index 7b3dcc46..00000000 --- a/src/ServiceHost/Session/EditorSession.cs +++ /dev/null @@ -1,76 +0,0 @@ -// -// 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.Session; -using Microsoft.SqlTools.ServiceLayer.LanguageService; -using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; - -namespace Microsoft.SqlTools.EditorServices -{ - /// - /// Manages a single session for all editor services. This - /// includes managing all open script files for the session. - /// - public class EditorSession : IDisposable - { - #region Properties - - /// - /// Gets the Workspace instance for this session. - /// - public Workspace Workspace { get; private set; } - - /// - /// Gets or sets the Language Service - /// - /// - public LanguageService LanguageService { get; set; } - - /// - /// Gets the SqlToolsContext instance for this session. - /// - public SqlToolsContext SqlToolsContext { get; private set; } - - #endregion - - #region Public Methods - - /// - /// Starts the session using the provided IConsoleHost implementation - /// for the ConsoleService. - /// - /// - /// Provides details about the host application. - /// - /// - /// An object containing the profile paths for the session. - /// - public void StartSession(HostDetails hostDetails, ProfilePaths profilePaths) - { - // Initialize all services - this.SqlToolsContext = new SqlToolsContext(hostDetails, profilePaths); - this.LanguageService = new LanguageService(this.SqlToolsContext); - - // Create a workspace to contain open files - this.Workspace = new Workspace(this.SqlToolsContext.SqlToolsVersion); - } - - #endregion - - #region IDisposable Implementation - - /// - /// Disposes of any Runspaces that were created for the - /// services used in this session. - /// - public void Dispose() - { - } - - #endregion - - } -} diff --git a/src/ServiceHost/Session/HostDetails.cs b/src/ServiceHost/SqlContext/HostDetails.cs similarity index 98% rename from src/ServiceHost/Session/HostDetails.cs rename to src/ServiceHost/SqlContext/HostDetails.cs index 1a5fc80d..1b78faa4 100644 --- a/src/ServiceHost/Session/HostDetails.cs +++ b/src/ServiceHost/SqlContext/HostDetails.cs @@ -5,7 +5,7 @@ using System; -namespace Microsoft.SqlTools.EditorServices.Session +namespace Microsoft.SqlTools.ServiceLayer.SqlContext { /// /// Contains details about the current host application (most diff --git a/src/ServiceHost/Session/ProfilePaths.cs b/src/ServiceHost/SqlContext/ProfilePaths.cs similarity index 98% rename from src/ServiceHost/Session/ProfilePaths.cs rename to src/ServiceHost/SqlContext/ProfilePaths.cs index 4af38521..f841970d 100644 --- a/src/ServiceHost/Session/ProfilePaths.cs +++ b/src/ServiceHost/SqlContext/ProfilePaths.cs @@ -3,12 +3,11 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using System; using System.Collections.Generic; using System.IO; using System.Linq; -namespace Microsoft.SqlTools.EditorServices.Session +namespace Microsoft.SqlTools.ServiceLayer.SqlContext { /// /// Provides profile path resolution behavior relative to the name diff --git a/src/ServiceHost/Session/SqlToolsContext.cs b/src/ServiceHost/SqlContext/SqlToolsContext.cs similarity index 91% rename from src/ServiceHost/Session/SqlToolsContext.cs rename to src/ServiceHost/SqlContext/SqlToolsContext.cs index d8016afd..bf4d67c9 100644 --- a/src/ServiceHost/Session/SqlToolsContext.cs +++ b/src/ServiceHost/SqlContext/SqlToolsContext.cs @@ -5,7 +5,7 @@ using System; -namespace Microsoft.SqlTools.EditorServices.Session +namespace Microsoft.SqlTools.ServiceLayer.SqlContext { public class SqlToolsContext { diff --git a/src/ServiceHost/ServiceHost/ServiceHostSettings.cs b/src/ServiceHost/SqlContext/SqlToolsSettings.cs similarity index 82% rename from src/ServiceHost/ServiceHost/ServiceHostSettings.cs rename to src/ServiceHost/SqlContext/SqlToolsSettings.cs index 53d99647..a6f242ed 100644 --- a/src/ServiceHost/ServiceHost/ServiceHostSettings.cs +++ b/src/ServiceHost/SqlContext/SqlToolsSettings.cs @@ -1,25 +1,26 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -using System.IO; +using System.IO; using Microsoft.SqlTools.EditorServices.Utility; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost +namespace Microsoft.SqlTools.ServiceLayer.SqlContext { - public class ServiceHostSettings + public class SqlToolsSettings { - public bool EnableProfileLoading { get; set; } + // TODO: Is this needed? I can't make sense of this comment. + // NOTE: This property is capitalized as 'SqlTools' because the + // mode name sent from the client is written as 'SqlTools' and + // JSON.net is using camelCasing. + //public ServiceHostSettings SqlTools { get; set; } - public ScriptAnalysisSettings ScriptAnalysis { get; set; } - - public ServiceHostSettings() + public SqlToolsSettings() { this.ScriptAnalysis = new ScriptAnalysisSettings(); } - public void Update(ServiceHostSettings settings, string workspaceRootPath) + public bool EnableProfileLoading { get; set; } + + public ScriptAnalysisSettings ScriptAnalysis { get; set; } + + public void Update(SqlToolsSettings settings, string workspaceRootPath) { if (settings != null) { @@ -28,7 +29,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost } } } - public class ScriptAnalysisSettings { @@ -77,14 +77,4 @@ namespace Microsoft.SqlTools.ServiceLayer.ServiceHost } } } - - - public class LanguageServerSettingsWrapper - { - // NOTE: This property is capitalized as 'SqlTools' because the - // mode name sent from the client is written as 'SqlTools' and - // JSON.net is using camelCasing. - - public ServiceHostSettings SqlTools { get; set; } - } } diff --git a/src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs b/src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs index 4e30b840..134cdb9b 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs +++ b/src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs @@ -16,12 +16,6 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts /// public class ScriptFile { - #region Private Fields - - private Version SqlToolsVersion; - - #endregion - #region Properties /// @@ -113,18 +107,15 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts /// The path at which the script file resides. /// The path which the client uses to identify the file. /// The TextReader to use for reading the file's contents. - /// The version of SqlTools for which the script is being parsed. public ScriptFile( string filePath, string clientFilePath, - TextReader textReader, - Version SqlToolsVersion) + TextReader textReader) { this.FilePath = filePath; this.ClientFilePath = clientFilePath; this.IsAnalysisEnabled = true; this.IsInMemory = Workspace.IsPathInMemory(filePath); - this.SqlToolsVersion = SqlToolsVersion; this.SetFileContents(textReader.ReadToEnd()); } @@ -135,17 +126,14 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts /// The path at which the script file resides. /// The path which the client uses to identify the file. /// The initial contents of the script file. - /// The version of SqlTools for which the script is being parsed. public ScriptFile( string filePath, string clientFilePath, - string initialBuffer, - Version SqlToolsVersion) + string initialBuffer) { this.FilePath = filePath; this.ClientFilePath = clientFilePath; this.IsAnalysisEnabled = true; - this.SqlToolsVersion = SqlToolsVersion; this.SetFileContents(initialBuffer); } diff --git a/src/ServiceHost/WorkspaceService/Contracts/Workspace.cs b/src/ServiceHost/WorkspaceService/Workspace.cs similarity index 90% rename from src/ServiceHost/WorkspaceService/Contracts/Workspace.cs rename to src/ServiceHost/WorkspaceService/Workspace.cs index 83b655fd..6aa8f479 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/Workspace.cs +++ b/src/ServiceHost/WorkspaceService/Workspace.cs @@ -3,25 +3,25 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.EditorServices.Utility; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Linq; +using Microsoft.SqlTools.EditorServices.Utility; +using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService { /// /// Manages a "workspace" of script files that are open for a particular /// editing session. Also helps to navigate references between ScriptFiles. /// - public class Workspace + public class Workspace : IDisposable { - #region Private Fields + #region Private Fields - private Version SqlToolsVersion; private Dictionary workspaceFiles = new Dictionary(); #endregion @@ -40,10 +40,8 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts /// /// Creates a new instance of the Workspace class. /// - /// The version of SqlTools for which scripts will be parsed. - public Workspace(Version SqlToolsVersion) + public Workspace() { - this.SqlToolsVersion = SqlToolsVersion; } #endregion @@ -78,12 +76,7 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts using (FileStream fileStream = new FileStream(resolvedFilePath, FileMode.Open, FileAccess.Read)) using (StreamReader streamReader = new StreamReader(fileStream, Encoding.UTF8)) { - scriptFile = - new ScriptFile( - resolvedFilePath, - filePath, - streamReader, - this.SqlToolsVersion); + scriptFile = new ScriptFile(resolvedFilePath, filePath,streamReader); this.workspaceFiles.Add(keyName, scriptFile); } @@ -169,12 +162,7 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts ScriptFile scriptFile = null; if (!this.workspaceFiles.TryGetValue(keyName, out scriptFile)) { - scriptFile = - new ScriptFile( - resolvedFilePath, - filePath, - initialBuffer, - this.SqlToolsVersion); + scriptFile = new ScriptFile(resolvedFilePath, filePath, initialBuffer); this.workspaceFiles.Add(keyName, scriptFile); @@ -244,5 +232,17 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts } #endregion + + #region IDisposable Implementation + + /// + /// Disposes of any Runspaces that were created for the + /// services used in this session. + /// + public void Dispose() + { + } + + #endregion } } diff --git a/src/ServiceHost/WorkspaceService/WorkspaceService.cs b/src/ServiceHost/WorkspaceService/WorkspaceService.cs new file mode 100644 index 00000000..fa92997f --- /dev/null +++ b/src/ServiceHost/WorkspaceService/WorkspaceService.cs @@ -0,0 +1,216 @@ +// +// 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 System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Microsoft.SqlTools.EditorServices.Utility; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol; +using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; +using System.Linq; + +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService +{ + public class WorkspaceService where TConfig : new() + { + + #region Singleton Instance Implementation + + private static WorkspaceService instance; + + public static WorkspaceService Instance + { + get + { + if (instance == null) + { + instance = new WorkspaceService(); + } + return instance; + } + } + + private WorkspaceService() + { + ConfigurationNotificationHandlers = new List(); + TextDocumentChangeHandlers = new List(); + } + + #endregion + + #region Properties + + public Workspace Workspace { get; private set; } + + public TConfig CurrentSettings { get; private set; } + + public delegate Task DidChangeConfigurationNotificationHandler(TConfig newSettings, TConfig oldSettings, EventContext eventContext); + + public delegate Task DidChangeTextDocumentNotificationTask(ScriptFile[] changedFiles, EventContext eventContext); + + public List ConfigurationNotificationHandlers; + public List TextDocumentChangeHandlers; + + + #endregion + + #region Public Methods + + public void InitializeService(ServiceHost.ServiceHost serviceHost) + { + // Create a workspace that will handle state for the session + Workspace = new Workspace(); + CurrentSettings = new TConfig(); + + // Register the handlers for when changes to the workspae occur + serviceHost.SetEventHandler(DidChangeTextDocumentNotification.Type, HandleDidChangeTextDocumentNotification); + serviceHost.SetEventHandler(DidOpenTextDocumentNotification.Type, HandleDidOpenTextDocumentNotification); + serviceHost.SetEventHandler(DidCloseTextDocumentNotification.Type, HandleDidCloseTextDocumentNotification); + serviceHost.SetEventHandler(DidChangeConfigurationNotification.Type, HandleDidChangeConfigurationNotification); + + // Register an initialization handler that sets the workspace path + serviceHost.RegisterInitializeTask(async (parameters, contect) => + { + Logger.Write(LogLevel.Verbose, "Initializing workspace service"); + + if (Workspace != null) + { + Workspace.WorkspacePath = parameters.RootPath; + } + await Task.FromResult(0); + }); + + // Register a shutdown request that disposes the workspace + serviceHost.RegisterShutdownTask(async (parameters, context) => + { + Logger.Write(LogLevel.Verbose, "Shutting down workspace service"); + + if (Workspace != null) + { + Workspace.Dispose(); + Workspace = null; + } + await Task.FromResult(0); + }); + } + + /// + /// Adds a new task to be called when the configuration has been changed. Use this to + /// handle changing configuration and changing the current configuration. + /// + /// Task to handle the request + public void RegisterDidChangeConfigurationNotificationTask(DidChangeConfigurationNotificationHandler task) + { + ConfigurationNotificationHandlers.Add(task); + } + + /// + /// Adds a new task to be called when the text of a document changes. + /// + /// Delegate to call when the document changes + public void RegisterDidChangeTextDocumentNotificationTask(DidChangeTextDocumentNotificationTask task) + { + TextDocumentChangeHandlers.Add(task); + } + + #endregion + + #region Event Handlers + + /// + /// Handles text document change events + /// + /// + /// + /// + protected Task HandleDidChangeTextDocumentNotification( + DidChangeTextDocumentParams textChangeParams, + EventContext eventContext) + { + StringBuilder msg = new StringBuilder(); + msg.Append("HandleDidChangeTextDocumentNotification"); + List changedFiles = new List(); + + // A text change notification can batch multiple change requests + foreach (var textChange in textChangeParams.ContentChanges) + { + string fileUri = textChangeParams.TextDocument.Uri; + msg.AppendLine(String.Format(" File: {0}", fileUri)); + + ScriptFile changedFile = Workspace.GetFile(fileUri); + + changedFile.ApplyChange( + GetFileChangeDetails( + textChange.Range.Value, + textChange.Text)); + + changedFiles.Add(changedFile); + } + + Logger.Write(LogLevel.Verbose, msg.ToString()); + + var handlers = TextDocumentChangeHandlers.Select(t => t(changedFiles.ToArray(), eventContext)).ToArray(); + return Task.WhenAll(handlers); + } + + protected Task HandleDidOpenTextDocumentNotification( + DidOpenTextDocumentNotification openParams, + EventContext eventContext) + { + Logger.Write(LogLevel.Verbose, "HandleDidOpenTextDocumentNotification"); + return Task.FromResult(true); + } + + protected Task HandleDidCloseTextDocumentNotification( + TextDocumentIdentifier closeParams, + EventContext eventContext) + { + Logger.Write(LogLevel.Verbose, "HandleDidCloseTextDocumentNotification"); + return Task.FromResult(true); + } + + /// + /// Handles the configuration change event + /// + /// + /// + protected async Task HandleDidChangeConfigurationNotification( + DidChangeConfigurationParams configChangeParams, + EventContext eventContext) + { + Logger.Write(LogLevel.Verbose, "HandleDidChangeConfigurationNotification"); + + // Propagate the changes to the event handlers + var configUpdateTasks = ConfigurationNotificationHandlers.Select( + t => t(configChangeParams.Settings, CurrentSettings, eventContext)).ToArray(); + await Task.WhenAll(configUpdateTasks); + } + + #endregion + + #region Private Helpers + + /// + /// Switch from 0-based offsets to 1 based offsets + /// + /// + /// + private static FileChange GetFileChangeDetails(Range changeRange, string insertString) + { + // The protocol's positions are zero-based so add 1 to all offsets + return new FileChange + { + InsertString = insertString, + Line = changeRange.Start.Line + 1, + Offset = changeRange.Start.Character + 1, + EndLine = changeRange.End.Line + 1, + EndOffset = changeRange.End.Character + 1 + }; + } + + #endregion + } +} From bd83045a0aec80b64d7cde0cc40e53432d4b44a8 Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Fri, 22 Jul 2016 16:56:34 -0700 Subject: [PATCH 10/15] Applying refactor to test project For some strange reason, the using statements don't seem to want to work for the Message type. The full name has been used instead, but it's an ugly workaround for the time being. --- .../Message/MessageReaderWriterTests.cs | 14 +++++++------- test/ServiceHost.Test/Message/TestMessageTypes.cs | 9 +++------ test/ServiceHost.Test/ServiceHost.Test.xproj | 2 +- .../JsonRpcMessageSerializerTests.cs | 13 ++++++------- 4 files changed, 17 insertions(+), 21 deletions(-) rename test/ServiceHost.Test/{LanguageServer => ServiceHost}/JsonRpcMessageSerializerTests.cs (89%) diff --git a/test/ServiceHost.Test/Message/MessageReaderWriterTests.cs b/test/ServiceHost.Test/Message/MessageReaderWriterTests.cs index 82e619f5..087c63c4 100644 --- a/test/ServiceHost.Test/Message/MessageReaderWriterTests.cs +++ b/test/ServiceHost.Test/Message/MessageReaderWriterTests.cs @@ -3,15 +3,15 @@ // 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.EditorServices.Protocol.MessageProtocol.Serializers; using System; using System.IO; using System.Text; using System.Threading.Tasks; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers; using Xunit; -namespace Microsoft.SqlTools.EditorServices.Test.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.Test.Message { public class MessageReaderWriterTests { @@ -38,7 +38,7 @@ namespace Microsoft.SqlTools.EditorServices.Test.Protocol.MessageProtocol // Write the message and then roll back the stream to be read // TODO: This will need to be redone! - await messageWriter.WriteMessage(Message.Event("testEvent", null)); + await messageWriter.WriteMessage(ServiceLayer.ServiceHost.Protocol.Contracts.Message.Event("testEvent", null)); outputStream.Seek(0, SeekOrigin.Begin); string expectedHeaderString = @@ -82,7 +82,7 @@ namespace Microsoft.SqlTools.EditorServices.Test.Protocol.MessageProtocol inputStream.Flush(); inputStream.Seek(0, SeekOrigin.Begin); - Message messageResult = messageReader.ReadMessage().Result; + ServiceLayer.ServiceHost.Protocol.Contracts.Message messageResult = messageReader.ReadMessage().Result; Assert.Equal("testEvent", messageResult.Method); inputStream.Dispose(); @@ -117,7 +117,7 @@ namespace Microsoft.SqlTools.EditorServices.Test.Protocol.MessageProtocol // Read the written messages from the stream for (int i = 0; i < overflowMessageCount; i++) { - Message messageResult = messageReader.ReadMessage().Result; + ServiceLayer.ServiceHost.Protocol.Contracts.Message messageResult = messageReader.ReadMessage().Result; Assert.Equal("testEvent", messageResult.Method); } @@ -145,7 +145,7 @@ namespace Microsoft.SqlTools.EditorServices.Test.Protocol.MessageProtocol inputStream.Flush(); inputStream.Seek(0, SeekOrigin.Begin); - Message messageResult = messageReader.ReadMessage().Result; + ServiceLayer.ServiceHost.Protocol.Contracts.Message messageResult = messageReader.ReadMessage().Result; Assert.Equal("testEvent", messageResult.Method); inputStream.Dispose(); diff --git a/test/ServiceHost.Test/Message/TestMessageTypes.cs b/test/ServiceHost.Test/Message/TestMessageTypes.cs index cc5981dc..f0819449 100644 --- a/test/ServiceHost.Test/Message/TestMessageTypes.cs +++ b/test/ServiceHost.Test/Message/TestMessageTypes.cs @@ -3,19 +3,16 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol; -using System; using System.Threading.Tasks; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol; -namespace Microsoft.SqlTools.EditorServices.Test.Protocol.MessageProtocol +namespace Microsoft.SqlTools.ServiceLayer.Test.Message { #region Request Types internal class TestRequest { - public Task ProcessMessage( - EditorSession editorSession, - MessageWriter messageWriter) + public Task ProcessMessage(MessageWriter messageWriter) { return Task.FromResult(false); } diff --git a/test/ServiceHost.Test/ServiceHost.Test.xproj b/test/ServiceHost.Test/ServiceHost.Test.xproj index 7e4a3242..5e9d1a09 100644 --- a/test/ServiceHost.Test/ServiceHost.Test.xproj +++ b/test/ServiceHost.Test/ServiceHost.Test.xproj @@ -7,7 +7,7 @@ 2d771d16-9d85-4053-9f79-e2034737deef - Microsoft.SqlTools.EditorServices.Test.Protocol + Microsoft.SqlTools.ServiceLayer.Test .\obj .\bin\ v4.5.2 diff --git a/test/ServiceHost.Test/LanguageServer/JsonRpcMessageSerializerTests.cs b/test/ServiceHost.Test/ServiceHost/JsonRpcMessageSerializerTests.cs similarity index 89% rename from test/ServiceHost.Test/LanguageServer/JsonRpcMessageSerializerTests.cs rename to test/ServiceHost.Test/ServiceHost/JsonRpcMessageSerializerTests.cs index 9ec341c5..9b9c3bf5 100644 --- a/test/ServiceHost.Test/LanguageServer/JsonRpcMessageSerializerTests.cs +++ b/test/ServiceHost.Test/ServiceHost/JsonRpcMessageSerializerTests.cs @@ -3,12 +3,11 @@ // 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.EditorServices.Protocol.MessageProtocol.Serializers; +using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers; using Newtonsoft.Json.Linq; using Xunit; -namespace Microsoft.SqlTools.EditorServices.Test.Protocol.LanguageServer +namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost { public class TestMessageContents { @@ -44,7 +43,7 @@ namespace Microsoft.SqlTools.EditorServices.Test.Protocol.LanguageServer { var messageObj = this.messageSerializer.SerializeMessage( - Message.Request( + ServiceLayer.ServiceHost.Protocol.Contracts.Message.Request( MessageId, MethodName, MessageContent)); @@ -61,7 +60,7 @@ namespace Microsoft.SqlTools.EditorServices.Test.Protocol.LanguageServer { var messageObj = this.messageSerializer.SerializeMessage( - Message.Event( + ServiceLayer.ServiceHost.Protocol.Contracts.Message.Event( MethodName, MessageContent)); @@ -76,7 +75,7 @@ namespace Microsoft.SqlTools.EditorServices.Test.Protocol.LanguageServer { var messageObj = this.messageSerializer.SerializeMessage( - Message.Response( + ServiceLayer.ServiceHost.Protocol.Contracts.Message.Response( MessageId, null, MessageContent)); @@ -92,7 +91,7 @@ namespace Microsoft.SqlTools.EditorServices.Test.Protocol.LanguageServer { var messageObj = this.messageSerializer.SerializeMessage( - Message.ResponseError( + ServiceLayer.ServiceHost.Protocol.Contracts.Message.ResponseError( MessageId, null, MessageContent)); From 31576d0731e199e494949d807f1a739882dbbc4a Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Mon, 25 Jul 2016 11:43:26 -0700 Subject: [PATCH 11/15] Renaming namespaces to prevent issues with class names --- .../Contracts/ClientCapabilities.cs | 2 +- .../Contracts/Initialize.cs | 4 ++-- .../Contracts/ServerCapabilities.cs | 2 +- .../{ServiceHost => Hosting}/Contracts/Shutdown.cs | 4 ++-- .../Protocol/Channel/ChannelBase.cs | 4 ++-- .../Protocol/Channel/StdioClientChannel.cs | 4 ++-- .../Protocol/Channel/StdioServerChannel.cs | 4 ++-- .../{ServiceHost => Hosting}/Protocol/Constants.cs | 2 +- .../Protocol/Contracts/EventType.cs | 2 +- .../Protocol/Contracts/Message.cs | 2 +- .../Protocol/Contracts/RequestType.cs | 2 +- .../Protocol/EventContext.cs | 4 ++-- .../Protocol/IMessageSender.cs | 4 ++-- .../Protocol/MessageDispatcher.cs | 6 +++--- .../Protocol/MessageParseException.cs | 2 +- .../Protocol/MessageProtocolType.cs | 2 +- .../Protocol/MessageReader.cs | 6 +++--- .../Protocol/MessageWriter.cs | 6 +++--- .../Protocol/ProtocolEndpoint.cs | 6 +++--- .../Protocol/RequestContext.cs | 4 ++-- .../Protocol/Serializers/IMessageSerializer.cs | 4 ++-- .../Serializers/JsonRpcMessageSerializer.cs | 4 ++-- .../Protocol/Serializers/V8MessageSerializer.cs | 4 ++-- .../{ServiceHost => Hosting}/ServiceHost.cs | 8 ++++---- .../{ServiceHost => Hosting}/ServiceHostBase.cs | 10 +++++----- .../ServiceHostEditorOperations.cs | 0 .../Contracts/Completion.cs | 6 +++--- .../Contracts/Definition.cs | 6 +++--- .../Contracts/Diagnostics.cs | 6 +++--- .../Contracts/DocumentHighlight.cs | 6 +++--- .../Contracts/ExpandAliasRequest.cs | 4 ++-- .../Contracts/FindModuleRequest.cs | 4 ++-- .../Contracts/Hover.cs | 6 +++--- .../Contracts/InstallModuleRequest.cs | 4 ++-- .../Contracts/References.cs | 6 +++--- .../Contracts/ShowOnlineHelpRequest.cs | 4 ++-- .../Contracts/SignatureHelp.cs | 6 +++--- .../LanguageService.cs | 13 +++++++------ src/ServiceHost/Program.cs | 9 ++++++--- .../Contracts/BufferPosition.cs | 2 +- .../Contracts/BufferRange.cs | 2 +- .../Contracts/Configuration.cs | 4 ++-- .../Contracts/FileChange.cs | 2 +- .../Contracts/FilePosition.cs | 2 +- .../Contracts/ScriptFile.cs | 2 +- .../Contracts/ScriptFileMarker.cs | 2 +- .../Contracts/ScriptRegion.cs | 2 +- .../Contracts/TextDocument.cs | 4 ++-- .../Contracts/WorkspaceSymbols.cs | 4 ++-- .../Workspace.cs | 4 ++-- .../WorkspaceService.cs | 9 +++++---- .../Message/MessageReaderWriterTests.cs | 13 +++++++------ test/ServiceHost.Test/Message/TestMessageTypes.cs | 2 +- test/ServiceHost.Test/ServiceHost.Test.xproj | 3 +++ .../ServiceHost/JsonRpcMessageSerializerTests.cs | 11 ++++++----- 55 files changed, 130 insertions(+), 120 deletions(-) rename src/ServiceHost/{ServiceHost => Hosting}/Contracts/ClientCapabilities.cs (86%) rename src/ServiceHost/{ServiceHost => Hosting}/Contracts/Initialize.cs (91%) rename src/ServiceHost/{ServiceHost => Hosting}/Contracts/ServerCapabilities.cs (96%) rename src/ServiceHost/{ServiceHost => Hosting}/Contracts/Shutdown.cs (85%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/Channel/ChannelBase.cs (95%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/Channel/StdioClientChannel.cs (96%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/Channel/StdioServerChannel.cs (92%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/Constants.cs (91%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/Contracts/EventType.cs (93%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/Contracts/Message.cs (98%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/Contracts/RequestType.cs (88%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/EventContext.cs (85%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/IMessageSender.cs (80%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/MessageDispatcher.cs (98%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/MessageParseException.cs (90%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/MessageProtocolType.cs (89%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/MessageReader.cs (97%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/MessageWriter.cs (95%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/ProtocolEndpoint.cs (98%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/RequestContext.cs (90%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/Serializers/IMessageSerializer.cs (87%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/Serializers/JsonRpcMessageSerializer.cs (95%) rename src/ServiceHost/{ServiceHost => Hosting}/Protocol/Serializers/V8MessageSerializer.cs (96%) rename src/ServiceHost/{ServiceHost => Hosting}/ServiceHost.cs (95%) rename src/ServiceHost/{ServiceHost => Hosting}/ServiceHostBase.cs (78%) rename src/ServiceHost/{ServiceHost => Hosting}/ServiceHostEditorOperations.cs (100%) rename src/ServiceHost/{LanguageService => LanguageServices}/Contracts/Completion.cs (92%) rename src/ServiceHost/{LanguageService => LanguageServices}/Contracts/Definition.cs (66%) rename src/ServiceHost/{LanguageService => LanguageServices}/Contracts/Diagnostics.cs (90%) rename src/ServiceHost/{LanguageService => LanguageServices}/Contracts/DocumentHighlight.cs (77%) rename src/ServiceHost/{LanguageService => LanguageServices}/Contracts/ExpandAliasRequest.cs (72%) rename src/ServiceHost/{LanguageService => LanguageServices}/Contracts/FindModuleRequest.cs (80%) rename src/ServiceHost/{LanguageService => LanguageServices}/Contracts/Hover.cs (76%) rename src/ServiceHost/{LanguageService => LanguageServices}/Contracts/InstallModuleRequest.cs (72%) rename src/ServiceHost/{LanguageService => LanguageServices}/Contracts/References.cs (75%) rename src/ServiceHost/{LanguageService => LanguageServices}/Contracts/ShowOnlineHelpRequest.cs (72%) rename src/ServiceHost/{LanguageService => LanguageServices}/Contracts/SignatureHelp.cs (82%) rename src/ServiceHost/{LanguageService => LanguageServices}/LanguageService.cs (97%) rename src/ServiceHost/{WorkspaceService => WorkspaceServices}/Contracts/BufferPosition.cs (98%) rename src/ServiceHost/{WorkspaceService => WorkspaceServices}/Contracts/BufferRange.cs (98%) rename src/ServiceHost/{WorkspaceService => WorkspaceServices}/Contracts/Configuration.cs (80%) rename src/ServiceHost/{WorkspaceService => WorkspaceServices}/Contracts/FileChange.cs (93%) rename src/ServiceHost/{WorkspaceService => WorkspaceServices}/Contracts/FilePosition.cs (98%) rename src/ServiceHost/{WorkspaceService => WorkspaceServices}/Contracts/ScriptFile.cs (99%) rename src/ServiceHost/{WorkspaceService => WorkspaceServices}/Contracts/ScriptFileMarker.cs (95%) rename src/ServiceHost/{WorkspaceService => WorkspaceServices}/Contracts/ScriptRegion.cs (97%) rename src/ServiceHost/{WorkspaceService => WorkspaceServices}/Contracts/TextDocument.cs (97%) rename src/ServiceHost/{WorkspaceService => WorkspaceServices}/Contracts/WorkspaceSymbols.cs (91%) rename src/ServiceHost/{WorkspaceService => WorkspaceServices}/Workspace.cs (98%) rename src/ServiceHost/{WorkspaceService => WorkspaceServices}/WorkspaceService.cs (96%) diff --git a/src/ServiceHost/ServiceHost/Contracts/ClientCapabilities.cs b/src/ServiceHost/Hosting/Contracts/ClientCapabilities.cs similarity index 86% rename from src/ServiceHost/ServiceHost/Contracts/ClientCapabilities.cs rename to src/ServiceHost/Hosting/Contracts/ClientCapabilities.cs index e8b084e7..397deceb 100644 --- a/src/ServiceHost/ServiceHost/Contracts/ClientCapabilities.cs +++ b/src/ServiceHost/Hosting/Contracts/ClientCapabilities.cs @@ -4,7 +4,7 @@ // -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Contracts { /// /// Defines a class that describes the capabilities of a language diff --git a/src/ServiceHost/ServiceHost/Contracts/Initialize.cs b/src/ServiceHost/Hosting/Contracts/Initialize.cs similarity index 91% rename from src/ServiceHost/ServiceHost/Contracts/Initialize.cs rename to src/ServiceHost/Hosting/Contracts/Initialize.cs index a5dc1eff..215edf87 100644 --- a/src/ServiceHost/ServiceHost/Contracts/Initialize.cs +++ b/src/ServiceHost/Hosting/Contracts/Initialize.cs @@ -3,9 +3,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Contracts { public class InitializeRequest { diff --git a/src/ServiceHost/ServiceHost/Contracts/ServerCapabilities.cs b/src/ServiceHost/Hosting/Contracts/ServerCapabilities.cs similarity index 96% rename from src/ServiceHost/ServiceHost/Contracts/ServerCapabilities.cs rename to src/ServiceHost/Hosting/Contracts/ServerCapabilities.cs index f378aa9e..32f0e736 100644 --- a/src/ServiceHost/ServiceHost/Contracts/ServerCapabilities.cs +++ b/src/ServiceHost/Hosting/Contracts/ServerCapabilities.cs @@ -3,7 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Contracts { public class ServerCapabilities { diff --git a/src/ServiceHost/ServiceHost/Contracts/Shutdown.cs b/src/ServiceHost/Hosting/Contracts/Shutdown.cs similarity index 85% rename from src/ServiceHost/ServiceHost/Contracts/Shutdown.cs rename to src/ServiceHost/Hosting/Contracts/Shutdown.cs index 395aaef0..1ccb9cfc 100644 --- a/src/ServiceHost/ServiceHost/Contracts/Shutdown.cs +++ b/src/ServiceHost/Hosting/Contracts/Shutdown.cs @@ -3,9 +3,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Contracts { /// /// Defines a message that is sent from the client to request diff --git a/src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs b/src/ServiceHost/Hosting/Protocol/Channel/ChannelBase.cs similarity index 95% rename from src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs rename to src/ServiceHost/Hosting/Protocol/Channel/ChannelBase.cs index 3d55ace4..48cd66aa 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Channel/ChannelBase.cs +++ b/src/ServiceHost/Hosting/Protocol/Channel/ChannelBase.cs @@ -4,9 +4,9 @@ // using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel { /// /// Defines a base implementation for servers and their clients over a diff --git a/src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs b/src/ServiceHost/Hosting/Protocol/Channel/StdioClientChannel.cs similarity index 96% rename from src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs rename to src/ServiceHost/Hosting/Protocol/Channel/StdioClientChannel.cs index 83bf5c38..02b79c6b 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Channel/StdioClientChannel.cs +++ b/src/ServiceHost/Hosting/Protocol/Channel/StdioClientChannel.cs @@ -7,9 +7,9 @@ using System.Diagnostics; using System.IO; using System.Text; using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel { /// /// Provides a client implementation for the standard I/O channel. diff --git a/src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs b/src/ServiceHost/Hosting/Protocol/Channel/StdioServerChannel.cs similarity index 92% rename from src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs rename to src/ServiceHost/Hosting/Protocol/Channel/StdioServerChannel.cs index 9aa164e2..204a9908 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Channel/StdioServerChannel.cs +++ b/src/ServiceHost/Hosting/Protocol/Channel/StdioServerChannel.cs @@ -6,9 +6,9 @@ using System.IO; using System.Text; using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel { /// /// Provides a server implementation for the standard I/O channel. diff --git a/src/ServiceHost/ServiceHost/Protocol/Constants.cs b/src/ServiceHost/Hosting/Protocol/Constants.cs similarity index 91% rename from src/ServiceHost/ServiceHost/Protocol/Constants.cs rename to src/ServiceHost/Hosting/Protocol/Constants.cs index 81dd58ea..14f3d762 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Constants.cs +++ b/src/ServiceHost/Hosting/Protocol/Constants.cs @@ -6,7 +6,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol { public static class Constants { diff --git a/src/ServiceHost/ServiceHost/Protocol/Contracts/EventType.cs b/src/ServiceHost/Hosting/Protocol/Contracts/EventType.cs similarity index 93% rename from src/ServiceHost/ServiceHost/Protocol/Contracts/EventType.cs rename to src/ServiceHost/Hosting/Protocol/Contracts/EventType.cs index 94612af8..4d9a251b 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Contracts/EventType.cs +++ b/src/ServiceHost/Hosting/Protocol/Contracts/EventType.cs @@ -3,7 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts { /// /// Defines an event type with a particular method name. diff --git a/src/ServiceHost/ServiceHost/Protocol/Contracts/Message.cs b/src/ServiceHost/Hosting/Protocol/Contracts/Message.cs similarity index 98% rename from src/ServiceHost/ServiceHost/Protocol/Contracts/Message.cs rename to src/ServiceHost/Hosting/Protocol/Contracts/Message.cs index 2474b094..6af6a101 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Contracts/Message.cs +++ b/src/ServiceHost/Hosting/Protocol/Contracts/Message.cs @@ -6,7 +6,7 @@ using System.Diagnostics; using Newtonsoft.Json.Linq; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts { /// /// Defines all possible message types. diff --git a/src/ServiceHost/ServiceHost/Protocol/Contracts/RequestType.cs b/src/ServiceHost/Hosting/Protocol/Contracts/RequestType.cs similarity index 88% rename from src/ServiceHost/ServiceHost/Protocol/Contracts/RequestType.cs rename to src/ServiceHost/Hosting/Protocol/Contracts/RequestType.cs index 9206cb66..67676259 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Contracts/RequestType.cs +++ b/src/ServiceHost/Hosting/Protocol/Contracts/RequestType.cs @@ -5,7 +5,7 @@ using System.Diagnostics; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts { [DebuggerDisplay("RequestType MethodName = {MethodName}")] public class RequestType diff --git a/src/ServiceHost/ServiceHost/Protocol/EventContext.cs b/src/ServiceHost/Hosting/Protocol/EventContext.cs similarity index 85% rename from src/ServiceHost/ServiceHost/Protocol/EventContext.cs rename to src/ServiceHost/Hosting/Protocol/EventContext.cs index 8754351c..4a1bc40e 100644 --- a/src/ServiceHost/ServiceHost/Protocol/EventContext.cs +++ b/src/ServiceHost/Hosting/Protocol/EventContext.cs @@ -4,9 +4,9 @@ // using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol { /// /// Provides context for a received event so that handlers diff --git a/src/ServiceHost/ServiceHost/Protocol/IMessageSender.cs b/src/ServiceHost/Hosting/Protocol/IMessageSender.cs similarity index 80% rename from src/ServiceHost/ServiceHost/Protocol/IMessageSender.cs rename to src/ServiceHost/Hosting/Protocol/IMessageSender.cs index 2e0e461e..ba42d1b9 100644 --- a/src/ServiceHost/ServiceHost/Protocol/IMessageSender.cs +++ b/src/ServiceHost/Hosting/Protocol/IMessageSender.cs @@ -4,9 +4,9 @@ // using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol { internal interface IMessageSender { diff --git a/src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs b/src/ServiceHost/Hosting/Protocol/MessageDispatcher.cs similarity index 98% rename from src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs rename to src/ServiceHost/Hosting/Protocol/MessageDispatcher.cs index fe4ccdff..a18fa806 100644 --- a/src/ServiceHost/ServiceHost/Protocol/MessageDispatcher.cs +++ b/src/ServiceHost/Hosting/Protocol/MessageDispatcher.cs @@ -8,11 +8,11 @@ using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; using Microsoft.SqlTools.EditorServices.Utility; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol { public class MessageDispatcher { diff --git a/src/ServiceHost/ServiceHost/Protocol/MessageParseException.cs b/src/ServiceHost/Hosting/Protocol/MessageParseException.cs similarity index 90% rename from src/ServiceHost/ServiceHost/Protocol/MessageParseException.cs rename to src/ServiceHost/Hosting/Protocol/MessageParseException.cs index 76db24d3..b4ef94c2 100644 --- a/src/ServiceHost/ServiceHost/Protocol/MessageParseException.cs +++ b/src/ServiceHost/Hosting/Protocol/MessageParseException.cs @@ -5,7 +5,7 @@ using System; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol { public class MessageParseException : Exception { diff --git a/src/ServiceHost/ServiceHost/Protocol/MessageProtocolType.cs b/src/ServiceHost/Hosting/Protocol/MessageProtocolType.cs similarity index 89% rename from src/ServiceHost/ServiceHost/Protocol/MessageProtocolType.cs rename to src/ServiceHost/Hosting/Protocol/MessageProtocolType.cs index 09655481..480332fa 100644 --- a/src/ServiceHost/ServiceHost/Protocol/MessageProtocolType.cs +++ b/src/ServiceHost/Hosting/Protocol/MessageProtocolType.cs @@ -3,7 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol { /// /// Defines the possible message protocol types. diff --git a/src/ServiceHost/ServiceHost/Protocol/MessageReader.cs b/src/ServiceHost/Hosting/Protocol/MessageReader.cs similarity index 97% rename from src/ServiceHost/ServiceHost/Protocol/MessageReader.cs rename to src/ServiceHost/Hosting/Protocol/MessageReader.cs index 7722a426..f3857710 100644 --- a/src/ServiceHost/ServiceHost/Protocol/MessageReader.cs +++ b/src/ServiceHost/Hosting/Protocol/MessageReader.cs @@ -9,12 +9,12 @@ using System.IO; using System.Text; using System.Threading.Tasks; using Microsoft.SqlTools.EditorServices.Utility; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol { public class MessageReader { diff --git a/src/ServiceHost/ServiceHost/Protocol/MessageWriter.cs b/src/ServiceHost/Hosting/Protocol/MessageWriter.cs similarity index 95% rename from src/ServiceHost/ServiceHost/Protocol/MessageWriter.cs rename to src/ServiceHost/Hosting/Protocol/MessageWriter.cs index 4098d181..b269f750 100644 --- a/src/ServiceHost/ServiceHost/Protocol/MessageWriter.cs +++ b/src/ServiceHost/Hosting/Protocol/MessageWriter.cs @@ -7,12 +7,12 @@ using System.IO; using System.Text; using System.Threading.Tasks; using Microsoft.SqlTools.EditorServices.Utility; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol { public class MessageWriter { diff --git a/src/ServiceHost/ServiceHost/Protocol/ProtocolEndpoint.cs b/src/ServiceHost/Hosting/Protocol/ProtocolEndpoint.cs similarity index 98% rename from src/ServiceHost/ServiceHost/Protocol/ProtocolEndpoint.cs rename to src/ServiceHost/Hosting/Protocol/ProtocolEndpoint.cs index 27601412..2068f5c8 100644 --- a/src/ServiceHost/ServiceHost/Protocol/ProtocolEndpoint.cs +++ b/src/ServiceHost/Hosting/Protocol/ProtocolEndpoint.cs @@ -7,10 +7,10 @@ using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol { /// /// Provides behavior for a client or server endpoint that diff --git a/src/ServiceHost/ServiceHost/Protocol/RequestContext.cs b/src/ServiceHost/Hosting/Protocol/RequestContext.cs similarity index 90% rename from src/ServiceHost/ServiceHost/Protocol/RequestContext.cs rename to src/ServiceHost/Hosting/Protocol/RequestContext.cs index 6d09294e..153e46d6 100644 --- a/src/ServiceHost/ServiceHost/Protocol/RequestContext.cs +++ b/src/ServiceHost/Hosting/Protocol/RequestContext.cs @@ -4,10 +4,10 @@ // using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; using Newtonsoft.Json.Linq; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol { public class RequestContext { diff --git a/src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs b/src/ServiceHost/Hosting/Protocol/Serializers/IMessageSerializer.cs similarity index 87% rename from src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs rename to src/ServiceHost/Hosting/Protocol/Serializers/IMessageSerializer.cs index de537b1d..6a1133ff 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Serializers/IMessageSerializer.cs +++ b/src/ServiceHost/Hosting/Protocol/Serializers/IMessageSerializer.cs @@ -3,10 +3,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; using Newtonsoft.Json.Linq; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers { /// /// Defines a common interface for message serializers. diff --git a/src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs b/src/ServiceHost/Hosting/Protocol/Serializers/JsonRpcMessageSerializer.cs similarity index 95% rename from src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs rename to src/ServiceHost/Hosting/Protocol/Serializers/JsonRpcMessageSerializer.cs index bf29a530..0ccca078 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Serializers/JsonRpcMessageSerializer.cs +++ b/src/ServiceHost/Hosting/Protocol/Serializers/JsonRpcMessageSerializer.cs @@ -3,10 +3,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; using Newtonsoft.Json.Linq; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers { /// /// Serializes messages in the JSON RPC format. Used primarily diff --git a/src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs b/src/ServiceHost/Hosting/Protocol/Serializers/V8MessageSerializer.cs similarity index 96% rename from src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs rename to src/ServiceHost/Hosting/Protocol/Serializers/V8MessageSerializer.cs index 7ac68143..f1385e00 100644 --- a/src/ServiceHost/ServiceHost/Protocol/Serializers/V8MessageSerializer.cs +++ b/src/ServiceHost/Hosting/Protocol/Serializers/V8MessageSerializer.cs @@ -5,9 +5,9 @@ using Newtonsoft.Json.Linq; using System; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers +namespace Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers { /// /// Serializes messages in the V8 format. Used primarily for debug adapters. diff --git a/src/ServiceHost/ServiceHost/ServiceHost.cs b/src/ServiceHost/Hosting/ServiceHost.cs similarity index 95% rename from src/ServiceHost/ServiceHost/ServiceHost.cs rename to src/ServiceHost/Hosting/ServiceHost.cs index 1e433b91..1a499ea6 100644 --- a/src/ServiceHost/ServiceHost/ServiceHost.cs +++ b/src/ServiceHost/Hosting/ServiceHost.cs @@ -7,11 +7,11 @@ using System.Threading.Tasks; using System.Collections.Generic; using System.Linq; using Microsoft.SqlTools.EditorServices.Utility; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel; +using Microsoft.SqlTools.ServiceLayer.Hosting.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost +namespace Microsoft.SqlTools.ServiceLayer.Hosting { /// /// SQL Tools VS Code Language Server request handler diff --git a/src/ServiceHost/ServiceHost/ServiceHostBase.cs b/src/ServiceHost/Hosting/ServiceHostBase.cs similarity index 78% rename from src/ServiceHost/ServiceHost/ServiceHostBase.cs rename to src/ServiceHost/Hosting/ServiceHostBase.cs index eb6ec946..8158822b 100644 --- a/src/ServiceHost/ServiceHost/ServiceHostBase.cs +++ b/src/ServiceHost/Hosting/ServiceHostBase.cs @@ -4,18 +4,18 @@ // using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Contracts; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Channel; +using Microsoft.SqlTools.ServiceLayer.Hosting.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel; -namespace Microsoft.SqlTools.ServiceLayer.ServiceHost +namespace Microsoft.SqlTools.ServiceLayer.Hosting { public abstract class ServiceHostBase : ProtocolEndpoint { private bool isStarted; private TaskCompletionSource serverExitedTask; - public ServiceHostBase(ChannelBase serverChannel) : + protected ServiceHostBase(ChannelBase serverChannel) : base(serverChannel, MessageProtocolType.LanguageServer) { } diff --git a/src/ServiceHost/ServiceHost/ServiceHostEditorOperations.cs b/src/ServiceHost/Hosting/ServiceHostEditorOperations.cs similarity index 100% rename from src/ServiceHost/ServiceHost/ServiceHostEditorOperations.cs rename to src/ServiceHost/Hosting/ServiceHostEditorOperations.cs diff --git a/src/ServiceHost/LanguageService/Contracts/Completion.cs b/src/ServiceHost/LanguageServices/Contracts/Completion.cs similarity index 92% rename from src/ServiceHost/LanguageService/Contracts/Completion.cs rename to src/ServiceHost/LanguageServices/Contracts/Completion.cs index ef78330d..6dc41130 100644 --- a/src/ServiceHost/LanguageService/Contracts/Completion.cs +++ b/src/ServiceHost/LanguageServices/Contracts/Completion.cs @@ -4,10 +4,10 @@ // using System.Diagnostics; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts { public class CompletionRequest { diff --git a/src/ServiceHost/LanguageService/Contracts/Definition.cs b/src/ServiceHost/LanguageServices/Contracts/Definition.cs similarity index 66% rename from src/ServiceHost/LanguageService/Contracts/Definition.cs rename to src/ServiceHost/LanguageServices/Contracts/Definition.cs index b6a211e6..1c40996f 100644 --- a/src/ServiceHost/LanguageService/Contracts/Definition.cs +++ b/src/ServiceHost/LanguageServices/Contracts/Definition.cs @@ -3,10 +3,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts { public class DefinitionRequest { diff --git a/src/ServiceHost/LanguageService/Contracts/Diagnostics.cs b/src/ServiceHost/LanguageServices/Contracts/Diagnostics.cs similarity index 90% rename from src/ServiceHost/LanguageService/Contracts/Diagnostics.cs rename to src/ServiceHost/LanguageServices/Contracts/Diagnostics.cs index c1895bdf..a591b925 100644 --- a/src/ServiceHost/LanguageService/Contracts/Diagnostics.cs +++ b/src/ServiceHost/LanguageServices/Contracts/Diagnostics.cs @@ -3,10 +3,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts { public class PublishDiagnosticsNotification { diff --git a/src/ServiceHost/LanguageService/Contracts/DocumentHighlight.cs b/src/ServiceHost/LanguageServices/Contracts/DocumentHighlight.cs similarity index 77% rename from src/ServiceHost/LanguageService/Contracts/DocumentHighlight.cs rename to src/ServiceHost/LanguageServices/Contracts/DocumentHighlight.cs index db459eb4..f266801f 100644 --- a/src/ServiceHost/LanguageService/Contracts/DocumentHighlight.cs +++ b/src/ServiceHost/LanguageServices/Contracts/DocumentHighlight.cs @@ -3,10 +3,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts { public enum DocumentHighlightKind { diff --git a/src/ServiceHost/LanguageService/Contracts/ExpandAliasRequest.cs b/src/ServiceHost/LanguageServices/Contracts/ExpandAliasRequest.cs similarity index 72% rename from src/ServiceHost/LanguageService/Contracts/ExpandAliasRequest.cs rename to src/ServiceHost/LanguageServices/Contracts/ExpandAliasRequest.cs index 7a970db5..e758aa3d 100644 --- a/src/ServiceHost/LanguageService/Contracts/ExpandAliasRequest.cs +++ b/src/ServiceHost/LanguageServices/Contracts/ExpandAliasRequest.cs @@ -3,9 +3,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts { public class ExpandAliasRequest { diff --git a/src/ServiceHost/LanguageService/Contracts/FindModuleRequest.cs b/src/ServiceHost/LanguageServices/Contracts/FindModuleRequest.cs similarity index 80% rename from src/ServiceHost/LanguageService/Contracts/FindModuleRequest.cs rename to src/ServiceHost/LanguageServices/Contracts/FindModuleRequest.cs index dff3939c..5de004d5 100644 --- a/src/ServiceHost/LanguageService/Contracts/FindModuleRequest.cs +++ b/src/ServiceHost/LanguageServices/Contracts/FindModuleRequest.cs @@ -4,9 +4,9 @@ // using System.Collections.Generic; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts { public class FindModuleRequest { diff --git a/src/ServiceHost/LanguageService/Contracts/Hover.cs b/src/ServiceHost/LanguageServices/Contracts/Hover.cs similarity index 76% rename from src/ServiceHost/LanguageService/Contracts/Hover.cs rename to src/ServiceHost/LanguageServices/Contracts/Hover.cs index dd7f05c0..04c27d33 100644 --- a/src/ServiceHost/LanguageService/Contracts/Hover.cs +++ b/src/ServiceHost/LanguageServices/Contracts/Hover.cs @@ -3,10 +3,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts { public class MarkedString { diff --git a/src/ServiceHost/LanguageService/Contracts/InstallModuleRequest.cs b/src/ServiceHost/LanguageServices/Contracts/InstallModuleRequest.cs similarity index 72% rename from src/ServiceHost/LanguageService/Contracts/InstallModuleRequest.cs rename to src/ServiceHost/LanguageServices/Contracts/InstallModuleRequest.cs index 361bb60f..fc5bc289 100644 --- a/src/ServiceHost/LanguageService/Contracts/InstallModuleRequest.cs +++ b/src/ServiceHost/LanguageServices/Contracts/InstallModuleRequest.cs @@ -3,9 +3,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts { class InstallModuleRequest { diff --git a/src/ServiceHost/LanguageService/Contracts/References.cs b/src/ServiceHost/LanguageServices/Contracts/References.cs similarity index 75% rename from src/ServiceHost/LanguageService/Contracts/References.cs rename to src/ServiceHost/LanguageServices/Contracts/References.cs index d2e12ccd..ad2f23bd 100644 --- a/src/ServiceHost/LanguageService/Contracts/References.cs +++ b/src/ServiceHost/LanguageServices/Contracts/References.cs @@ -3,10 +3,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts { public class ReferencesRequest { diff --git a/src/ServiceHost/LanguageService/Contracts/ShowOnlineHelpRequest.cs b/src/ServiceHost/LanguageServices/Contracts/ShowOnlineHelpRequest.cs similarity index 72% rename from src/ServiceHost/LanguageService/Contracts/ShowOnlineHelpRequest.cs rename to src/ServiceHost/LanguageServices/Contracts/ShowOnlineHelpRequest.cs index d77eeafa..d8cf3f48 100644 --- a/src/ServiceHost/LanguageService/Contracts/ShowOnlineHelpRequest.cs +++ b/src/ServiceHost/LanguageServices/Contracts/ShowOnlineHelpRequest.cs @@ -3,9 +3,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts { public class ShowOnlineHelpRequest { diff --git a/src/ServiceHost/LanguageService/Contracts/SignatureHelp.cs b/src/ServiceHost/LanguageServices/Contracts/SignatureHelp.cs similarity index 82% rename from src/ServiceHost/LanguageService/Contracts/SignatureHelp.cs rename to src/ServiceHost/LanguageServices/Contracts/SignatureHelp.cs index 26e62b21..bd1103c9 100644 --- a/src/ServiceHost/LanguageService/Contracts/SignatureHelp.cs +++ b/src/ServiceHost/LanguageServices/Contracts/SignatureHelp.cs @@ -3,10 +3,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; -using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts { public class SignatureHelpRequest { diff --git a/src/ServiceHost/LanguageService/LanguageService.cs b/src/ServiceHost/LanguageServices/LanguageService.cs similarity index 97% rename from src/ServiceHost/LanguageService/LanguageService.cs rename to src/ServiceHost/LanguageServices/LanguageService.cs index 05cc90c5..51edcad4 100644 --- a/src/ServiceHost/LanguageService/LanguageService.cs +++ b/src/ServiceHost/LanguageServices/LanguageService.cs @@ -7,14 +7,15 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.SqlTools.EditorServices.Utility; -using Microsoft.SqlTools.ServiceLayer.LanguageService.Contracts; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol; +using Microsoft.SqlTools.ServiceLayer.Hosting; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; +using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts; using Microsoft.SqlTools.ServiceLayer.SqlContext; -using Microsoft.SqlTools.ServiceLayer.WorkspaceService; -using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; using System.Linq; -namespace Microsoft.SqlTools.ServiceLayer.LanguageService +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices { /// /// Main class for Language Service functionality @@ -71,7 +72,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageService #endregion - public void InitializeService(ServiceHost.ServiceHost serviceHost, SqlToolsContext context) + public void InitializeService(ServiceHost serviceHost, SqlToolsContext context) { // Register the requests that this service will handle serviceHost.SetRequestHandler(DefinitionRequest.Type, HandleDefinitionRequest); diff --git a/src/ServiceHost/Program.cs b/src/ServiceHost/Program.cs index 9717feb3..6879aabb 100644 --- a/src/ServiceHost/Program.cs +++ b/src/ServiceHost/Program.cs @@ -3,7 +3,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.SqlTools.EditorServices.Utility; +using Microsoft.SqlTools.ServiceLayer.Hosting; using Microsoft.SqlTools.ServiceLayer.SqlContext; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices; +using Microsoft.SqlTools.ServiceLayer.LanguageServices; namespace Microsoft.SqlTools.ServiceLayer { @@ -32,11 +35,11 @@ namespace Microsoft.SqlTools.ServiceLayer SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails, profilePaths); // Create the service host - ServiceHost.ServiceHost serviceHost = ServiceHost.ServiceHost.Create(); + ServiceHost serviceHost = ServiceHost.Create(); // Initialize the services that will be hosted here - WorkspaceService.WorkspaceService.Instance.InitializeService(serviceHost); - LanguageService.LanguageService.Instance.InitializeService(serviceHost, sqlToolsContext); + WorkspaceService.Instance.InitializeService(serviceHost); + LanguageService.Instance.InitializeService(serviceHost, sqlToolsContext); // Start the service serviceHost.Start().Wait(); diff --git a/src/ServiceHost/WorkspaceService/Contracts/BufferPosition.cs b/src/ServiceHost/WorkspaceServices/Contracts/BufferPosition.cs similarity index 98% rename from src/ServiceHost/WorkspaceService/Contracts/BufferPosition.cs rename to src/ServiceHost/WorkspaceServices/Contracts/BufferPosition.cs index 020548f6..f74ade68 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/BufferPosition.cs +++ b/src/ServiceHost/WorkspaceServices/Contracts/BufferPosition.cs @@ -5,7 +5,7 @@ using System.Diagnostics; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts { /// /// Provides details about a position in a file buffer. All diff --git a/src/ServiceHost/WorkspaceService/Contracts/BufferRange.cs b/src/ServiceHost/WorkspaceServices/Contracts/BufferRange.cs similarity index 98% rename from src/ServiceHost/WorkspaceService/Contracts/BufferRange.cs rename to src/ServiceHost/WorkspaceServices/Contracts/BufferRange.cs index f46abb96..99316fe5 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/BufferRange.cs +++ b/src/ServiceHost/WorkspaceServices/Contracts/BufferRange.cs @@ -6,7 +6,7 @@ using System; using System.Diagnostics; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts { /// /// Provides details about a range between two positions in diff --git a/src/ServiceHost/WorkspaceService/Contracts/Configuration.cs b/src/ServiceHost/WorkspaceServices/Contracts/Configuration.cs similarity index 80% rename from src/ServiceHost/WorkspaceService/Contracts/Configuration.cs rename to src/ServiceHost/WorkspaceServices/Contracts/Configuration.cs index 45697554..ff1e5096 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/Configuration.cs +++ b/src/ServiceHost/WorkspaceServices/Contracts/Configuration.cs @@ -3,9 +3,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts { public class DidChangeConfigurationNotification { diff --git a/src/ServiceHost/WorkspaceService/Contracts/FileChange.cs b/src/ServiceHost/WorkspaceServices/Contracts/FileChange.cs similarity index 93% rename from src/ServiceHost/WorkspaceService/Contracts/FileChange.cs rename to src/ServiceHost/WorkspaceServices/Contracts/FileChange.cs index a4398afe..7e1af148 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/FileChange.cs +++ b/src/ServiceHost/WorkspaceServices/Contracts/FileChange.cs @@ -3,7 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts { /// /// Contains details relating to a content change in an open file. diff --git a/src/ServiceHost/WorkspaceService/Contracts/FilePosition.cs b/src/ServiceHost/WorkspaceServices/Contracts/FilePosition.cs similarity index 98% rename from src/ServiceHost/WorkspaceService/Contracts/FilePosition.cs rename to src/ServiceHost/WorkspaceServices/Contracts/FilePosition.cs index 13e205ca..01ed012d 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/FilePosition.cs +++ b/src/ServiceHost/WorkspaceServices/Contracts/FilePosition.cs @@ -3,7 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts { /// /// Provides details and operations for a buffer position in a diff --git a/src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs b/src/ServiceHost/WorkspaceServices/Contracts/ScriptFile.cs similarity index 99% rename from src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs rename to src/ServiceHost/WorkspaceServices/Contracts/ScriptFile.cs index 134cdb9b..b28a88db 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/ScriptFile.cs +++ b/src/ServiceHost/WorkspaceServices/Contracts/ScriptFile.cs @@ -9,7 +9,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts { /// /// Contains the details and contents of an open script file. diff --git a/src/ServiceHost/WorkspaceService/Contracts/ScriptFileMarker.cs b/src/ServiceHost/WorkspaceServices/Contracts/ScriptFileMarker.cs similarity index 95% rename from src/ServiceHost/WorkspaceService/Contracts/ScriptFileMarker.cs rename to src/ServiceHost/WorkspaceServices/Contracts/ScriptFileMarker.cs index a43de169..35ba21fa 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/ScriptFileMarker.cs +++ b/src/ServiceHost/WorkspaceServices/Contracts/ScriptFileMarker.cs @@ -3,7 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts { /// /// Defines the message level of a script file marker. diff --git a/src/ServiceHost/WorkspaceService/Contracts/ScriptRegion.cs b/src/ServiceHost/WorkspaceServices/Contracts/ScriptRegion.cs similarity index 97% rename from src/ServiceHost/WorkspaceService/Contracts/ScriptRegion.cs rename to src/ServiceHost/WorkspaceServices/Contracts/ScriptRegion.cs index 943e2252..1ac56d01 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/ScriptRegion.cs +++ b/src/ServiceHost/WorkspaceServices/Contracts/ScriptRegion.cs @@ -5,7 +5,7 @@ //using System.Management.Automation.Language; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts { /// /// Contains details about a specific region of text in script file. diff --git a/src/ServiceHost/WorkspaceService/Contracts/TextDocument.cs b/src/ServiceHost/WorkspaceServices/Contracts/TextDocument.cs similarity index 97% rename from src/ServiceHost/WorkspaceService/Contracts/TextDocument.cs rename to src/ServiceHost/WorkspaceServices/Contracts/TextDocument.cs index e091b315..0708316d 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/TextDocument.cs +++ b/src/ServiceHost/WorkspaceServices/Contracts/TextDocument.cs @@ -4,9 +4,9 @@ // using System.Diagnostics; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts { /// /// Defines a base parameter class for identifying a text document. diff --git a/src/ServiceHost/WorkspaceService/Contracts/WorkspaceSymbols.cs b/src/ServiceHost/WorkspaceServices/Contracts/WorkspaceSymbols.cs similarity index 91% rename from src/ServiceHost/WorkspaceService/Contracts/WorkspaceSymbols.cs rename to src/ServiceHost/WorkspaceServices/Contracts/WorkspaceSymbols.cs index 347a9468..1b7731eb 100644 --- a/src/ServiceHost/WorkspaceService/Contracts/WorkspaceSymbols.cs +++ b/src/ServiceHost/WorkspaceServices/Contracts/WorkspaceSymbols.cs @@ -3,9 +3,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts { public enum SymbolKind { diff --git a/src/ServiceHost/WorkspaceService/Workspace.cs b/src/ServiceHost/WorkspaceServices/Workspace.cs similarity index 98% rename from src/ServiceHost/WorkspaceService/Workspace.cs rename to src/ServiceHost/WorkspaceServices/Workspace.cs index 6aa8f479..921ecc7c 100644 --- a/src/ServiceHost/WorkspaceService/Workspace.cs +++ b/src/ServiceHost/WorkspaceServices/Workspace.cs @@ -10,9 +10,9 @@ using System.Text; using System.Text.RegularExpressions; using System.Linq; using Microsoft.SqlTools.EditorServices.Utility; -using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices { /// /// Manages a "workspace" of script files that are open for a particular diff --git a/src/ServiceHost/WorkspaceService/WorkspaceService.cs b/src/ServiceHost/WorkspaceServices/WorkspaceService.cs similarity index 96% rename from src/ServiceHost/WorkspaceService/WorkspaceService.cs rename to src/ServiceHost/WorkspaceServices/WorkspaceService.cs index fa92997f..2fd3e48c 100644 --- a/src/ServiceHost/WorkspaceService/WorkspaceService.cs +++ b/src/ServiceHost/WorkspaceServices/WorkspaceService.cs @@ -8,11 +8,12 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Microsoft.SqlTools.EditorServices.Utility; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol; -using Microsoft.SqlTools.ServiceLayer.WorkspaceService.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; using System.Linq; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService +namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices { public class WorkspaceService where TConfig : new() { @@ -59,7 +60,7 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceService #region Public Methods - public void InitializeService(ServiceHost.ServiceHost serviceHost) + public void InitializeService(ServiceHost serviceHost) { // Create a workspace that will handle state for the session Workspace = new Workspace(); diff --git a/test/ServiceHost.Test/Message/MessageReaderWriterTests.cs b/test/ServiceHost.Test/Message/MessageReaderWriterTests.cs index 087c63c4..54fbf01f 100644 --- a/test/ServiceHost.Test/Message/MessageReaderWriterTests.cs +++ b/test/ServiceHost.Test/Message/MessageReaderWriterTests.cs @@ -7,8 +7,9 @@ using System; using System.IO; using System.Text; using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; +using HostingMessage = Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts.Message; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers; using Xunit; namespace Microsoft.SqlTools.ServiceLayer.Test.Message @@ -38,7 +39,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Message // Write the message and then roll back the stream to be read // TODO: This will need to be redone! - await messageWriter.WriteMessage(ServiceLayer.ServiceHost.Protocol.Contracts.Message.Event("testEvent", null)); + await messageWriter.WriteMessage(HostingMessage.Event("testEvent", null)); outputStream.Seek(0, SeekOrigin.Begin); string expectedHeaderString = @@ -82,7 +83,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Message inputStream.Flush(); inputStream.Seek(0, SeekOrigin.Begin); - ServiceLayer.ServiceHost.Protocol.Contracts.Message messageResult = messageReader.ReadMessage().Result; + HostingMessage messageResult = messageReader.ReadMessage().Result; Assert.Equal("testEvent", messageResult.Method); inputStream.Dispose(); @@ -117,7 +118,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Message // Read the written messages from the stream for (int i = 0; i < overflowMessageCount; i++) { - ServiceLayer.ServiceHost.Protocol.Contracts.Message messageResult = messageReader.ReadMessage().Result; + HostingMessage messageResult = messageReader.ReadMessage().Result; Assert.Equal("testEvent", messageResult.Method); } @@ -145,7 +146,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Message inputStream.Flush(); inputStream.Seek(0, SeekOrigin.Begin); - ServiceLayer.ServiceHost.Protocol.Contracts.Message messageResult = messageReader.ReadMessage().Result; + HostingMessage messageResult = messageReader.ReadMessage().Result; Assert.Equal("testEvent", messageResult.Method); inputStream.Dispose(); diff --git a/test/ServiceHost.Test/Message/TestMessageTypes.cs b/test/ServiceHost.Test/Message/TestMessageTypes.cs index f0819449..0ba08056 100644 --- a/test/ServiceHost.Test/Message/TestMessageTypes.cs +++ b/test/ServiceHost.Test/Message/TestMessageTypes.cs @@ -4,7 +4,7 @@ // using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; namespace Microsoft.SqlTools.ServiceLayer.Test.Message { diff --git a/test/ServiceHost.Test/ServiceHost.Test.xproj b/test/ServiceHost.Test/ServiceHost.Test.xproj index 5e9d1a09..cb4c13ed 100644 --- a/test/ServiceHost.Test/ServiceHost.Test.xproj +++ b/test/ServiceHost.Test/ServiceHost.Test.xproj @@ -15,5 +15,8 @@ 2.0 + + + \ No newline at end of file diff --git a/test/ServiceHost.Test/ServiceHost/JsonRpcMessageSerializerTests.cs b/test/ServiceHost.Test/ServiceHost/JsonRpcMessageSerializerTests.cs index 9b9c3bf5..d50f02da 100644 --- a/test/ServiceHost.Test/ServiceHost/JsonRpcMessageSerializerTests.cs +++ b/test/ServiceHost.Test/ServiceHost/JsonRpcMessageSerializerTests.cs @@ -3,7 +3,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.ServiceHost.Protocol.Serializers; +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers; +using HostingMessage = Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts.Message; using Newtonsoft.Json.Linq; using Xunit; @@ -43,7 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost { var messageObj = this.messageSerializer.SerializeMessage( - ServiceLayer.ServiceHost.Protocol.Contracts.Message.Request( + HostingMessage.Request( MessageId, MethodName, MessageContent)); @@ -60,7 +61,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost { var messageObj = this.messageSerializer.SerializeMessage( - ServiceLayer.ServiceHost.Protocol.Contracts.Message.Event( + HostingMessage.Event( MethodName, MessageContent)); @@ -75,7 +76,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost { var messageObj = this.messageSerializer.SerializeMessage( - ServiceLayer.ServiceHost.Protocol.Contracts.Message.Response( + HostingMessage.Response( MessageId, null, MessageContent)); @@ -91,7 +92,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost { var messageObj = this.messageSerializer.SerializeMessage( - ServiceLayer.ServiceHost.Protocol.Contracts.Message.ResponseError( + HostingMessage.ResponseError( MessageId, null, MessageContent)); From 46032d3e2e2a54e27610c05e876384657043195d Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Mon, 25 Jul 2016 12:15:03 -0700 Subject: [PATCH 12/15] Making singleton instances threadsafe --- src/ServiceHost/Hosting/ServiceHost.cs | 13 +++++------ .../LanguageServices/LanguageService.cs | 17 ++++---------- .../WorkspaceServices/WorkspaceService.cs | 22 ++++++------------- 3 files changed, 16 insertions(+), 36 deletions(-) diff --git a/src/ServiceHost/Hosting/ServiceHost.cs b/src/ServiceHost/Hosting/ServiceHost.cs index 1a499ea6..f8808af6 100644 --- a/src/ServiceHost/Hosting/ServiceHost.cs +++ b/src/ServiceHost/Hosting/ServiceHost.cs @@ -3,6 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // +using System; using System.Threading.Tasks; using System.Collections.Generic; using System.Linq; @@ -16,14 +17,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting /// /// SQL Tools VS Code Language Server request handler /// - public class ServiceHost : ServiceHostBase + public sealed class ServiceHost : ServiceHostBase { #region Singleton Instance Code /// - /// Singleton instance of the instance + /// Singleton instance of the service host for internal storage /// - private static ServiceHost instance; + private static readonly Lazy instance = new Lazy(() => new ServiceHost()); /// /// Creates or retrieves the current instance of the ServiceHost @@ -31,11 +32,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting /// Instance of the service host public static ServiceHost Create() { - if (instance == null) - { - instance = new ServiceHost(); - } - return instance; + return instance.Value; } /// diff --git a/src/ServiceHost/LanguageServices/LanguageService.cs b/src/ServiceHost/LanguageServices/LanguageService.cs index 51edcad4..05f42fb3 100644 --- a/src/ServiceHost/LanguageServices/LanguageService.cs +++ b/src/ServiceHost/LanguageServices/LanguageService.cs @@ -20,32 +20,23 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices /// /// Main class for Language Service functionality /// - public class LanguageService + public sealed class LanguageService { #region Singleton Instance Implementation - private static LanguageService instance; + private static readonly Lazy instance = new Lazy(() => new LanguageService()); public static LanguageService Instance { - get - { - if (instance == null) - { - instance = new LanguageService(); - } - return instance; - } + get { return instance.Value; } } /// - /// Default, parameterless contstructor. - /// TODO: Remove once the SqlToolsContext stuff is sorted out + /// Default, parameterless constructor. /// private LanguageService() { - } #endregion diff --git a/src/ServiceHost/WorkspaceServices/WorkspaceService.cs b/src/ServiceHost/WorkspaceServices/WorkspaceService.cs index 2fd3e48c..7be53481 100644 --- a/src/ServiceHost/WorkspaceServices/WorkspaceService.cs +++ b/src/ServiceHost/WorkspaceServices/WorkspaceService.cs @@ -15,23 +15,16 @@ using System.Linq; namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices { - public class WorkspaceService where TConfig : new() + public class WorkspaceService where TConfig : class, new() { #region Singleton Instance Implementation - private static WorkspaceService instance; + private static readonly Lazy> instance = new Lazy>(() => new WorkspaceService()); public static WorkspaceService Instance { - get - { - if (instance == null) - { - instance = new WorkspaceService(); - } - return instance; - } + get { return instance.Value; } } private WorkspaceService() @@ -52,9 +45,8 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices public delegate Task DidChangeTextDocumentNotificationTask(ScriptFile[] changedFiles, EventContext eventContext); - public List ConfigurationNotificationHandlers; - public List TextDocumentChangeHandlers; - + private List ConfigurationNotificationHandlers { get; set; } + private List TextDocumentChangeHandlers { get; set; } #endregion @@ -153,7 +145,7 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices Logger.Write(LogLevel.Verbose, msg.ToString()); - var handlers = TextDocumentChangeHandlers.Select(t => t(changedFiles.ToArray(), eventContext)).ToArray(); + var handlers = TextDocumentChangeHandlers.Select(t => t(changedFiles.ToArray(), eventContext)); return Task.WhenAll(handlers); } @@ -186,7 +178,7 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices // Propagate the changes to the event handlers var configUpdateTasks = ConfigurationNotificationHandlers.Select( - t => t(configChangeParams.Settings, CurrentSettings, eventContext)).ToArray(); + t => t(configChangeParams.Settings, CurrentSettings, eventContext)); await Task.WhenAll(configUpdateTasks); } From 6664de225205eec93445017a8b97f9a671061668 Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Mon, 25 Jul 2016 12:37:48 -0700 Subject: [PATCH 13/15] Renaming callbacks to be more sane --- src/ServiceHost/Hosting/ServiceHost.cs | 39 ++++++++-------- .../LanguageServices/LanguageService.cs | 2 +- src/ServiceHost/Program.cs | 4 +- .../WorkspaceServices/WorkspaceService.cs | 45 +++++++++++++------ 4 files changed, 54 insertions(+), 36 deletions(-) diff --git a/src/ServiceHost/Hosting/ServiceHost.cs b/src/ServiceHost/Hosting/ServiceHost.cs index f8808af6..fcaaffcd 100644 --- a/src/ServiceHost/Hosting/ServiceHost.cs +++ b/src/ServiceHost/Hosting/ServiceHost.cs @@ -4,9 +4,9 @@ // using System; +using System.Linq; using System.Threading.Tasks; using System.Collections.Generic; -using System.Linq; using Microsoft.SqlTools.EditorServices.Utility; using Microsoft.SqlTools.ServiceLayer.Hosting.Contracts; using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; @@ -27,12 +27,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting private static readonly Lazy instance = new Lazy(() => new ServiceHost()); /// - /// Creates or retrieves the current instance of the ServiceHost + /// Current instance of the ServiceHost /// - /// Instance of the service host - public static ServiceHost Create() + public static ServiceHost Instance { - return instance.Value; + get { return instance.Value; } } /// @@ -42,8 +41,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting private ServiceHost() : base(new StdioServerChannel()) { // Initialize the shutdown activities - shutdownActivities = new List(); - initializeActivities = new List(); + shutdownCallbacks = new List(); + initializeCallbacks = new List(); // Register the requests that this service host will handle this.SetRequestHandler(InitializeRequest.Type, this.HandleInitializeRequest); @@ -54,34 +53,34 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting #region Member Variables - public delegate Task ShutdownHandler(object shutdownParams, RequestContext shutdownRequestContext); + public delegate Task ShutdownCallback(object shutdownParams, RequestContext shutdownRequestContext); - public delegate Task InitializeHandler(InitializeRequest startupParams, RequestContext requestContext); + public delegate Task InitializeCallback(InitializeRequest startupParams, RequestContext requestContext); - private readonly List shutdownActivities; + private readonly List shutdownCallbacks; - private readonly List initializeActivities; + private readonly List initializeCallbacks; #endregion #region Public Methods /// - /// 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 /// - /// - public void RegisterShutdownTask(ShutdownHandler activity) + /// Callback to perform when a shutdown request is submitted + public void RegisterShutdownTask(ShutdownCallback callback) { - shutdownActivities.Add(activity); + shutdownCallbacks.Add(callback); } /// /// Add a new method to be called when the initialize request is submitted /// - /// - public void RegisterInitializeTask(InitializeHandler activity) + /// Callback to perform when an initialize request is submitted + public void RegisterInitializeTask(InitializeCallback callback) { - initializeActivities.Add(activity); + initializeCallbacks.Add(callback); } #endregion @@ -96,7 +95,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting 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(); + Task[] shutdownTasks = shutdownCallbacks.Select(t => t(shutdownParams, requestContext)).ToArray(); await Task.WhenAll(shutdownTasks); } @@ -111,7 +110,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting Logger.Write(LogLevel.Verbose, "HandleInitializationRequest"); // 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); // TODO: Figure out where this needs to go to be agnostic of the language diff --git a/src/ServiceHost/LanguageServices/LanguageService.cs b/src/ServiceHost/LanguageServices/LanguageService.cs index 05f42fb3..42bbdec5 100644 --- a/src/ServiceHost/LanguageServices/LanguageService.cs +++ b/src/ServiceHost/LanguageServices/LanguageService.cs @@ -84,7 +84,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices }); // Register the configuration update handler - WorkspaceService.Instance.RegisterDidChangeConfigurationNotificationTask(HandleDidChangeConfigurationNotification); + WorkspaceService.Instance.RegisterConfigChangeCallback(HandleDidChangeConfigurationNotification); // Store the SqlToolsContext for future use Context = context; diff --git a/src/ServiceHost/Program.cs b/src/ServiceHost/Program.cs index 6879aabb..53c15d3a 100644 --- a/src/ServiceHost/Program.cs +++ b/src/ServiceHost/Program.cs @@ -34,8 +34,8 @@ namespace Microsoft.SqlTools.ServiceLayer var profilePaths = new ProfilePaths(hostProfileId, "baseAllUsersPath", "baseCurrentUserPath"); SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails, profilePaths); - // Create the service host - ServiceHost serviceHost = ServiceHost.Create(); + // Grab the instance of the service host + ServiceHost serviceHost = ServiceHost.Instance; // Initialize the services that will be hosted here WorkspaceService.Instance.InitializeService(serviceHost); diff --git a/src/ServiceHost/WorkspaceServices/WorkspaceService.cs b/src/ServiceHost/WorkspaceServices/WorkspaceService.cs index 7be53481..6eb0c8c9 100644 --- a/src/ServiceHost/WorkspaceServices/WorkspaceService.cs +++ b/src/ServiceHost/WorkspaceServices/WorkspaceService.cs @@ -5,13 +5,13 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.SqlTools.EditorServices.Utility; using Microsoft.SqlTools.ServiceLayer.Hosting; using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; -using System.Linq; namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices { @@ -29,8 +29,8 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices private WorkspaceService() { - ConfigurationNotificationHandlers = new List(); - TextDocumentChangeHandlers = new List(); + ConfigChangeCallbacks = new List(); + TextDocChangeCallbacks = new List(); } #endregion @@ -41,12 +41,31 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices public TConfig CurrentSettings { get; private set; } - public delegate Task DidChangeConfigurationNotificationHandler(TConfig newSettings, TConfig oldSettings, EventContext eventContext); + /// + /// Delegate for callbacks that occur when the configuration for the workspace changes + /// + /// The settings that were just set + /// The settings before they were changed + /// Context of the event that triggered the callback + /// + public delegate Task ConfigChangeCallback(TConfig newSettings, TConfig oldSettings, EventContext eventContext); - public delegate Task DidChangeTextDocumentNotificationTask(ScriptFile[] changedFiles, EventContext eventContext); + /// + /// Delegate for callbacks that occur when the current text document changes + /// + /// Array of files that changed + /// Context of the event raised for the changed files + public delegate Task TextDocChangeCallback(ScriptFile[] changedFiles, EventContext eventContext); - private List ConfigurationNotificationHandlers { get; set; } - private List TextDocumentChangeHandlers { get; set; } + /// + /// List of callbacks to call when the configuration of the workspace changes + /// + private List ConfigChangeCallbacks { get; set; } + + /// + /// List of callbacks to call when the current text document changes + /// + private List TextDocChangeCallbacks { get; set; } #endregion @@ -95,18 +114,18 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices /// handle changing configuration and changing the current configuration. /// /// Task to handle the request - public void RegisterDidChangeConfigurationNotificationTask(DidChangeConfigurationNotificationHandler task) + public void RegisterConfigChangeCallback(ConfigChangeCallback task) { - ConfigurationNotificationHandlers.Add(task); + ConfigChangeCallbacks.Add(task); } /// /// Adds a new task to be called when the text of a document changes. /// /// Delegate to call when the document changes - public void RegisterDidChangeTextDocumentNotificationTask(DidChangeTextDocumentNotificationTask task) + public void RegisterTextDocChangeCallback(TextDocChangeCallback task) { - TextDocumentChangeHandlers.Add(task); + TextDocChangeCallbacks.Add(task); } #endregion @@ -145,7 +164,7 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices 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); } @@ -177,7 +196,7 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices Logger.Write(LogLevel.Verbose, "HandleDidChangeConfigurationNotification"); // Propagate the changes to the event handlers - var configUpdateTasks = ConfigurationNotificationHandlers.Select( + var configUpdateTasks = ConfigChangeCallbacks.Select( t => t(configChangeParams.Settings, CurrentSettings, eventContext)); await Task.WhenAll(configUpdateTasks); } From 53e26798fc28cfa55dfe4836238c16f3c346ac46 Mon Sep 17 00:00:00 2001 From: Karl Burtram Date: Mon, 25 Jul 2016 13:04:14 -0700 Subject: [PATCH 14/15] Language Service diagnostics and autocomplete (#9) * Merge master to dev (#4) * Misc. clean-ups related to removing unneeded PowerShell Language Service code. * Remove unneeded files and clean up remaining code. * Enable file change tracking with Workspace and EditorSession. * Setup standard src, test folder structure. Add unit test project. * Actually stage the deletes. Update .gitignore * Integrate SqlParser into the onchange diagnostics to provide error messages. * Add tests for the language service diagnostics * Initial implementation for autocomplete. * Switch to using sys.tables for autocomplete Move some code into a better class * Delete unused csproj file. * Add nuget.config to pickup SQL Parser nuget package --- nuget.config | 15 ++ .../Connection/ConnectionMessages.cs | 63 +++++++ .../Connection/ConnectionService.cs | 160 ++++++++++++++++++ src/ServiceHost/Connection/ISqlConnection.cs | 34 ++++ src/ServiceHost/Connection/SqlConnection.cs | 72 ++++++++ .../LanguageSupport/AutoCompleteService.cs | 112 ++++++++++++ .../LanguageSupport/LanguageService.cs | 57 +++++-- src/ServiceHost/Server/LanguageServer.cs | 94 ++++++++-- src/ServiceHost/Workspace/ScriptFile.cs | 21 ++- src/ServiceHost/project.json | 5 +- .../Connection/ConnectionServiceTests.cs | 60 +++++++ .../LanguageServer/LanguageServiceTests.cs | 126 ++++++++++++++ test/ServiceHost.Test/Utility/TestObjects.cs | 108 ++++++++++++ test/ServiceHost.Test/project.json | 8 +- 14 files changed, 894 insertions(+), 41 deletions(-) create mode 100644 nuget.config create mode 100644 src/ServiceHost/Connection/ConnectionMessages.cs create mode 100644 src/ServiceHost/Connection/ConnectionService.cs create mode 100644 src/ServiceHost/Connection/ISqlConnection.cs create mode 100644 src/ServiceHost/Connection/SqlConnection.cs create mode 100644 src/ServiceHost/LanguageSupport/AutoCompleteService.cs create mode 100644 test/ServiceHost.Test/Connection/ConnectionServiceTests.cs create mode 100644 test/ServiceHost.Test/LanguageServer/LanguageServiceTests.cs create mode 100644 test/ServiceHost.Test/Utility/TestObjects.cs diff --git a/nuget.config b/nuget.config new file mode 100644 index 00000000..33539216 --- /dev/null +++ b/nuget.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/ServiceHost/Connection/ConnectionMessages.cs b/src/ServiceHost/Connection/ConnectionMessages.cs new file mode 100644 index 00000000..814e55f0 --- /dev/null +++ b/src/ServiceHost/Connection/ConnectionMessages.cs @@ -0,0 +1,63 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol; + +namespace Microsoft.SqlTools.EditorServices.Connection +{ + /// + /// Message format for the initial connection request + /// + public class ConnectionDetails + { + /// + /// Gets or sets the connection server name + /// + public string ServerName { get; set; } + + /// + /// Gets or sets the connection database name + /// + public string DatabaseName { get; set; } + + /// + /// Gets or sets the connection user name + /// + public string UserName { get; set; } + + /// + /// Gets or sets the connection password + /// + /// + public string Password { get; set; } + } + + /// + /// Message format for the connection result response + /// + public class ConnectionResult + { + /// + /// Gets or sets the connection id + /// + public int ConnectionId { get; set; } + + /// + /// Gets or sets any connection error messages + /// + public string Messages { get; set; } + } + + /// + /// Connect request mapping entry + /// + public class ConnectionRequest + { + public static readonly + RequestType Type = + RequestType.Create("connection/connect"); + } + +} diff --git a/src/ServiceHost/Connection/ConnectionService.cs b/src/ServiceHost/Connection/ConnectionService.cs new file mode 100644 index 00000000..8f0634a7 --- /dev/null +++ b/src/ServiceHost/Connection/ConnectionService.cs @@ -0,0 +1,160 @@ +// +// 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 System.Collections.Generic; +using System.Data.SqlClient; +using System.Threading.Tasks; + +namespace Microsoft.SqlTools.EditorServices.Connection +{ + /// + /// Main class for the Connection Management services + /// + public class ConnectionService + { + /// + /// Singleton service instance + /// + private static Lazy instance + = new Lazy(() => new ConnectionService()); + + /// + /// The SQL connection factory object + /// + private ISqlConnectionFactory connectionFactory; + + /// + /// The current connection id that was previously used + /// + private int maxConnectionId = 0; + + /// + /// Active connections lazy dictionary instance + /// + private Lazy> activeConnections + = new Lazy>(() + => new Dictionary()); + + /// + /// Callback for onconnection handler + /// + /// + public delegate Task OnConnectionHandler(ISqlConnection sqlConnection); + + /// + /// List of onconnection handlers + /// + private readonly List onConnectionActivities = new List(); + + /// + /// Gets the active connection map + /// + public Dictionary ActiveConnections + { + get + { + return activeConnections.Value; + } + } + + /// + /// Gets the singleton service instance + /// + public static ConnectionService Instance + { + get + { + return instance.Value; + } + } + + /// + /// Gets the SQL connection factory instance + /// + public ISqlConnectionFactory ConnectionFactory + { + get + { + if (this.connectionFactory == null) + { + this.connectionFactory = new SqlConnectionFactory(); + } + return this.connectionFactory; + } + } + + /// + /// Default constructor is private since it's a singleton class + /// + private ConnectionService() + { + } + + /// + /// Test constructor that injects dependency interfaces + /// + /// + public ConnectionService(ISqlConnectionFactory testFactory) + { + this.connectionFactory = testFactory; + } + + /// + /// Open a connection with the specified connection details + /// + /// + public ConnectionResult Connect(ConnectionDetails connectionDetails) + { + // build the connection string from the input parameters + string connectionString = BuildConnectionString(connectionDetails); + + // create a sql connection instance + ISqlConnection connection = this.ConnectionFactory.CreateSqlConnection(); + + // open the database + connection.OpenDatabaseConnection(connectionString); + + // map the connection id to the connection object for future lookups + this.ActiveConnections.Add(++maxConnectionId, connection); + + // invoke callback notifications + foreach (var activity in this.onConnectionActivities) + { + activity(connection); + } + + // return the connection result + return new ConnectionResult() + { + ConnectionId = maxConnectionId + }; + } + + /// + /// Add a new method to be called when the onconnection request is submitted + /// + /// + public void RegisterOnConnectionTask(OnConnectionHandler activity) + { + onConnectionActivities.Add(activity); + } + + /// + /// Build a connection string from a connection details instance + /// + /// + private string BuildConnectionString(ConnectionDetails connectionDetails) + { + SqlConnectionStringBuilder connectionBuilder = new SqlConnectionStringBuilder(); + connectionBuilder["Data Source"] = connectionDetails.ServerName; + connectionBuilder["Integrated Security"] = false; + connectionBuilder["User Id"] = connectionDetails.UserName; + connectionBuilder["Password"] = connectionDetails.Password; + connectionBuilder["Initial Catalog"] = connectionDetails.DatabaseName; + return connectionBuilder.ToString(); + } + } +} diff --git a/src/ServiceHost/Connection/ISqlConnection.cs b/src/ServiceHost/Connection/ISqlConnection.cs new file mode 100644 index 00000000..4ef80c5e --- /dev/null +++ b/src/ServiceHost/Connection/ISqlConnection.cs @@ -0,0 +1,34 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System.Collections.Generic; + +namespace Microsoft.SqlTools.EditorServices.Connection +{ + /// + /// Interface for the SQL Connection factory + /// + public interface ISqlConnectionFactory + { + /// + /// Create a new SQL Connection object + /// + ISqlConnection CreateSqlConnection(); + } + + /// + /// Interface for the SQL Connection wrapper + /// + public interface ISqlConnection + { + /// + /// Open a connection to the provided connection string + /// + /// + void OpenDatabaseConnection(string connectionString); + + IEnumerable GetServerObjects(); + } +} diff --git a/src/ServiceHost/Connection/SqlConnection.cs b/src/ServiceHost/Connection/SqlConnection.cs new file mode 100644 index 00000000..5bb92553 --- /dev/null +++ b/src/ServiceHost/Connection/SqlConnection.cs @@ -0,0 +1,72 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; + +namespace Microsoft.SqlTools.EditorServices.Connection +{ + /// + /// Factory class to create SqlClientConnections + /// The purpose of the factory is to make it easier to mock out the database + /// in 'offline' unit test scenarios. + /// + public class SqlConnectionFactory : ISqlConnectionFactory + { + /// + /// Creates a new SqlClientConnection object + /// + public ISqlConnection CreateSqlConnection() + { + return new SqlClientConnection(); + } + } + + /// + /// Wrapper class that implements ISqlConnection and hosts a SqlConnection. + /// This wrapper exists primarily for decoupling to support unit testing. + /// + public class SqlClientConnection : ISqlConnection + { + /// + /// the underlying SQL connection + /// + private SqlConnection connection; + + /// + /// Opens a SqlConnection using provided connection string + /// + /// + public void OpenDatabaseConnection(string connectionString) + { + this.connection = new SqlConnection(connectionString); + this.connection.Open(); + } + + /// + /// Gets a list of database server schema objects + /// + /// + public IEnumerable GetServerObjects() + { + // Select the values from sys.tables to give a super basic + // autocomplete experience. This will be replaced by SMO. + SqlCommand command = connection.CreateCommand(); + command.CommandText = "SELECT name FROM sys.tables"; + command.CommandTimeout = 15; + command.CommandType = CommandType.Text; + var reader = command.ExecuteReader(); + + List results = new List(); + while (reader.Read()) + { + results.Add(reader[0].ToString()); + } + + return results; + } + } +} diff --git a/src/ServiceHost/LanguageSupport/AutoCompleteService.cs b/src/ServiceHost/LanguageSupport/AutoCompleteService.cs new file mode 100644 index 00000000..2cf98484 --- /dev/null +++ b/src/ServiceHost/LanguageSupport/AutoCompleteService.cs @@ -0,0 +1,112 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.SqlTools.EditorServices.Connection; +using Microsoft.SqlTools.EditorServices.Protocol.LanguageServer; +using System; +using System.Collections.Generic; + +namespace Microsoft.SqlTools.LanguageSupport +{ + /// + /// Main class for Autocomplete functionality + /// + public class AutoCompleteService + { + /// + /// Singleton service instance + /// + private static Lazy instance + = new Lazy(() => new AutoCompleteService()); + + /// + /// The current autocomplete candidate list + /// + private IEnumerable autoCompleteList; + + /// + /// Gets the current autocomplete candidate list + /// + public IEnumerable AutoCompleteList + { + get + { + return this.autoCompleteList; + } + } + + /// + /// Gets the singleton service instance + /// + public static AutoCompleteService Instance + { + get + { + return instance.Value; + } + } + + /// + /// Update the cached autocomplete candidate list when the user connects to a database + /// + /// + public void UpdateAutoCompleteCache(ISqlConnection connection) + { + this.autoCompleteList = connection.GetServerObjects(); + } + + /// + /// Return the completion item list for the current text position + /// + /// + public CompletionItem[] GetCompletionItems(TextDocumentPosition textDocumentPosition) + { + var completions = new List(); + + int i = 0; + + // the completion list will be null is user not connected to server + if (this.AutoCompleteList != null) + { + foreach (var autoCompleteItem in this.AutoCompleteList) + { + // convert the completion item candidates into CompletionItems + completions.Add(new CompletionItem() + { + Label = autoCompleteItem, + Kind = CompletionItemKind.Keyword, + Detail = autoCompleteItem + " details", + Documentation = autoCompleteItem + " documentation", + TextEdit = new TextEdit + { + NewText = autoCompleteItem, + Range = new Range + { + Start = new Position + { + Line = textDocumentPosition.Position.Line, + Character = textDocumentPosition.Position.Character + }, + End = new Position + { + Line = textDocumentPosition.Position.Line, + Character = textDocumentPosition.Position.Character + 5 + } + } + } + }); + + // only show 50 items + if (++i == 50) + { + break; + } + } + } + return completions.ToArray(); + } + + } +} diff --git a/src/ServiceHost/LanguageSupport/LanguageService.cs b/src/ServiceHost/LanguageSupport/LanguageService.cs index 3ab77697..ff4f4a65 100644 --- a/src/ServiceHost/LanguageSupport/LanguageService.cs +++ b/src/ServiceHost/LanguageSupport/LanguageService.cs @@ -5,6 +5,8 @@ using Microsoft.SqlTools.EditorServices; using Microsoft.SqlTools.EditorServices.Session; +using Microsoft.SqlServer.Management.SqlParser.Parser; +using System.Collections.Generic; namespace Microsoft.SqlTools.LanguageSupport { @@ -13,6 +15,11 @@ namespace Microsoft.SqlTools.LanguageSupport /// public class LanguageService { + /// + /// The cached parse result from previous incremental parse + /// + private ParseResult prevParseResult; + /// /// Gets or sets the current SQL Tools context /// @@ -34,24 +41,38 @@ namespace Microsoft.SqlTools.LanguageSupport /// public ScriptFileMarker[] GetSemanticMarkers(ScriptFile scriptFile) { - // the commented out snippet is an example of how to create a error marker - // semanticMarkers = new ScriptFileMarker[1]; - // semanticMarkers[0] = new ScriptFileMarker() - // { - // Message = "Error message", - // Level = ScriptFileMarkerLevel.Error, - // ScriptRegion = new ScriptRegion() - // { - // File = scriptFile.FilePath, - // StartLineNumber = 2, - // StartColumnNumber = 2, - // StartOffset = 0, - // EndLineNumber = 4, - // EndColumnNumber = 10, - // EndOffset = 0 - // } - // }; - return new ScriptFileMarker[0]; + // parse current SQL file contents to retrieve a list of errors + ParseOptions parseOptions = new ParseOptions(); + ParseResult parseResult = Parser.IncrementalParse( + scriptFile.Contents, + prevParseResult, + parseOptions); + + // save previous result for next incremental parse + this.prevParseResult = parseResult; + + // build a list of SQL script file markers from the errors + List markers = new List(); + foreach (var error in parseResult.Errors) + { + markers.Add(new ScriptFileMarker() + { + Message = error.Message, + Level = ScriptFileMarkerLevel.Error, + ScriptRegion = new ScriptRegion() + { + File = scriptFile.FilePath, + StartLineNumber = error.Start.LineNumber, + StartColumnNumber = error.Start.ColumnNumber, + StartOffset = 0, + EndLineNumber = error.End.LineNumber, + EndColumnNumber = error.End.ColumnNumber, + EndOffset = 0 + } + }); + } + + return markers.ToArray(); } } } diff --git a/src/ServiceHost/Server/LanguageServer.cs b/src/ServiceHost/Server/LanguageServer.cs index d6719141..c2952f92 100644 --- a/src/ServiceHost/Server/LanguageServer.cs +++ b/src/ServiceHost/Server/LanguageServer.cs @@ -13,6 +13,8 @@ using System.Text; using System.Threading; using System.Linq; using System; +using Microsoft.SqlTools.EditorServices.Connection; +using Microsoft.SqlTools.LanguageSupport; namespace Microsoft.SqlTools.EditorServices.Protocol.Server { @@ -57,7 +59,22 @@ namespace Microsoft.SqlTools.EditorServices.Protocol.Server this.SetRequestHandler(DocumentHighlightRequest.Type, this.HandleDocumentHighlightRequest); this.SetRequestHandler(HoverRequest.Type, this.HandleHoverRequest); this.SetRequestHandler(DocumentSymbolRequest.Type, this.HandleDocumentSymbolRequest); - this.SetRequestHandler(WorkspaceSymbolRequest.Type, this.HandleWorkspaceSymbolRequest); + this.SetRequestHandler(WorkspaceSymbolRequest.Type, this.HandleWorkspaceSymbolRequest); + + this.SetRequestHandler(ConnectionRequest.Type, this.HandleConnectRequest); + + // register an OnConnection callback + ConnectionService.Instance.RegisterOnConnectionTask(OnConnection); + } + + /// + /// Callback for when a user connection is done processing + /// + /// + public Task OnConnection(ISqlConnection sqlConnection) + { + AutoCompleteService.Instance.UpdateAutoCompleteCache(sqlConnection); + return Task.FromResult(true); } /// @@ -122,7 +139,7 @@ namespace Microsoft.SqlTools.EditorServices.Protocol.Server /// /// /// - protected Task HandleDidChangeTextDocumentNotification( + protected async Task HandleDidChangeTextDocumentNotification( DidChangeTextDocumentParams textChangeParams, EventContext eventContext) { @@ -133,7 +150,7 @@ namespace Microsoft.SqlTools.EditorServices.Protocol.Server // A text change notification can batch multiple change requests foreach (var textChange in textChangeParams.ContentChanges) { - string fileUri = textChangeParams.TextDocument.Uri; + string fileUri = textChangeParams.Uri ?? textChangeParams.TextDocument.Uri; msg.AppendLine(); msg.Append(" File: "); msg.Append(fileUri); @@ -150,23 +167,46 @@ namespace Microsoft.SqlTools.EditorServices.Protocol.Server Logger.Write(LogLevel.Verbose, msg.ToString()); - this.RunScriptDiagnostics( + await this.RunScriptDiagnostics( changedFiles.ToArray(), editorSession, eventContext); + await Task.FromResult(true); + } + + /// + /// Handle the file open notification + /// + /// + /// + protected Task HandleDidOpenTextDocumentNotification( + DidOpenTextDocumentNotification openParams, + EventContext eventContext) + { + Logger.Write(LogLevel.Verbose, "HandleDidOpenTextDocumentNotification"); + + // read the SQL file contents into the ScriptFile + ScriptFile openedFile = + editorSession.Workspace.GetFileBuffer( + openParams.Uri, + openParams.Text); + + // run diagnostics on the opened file + this.RunScriptDiagnostics( + new ScriptFile[] { openedFile }, + editorSession, + eventContext); + return Task.FromResult(true); } - protected Task HandleDidOpenTextDocumentNotification( - DidOpenTextDocumentNotification openParams, - EventContext eventContext) - { - Logger.Write(LogLevel.Verbose, "HandleDidOpenTextDocumentNotification"); - return Task.FromResult(true); - } - - protected Task HandleDidCloseTextDocumentNotification( + /// + /// Handle the close document notication + /// + /// + /// + protected Task HandleDidCloseTextDocumentNotification( TextDocumentIdentifier closeParams, EventContext eventContext) { @@ -240,12 +280,20 @@ namespace Microsoft.SqlTools.EditorServices.Protocol.Server await Task.FromResult(true); } + /// + /// Handles the completion list request + /// + /// + /// protected async Task HandleCompletionRequest( TextDocumentPosition textDocumentPosition, RequestContext requestContext) { Logger.Write(LogLevel.Verbose, "HandleCompletionRequest"); - await Task.FromResult(true); + + // get teh current list of completion items and return to client + var completionItems = AutoCompleteService.Instance.GetCompletionItems(textDocumentPosition); + await requestContext.SendResult(completionItems); } protected async Task HandleCompletionResolveRequest( @@ -296,6 +344,24 @@ namespace Microsoft.SqlTools.EditorServices.Protocol.Server await Task.FromResult(true); } + /// + /// Handle new connection requests + /// + /// + /// + /// + protected async Task HandleConnectRequest( + ConnectionDetails connectionDetails, + RequestContext requestContext) + { + Logger.Write(LogLevel.Verbose, "HandleConnectRequest"); + + // open connection base on request details + ConnectionResult result = ConnectionService.Instance.Connect(connectionDetails); + + await requestContext.SendResult(result); + } + /// /// Runs script diagnostics on changed files /// diff --git a/src/ServiceHost/Workspace/ScriptFile.cs b/src/ServiceHost/Workspace/ScriptFile.cs index 90d66244..166b50ea 100644 --- a/src/ServiceHost/Workspace/ScriptFile.cs +++ b/src/ServiceHost/Workspace/ScriptFile.cs @@ -106,6 +106,13 @@ namespace Microsoft.SqlTools.EditorServices #region Constructors + /// + /// Add a default constructor for testing + /// + public ScriptFile() + { + } + /// /// Creates a new ScriptFile instance by reading file contents from /// the given TextReader. @@ -433,11 +440,11 @@ namespace Microsoft.SqlTools.EditorServices return new BufferRange(startPosition, endPosition); } - #endregion - - #region Private Methods - - private void SetFileContents(string fileContents) + /// + /// Set the script files contents + /// + /// + public void SetFileContents(string fileContents) { // Split the file contents into lines and trim // any carriage returns from the strings. @@ -451,6 +458,10 @@ namespace Microsoft.SqlTools.EditorServices this.ParseFileContents(); } + #endregion + + #region Private Methods + /// /// Parses the current file contents to get the AST, tokens, /// and parse errors. diff --git a/src/ServiceHost/project.json b/src/ServiceHost/project.json index 11340892..31dac66d 100644 --- a/src/ServiceHost/project.json +++ b/src/ServiceHost/project.json @@ -5,7 +5,10 @@ "emitEntryPoint": true }, "dependencies": { - "Newtonsoft.Json": "9.0.1" + "Newtonsoft.Json": "9.0.1", + "Microsoft.SqlServer.SqlParser": "140.1.3", + "System.Data.Common": "4.1.0", + "System.Data.SqlClient": "4.1.0" }, "frameworks": { "netcoreapp1.0": { diff --git a/test/ServiceHost.Test/Connection/ConnectionServiceTests.cs b/test/ServiceHost.Test/Connection/ConnectionServiceTests.cs new file mode 100644 index 00000000..6796183c --- /dev/null +++ b/test/ServiceHost.Test/Connection/ConnectionServiceTests.cs @@ -0,0 +1,60 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System.Threading.Tasks; +using Microsoft.SqlTools.Test.Utility; +using Xunit; + +namespace Microsoft.SqlTools.Test.Connection +{ + /// + /// Tests for the ServiceHost Connection Service tests + /// + public class ConnectionServiceTests + { + #region "Connection tests" + + /// + /// Verify that the SQL parser correctly detects errors in text + /// + [Fact] + public void ConnectToDatabaseTest() + { + // connect to a database instance + var connectionResult = + TestObjects.GetTestConnectionService() + .Connect(TestObjects.GetTestConnectionDetails()); + + // verify that a valid connection id was returned + Assert.True(connectionResult.ConnectionId > 0); + } + + /// + /// Verify that the SQL parser correctly detects errors in text + /// + [Fact] + public void OnConnectionCallbackHandlerTest() + { + bool callbackInvoked = false; + + // setup connection service with callback + var connectionService = TestObjects.GetTestConnectionService(); + connectionService.RegisterOnConnectionTask( + (sqlConnection) => { + callbackInvoked = true; + return Task.FromResult(true); + } + ); + + // connect to a database instance + var connectionResult = connectionService.Connect(TestObjects.GetTestConnectionDetails()); + + // verify that a valid connection id was returned + Assert.True(callbackInvoked); + } + + #endregion + } +} diff --git a/test/ServiceHost.Test/LanguageServer/LanguageServiceTests.cs b/test/ServiceHost.Test/LanguageServer/LanguageServiceTests.cs new file mode 100644 index 00000000..36aac6b4 --- /dev/null +++ b/test/ServiceHost.Test/LanguageServer/LanguageServiceTests.cs @@ -0,0 +1,126 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.SqlTools.EditorServices; +using Microsoft.SqlTools.EditorServices.Session; +using Microsoft.SqlTools.LanguageSupport; +using Microsoft.SqlTools.Test.Connection; +using Microsoft.SqlTools.Test.Utility; +using Xunit; + +namespace Microsoft.SqlTools.Test.LanguageServer +{ + /// + /// Tests for the ServiceHost Language Service tests + /// + public class LanguageServiceTests + { + #region "Diagnostics tests" + + /// + /// Verify that the SQL parser correctly detects errors in text + /// + [Fact] + public void ParseSelectStatementWithoutErrors() + { + // sql statement with no errors + const string sqlWithErrors = "SELECT * FROM sys.objects"; + + // get the test service + LanguageService service = TestObjects.GetTestLanguageService(); + + // parse the sql statement + var scriptFile = new ScriptFile(); + scriptFile.SetFileContents(sqlWithErrors); + ScriptFileMarker[] fileMarkers = service.GetSemanticMarkers(scriptFile); + + // verify there are no errors + Assert.Equal(0, fileMarkers.Length); + } + + /// + /// Verify that the SQL parser correctly detects errors in text + /// + [Fact] + public void ParseSelectStatementWithError() + { + // sql statement with errors + const string sqlWithErrors = "SELECT *** FROM sys.objects"; + + // get test service + LanguageService service = TestObjects.GetTestLanguageService(); + + // parse sql statement + var scriptFile = new ScriptFile(); + scriptFile.SetFileContents(sqlWithErrors); + ScriptFileMarker[] fileMarkers = service.GetSemanticMarkers(scriptFile); + + // verify there is one error + Assert.Equal(1, fileMarkers.Length); + + // verify the position of the error + Assert.Equal(9, fileMarkers[0].ScriptRegion.StartColumnNumber); + Assert.Equal(1, fileMarkers[0].ScriptRegion.StartLineNumber); + Assert.Equal(10, fileMarkers[0].ScriptRegion.EndColumnNumber); + Assert.Equal(1, fileMarkers[0].ScriptRegion.EndLineNumber); + } + + /// + /// Verify that the SQL parser correctly detects errors in text + /// + [Fact] + public void ParseMultilineSqlWithErrors() + { + // multiline sql with errors + const string sqlWithErrors = + "SELECT *** FROM sys.objects;\n" + + "GO\n" + + "SELECT *** FROM sys.objects;\n"; + + // get test service + LanguageService service = TestObjects.GetTestLanguageService(); + + // parse sql + var scriptFile = new ScriptFile(); + scriptFile.SetFileContents(sqlWithErrors); + ScriptFileMarker[] fileMarkers = service.GetSemanticMarkers(scriptFile); + + // verify there are two errors + Assert.Equal(2, fileMarkers.Length); + + // check position of first error + Assert.Equal(9, fileMarkers[0].ScriptRegion.StartColumnNumber); + Assert.Equal(1, fileMarkers[0].ScriptRegion.StartLineNumber); + Assert.Equal(10, fileMarkers[0].ScriptRegion.EndColumnNumber); + Assert.Equal(1, fileMarkers[0].ScriptRegion.EndLineNumber); + + // check position of second error + Assert.Equal(9, fileMarkers[1].ScriptRegion.StartColumnNumber); + Assert.Equal(3, fileMarkers[1].ScriptRegion.StartLineNumber); + Assert.Equal(10, fileMarkers[1].ScriptRegion.EndColumnNumber); + Assert.Equal(3, fileMarkers[1].ScriptRegion.EndLineNumber); + } + + #endregion + + #region "Autocomplete Tests" + + /// + /// Verify that the SQL parser correctly detects errors in text + /// + [Fact] + public void AutocompleteTest() + { + var autocompleteService = TestObjects.GetAutoCompleteService(); + var connectionService = TestObjects.GetTestConnectionService(); + var connectionResult = connectionService.Connect(TestObjects.GetTestConnectionDetails()); + var sqlConnection = connectionService.ActiveConnections[connectionResult.ConnectionId]; + autocompleteService.UpdateAutoCompleteCache(sqlConnection); + } + + #endregion + } +} + diff --git a/test/ServiceHost.Test/Utility/TestObjects.cs b/test/ServiceHost.Test/Utility/TestObjects.cs new file mode 100644 index 00000000..22fc3f4d --- /dev/null +++ b/test/ServiceHost.Test/Utility/TestObjects.cs @@ -0,0 +1,108 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +//#define USE_LIVE_CONNECTION + +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.SqlTools.EditorServices.Connection; +using Microsoft.SqlTools.EditorServices.Session; +using Microsoft.SqlTools.LanguageSupport; +using Xunit; + +namespace Microsoft.SqlTools.Test.Utility +{ + /// + /// Tests for the ServiceHost Connection Service tests + /// + public class TestObjects + { + /// + /// Creates a test connection service + /// + public static ConnectionService GetTestConnectionService() + { +#if !USE_LIVE_CONNECTION + // use mock database connection + return new ConnectionService(new TestSqlConnectionFactory()); +#else + // connect to a real server instance + return ConnectionService.Instance; +#endif + } + + /// + /// Creates a test connection details object + /// + public static ConnectionDetails GetTestConnectionDetails() + { + return new ConnectionDetails() + { + UserName = "sa", + Password = "Yukon900", + DatabaseName = "AdventureWorks2016CTP3_2", + ServerName = "sqltools11" + }; + } + + /// + /// Create a test language service instance + /// + /// + public static LanguageService GetTestLanguageService() + { + return new LanguageService(new SqlToolsContext(null, null)); + } + + /// + /// Creates a test autocomplete service instance + /// + public static AutoCompleteService GetAutoCompleteService() + { + return AutoCompleteService.Instance; + } + + /// + /// Creates a test sql connection factory instance + /// + public static ISqlConnectionFactory GetTestSqlConnectionFactory() + { +#if !USE_LIVE_CONNECTION + // use mock database connection + return new TestSqlConnectionFactory(); +#else + // connect to a real server instance + return ConnectionService.Instance.ConnectionFactory; +#endif + + } + } + + /// + /// Test mock class for SqlConnection wrapper + /// + public class TestSqlConnection : ISqlConnection + { + public void OpenDatabaseConnection(string connectionString) + { + } + + public IEnumerable GetServerObjects() + { + return null; + } + } + + /// + /// Test mock class for SqlConnection factory + /// + public class TestSqlConnectionFactory : ISqlConnectionFactory + { + public ISqlConnection CreateSqlConnection() + { + return new TestSqlConnection(); + } + } +} diff --git a/test/ServiceHost.Test/project.json b/test/ServiceHost.Test/project.json index b7f00724..a248b200 100644 --- a/test/ServiceHost.Test/project.json +++ b/test/ServiceHost.Test/project.json @@ -6,11 +6,13 @@ "dependencies": { "Newtonsoft.Json": "9.0.1", "System.Runtime.Serialization.Primitives": "4.1.1", + "System.Data.Common": "4.1.0", + "System.Data.SqlClient": "4.1.0", "xunit": "2.1.0", "dotnet-test-xunit": "1.0.0-rc2-192208-24", - "ServiceHost": { - "target": "project" - } + "ServiceHost": { + "target": "project" + } }, "testRunner": "xunit", "frameworks": { From 639ab4f205c094c9c65e7655cf1f02888185b625 Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Mon, 25 Jul 2016 13:33:04 -0700 Subject: [PATCH 15/15] Small items for code review iteration * Removing unused OutputType and OutputWrittenEventArgs classes * Adding class comment blocks * Tweaking a couple comment blocks as per @kcunanne comments --- src/ServiceHost/Hosting/ServiceHost.cs | 4 +- .../LanguageServices/LanguageService.cs | 3 +- src/ServiceHost/Session/OutputType.cs | 41 ------------ .../Session/OutputWrittenEventArgs.cs | 65 ------------------- src/ServiceHost/SqlContext/SqlToolsContext.cs | 3 + .../SqlContext/SqlToolsSettings.cs | 6 ++ .../WorkspaceServices/WorkspaceService.cs | 13 ++-- 7 files changed, 22 insertions(+), 113 deletions(-) delete mode 100644 src/ServiceHost/Session/OutputType.cs delete mode 100644 src/ServiceHost/Session/OutputWrittenEventArgs.cs diff --git a/src/ServiceHost/Hosting/ServiceHost.cs b/src/ServiceHost/Hosting/ServiceHost.cs index fcaaffcd..dbc561fe 100644 --- a/src/ServiceHost/Hosting/ServiceHost.cs +++ b/src/ServiceHost/Hosting/ServiceHost.cs @@ -15,7 +15,9 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel; namespace Microsoft.SqlTools.ServiceLayer.Hosting { /// - /// SQL Tools VS Code Language Server request handler + /// SQL Tools VS Code Language Server request handler. Provides the entire JSON RPC + /// implementation for sending/receiving JSON requests and dispatching the requests to + /// handlers that are registered prior to startup. /// public sealed class ServiceHost : ServiceHostBase { diff --git a/src/ServiceHost/LanguageServices/LanguageService.cs b/src/ServiceHost/LanguageServices/LanguageService.cs index 42bbdec5..d88cfd92 100644 --- a/src/ServiceHost/LanguageServices/LanguageService.cs +++ b/src/ServiceHost/LanguageServices/LanguageService.cs @@ -18,7 +18,8 @@ using System.Linq; namespace Microsoft.SqlTools.ServiceLayer.LanguageServices { /// - /// Main class for Language Service functionality + /// Main class for Language Service functionality including anything that reqires knowledge of + /// the language to perfom, such as definitions, intellisense, etc. /// public sealed class LanguageService { diff --git a/src/ServiceHost/Session/OutputType.cs b/src/ServiceHost/Session/OutputType.cs deleted file mode 100644 index 8ba866d7..00000000 --- a/src/ServiceHost/Session/OutputType.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -namespace Microsoft.SqlTools.EditorServices -{ - /// - /// Enumerates the types of output lines that will be sent - /// to an IConsoleHost implementation. - /// - public enum OutputType - { - /// - /// A normal output line, usually written with the or Write-Host or - /// Write-Output cmdlets. - /// - Normal, - - /// - /// A debug output line, written with the Write-Debug cmdlet. - /// - Debug, - - /// - /// A verbose output line, written with the Write-Verbose cmdlet. - /// - Verbose, - - /// - /// A warning output line, written with the Write-Warning cmdlet. - /// - Warning, - - /// - /// An error output line, written with the Write-Error cmdlet or - /// as a result of some error during SqlTools pipeline execution. - /// - Error - } -} diff --git a/src/ServiceHost/Session/OutputWrittenEventArgs.cs b/src/ServiceHost/Session/OutputWrittenEventArgs.cs deleted file mode 100644 index 4b1dbbe3..00000000 --- a/src/ServiceHost/Session/OutputWrittenEventArgs.cs +++ /dev/null @@ -1,65 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -using System; - -namespace Microsoft.SqlTools.EditorServices -{ - /// - /// Provides details about output that has been written to the - /// SqlTools host. - /// - public class OutputWrittenEventArgs - { - /// - /// Gets the text of the output. - /// - public string OutputText { get; private set; } - - /// - /// Gets the type of the output. - /// - public OutputType OutputType { get; private set; } - - /// - /// Gets a boolean which indicates whether a newline - /// should be written after the output. - /// - public bool IncludeNewLine { get; private set; } - - /// - /// Gets the foreground color of the output text. - /// - public ConsoleColor ForegroundColor { get; private set; } - - /// - /// Gets the background color of the output text. - /// - public ConsoleColor BackgroundColor { get; private set; } - - /// - /// Creates an instance of the OutputWrittenEventArgs class. - /// - /// The text of the output. - /// A boolean which indicates whether a newline should be written after the output. - /// The type of the output. - /// The foreground color of the output text. - /// The background color of the output text. - public OutputWrittenEventArgs( - string outputText, - bool includeNewLine, - OutputType outputType, - ConsoleColor foregroundColor, - ConsoleColor backgroundColor) - { - this.OutputText = outputText; - this.IncludeNewLine = includeNewLine; - this.OutputType = outputType; - this.ForegroundColor = foregroundColor; - this.BackgroundColor = backgroundColor; - } - } -} - diff --git a/src/ServiceHost/SqlContext/SqlToolsContext.cs b/src/ServiceHost/SqlContext/SqlToolsContext.cs index bf4d67c9..d110f28c 100644 --- a/src/ServiceHost/SqlContext/SqlToolsContext.cs +++ b/src/ServiceHost/SqlContext/SqlToolsContext.cs @@ -7,6 +7,9 @@ using System; namespace Microsoft.SqlTools.ServiceLayer.SqlContext { + /// + /// Context for SQL Tools + /// public class SqlToolsContext { /// diff --git a/src/ServiceHost/SqlContext/SqlToolsSettings.cs b/src/ServiceHost/SqlContext/SqlToolsSettings.cs index a6f242ed..07ea0ffe 100644 --- a/src/ServiceHost/SqlContext/SqlToolsSettings.cs +++ b/src/ServiceHost/SqlContext/SqlToolsSettings.cs @@ -3,6 +3,9 @@ using Microsoft.SqlTools.EditorServices.Utility; namespace Microsoft.SqlTools.ServiceLayer.SqlContext { + /// + /// Class for serialization and deserialization of the settings the SQL Tools Service needs. + /// public class SqlToolsSettings { // TODO: Is this needed? I can't make sense of this comment. @@ -30,6 +33,9 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext } } + /// + /// Sub class for serialization and deserialization of script analysis settings + /// public class ScriptAnalysisSettings { public bool? Enable { get; set; } diff --git a/src/ServiceHost/WorkspaceServices/WorkspaceService.cs b/src/ServiceHost/WorkspaceServices/WorkspaceService.cs index 6eb0c8c9..a0b537a0 100644 --- a/src/ServiceHost/WorkspaceServices/WorkspaceService.cs +++ b/src/ServiceHost/WorkspaceServices/WorkspaceService.cs @@ -15,6 +15,14 @@ using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices { + /// + /// Class for handling requests/events that deal with the state of the workspace, including the + /// opening and closing of files, the changing of configuration, etc. + /// + /// + /// The type of the class used for serializing and deserializing the configuration. Must be the + /// actual type of the instance otherwise deserialization will be incomplete. + /// public class WorkspaceService where TConfig : class, new() { @@ -135,9 +143,6 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices /// /// Handles text document change events /// - /// - /// - /// protected Task HandleDidChangeTextDocumentNotification( DidChangeTextDocumentParams textChangeParams, EventContext eventContext) @@ -187,8 +192,6 @@ namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices /// /// Handles the configuration change event /// - /// - /// protected async Task HandleDidChangeConfigurationNotification( DidChangeConfigurationParams configChangeParams, EventContext eventContext)