diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..d1fcfc4e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+bin
+obj
+project.lock.json
\ No newline at end of file
diff --git a/README.md b/README.md
index 61e90e7a..e38a335b 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,2 @@
# sqltoolsservice
-SQL Tools API service repo.
+SQL Tools Service host
diff --git a/ServiceHost/.vscode/launch.json b/ServiceHost/.vscode/launch.json
new file mode 100644
index 00000000..51cdc900
--- /dev/null
+++ b/ServiceHost/.vscode/launch.json
@@ -0,0 +1,22 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": ".NET Core Launch (console)",
+ "type": "coreclr",
+ "request": "launch",
+ "preLaunchTask": "build",
+ "program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/servicehost.dll",
+ "args": [],
+ "cwd": "${workspaceRoot}",
+ "externalConsole": true,
+ "stopAtEntry": false
+ },
+ {
+ "name": ".NET Core Attach",
+ "type": "coreclr",
+ "request": "attach",
+ "processId": 16900
+ }
+ ]
+}
\ No newline at end of file
diff --git a/ServiceHost/.vscode/tasks.json b/ServiceHost/.vscode/tasks.json
new file mode 100644
index 00000000..67d6eb75
--- /dev/null
+++ b/ServiceHost/.vscode/tasks.json
@@ -0,0 +1,14 @@
+{
+ "version": "0.1.0",
+ "command": "dotnet",
+ "isShellCommand": true,
+ "args": [],
+ "tasks": [
+ {
+ "taskName": "build",
+ "args": [],
+ "isBuildCommand": true,
+ "problemMatcher": "$msCompile"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/ServiceHost/Client/DebugAdapterClientBase.cs b/ServiceHost/Client/DebugAdapterClientBase.cs
new file mode 100644
index 00000000..5e6a1758
--- /dev/null
+++ b/ServiceHost/Client/DebugAdapterClientBase.cs
@@ -0,0 +1,48 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter;
+using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
+using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.Channel;
+using System.Threading.Tasks;
+
+namespace Microsoft.PowerShell.EditorServices.Protocol.Client
+{
+ public class DebugAdapterClient : ProtocolEndpoint
+ {
+ public DebugAdapterClient(ChannelBase clientChannel)
+ : base(clientChannel, MessageProtocolType.DebugAdapter)
+ {
+ }
+
+ public async Task LaunchScript(string scriptFilePath)
+ {
+ await this.SendRequest(
+ LaunchRequest.Type,
+ new LaunchRequestArguments {
+ Program = scriptFilePath
+ });
+
+ await this.SendRequest(ConfigurationDoneRequest.Type, null);
+ }
+
+ protected override Task OnStart()
+ {
+ return Task.FromResult(true);
+ }
+
+ protected override Task OnConnect()
+ {
+ // Initialize the debug adapter
+ return this.SendRequest(
+ InitializeRequest.Type,
+ new InitializeRequestArguments
+ {
+ LinesStartAt1 = true
+ });
+ }
+ }
+}
+
diff --git a/ServiceHost/Client/LanguageClientBase.cs b/ServiceHost/Client/LanguageClientBase.cs
new file mode 100644
index 00000000..665383d0
--- /dev/null
+++ b/ServiceHost/Client/LanguageClientBase.cs
@@ -0,0 +1,44 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using Microsoft.PowerShell.EditorServices.Protocol.LanguageServer;
+using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
+using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.Channel;
+using System.Threading.Tasks;
+
+namespace Microsoft.PowerShell.EditorServices.Protocol.Client
+{
+ ///
+ /// Provides a base implementation for language server clients.
+ ///
+ public abstract class LanguageClientBase : ProtocolEndpoint
+ {
+ ///
+ /// Initializes an instance of the language client using the
+ /// specified channel for communication.
+ ///
+ /// The channel to use for communication with the server.
+ public LanguageClientBase(ChannelBase clientChannel)
+ : base(clientChannel, MessageProtocolType.LanguageServer)
+ {
+ }
+
+ protected override Task OnStart()
+ {
+ // Initialize the implementation class
+ return this.Initialize();
+ }
+
+ protected override async Task OnStop()
+ {
+ // First, notify the language server that we're stopping
+ var response = await this.SendRequest(ShutdownRequest.Type, new object());
+ await this.SendEvent(ExitNotification.Type, new object());
+ }
+
+ protected abstract Task Initialize();
+ }
+}
+
diff --git a/ServiceHost/Client/LanguageServiceClient.cs b/ServiceHost/Client/LanguageServiceClient.cs
new file mode 100644
index 00000000..67d769ed
--- /dev/null
+++ b/ServiceHost/Client/LanguageServiceClient.cs
@@ -0,0 +1,121 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using Microsoft.PowerShell.EditorServices.Protocol.LanguageServer;
+using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
+using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.Channel;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace Microsoft.PowerShell.EditorServices.Protocol.Client
+{
+ public class LanguageServiceClient : LanguageClientBase
+ {
+ private Dictionary cachedDiagnostics =
+ new Dictionary();
+
+ public LanguageServiceClient(ChannelBase clientChannel)
+ : base(clientChannel)
+ {
+ }
+
+ protected override Task Initialize()
+ {
+ // Add handlers for common events
+ this.SetEventHandler(PublishDiagnosticsNotification.Type, HandlePublishDiagnosticsEvent);
+
+ return Task.FromResult(true);
+ }
+
+ protected override Task OnConnect()
+ {
+ // Send the 'initialize' request and wait for the response
+ var initializeRequest = new InitializeRequest
+ {
+ RootPath = "",
+ Capabilities = new ClientCapabilities()
+ };
+
+ return this.SendRequest(
+ InitializeRequest.Type,
+ initializeRequest);
+ }
+
+ #region Events
+
+ public event EventHandler DiagnosticsReceived;
+
+ protected void OnDiagnosticsReceived(string filePath)
+ {
+ if (this.DiagnosticsReceived != null)
+ {
+ this.DiagnosticsReceived(this, filePath);
+ }
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ private Task HandlePublishDiagnosticsEvent(
+ PublishDiagnosticsNotification diagnostics,
+ EventContext eventContext)
+ {
+ string normalizedPath = diagnostics.Uri.ToLower();
+
+ this.cachedDiagnostics[normalizedPath] =
+ diagnostics.Diagnostics
+ .Select(GetMarkerFromDiagnostic)
+ .ToArray();
+
+ this.OnDiagnosticsReceived(normalizedPath);
+
+ return Task.FromResult(true);
+ }
+
+ private static ScriptFileMarker GetMarkerFromDiagnostic(Diagnostic diagnostic)
+ {
+ DiagnosticSeverity severity =
+ diagnostic.Severity.GetValueOrDefault(
+ DiagnosticSeverity.Error);
+
+ return new ScriptFileMarker
+ {
+ Level = MapDiagnosticSeverityToLevel(severity),
+ Message = diagnostic.Message,
+ ScriptRegion = new ScriptRegion
+ {
+ StartLineNumber = diagnostic.Range.Start.Line + 1,
+ StartColumnNumber = diagnostic.Range.Start.Character + 1,
+ EndLineNumber = diagnostic.Range.End.Line + 1,
+ EndColumnNumber = diagnostic.Range.End.Character + 1
+ }
+ };
+ }
+
+ private static ScriptFileMarkerLevel MapDiagnosticSeverityToLevel(DiagnosticSeverity severity)
+ {
+ switch (severity)
+ {
+ case DiagnosticSeverity.Hint:
+ case DiagnosticSeverity.Information:
+ return ScriptFileMarkerLevel.Information;
+
+ case DiagnosticSeverity.Warning:
+ return ScriptFileMarkerLevel.Warning;
+
+ case DiagnosticSeverity.Error:
+ return ScriptFileMarkerLevel.Error;
+
+ default:
+ return ScriptFileMarkerLevel.Error;
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/ServiceHost/DebugAdapter/AttachRequest.cs b/ServiceHost/DebugAdapter/AttachRequest.cs
new file mode 100644
index 00000000..4b8faa9c
--- /dev/null
+++ b/ServiceHost/DebugAdapter/AttachRequest.cs
@@ -0,0 +1,23 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
+
+namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter
+{
+ public class AttachRequest
+ {
+ public static readonly
+ RequestType Type =
+ RequestType.Create("attach");
+ }
+
+ public class AttachRequestArguments
+ {
+ public string Address { get; set; }
+
+ public int Port { get; set; }
+ }
+}
diff --git a/ServiceHost/DebugAdapter/Breakpoint.cs b/ServiceHost/DebugAdapter/Breakpoint.cs
new file mode 100644
index 00000000..db04972c
--- /dev/null
+++ b/ServiceHost/DebugAdapter/Breakpoint.cs
@@ -0,0 +1,81 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using Microsoft.PowerShell.EditorServices.Utility;
+
+namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter
+{
+ public class Breakpoint
+ {
+ ///
+ /// Gets an boolean indicator that if true, breakpoint could be set
+ /// (but not necessarily at the desired location).
+ ///
+ public bool Verified { get; set; }
+
+ ///
+ /// Gets an optional message about the state of the breakpoint. This is shown to the user
+ /// and can be used to explain why a breakpoint could not be verified.
+ ///
+ public string Message { get; set; }
+
+ public string Source { get; set; }
+
+ public int? Line { get; set; }
+
+ public int? Column { get; set; }
+
+ private Breakpoint()
+ {
+ }
+
+#if false
+ public static Breakpoint Create(
+ BreakpointDetails breakpointDetails)
+ {
+ //Validate.IsNotNull(nameof(breakpointDetails), breakpointDetails);
+
+ return new Breakpoint
+ {
+ Verified = breakpointDetails.Verified,
+ Message = breakpointDetails.Message,
+ Source = breakpointDetails.Source,
+ Line = breakpointDetails.LineNumber,
+ Column = breakpointDetails.ColumnNumber
+ };
+ }
+
+ public static Breakpoint Create(
+ CommandBreakpointDetails breakpointDetails)
+ {
+ //Validate.IsNotNull(nameof(breakpointDetails), breakpointDetails);
+
+ return new Breakpoint {
+ Verified = breakpointDetails.Verified,
+ Message = breakpointDetails.Message
+ };
+ }
+#endif
+
+ public static Breakpoint Create(
+ SourceBreakpoint sourceBreakpoint,
+ string source,
+ string message,
+ bool verified = false)
+ {
+ Validate.IsNotNull(nameof(sourceBreakpoint), sourceBreakpoint);
+ Validate.IsNotNull(nameof(source), source);
+ Validate.IsNotNull(nameof(message), message);
+
+ return new Breakpoint {
+ Verified = verified,
+ Message = message,
+ Source = source,
+ Line = sourceBreakpoint.Line,
+ Column = sourceBreakpoint.Column
+ };
+ }
+ }
+}
diff --git a/ServiceHost/DebugAdapter/ConfigurationDoneRequest.cs b/ServiceHost/DebugAdapter/ConfigurationDoneRequest.cs
new file mode 100644
index 00000000..ef5e0c8e
--- /dev/null
+++ b/ServiceHost/DebugAdapter/ConfigurationDoneRequest.cs
@@ -0,0 +1,16 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
+
+namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter
+{
+ public class ConfigurationDoneRequest
+ {
+ public static readonly
+ RequestType