Servicehost cleanup (#1)

Merge some code clean ups.  Find+Replace 'PowerShell' with 'SQL Tools'.
Enable logger in ServiceHost project.
This commit is contained in:
Karl Burtram
2016-07-15 20:48:31 -07:00
committed by GitHub
parent 790825cfab
commit c78292a680
108 changed files with 347 additions and 340 deletions

View File

@@ -5,11 +5,11 @@
#if false
using Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter;
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.Channel;
using Microsoft.PowerShell.EditorServices.Session;
using Microsoft.PowerShell.EditorServices.Utility;
using Microsoft.SqlTools.EditorServices.Protocol.DebugAdapter;
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Channel;
using Microsoft.SqlTools.EditorServices.Session;
using Microsoft.SqlTools.EditorServices.Utility;
using System;
using System.Collections.Generic;
using System.IO;
@@ -17,7 +17,7 @@ using System.Linq;
using System.Management.Automation;
using System.Threading.Tasks;
namespace Microsoft.PowerShell.EditorServices.Protocol.Server
namespace Microsoft.SqlTools.EditorServices.Protocol.Server
{
public class DebugAdapter : DebugAdapterBase
{
@@ -40,7 +40,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
this.editorSession = new EditorSession();
this.editorSession.StartSession(hostDetails, profilePaths);
this.editorSession.DebugService.DebuggerStopped += this.DebugService_DebuggerStopped;
this.editorSession.ConsoleService.OutputWritten += this.powerShellContext_OutputWritten;
this.editorSession.ConsoleService.OutputWritten += this.SqlToolsContext_OutputWritten;
// Set up the output debouncer to throttle output event writes
this.outputDebouncer = new OutputDebouncer(this);
@@ -75,7 +75,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
protected Task LaunchScript(RequestContext<object> requestContext)
{
return editorSession.PowerShellContext
return editorSession.SqlToolsContext
.ExecuteScriptAtPath(this.scriptPathToLaunch, this.arguments)
.ContinueWith(
async (t) => {
@@ -130,11 +130,11 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
LaunchRequestArguments launchParams,
RequestContext<object> requestContext)
{
// Set the working directory for the PowerShell runspace to the cwd passed in via launch.json.
// Set the working directory for the SqlTools runspace to the cwd passed in via launch.json.
// In case that is null, use the the folder of the script to be executed. If the resulting
// working dir path is a file path then extract the directory and use that.
string workingDir = launchParams.Cwd ?? launchParams.Program;
workingDir = PowerShellContext.UnescapePath(workingDir);
workingDir = SqlToolsContext.UnescapePath(workingDir);
try
{
if ((File.GetAttributes(workingDir) & FileAttributes.Directory) != FileAttributes.Directory)
@@ -153,7 +153,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
#endif
}
editorSession.PowerShellContext.SetWorkingDirectory(workingDir);
editorSession.SqlToolsContext.SetWorkingDirectory(workingDir);
Logger.Write(LogLevel.Verbose, "Working dir set to: " + workingDir);
// Prepare arguments to the script - if specified
@@ -203,18 +203,18 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
handler =
async (o, e) =>
{
if (e.NewSessionState == PowerShellContextState.Ready)
if (e.NewSessionState == SqlToolsContextState.Ready)
{
await requestContext.SendResult(null);
editorSession.PowerShellContext.SessionStateChanged -= handler;
editorSession.SqlToolsContext.SessionStateChanged -= handler;
// Stop the server
this.Stop();
}
};
editorSession.PowerShellContext.SessionStateChanged += handler;
editorSession.PowerShellContext.AbortExecution();
editorSession.SqlToolsContext.SessionStateChanged += handler;
editorSession.SqlToolsContext.AbortExecution();
return Task.FromResult(true);
}
@@ -571,7 +571,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
});
}
async void powerShellContext_OutputWritten(object sender, OutputWrittenEventArgs e)
async void SqlToolsContext_OutputWritten(object sender, OutputWrittenEventArgs e)
{
// Queue the output for writing
await this.outputDebouncer.Invoke(e);

View File

@@ -3,12 +3,12 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
#if false
using Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter;
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.Channel;
using Microsoft.SqlTools.EditorServices.Protocol.DebugAdapter;
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Channel;
using System.Threading.Tasks;
namespace Microsoft.PowerShell.EditorServices.Protocol.Server
namespace Microsoft.SqlTools.EditorServices.Protocol.Server
{
public abstract class DebugAdapterBase : ProtocolEndpoint
{

View File

@@ -4,12 +4,12 @@
//
//using Microsoft.PowerShell.EditorServices.Extensions;
using Microsoft.PowerShell.EditorServices.Protocol.LanguageServer;
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.Channel;
using Microsoft.PowerShell.EditorServices.Session;
//using Microsoft.PowerShell.EditorServices.Utility;
//using Microsoft.SqlTools.EditorServices.Extensions;
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 Microsoft.SqlTools.EditorServices.Utility;
using System;
using System.Collections.Generic;
using System.IO;
@@ -18,9 +18,9 @@ using System.Linq;
//using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using DebugAdapterMessages = Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter;
using DebugAdapterMessages = Microsoft.SqlTools.EditorServices.Protocol.DebugAdapter;
namespace Microsoft.PowerShell.EditorServices.Protocol.Server
namespace Microsoft.SqlTools.EditorServices.Protocol.Server
{
public class LanguageServer : LanguageServerBase
{
@@ -49,7 +49,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
#if false
this.editorSession = new EditorSession();
this.editorSession.StartSession(hostDetails, profilePaths);
this.editorSession.ConsoleService.OutputWritten += this.powerShellContext_OutputWritten;
this.editorSession.ConsoleService.OutputWritten += this.SqlToolsContext_OutputWritten;
// Attach to ExtensionService events
this.editorSession.ExtensionService.CommandAdded += ExtensionService_ExtensionAdded;
@@ -206,7 +206,7 @@ protected async Task HandleInitializeRequest(
psCommand.AddArgument(helpParams);
psCommand.AddParameter("Online");
await editorSession.PowerShellContext.ExecuteCommand<object>(psCommand);
await editorSession.SqlToolsContext.ExecuteCommand<object>(psCommand);
await requestContext.SendResult(null);
}
@@ -219,7 +219,7 @@ protected async Task HandleInitializeRequest(
var script = string.Format("Install-Module -Name {0} -Scope CurrentUser", moduleName);
var executeTask =
editorSession.PowerShellContext.ExecuteScriptString(
editorSession.SqlToolsContext.ExecuteScriptString(
script,
true,
true).ConfigureAwait(false);
@@ -281,11 +281,11 @@ function __Expand-Alias {
}";
var psCommand = new PSCommand();
psCommand.AddScript(script);
await this.editorSession.PowerShellContext.ExecuteCommand<PSObject>(psCommand);
await this.editorSession.SqlToolsContext.ExecuteCommand<PSObject>(psCommand);
psCommand = new PSCommand();
psCommand.AddCommand("__Expand-Alias").AddArgument(content);
var result = await this.editorSession.PowerShellContext.ExecuteCommand<string>(psCommand);
var result = await this.editorSession.SqlToolsContext.ExecuteCommand<string>(psCommand);
await requestContext.SendResult(result.First().ToString());
}
@@ -297,7 +297,7 @@ function __Expand-Alias {
var psCommand = new PSCommand();
psCommand.AddScript("Find-Module | Select Name, Description");
var modules = await editorSession.PowerShellContext.ExecuteCommand<PSObject>(psCommand);
var modules = await editorSession.SqlToolsContext.ExecuteCommand<PSObject>(psCommand);
var moduleList = new List<PSModuleMessage>();
@@ -388,14 +388,14 @@ function __Expand-Alias {
this.currentSettings.ScriptAnalysis.SettingsPath;
this.currentSettings.Update(
configChangeParams.Settings.Powershell,
configChangeParams.Settings.SqlTools,
this.editorSession.Workspace.WorkspacePath);
if (!this.profilesLoaded &&
this.currentSettings.EnableProfileLoading &&
oldLoadProfiles != this.currentSettings.EnableProfileLoading)
{
await this.editorSession.PowerShellContext.LoadHostProfiles();
await this.editorSession.SqlToolsContext.LoadHostProfiles();
this.profilesLoaded = true;
}
@@ -570,12 +570,12 @@ function __Expand-Alias {
CommandInfo commandInfo =
await CommandHelpers.GetCommandInfo(
completionItem.Label,
this.editorSession.PowerShellContext);
this.editorSession.SqlToolsContext);
completionItem.Documentation =
await CommandHelpers.GetCommandSynopsis(
commandInfo,
this.editorSession.PowerShellContext);
this.editorSession.SqlToolsContext);
}
// Send back the updated CompletionItem
@@ -696,7 +696,7 @@ function __Expand-Alias {
symbolInfo.Add(
new MarkedString
{
Language = "PowerShell",
Language = "SqlTools",
Value = symbolDetails.DisplayString
});
@@ -853,7 +853,7 @@ function __Expand-Alias {
// is executing. This important in cases where the pipeline thread
// gets blocked by something in the script like a prompt to the user.
var executeTask =
this.editorSession.PowerShellContext.ExecuteScriptString(
this.editorSession.SqlToolsContext.ExecuteScriptString(
evaluateParams.Expression,
true,
true);
@@ -881,7 +881,7 @@ function __Expand-Alias {
#region Event Handlers
private async void powerShellContext_OutputWritten(object sender, OutputWrittenEventArgs e)
private async void SqlToolsContext_OutputWritten(object sender, OutputWrittenEventArgs e)
{
// Queue the output for writing
await this.outputDebouncer.Invoke(e);
@@ -1149,7 +1149,7 @@ function __Expand-Alias {
(completionDetails.CompletionType == CompletionType.ParameterName))
{
// Look for type encoded in the tooltip for parameters and variables.
// Display PowerShell type names in [] to be consistent with PowerShell syntax
// Display SqlTools type names in [] to be consistent with SqlTools syntax
// and now the debugger displays type names.
var matches = Regex.Matches(completionDetails.ToolTipText, @"^(\[.+\])");
if ((matches.Count > 0) && (matches[0].Groups.Count > 1))
@@ -1187,7 +1187,7 @@ function __Expand-Alias {
}
// We want a special "sort order" for parameters that is not lexicographical.
// Fortunately, PowerShell returns parameters in the preferred sort order by
// Fortunately, SqlTools returns parameters in the preferred sort order by
// default (with common params at the end). We just need to make sure the default
// order also be the lexicographical order which we do by prefixig the ListItemText
// with a leading 0's four digit index. This would not sort correctly for a list

View File

@@ -3,12 +3,12 @@
// 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 Microsoft.SqlTools.EditorServices.Protocol.LanguageServer;
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Channel;
using System.Threading.Tasks;
namespace Microsoft.PowerShell.EditorServices.Protocol.Server
namespace Microsoft.SqlTools.EditorServices.Protocol.Server
{
public abstract class LanguageServerBase : ProtocolEndpoint
{

View File

@@ -3,12 +3,12 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
#if false
using Microsoft.PowerShell.EditorServices.Extensions;
using Microsoft.PowerShell.EditorServices.Protocol.LanguageServer;
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
using Microsoft.SqlTools.EditorServices.Extensions;
using Microsoft.SqlTools.EditorServices.Protocol.LanguageServer;
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
using System.Threading.Tasks;
namespace Microsoft.PowerShell.EditorServices.Protocol.Server
namespace Microsoft.SqlTools.EditorServices.Protocol.Server
{
internal class LanguageServerEditorOperations : IEditorOperations
{

View File

@@ -4,9 +4,9 @@
//
using System.IO;
using Microsoft.PowerShell.EditorServices.Utility;
using Microsoft.SqlTools.EditorServices.Utility;
namespace Microsoft.PowerShell.EditorServices.Protocol.Server
namespace Microsoft.SqlTools.EditorServices.Protocol.Server
{
public class LanguageServerSettings
{
@@ -57,7 +57,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
if (string.IsNullOrEmpty(workspaceRootPath))
{
// The workspace root path could be an empty string
// when the user has opened a PowerShell script file
// when the user has opened a SqlTools script file
// without opening an entire folder (workspace) first.
// In this case we should just log an error and let
// the specified settings path go through even though
@@ -79,10 +79,10 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
public class LanguageServerSettingsWrapper
{
// NOTE: This property is capitalized as 'Powershell' because the
// mode name sent from the client is written as 'powershell' and
// 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 LanguageServerSettings Powershell { get; set; }
public LanguageServerSettings SqlTools { get; set; }
}
}

View File

@@ -3,12 +3,12 @@
// 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.Utility;
using Microsoft.SqlTools.EditorServices.Protocol.DebugAdapter;
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
using Microsoft.SqlTools.EditorServices.Utility;
using System.Threading.Tasks;
namespace Microsoft.PowerShell.EditorServices.Protocol.Server
namespace Microsoft.SqlTools.EditorServices.Protocol.Server
{
/// <summary>
/// Throttles output written via OutputEvents by batching all output

View File

@@ -5,13 +5,13 @@
#if false
using System;
using Microsoft.PowerShell.EditorServices.Console;
using Microsoft.PowerShell.EditorServices.Protocol.Messages;
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
using Microsoft.PowerShell.EditorServices.Utility;
using Microsoft.SqlTools.EditorServices.Console;
using Microsoft.SqlTools.EditorServices.Protocol.Messages;
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
using Microsoft.SqlTools.EditorServices.Utility;
using System.Threading.Tasks;
namespace Microsoft.PowerShell.EditorServices.Protocol.Server
namespace Microsoft.SqlTools.EditorServices.Protocol.Server
{
internal class ProtocolPromptHandlerContext : IPromptHandlerContext
{