diff --git a/PowerShellEditorServices.build.ps1 b/PowerShellEditorServices.build.ps1 index 5b99a9fb7..861f5d368 100644 --- a/PowerShellEditorServices.build.ps1 +++ b/PowerShellEditorServices.build.ps1 @@ -18,7 +18,7 @@ if ($PSVersionTable.PSEdition -ne "Core") { Add-Type -Assembly System.IO.Compression.FileSystem } -task SetupDotNet -Before Restore, Clean, Build, Test, TestPowerShellApi, PackageNuGet { +task SetupDotNet -Before Restore, Clean, Build, TestHost, TestServer, TestProtocol, TestPowerShellApi, PackageNuGet { $requiredSdkVersion = "1.0.0" @@ -157,9 +157,17 @@ function UploadTestLogs { } } -task Test -If { !$script:IsUnix } { +task Test TestServer,TestProtocol,TestHost + +task TestServer -If { !$script:IsUnix } { exec { & $script:dotnetExe test -c $Configuration -f net452 .\test\PowerShellEditorServices.Test\PowerShellEditorServices.Test.csproj } +} + +task TestProtocol -If { !$script:IsUnix} { exec { & $script:dotnetExe test -c $Configuration -f net452 .\test\PowerShellEditorServices.Test.Protocol\PowerShellEditorServices.Test.Protocol.csproj } +} + +task TestHost -If { !$script:IsUnix} { exec { & $script:dotnetExe test -c $Configuration -f net452 .\test\PowerShellEditorServices.Test.Host\PowerShellEditorServices.Test.Host.csproj } } diff --git a/src/PowerShellEditorServices.Protocol/Client/LanguageClientBase.cs b/src/PowerShellEditorServices.Protocol/Client/LanguageClientBase.cs index 665383d0d..4cbd62aa0 100644 --- a/src/PowerShellEditorServices.Protocol/Client/LanguageClientBase.cs +++ b/src/PowerShellEditorServices.Protocol/Client/LanguageClientBase.cs @@ -34,7 +34,7 @@ protected override Task OnStart() protected override async Task OnStop() { // First, notify the language server that we're stopping - var response = await this.SendRequest(ShutdownRequest.Type, new object()); + var response = await this.SendRequest(ShutdownRequest.Type); await this.SendEvent(ExitNotification.Type, new object()); } diff --git a/src/PowerShellEditorServices.Protocol/Client/LanguageServiceClient.cs b/src/PowerShellEditorServices.Protocol/Client/LanguageServiceClient.cs index 67d769ed3..63fde920f 100644 --- a/src/PowerShellEditorServices.Protocol/Client/LanguageServiceClient.cs +++ b/src/PowerShellEditorServices.Protocol/Client/LanguageServiceClient.cs @@ -15,7 +15,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Client { public class LanguageServiceClient : LanguageClientBase { - private Dictionary cachedDiagnostics = + private Dictionary cachedDiagnostics = new Dictionary(); public LanguageServiceClient(ChannelBase clientChannel) @@ -34,15 +34,15 @@ protected override Task Initialize() protected override Task OnConnect() { // Send the 'initialize' request and wait for the response - var initializeRequest = new InitializeRequest + var initializeParams = new InitializeParams { RootPath = "", Capabilities = new ClientCapabilities() }; return this.SendRequest( - InitializeRequest.Type, - initializeRequest); + InitializeRequest.Type, + initializeParams); } #region Events @@ -62,7 +62,7 @@ protected void OnDiagnosticsReceived(string filePath) #region Private Methods private Task HandlePublishDiagnosticsEvent( - PublishDiagnosticsNotification diagnostics, + PublishDiagnosticsNotification diagnostics, EventContext eventContext) { string normalizedPath = diagnostics.Uri.ToLower(); @@ -79,7 +79,7 @@ private Task HandlePublishDiagnosticsEvent( private static ScriptFileMarker GetMarkerFromDiagnostic(Diagnostic diagnostic) { - DiagnosticSeverity severity = + DiagnosticSeverity severity = diagnostic.Severity.GetValueOrDefault( DiagnosticSeverity.Error); diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs index 4699a4315..e9734e002 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class AttachRequest { public static readonly - RequestType Type = - RequestType.Create("attach"); + RequestType Type = + RequestType.Create("attach"); } public class AttachRequestArguments diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/ConfigurationDoneRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/ConfigurationDoneRequest.cs index ef5e0c8ef..11cbc4ded 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/ConfigurationDoneRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/ConfigurationDoneRequest.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class ConfigurationDoneRequest { public static readonly - RequestType Type = - RequestType.Create("configurationDone"); + RequestType Type = + RequestType.Create("configurationDone"); } } diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/ContinueRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/ContinueRequest.cs index 5ee5b2ec9..3f9dbc59c 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/ContinueRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/ContinueRequest.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class ContinueRequest { public static readonly - RequestType Type = - RequestType.Create("continue"); + RequestType Type = + RequestType.Create("continue"); } } diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/ContinuedEvent.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/ContinuedEvent.cs index 8e307500a..af442750f 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/ContinuedEvent.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/ContinuedEvent.cs @@ -3,6 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // +using System; using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter @@ -10,8 +11,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class ContinuedEvent { public static readonly - EventType Type = - EventType.Create("continued"); + NotificationType Type = + NotificationType.Create("continued"); public int ThreadId { get; set; } diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/DisconnectRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/DisconnectRequest.cs index 7f7036b0c..2235206cd 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/DisconnectRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/DisconnectRequest.cs @@ -7,11 +7,11 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter { - public class DisconnectRequest + public class DisconnectRequest { public static readonly - RequestType Type = - RequestType.Create("disconnect"); + RequestType Type = + RequestType.Create("disconnect"); } } diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/EvaluateRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/EvaluateRequest.cs index b079f59ae..d45e7d44a 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/EvaluateRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/EvaluateRequest.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class EvaluateRequest { public static readonly - RequestType Type = - RequestType.Create("evaluate"); + RequestType Type = + RequestType.Create("evaluate"); } public class EvaluateRequestArguments diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/ExitedEvent.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/ExitedEvent.cs index 8a2189736..9f1a0d6ce 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/ExitedEvent.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/ExitedEvent.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class ExitedEvent { public static readonly - EventType Type = - EventType.Create("exited"); + NotificationType Type = + NotificationType.Create("exited"); } public class ExitedEventBody diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/InitializeRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/InitializeRequest.cs index 52a8869d3..7904759d9 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/InitializeRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/InitializeRequest.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class InitializeRequest { public static readonly - RequestType Type = - RequestType.Create("initialize"); + RequestType Type = + RequestType.Create("initialize"); } public class InitializeRequestArguments diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/InitializedEvent.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/InitializedEvent.cs index 68ed66807..7253b7b30 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/InitializedEvent.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/InitializedEvent.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class InitializedEvent { public static readonly - EventType Type = - EventType.Create("initialized"); + NotificationType Type = + NotificationType.Create("initialized"); } } diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/LaunchRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/LaunchRequest.cs index b81e56f8d..d0a2435ff 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/LaunchRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/LaunchRequest.cs @@ -12,8 +12,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class LaunchRequest { public static readonly - RequestType Type = - RequestType.Create("launch"); + RequestType Type = + RequestType.Create("launch"); } public class LaunchRequestArguments @@ -36,7 +36,7 @@ public class LaunchRequestArguments public bool NoDebug { get; set; } /// - /// Gets or sets a boolean value that determines whether to automatically stop + /// Gets or sets a boolean value that determines whether to automatically stop /// target after launch. If not specified, target does not stop. /// public bool StopOnEntry { get; set; } @@ -53,7 +53,7 @@ public class LaunchRequestArguments public string Cwd { get; set; } /// - /// Gets or sets the absolute path to the runtime executable to be used. + /// Gets or sets the absolute path to the runtime executable to be used. /// Default is the runtime executable on the PATH. /// public string RuntimeExecutable { get; set; } @@ -64,7 +64,7 @@ public class LaunchRequestArguments public string[] RuntimeArgs { get; set; } /// - /// Gets or sets optional environment variables to pass to the debuggee. The string valued + /// Gets or sets optional environment variables to pass to the debuggee. The string valued /// properties of the 'environmentVariables' are used as key/value pairs. /// public Dictionary Env { get; set; } diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/NextRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/NextRequest.cs index 5cb2e6acd..1a254b96f 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/NextRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/NextRequest.cs @@ -13,8 +13,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class NextRequest { public static readonly - RequestType Type = - RequestType.Create("next"); + RequestType Type = + RequestType.Create("next"); } } diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/OutputEvent.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/OutputEvent.cs index a9cfee8c3..0044855c4 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/OutputEvent.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/OutputEvent.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class OutputEvent { public static readonly - EventType Type = - EventType.Create("output"); + NotificationType Type = + NotificationType.Create("output"); } public class OutputEventBody diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/PauseRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/PauseRequest.cs index 86ceee4f4..6fa67c584 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/PauseRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/PauseRequest.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class PauseRequest { public static readonly - RequestType Type = - RequestType.Create("pause"); + RequestType Type = + RequestType.Create("pause"); } } diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/ScopesRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/ScopesRequest.cs index 044f5bf73..4905ffdfe 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/ScopesRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/ScopesRequest.cs @@ -11,8 +11,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class ScopesRequest { public static readonly - RequestType Type = - RequestType.Create("scopes"); + RequestType Type = + RequestType.Create("scopes"); } [DebuggerDisplay("FrameId = {FrameId}")] diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/SetBreakpointsRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/SetBreakpointsRequest.cs index 5b0f88bf2..82d41ac53 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/SetBreakpointsRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/SetBreakpointsRequest.cs @@ -16,8 +16,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class SetBreakpointsRequest { public static readonly - RequestType Type = - RequestType.Create("setBreakpoints"); + RequestType Type = + RequestType.Create("setBreakpoints"); } public class SetBreakpointsRequestArguments diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/SetExceptionBreakpointsRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/SetExceptionBreakpointsRequest.cs index a586f27bf..6a7313324 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/SetExceptionBreakpointsRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/SetExceptionBreakpointsRequest.cs @@ -14,8 +14,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class SetExceptionBreakpointsRequest { public static readonly - RequestType Type = - RequestType.Create("setExceptionBreakpoints"); + RequestType Type = + RequestType.Create("setExceptionBreakpoints"); } /// diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/SetFunctionBreakpointsRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/SetFunctionBreakpointsRequest.cs index 73b75f82e..6fb951553 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/SetFunctionBreakpointsRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/SetFunctionBreakpointsRequest.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class SetFunctionBreakpointsRequest { public static readonly - RequestType Type = - RequestType.Create("setFunctionBreakpoints"); + RequestType Type = + RequestType.Create("setFunctionBreakpoints"); } public class SetFunctionBreakpointsRequestArguments diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/SetVariableRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/SetVariableRequest.cs index 333327454..47e41cb36 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/SetVariableRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/SetVariableRequest.cs @@ -15,8 +15,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class SetVariableRequest { public static readonly - RequestType Type = - RequestType.Create("setVariable"); + RequestType Type = + RequestType.Create("setVariable"); } [DebuggerDisplay("VariablesReference = {VariablesReference}")] diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/SourceRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/SourceRequest.cs index 9d185af23..48a2b0a17 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/SourceRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/SourceRequest.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class SourceRequest { public static readonly - RequestType Type = - RequestType.Create("source"); + RequestType Type = + RequestType.Create("source"); } public class SourceRequestArguments diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/StackTraceRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/StackTraceRequest.cs index 06929ba45..4188dcab6 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/StackTraceRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/StackTraceRequest.cs @@ -11,8 +11,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class StackTraceRequest { public static readonly - RequestType Type = - RequestType.Create("stackTrace"); + RequestType Type = + RequestType.Create("stackTrace"); } [DebuggerDisplay("ThreadId = {ThreadId}, Levels = {Levels}")] diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/StartedEvent.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/StartedEvent.cs index f08f504b4..5b32d4a84 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/StartedEvent.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/StartedEvent.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class StartedEvent { public static readonly - EventType Type = - EventType.Create("started"); + NotificationType Type = + NotificationType.Create("started"); } } diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/StepInRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/StepInRequest.cs index cfd8f7648..ec825ebbd 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/StepInRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/StepInRequest.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class StepInRequest { public static readonly - RequestType Type = - RequestType.Create("stepIn"); + RequestType Type = + RequestType.Create("stepIn"); } } diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/StepOutRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/StepOutRequest.cs index 5b86f3f7c..be0a31807 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/StepOutRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/StepOutRequest.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class StepOutRequest { public static readonly - RequestType Type = - RequestType.Create("stepOut"); + RequestType Type = + RequestType.Create("stepOut"); } } diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/StoppedEvent.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/StoppedEvent.cs index 8d88a1e5a..a3c2a7921 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/StoppedEvent.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/StoppedEvent.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class StoppedEvent { public static readonly - EventType Type = - EventType.Create("stopped"); + NotificationType Type = + NotificationType.Create("stopped"); } public class StoppedEventBody @@ -26,7 +26,7 @@ public class StoppedEventBody /// public int? ThreadId { get; set; } - public Source Source { get; set; } + public Source Source { get; set; } /// /// Gets or sets additional information such as an error message. diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/TerminatedEvent.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/TerminatedEvent.cs index 39202676d..514d0bcae 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/TerminatedEvent.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/TerminatedEvent.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class TerminatedEvent { public static readonly - EventType Type = - EventType.Create("terminated"); + NotificationType Type = + NotificationType.Create("terminated"); public bool Restart { get; set; } } diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/ThreadsRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/ThreadsRequest.cs index e72fcc969..24432d671 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/ThreadsRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/ThreadsRequest.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class ThreadsRequest { public static readonly - RequestType Type = - RequestType.Create("threads"); + RequestType Type = + RequestType.Create("threads"); } public class ThreadsResponseBody diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/VariablesRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/VariablesRequest.cs index 40dbaabb9..f387c500f 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/VariablesRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/VariablesRequest.cs @@ -11,8 +11,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter public class VariablesRequest { public static readonly - RequestType Type = - RequestType.Create("variables"); + RequestType Type = + RequestType.Create("variables"); } [DebuggerDisplay("VariablesReference = {VariablesReference}")] diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/ClientCapabilities.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/ClientCapabilities.cs index 2bebdeb65..f66982c43 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/ClientCapabilities.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/ClientCapabilities.cs @@ -18,6 +18,9 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer /// public class ClientCapabilities { + public WorkspaceClientCapabilities Workspace { get; set; } + public TextDocumentClientCapabilities TextDocument { get; set; } + public object Experimental { get; set; } } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/CodeAction.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/CodeAction.cs index deb0cb17f..a382d8dcf 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/CodeAction.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/CodeAction.cs @@ -6,13 +6,28 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class CodeActionRequest { public static readonly - RequestType Type = - RequestType.Create("textDocument/codeAction"); + RequestType Type = + RequestType.Create("textDocument/codeAction"); + } + /// + /// Parameters for CodeActionRequest. + /// + public class CodeActionParams + { + /// + /// The document in which the command was invoked. + /// public TextDocumentIdentifier TextDocument { get; set; } + /// + /// The range for which the command was invoked. + /// public Range Range { get; set; } + /// + /// Context carrying additional information. + /// public CodeActionContext Context { get; set; } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/Completion.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/Completion.cs index 72d4a6ded..38fb9e431 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/Completion.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/Completion.cs @@ -11,38 +11,51 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class CompletionRequest { public static readonly - RequestType Type = - RequestType.Create("textDocument/completion"); + RequestType Type = + RequestType.Create("textDocument/completion"); } public class CompletionResolveRequest { public static readonly - RequestType Type = - RequestType.Create("completionItem/resolve"); + RequestType Type = + RequestType.Create("completionItem/resolve"); + } + + /// + /// Completion registration options. + /// + public class CompletionRegistrationOptions : TextDocumentRegistrationOptions + { + // We duplicate the properties of completionOptions class here because + // we cannot derive from two classes. One way to get around this situation + // is to use define CompletionOptions as an interface instead of a class. + public bool? ResolveProvider { get; set; } + + public string[] TriggerCharacters { get; set; } } public enum CompletionItemKind { - Text = 1, - Method = 2, - Function = 3, - Constructor = 4, - Field = 5, - Variable = 6, - Class = 7, - Interface = 8, - Module = 9, - Property = 10, - Unit = 11, - Value = 12, - Enum = 13, - Keyword = 14, - Snippet = 15, - Color = 16, - File = 17, - Reference = 18, - Folder = 19 + Text = 1, + Method = 2, + Function = 3, + Constructor = 4, + Field = 5, + Variable = 6, + Class = 7, + Interface = 8, + Module = 9, + Property = 10, + Unit = 11, + Value = 12, + Enum = 13, + Keyword = 14, + Snippet = 15, + Color = 16, + File = 17, + Reference = 18, + Folder = 19 } [DebuggerDisplay("NewText = {NewText}, Range = {Range.Start.Line}:{Range.Start.Character} - {Range.End.Line}:{Range.End.Character}")] @@ -73,8 +86,16 @@ public class CompletionItem public string InsertText { get; set; } + public Range Range { get; set; } + + public string[] CommitCharacters { get; set; } + public TextEdit TextEdit { get; set; } + public TextEdit[] AdditionalTextEdits { get; set; } + + public CommandType Command { get; set; } + /// /// Gets or sets a custom data field that allows the server to mark /// each completion item with an identifier that will help correlate @@ -83,5 +104,33 @@ public class CompletionItem /// public object Data { get; set; } } + + /// + /// Represents a reference to a command. Provides a title which will be used to + /// represent a command in the UI and, optionally, an array of arguments which + /// will be passed to the command handler function when invoked. + /// + /// The name of the corresponding type in vscode-languageserver-node is Command + /// but since .net does not allow a property name (Command) and its enclosing + /// type name to be the same we change its name to CommandType. + /// + public class CommandType + { + /// + /// Title of the command. + /// + /// + public string Title { get; set; } + + /// + /// The identifier of the actual command handler. + /// + public string Command { get; set; } + + /// + /// Arguments that the command handler should be invoked with. + /// + public object[] Arguments { get; set; } + } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/Configuration.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/Configuration.cs index d4f57781d..a4228ee19 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/Configuration.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/Configuration.cs @@ -7,11 +7,11 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { - public class DidChangeConfigurationNotification + public class DidChangeConfigurationNotification { public static readonly - EventType> Type = - EventType>.Create("workspace/didChangeConfiguration"); + NotificationType, object> Type = + NotificationType, object>.Create("workspace/didChangeConfiguration"); } public class DidChangeConfigurationParams diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/Definition.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/Definition.cs index 37241dd63..336259ba9 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/Definition.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/Definition.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class DefinitionRequest { public static readonly - RequestType Type = - RequestType.Create("textDocument/definition"); + RequestType Type = + RequestType.Create("textDocument/definition"); } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/Diagnostics.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/Diagnostics.cs index 7aa99a69e..e5e46d45f 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/Diagnostics.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/Diagnostics.cs @@ -15,8 +15,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class PublishDiagnosticsNotification { public static readonly - EventType Type = - EventType.Create("textDocument/publishDiagnostics"); + NotificationType Type = + NotificationType.Create("textDocument/publishDiagnostics"); /// /// Gets or sets the URI for which diagnostic information is reported. @@ -29,7 +29,7 @@ public static readonly public Diagnostic[] Diagnostics { get; set; } } - public enum DiagnosticSeverity + public enum DiagnosticSeverity { /// /// Indicates that the diagnostic represents an error. diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/DocumentHighlight.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/DocumentHighlight.cs index c169acc44..cf8196f18 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/DocumentHighlight.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/DocumentHighlight.cs @@ -7,14 +7,14 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { - public enum DocumentHighlightKind + public enum DocumentHighlightKind { Text = 1, Read = 2, Write = 3 } - public class DocumentHighlight + public class DocumentHighlight { public Range Range { get; set; } @@ -24,8 +24,8 @@ public class DocumentHighlight public class DocumentHighlightRequest { public static readonly - RequestType Type = - RequestType.Create("textDocument/documentHighlight"); + RequestType Type = + RequestType.Create("textDocument/documentHighlight"); } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/DynamicRegistrationCapability.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/DynamicRegistrationCapability.cs new file mode 100644 index 000000000..64d2c35ce --- /dev/null +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/DynamicRegistrationCapability.cs @@ -0,0 +1,13 @@ +namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer +{ + /// + /// Class to represent if a capability supports dynamic registration. + /// + public class DynamicRegistrationCapability + { + /// + /// Whether the capability supports dynamic registration. + /// + public bool? DynamicRegistration { get; set; } + } +} diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs index ee39820bd..04d15c0e9 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class ExtensionCommandAddedNotification { public static readonly - EventType Type = - EventType.Create("powerShell/extensionCommandAdded"); + NotificationType Type = + NotificationType.Create("powerShell/extensionCommandAdded"); public string Name { get; set; } @@ -21,8 +21,8 @@ public static readonly public class ExtensionCommandUpdatedNotification { public static readonly - EventType Type = - EventType.Create("powerShell/extensionCommandUpdated"); + NotificationType Type = + NotificationType.Create("powerShell/extensionCommandUpdated"); public string Name { get; set; } } @@ -30,8 +30,8 @@ public static readonly public class ExtensionCommandRemovedNotification { public static readonly - EventType Type = - EventType.Create("powerShell/extensionCommandRemoved"); + NotificationType Type = + NotificationType.Create("powerShell/extensionCommandRemoved"); public string Name { get; set; } } @@ -49,8 +49,8 @@ public class ClientEditorContext public class InvokeExtensionCommandRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/invokeExtensionCommand"); + RequestType Type = + RequestType.Create("powerShell/invokeExtensionCommand"); public string Name { get; set; } @@ -60,8 +60,8 @@ public static readonly public class GetEditorContextRequest { public static readonly - RequestType Type = - RequestType.Create("editor/getEditorContext"); + RequestType Type = + RequestType.Create("editor/getEditorContext"); } public enum EditorCommandResponse @@ -73,8 +73,8 @@ public enum EditorCommandResponse public class InsertTextRequest { public static readonly - RequestType Type = - RequestType.Create("editor/insertText"); + RequestType Type = + RequestType.Create("editor/insertText"); public string FilePath { get; set; } @@ -86,8 +86,8 @@ public static readonly public class SetSelectionRequest { public static readonly - RequestType Type = - RequestType.Create("editor/setSelection"); + RequestType Type = + RequestType.Create("editor/setSelection"); public Range SelectionRange { get; set; } } @@ -95,8 +95,8 @@ public static readonly public class SetCursorPositionRequest { public static readonly - RequestType Type = - RequestType.Create("editor/setCursorPosition"); + RequestType Type = + RequestType.Create("editor/setCursorPosition"); public Position CursorPosition { get; set; } } @@ -104,43 +104,43 @@ public static readonly public class OpenFileRequest { public static readonly - RequestType Type = - RequestType.Create("editor/openFile"); + RequestType Type = + RequestType.Create("editor/openFile"); } public class CloseFileRequest { public static readonly - RequestType Type = - RequestType.Create("editor/closeFile"); + RequestType Type = + RequestType.Create("editor/closeFile"); } public class ShowInformationMessageRequest { public static readonly - RequestType Type = - RequestType.Create("editor/showInformationMessage"); + RequestType Type = + RequestType.Create("editor/showInformationMessage"); } public class ShowWarningMessageRequest { public static readonly - RequestType Type = - RequestType.Create("editor/showWarningMessage"); + RequestType Type = + RequestType.Create("editor/showWarningMessage"); } public class ShowErrorMessageRequest { public static readonly - RequestType Type = - RequestType.Create("editor/showErrorMessage"); + RequestType Type = + RequestType.Create("editor/showErrorMessage"); } public class SetStatusBarMessageRequest { public static readonly - RequestType Type = - RequestType.Create("editor/setStatusBarMessage"); + RequestType Type = + RequestType.Create("editor/setStatusBarMessage"); } public class StatusBarMessageDetails diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/ExpandAliasRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/ExpandAliasRequest.cs index cd79c92f2..d5c2a9bc9 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/ExpandAliasRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/ExpandAliasRequest.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class ExpandAliasRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/expandAlias"); + RequestType Type = + RequestType.Create("powerShell/expandAlias"); } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/FindModuleRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/FindModuleRequest.cs index 12ac6cf96..fe14fdb65 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/FindModuleRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/FindModuleRequest.cs @@ -11,8 +11,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class FindModuleRequest { public static readonly - RequestType, object> Type = - RequestType, object>.Create("powerShell/findModule"); + RequestType, object, object, object> Type = + RequestType, object, object, object>.Create("powerShell/findModule"); } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/GetPSHostProcessesRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/GetPSHostProcessesRequest.cs index 59d93ac6c..3c33a61d3 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/GetPSHostProcessesRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/GetPSHostProcessesRequest.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class GetPSHostProcessesRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/getPSHostProcesses"); + RequestType Type = + RequestType.Create("powerShell/getPSHostProcesses"); } public class GetPSHostProcessesResponse diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/GetPSSARulesRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/GetPSSARulesRequest.cs index 617e89c6e..2199558c5 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/GetPSSARulesRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/GetPSSARulesRequest.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer class GetPSSARulesRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/getPSSARules"); + RequestType Type = + RequestType.Create("powerShell/getPSSARules"); } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/Hover.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/Hover.cs index 2af60e515..5a036bd7b 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/Hover.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/Hover.cs @@ -29,8 +29,8 @@ public class Hover public class HoverRequest { public static readonly - RequestType Type = - RequestType.Create("textDocument/hover"); + RequestType Type = + RequestType.Create("textDocument/hover"); } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/Initialize.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/Initialize.cs index 40a9d1a23..be73b74a0 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/Initialize.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/Initialize.cs @@ -10,20 +10,53 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class InitializeRequest { public static readonly - RequestType Type = - RequestType.Create("initialize"); + RequestType Type = + RequestType.Create("initialize"); + } + public enum TraceType { + Off, + Messages, + Verbose + } + + public class InitializeParams { /// - /// Gets or sets the root path of the editor's open workspace. - /// If null it is assumed that a file was opened without having - /// a workspace open. + /// The process Id of the parent process that started the server + /// + public int ProcessId { get; set; } + + /// + /// The root path of the workspace. It is null if no folder is open. + /// + /// This property has been deprecated in favor of RootUri. /// public string RootPath { get; set; } /// - /// Gets or sets the capabilities provided by the client (editor). + /// The root uri of the workspace. It is null if not folder is open. If both + /// `RootUri` and `RootPath` are non-null, `RootUri` should be used. + /// + public string RootUri { get; set; } + + /// + /// The capabilities provided by the client. /// public ClientCapabilities Capabilities { get; set; } + + /// + /// User provided initialization options. + /// + /// This is defined as `any` type on the client side. + /// + public object InitializeOptions { get; set; } + + // TODO We need to verify if the deserializer will map the type defined in the client + // to an enum. + /// + /// The initial trace setting. If omitted trace is disabled. + /// + public TraceType Trace { get; set; } = TraceType.Off; } public class InitializeResult diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/InstallModuleRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/InstallModuleRequest.cs index 2be47ce90..096d0e461 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/InstallModuleRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/InstallModuleRequest.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer class InstallModuleRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/installModule"); + RequestType Type = + RequestType.Create("powerShell/installModule"); } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/PowerShellVersionRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/PowerShellVersionRequest.cs index 87a7ac20e..8f16b0abb 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/PowerShellVersionRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/PowerShellVersionRequest.cs @@ -11,8 +11,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class PowerShellVersionRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/getVersion"); + RequestType Type = + RequestType.Create("powerShell/getVersion"); } public class PowerShellVersion diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/ProjectTemplate.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/ProjectTemplate.cs index 74878cd43..1b7441b28 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/ProjectTemplate.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/ProjectTemplate.cs @@ -11,8 +11,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class NewProjectFromTemplateRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/newProjectFromTemplate"); + RequestType Type = + RequestType.Create("powerShell/newProjectFromTemplate"); public string DestinationPath { get; set; } @@ -27,8 +27,8 @@ public class NewProjectFromTemplateResponse public class GetProjectTemplatesRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/getProjectTemplates"); + RequestType Type = + RequestType.Create("powerShell/getProjectTemplates"); public bool IncludeInstalledModules { get; set; } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/References.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/References.cs index a55ebebf9..992464140 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/References.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/References.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class ReferencesRequest { public static readonly - RequestType Type = - RequestType.Create("textDocument/references"); + RequestType Type = + RequestType.Create("textDocument/references"); } public class ReferencesParams : TextDocumentPosition diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/RunspaceChanged.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/RunspaceChanged.cs index 77a0148dc..3f2448097 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/RunspaceChanged.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/RunspaceChanged.cs @@ -11,8 +11,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class RunspaceChangedEvent { public static readonly - EventType Type = - EventType.Create("powerShell/runspaceChanged"); + NotificationType Type = + NotificationType.Create("powerShell/runspaceChanged"); } public class RunspaceDetails diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/ScriptFileMarkersRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/ScriptFileMarkersRequest.cs index 868f53ead..5394ddd4c 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/ScriptFileMarkersRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/ScriptFileMarkersRequest.cs @@ -15,8 +15,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer class ScriptFileMarkersRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/getScriptFileMarkers"); + RequestType Type = + RequestType.Create("powerShell/getScriptFileMarkers"); } /// diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/ScriptRegionRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/ScriptRegionRequest.cs index 82791ec54..79b36161e 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/ScriptRegionRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/ScriptRegionRequest.cs @@ -13,8 +13,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer class ScriptRegionRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/getScriptRegion"); + RequestType Type = + RequestType.Create("powerShell/getScriptRegion"); } /// diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/ServerCapabilities.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/ServerCapabilities.cs index aeebb411d..26fec4ae1 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/ServerCapabilities.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/ServerCapabilities.cs @@ -26,6 +26,60 @@ public class ServerCapabilities public bool? WorkspaceSymbolProvider { get; set; } public bool? CodeActionProvider { get; set; } + + public bool? CodeLensProvider { get; set; } + + public bool? DocumentFormattingProvider { get; set; } + + public bool? DocumentRangeFormattingProvider { get; set; } + + public DocumentOnTypeFormattingOptions DocumentOnTypeFormattingProvider { get; set; } + + public bool? RenameProvider { get; set; } + + public DocumentLinkOptions DocumentLinkProvider { get; set; } + + public ExecuteCommandOptions ExecuteCommandProvider { get; set; } + + public object Experimental { get; set; } + } + + /// + /// Execute command options. + /// + public class ExecuteCommandOptions + { + /// + /// The commands to be executed on the server. + /// + public string[] Commands { get; set; } + } + + /// + /// Document link options. + /// + public class DocumentLinkOptions + { + /// + /// Document links have a resolve provider. + /// + public bool? ResolveProvider { get; set; } + } + + /// + /// Options that the server provides for OnTypeFormatting request. + /// + public class DocumentOnTypeFormattingOptions + { + /// + /// A character on which formatting should be triggered. + /// + public string FirstTriggerCharacter { get; set; } + + /// + /// More trigger characters. + /// + public string[] MoreTriggerCharacters { get; set; } } /// diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/SetPSSARulesRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/SetPSSARulesRequest.cs index 49723f708..e3298cbd8 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/SetPSSARulesRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/SetPSSARulesRequest.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer class SetPSSARulesRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/setPSSARules"); + RequestType Type = + RequestType.Create("powerShell/setPSSARules"); } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/ShowOnlineHelpRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/ShowOnlineHelpRequest.cs index 49c571faf..1e65df93d 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/ShowOnlineHelpRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/ShowOnlineHelpRequest.cs @@ -9,8 +9,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { public class ShowOnlineHelpRequest { - public static readonly - RequestType Type = - RequestType.Create("powerShell/showOnlineHelp"); + public static readonly + RequestType Type = + RequestType.Create("powerShell/showOnlineHelp"); } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/Shutdown.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/Shutdown.cs index 519719015..f5fffce1c 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/Shutdown.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/Shutdown.cs @@ -14,8 +14,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class ShutdownRequest { public static readonly - RequestType Type = - RequestType.Create("shutdown"); + RequestType0 Type = + RequestType0.Create("shutdown"); } /// @@ -25,8 +25,8 @@ public static readonly public class ExitNotification { public static readonly - EventType Type = - EventType.Create("exit"); + NotificationType Type = + NotificationType.Create("exit"); } } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/SignatureHelp.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/SignatureHelp.cs index 6387461dc..e24fa6358 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/SignatureHelp.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/SignatureHelp.cs @@ -10,8 +10,16 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer public class SignatureHelpRequest { public static readonly - RequestType Type = - RequestType.Create("textDocument/signatureHelp"); + RequestType Type = + RequestType.Create("textDocument/signatureHelp"); + } + + public class SignatureHelpRegistrationOptions : TextDocumentRegistrationOptions + { + // We duplicate the properties of SignatureHelpOptions class here because + // we cannot derive from two classes. One way to get around this situation + // is to use define SignatureHelpOptions as an interface instead of a class. + public string[] TriggerCharacters { get; set; } } public class ParameterInformation diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/TextDocument.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/TextDocument.cs index 92d516817..8920ef1c4 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/TextDocument.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/TextDocument.cs @@ -8,6 +8,39 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { + + /// + /// An item to transfer a text document from the client to the server + /// + [DebuggerDisplay("TextDocumentItem = {Uri}:{LanguageId}:{Version}:{Text}")] + public class TextDocumentItem + { + /// + /// Gets or sets the URI which identifies the path of the + /// text document. + /// + public string Uri { get; set; } + + /// + /// The text document's language identifier. + /// + /// + public string LanguageId { get; set; } + + /// + /// The version number of this document, which will strictly increase after each change, including + /// undo/redo. + /// + /// + public int Version { get; set; } + + /// + /// The content of the opened text document. + /// + /// + public string Text { get; set; } + } + /// /// Defines a base parameter class for identifying a text document. /// @@ -21,6 +54,17 @@ public class TextDocumentIdentifier public string Uri { get; set; } } + /// + /// An identifier to denote a specific version of a text document. + /// + public class VersionedTextDocumentIdentifier : TextDocumentIdentifier + { + /// + /// The version number of this document. + /// + public int Version { get; set; } + } + /// /// Defines a position in a text document. /// @@ -33,46 +77,166 @@ public class TextDocumentPosition : TextDocumentIdentifier public Position Position { get; set; } } - public class DidOpenTextDocumentNotification : TextDocumentIdentifier + /// + /// A parameter literal used in requests to pass a text document and a position inside that document. + /// + public class TextDocumentPositionParams + { + /// + /// The text document. + /// + /// + public TextDocumentIdentifier TextDocument { get; set; } + + /// + /// The position inside the text document. + /// + /// + public Position Position { get; set; } + } + + public class DidOpenTextDocumentNotification { public static readonly - EventType Type = - EventType.Create("textDocument/didOpen"); + NotificationType Type = + NotificationType.Create("textDocument/didOpen"); + } + /// + /// The parameters sent in an open text document notification + /// + public class DidOpenTextDocumentParams + { /// - /// Gets or sets the full content of the opened document. + /// The document that was opened. /// - public string Text { get; set; } + public TextDocumentItem TextDocument { get; set; } + } + + /// + /// General text document registration options. + /// + public class TextDocumentRegistrationOptions { + /// + /// A document selector to identify the scope of the registration. If set to null the document + /// selector provided on the client side will be used. + /// + public DocumentFilter[] DocumentSelector { get; set; } + } + + /// + /// A document filter denotes a document by different properties like the language, the scheme + /// of its resource, or a glob-pattern that is applied to the path. + /// + public class DocumentFilter + { + /// + /// A language id, like `powershell` + /// + public string Language { get; set; } + + /// + /// A Uri, like `file` or `untitled` + /// + public string Scheme { get; set; } + + /// + /// A glob pattern, like `*.{ps1,psd1}` + /// + public string Pattern { get; set; } } public class DidCloseTextDocumentNotification { public static readonly - EventType Type = - EventType.Create("textDocument/didClose"); + NotificationType Type = + NotificationType.Create("textDocument/didClose"); + } + + /// + /// The parameters sent in a close text document notification. + /// + public class DidCloseTextDocumentParams + { + /// + /// The document that was closed. + /// + public TextDocumentIdentifier TextDocument { get; set; } } public class DidSaveTextDocumentNotification { public static readonly - EventType Type = - EventType.Create("textDocument/didSave"); + NotificationType Type = + NotificationType.Create("textDocument/didSave"); + } + + /// + /// Save options. + /// + public class SaveOptions { + /// + /// The client is supposed to include the content on save. + /// + public bool? IncludeText { get; set; } } + public class TextDocumentSaveRegistrationOptions : TextDocumentRegistrationOptions + { + // We cannot inherit from two base classes (SaveOptions and TextDocumentRegistrationOptions) + // simultaneously, hence we repeat this IncludeText flag here. + /// + /// The client is supposed to include the content on save. + /// + public bool? IncludeText { get; set; } + } + + /// + /// The parameters sent in a save text document notification. + /// public class DidSaveTextDocumentParams { - public TextDocumentIdentifier TextDocument { get; set; } + /// + /// The document that was saved. + /// + public VersionedTextDocumentIdentifier TextDocument { get; set; } + + /// + /// Optional content when saved. Depends on the includeText value when the save notification was + /// included. + /// + public string Text { get; set; } } public class DidChangeTextDocumentNotification { public static readonly - EventType Type = - EventType.Create("textDocument/didChange"); + NotificationType Type = + NotificationType.Create("textDocument/didChange"); } - public class DidChangeTextDocumentParams : TextDocumentIdentifier + /// + /// Describe options to be used when registered for text document change events. + /// + public class TextDocumentChangeRegistrationOptions : TextDocumentRegistrationOptions { + /// + /// How documents are synced to the server. + /// + public TextDocumentSyncKind SyncKind { get; set; } + } + + /// + /// The change text document notification's paramters. + /// + public class DidChangeTextDocumentParams + { + /// + /// The document that did change. The version number points to the version after + /// all provided content changes have been applied. + /// + public VersionedTextDocumentIdentifier TextDocument; + /// /// Gets or sets the list of changes to the document content. /// @@ -89,7 +253,7 @@ public class TextDocumentChangeEvent /// /// Gets or sets the length of the Range being replaced in the - /// document. Will be null if the server's TextDocumentSyncKind is + /// document. Will be null if the server's TextDocumentSyncKind is /// Full. /// public int? RangeLength { get; set; } diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/TextDocumentClientCapabilities.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/TextDocumentClientCapabilities.cs new file mode 100644 index 000000000..c620ad056 --- /dev/null +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/TextDocumentClientCapabilities.cs @@ -0,0 +1,130 @@ +namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer +{ + public class TextDocumentClientCapabilities + { + /// + /// Synchronization capabilities the client supports. + /// + public SynchronizationCapabilities Synchronization { get; set; } + + /// + /// Capabilities specific to `textDocument/completion`. + /// + public CompletionCapabilities Completion { get; set; } + + /// + /// Capabilities specific to the `textDocument/hover`. + /// + public DynamicRegistrationCapability Hover { get; set; } + + /// + /// Capabilities specific to the `textDocument/signatureHelp`. + /// + public DynamicRegistrationCapability SignatureHelp { get; set; } + + /// + /// Capabilities specific to the `textDocument/references`. + /// + public DynamicRegistrationCapability References { get; set; } + + /// + /// Capabilities specific to the `textDocument/documentHighlight`. + /// + public DynamicRegistrationCapability DocumentHighlight { get; set; } + + /// + /// Capabilities specific to the `textDocument/documentSymbol`. + /// + public DynamicRegistrationCapability DocumentSymbol { get; set; } + + /// + /// Capabilities specific to the `textDocument/formatting`. + /// + public DynamicRegistrationCapability Formatting { get; set; } + + /// + /// Capabilities specific to the `textDocument/rangeFormatting`. + /// + public DynamicRegistrationCapability RangeFormatting { get; set; } + + /// + /// Capabilities specific to the `textDocument/onTypeFormatting`. + /// + public DynamicRegistrationCapability OnTypeFormatting { get; set; } + + /// + /// Capabilities specific to the `textDocument/definition`. + /// + public DynamicRegistrationCapability Definition { get; set; } + + /// + /// Capabilities specific to the `textDocument/codeAction`. + /// + public DynamicRegistrationCapability CodeAction { get; set; } + + /// + /// Capabilities specific to the `textDocument/codeLens`. + /// + public DynamicRegistrationCapability CodeLens { get; set; } + + /// + /// Capabilities specific to the `textDocument/documentLink`. + /// + public DynamicRegistrationCapability DocumentLink { get; set; } + + /// + /// Capabilities specific to the `textDocument/rename`. + /// + public DynamicRegistrationCapability Rename { get; set; } + } + + /// + /// Class to represent capabilities specific to `textDocument/completion`. + /// + public class CompletionCapabilities : DynamicRegistrationCapability + { + /// + /// The client supports the following `CompletionItem` specific capabilities. + /// + /// + public CompletionItemCapabilities CompletionItem { get; set; } + } + + /// + /// Class to represent capabilities specific to `CompletionItem`. + /// + public class CompletionItemCapabilities + { + /// + /// Client supports snippets as insert text. + /// + /// A snippet can define tab stops and placeholders with `$1`, `$2` + /// and `${3:foo}`. `$0` defines the final tab stop, it defaults to + /// the end of the snippet. Placeholders with equal identifiers are linked, + /// that is typing in one will update others too. + /// + public bool? SnippetSupport { get; set; } + } + + /// + /// Class to represent synchronization capabilities the client supports. + /// + public class SynchronizationCapabilities : DynamicRegistrationCapability + { + /// + /// The client supports sending will save notifications. + /// + public bool? WillSave { get; set; } + + /// + /// The client supports sending a will save request and waits for a response + /// providing text edits which will be applied to the document before it is save. + /// + public bool? WillSaveWaitUntil { get; set; } + + /// + /// The client supports did save notifications. + /// + public bool? DidSave { get; set; } + } +} diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/WorkspaceClientCapabilities.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/WorkspaceClientCapabilities.cs new file mode 100644 index 000000000..3e781a217 --- /dev/null +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/WorkspaceClientCapabilities.cs @@ -0,0 +1,47 @@ +namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer +{ + public class WorkspaceClientCapabilities + { + /// + /// The client supports applying batch edits to the workspace by + /// by supporting the request `workspace/applyEdit' + /// /// + bool? ApplyEdit { get; set; } + + /// + /// Capabilities specific to `WorkspaceEdit`. + /// + public WorkspaceEditCapabilities WorkspaceEdit { get; set; } + + /// + /// Capabilities specific to the `workspace/didChangeConfiguration` notification. + /// + public DynamicRegistrationCapability DidChangeConfiguration { get; set; } + + /// + /// Capabilities specific to the `workspace/didChangeWatchedFiles` notification. + /// + public DynamicRegistrationCapability DidChangeWatchedFiles { get; set; } + + /// + /// Capabilities specific to the `workspace/symbol` request. + /// + public DynamicRegistrationCapability Symbol { get; set; } + + /// + /// Capabilities specific to the `workspace/executeCommand` request. + /// + public DynamicRegistrationCapability ExecuteCommand { get; set; } + } + + /// + /// Class to represent capabilities specific to `WorkspaceEdit`. + /// + public class WorkspaceEditCapabilities + { + /// + /// The client supports versioned document changes in `WorkspaceEdit` + /// + bool? DocumentChanges { get; set; } + } +} diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/WorkspaceSymbols.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/WorkspaceSymbols.cs index 405d6e98e..97e990345 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/WorkspaceSymbols.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/WorkspaceSymbols.cs @@ -7,7 +7,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { - public enum SymbolKind + public enum SymbolKind { File = 1, Module = 2, @@ -29,7 +29,7 @@ public enum SymbolKind Array = 18, } - public class SymbolInformation + public class SymbolInformation { public string Name { get; set; } @@ -43,15 +43,26 @@ public class SymbolInformation public class DocumentSymbolRequest { public static readonly - RequestType Type = - RequestType.Create("textDocument/documentSymbol"); + RequestType Type = + RequestType.Create("textDocument/documentSymbol"); + } + + /// + /// Parameters for a DocumentSymbolRequest + /// + public class DocumentSymbolParams + { + /// + /// The text document. + /// + public TextDocumentIdentifier TextDocument { get; set; } } public class WorkspaceSymbolRequest { public static readonly - RequestType Type = - RequestType.Create("workspace/symbol"); + RequestType Type = + RequestType.Create("workspace/symbol"); } public class WorkspaceSymbolParams diff --git a/src/PowerShellEditorServices.Protocol/MessageProtocol/AbstractMessageType.cs b/src/PowerShellEditorServices.Protocol/MessageProtocol/AbstractMessageType.cs new file mode 100644 index 000000000..1b2fc37f9 --- /dev/null +++ b/src/PowerShellEditorServices.Protocol/MessageProtocol/AbstractMessageType.cs @@ -0,0 +1,35 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +namespace Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol +{ + /// + /// Defines an event type with a particular method name. + /// + /// The parameter type for this event. + public class AbstractMessageType + { + private string _method; + private int _numberOfParams; + + /// + /// Gets the method name for the event type. + /// + public string Method { get { return _method; } } + + /// + /// Gets the number of parameters. + /// + public int NumberOfParams { get; } + + public AbstractMessageType(string method, int numberOfParams) + { + _method = method; + _numberOfParams = numberOfParams; + } + } +} + + diff --git a/src/PowerShellEditorServices.Protocol/MessageProtocol/EventContext.cs b/src/PowerShellEditorServices.Protocol/MessageProtocol/EventContext.cs index e4f4051df..7af362f4e 100644 --- a/src/PowerShellEditorServices.Protocol/MessageProtocol/EventContext.cs +++ b/src/PowerShellEditorServices.Protocol/MessageProtocol/EventContext.cs @@ -21,8 +21,8 @@ public EventContext(MessageWriter messageWriter) this.messageWriter = messageWriter; } - public async Task SendEvent( - EventType eventType, + public async Task SendEvent( + NotificationType eventType, TParams eventParams) { await this.messageWriter.WriteEvent( diff --git a/src/PowerShellEditorServices.Protocol/MessageProtocol/EventType.cs b/src/PowerShellEditorServices.Protocol/MessageProtocol/EventType.cs index 1b2fe1893..58e2f1f59 100644 --- a/src/PowerShellEditorServices.Protocol/MessageProtocol/EventType.cs +++ b/src/PowerShellEditorServices.Protocol/MessageProtocol/EventType.cs @@ -9,24 +9,21 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol /// Defines an event type with a particular method name. /// /// The parameter type for this event. - public class EventType + public class NotificationType : AbstractMessageType { - /// - /// Gets the method name for the event type. - /// - public string MethodName { get; private set; } + private NotificationType(string method) : base(method, 1) + { + + } /// /// Creates an EventType instance with the given parameter type and method name. /// - /// The method name of the event. + /// The method name of the event. /// A new EventType instance for the defined type. - public static EventType Create(string methodName) + public static NotificationType Create(string method) { - return new EventType() - { - MethodName = methodName - }; + return new NotificationType(method); } } } diff --git a/src/PowerShellEditorServices.Protocol/MessageProtocol/IMessageSender.cs b/src/PowerShellEditorServices.Protocol/MessageProtocol/IMessageSender.cs index 804743573..5b4da2452 100644 --- a/src/PowerShellEditorServices.Protocol/MessageProtocol/IMessageSender.cs +++ b/src/PowerShellEditorServices.Protocol/MessageProtocol/IMessageSender.cs @@ -9,12 +9,12 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol { internal interface IMessageSender { - Task SendEvent( - EventType eventType, + Task SendEvent( + NotificationType eventType, TParams eventParams); - Task SendRequest( - RequestType requestType, + Task SendRequest( + RequestType requestType, TParams requestParams, bool waitForResponse); } diff --git a/src/PowerShellEditorServices.Protocol/MessageProtocol/MessageDispatcher.cs b/src/PowerShellEditorServices.Protocol/MessageProtocol/MessageDispatcher.cs index cda98a884..995d124d7 100644 --- a/src/PowerShellEditorServices.Protocol/MessageProtocol/MessageDispatcher.cs +++ b/src/PowerShellEditorServices.Protocol/MessageProtocol/MessageDispatcher.cs @@ -92,8 +92,8 @@ public void Stop() } } - public void SetRequestHandler( - RequestType requestType, + public void SetRequestHandler( + RequestType requestType, Func, Task> requestHandler) { this.SetRequestHandler( @@ -102,19 +102,19 @@ public void SetRequestHandler( false); } - public void SetRequestHandler( - RequestType requestType, + public void SetRequestHandler( + RequestType requestType, Func, Task> requestHandler, bool overrideExisting) { if (overrideExisting) { // Remove the existing handler so a new one can be set - this.requestHandlers.Remove(requestType.MethodName); + this.requestHandlers.Remove(requestType.Method); } this.requestHandlers.Add( - requestType.MethodName, + requestType.Method, (requestMessage, messageWriter) => { var requestContext = @@ -133,8 +133,8 @@ public void SetRequestHandler( }); } - public void SetEventHandler( - EventType eventType, + public void SetEventHandler( + NotificationType eventType, Func eventHandler) { this.SetEventHandler( @@ -143,19 +143,19 @@ public void SetEventHandler( false); } - public void SetEventHandler( - EventType eventType, + public void SetEventHandler( + NotificationType eventType, Func eventHandler, bool overrideExisting) { if (overrideExisting) { // Remove the existing handler so a new one can be set - this.eventHandlers.Remove(eventType.MethodName); + this.eventHandlers.Remove(eventType.Method); } this.eventHandlers.Add( - eventType.MethodName, + eventType.Method, (eventMessage, messageWriter) => { var eventContext = new EventContext(messageWriter); @@ -263,7 +263,7 @@ await this.DispatchMessage( } protected async Task DispatchMessage( - Message messageToDispatch, + Message messageToDispatch, MessageWriter messageWriter) { Task handlerToAwait = null; diff --git a/src/PowerShellEditorServices.Protocol/MessageProtocol/MessageWriter.cs b/src/PowerShellEditorServices.Protocol/MessageProtocol/MessageWriter.cs index 28fbe1eb6..b1936d40e 100644 --- a/src/PowerShellEditorServices.Protocol/MessageProtocol/MessageWriter.cs +++ b/src/PowerShellEditorServices.Protocol/MessageProtocol/MessageWriter.cs @@ -21,7 +21,7 @@ public class MessageWriter private IMessageSerializer messageSerializer; private AsyncLock writeLock = new AsyncLock(); - private JsonSerializer contentSerializer = + private JsonSerializer contentSerializer = JsonSerializer.Create( Constants.JsonSerializerSettings); @@ -71,7 +71,7 @@ public async Task WriteMessage(Message messageToWrite) Constants.JsonSerializerSettings); byte[] messageBytes = Encoding.UTF8.GetBytes(serializedMessage); - byte[] headerBytes = + byte[] headerBytes = Encoding.ASCII.GetBytes( string.Format( Constants.ContentLengthFormatString, @@ -89,8 +89,8 @@ public async Task WriteMessage(Message messageToWrite) } } - public async Task WriteRequest( - RequestType requestType, + public async Task WriteRequest( + RequestType requestType, TParams requestParams, int requestId) { @@ -102,8 +102,8 @@ public async Task WriteRequest( await this.WriteMessage( Message.Request( - requestId.ToString(), - requestType.MethodName, + requestId.ToString(), + requestType.Method, contentObject)); } @@ -122,7 +122,7 @@ await this.WriteMessage( contentObject)); } - public async Task WriteEvent(EventType eventType, TParams eventParams) + public async Task WriteEvent(NotificationType eventType, TParams eventParams) { // Allow null content JToken contentObject = @@ -132,7 +132,7 @@ public async Task WriteEvent(EventType eventType, TParams even await this.WriteMessage( Message.Event( - eventType.MethodName, + eventType.Method, contentObject)); } diff --git a/src/PowerShellEditorServices.Protocol/MessageProtocol/ProtocolEndpoint.cs b/src/PowerShellEditorServices.Protocol/MessageProtocol/ProtocolEndpoint.cs index 92aed5ecb..9ef13c828 100644 --- a/src/PowerShellEditorServices.Protocol/MessageProtocol/ProtocolEndpoint.cs +++ b/src/PowerShellEditorServices.Protocol/MessageProtocol/ProtocolEndpoint.cs @@ -59,7 +59,7 @@ public ProtocolEndpoint( this.messageProtocolType = messageProtocolType; this.originalSynchronizationContext = SynchronizationContext.Current; } - + /// /// Starts the language server client and sends the Initialize method. /// @@ -132,6 +132,15 @@ public async Task Stop() #region Message Sending + public Task SendRequest( + RequestType0 requestType0) + { + return this.SendRequest( + RequestType.ConvertToRequestType(requestType0), + null); + } + + /// /// Sends a request to the server /// @@ -140,15 +149,15 @@ public async Task Stop() /// /// /// - public Task SendRequest( - RequestType requestType, + public Task SendRequest( + RequestType requestType, TParams requestParams) { return this.SendRequest(requestType, requestParams, true); } - public async Task SendRequest( - RequestType requestType, + public async Task SendRequest( + RequestType requestType, TParams requestParams, bool waitForResponse) { @@ -173,13 +182,13 @@ public async Task SendRequest( { responseTask = new TaskCompletionSource(); this.pendingRequests.Add( - this.currentMessageId.ToString(), + this.currentMessageId.ToString(), responseTask); } - await this.protocolChannel.MessageWriter.WriteRequest( - requestType, - requestParams, + await this.protocolChannel.MessageWriter.WriteRequest( + requestType, + requestParams, this.currentMessageId); if (responseTask != null) @@ -205,8 +214,8 @@ await this.protocolChannel.MessageWriter.WriteRequest( /// The type of event being sent. /// The event parameters being sent. /// A Task that tracks completion of the send operation. - public Task SendEvent( - EventType eventType, + public Task SendEvent( + NotificationType eventType, TParams eventParams) { // Some requests may still be in the SynchronizationContext queue @@ -254,8 +263,20 @@ await this.protocolChannel.MessageWriter.WriteEvent( #region Message Handling - public void SetRequestHandler( - RequestType requestType, + public void SetRequestHandler( + RequestType0 requestType0, + Func, Task> requestHandler) + { + SetRequestHandler( + RequestType.ConvertToRequestType(requestType0), + (param1, requestContext) => + { + return requestHandler(requestContext); + }); + } + + public void SetRequestHandler( + RequestType requestType, Func, Task> requestHandler) { this.MessageDispatcher.SetRequestHandler( @@ -263,8 +284,8 @@ public void SetRequestHandler( requestHandler); } - public void SetEventHandler( - EventType eventType, + public void SetEventHandler( + NotificationType eventType, Func eventHandler) { this.MessageDispatcher.SetEventHandler( @@ -273,8 +294,8 @@ public void SetEventHandler( false); } - public void SetEventHandler( - EventType eventType, + public void SetEventHandler( + NotificationType eventType, Func eventHandler, bool overrideExisting) { diff --git a/src/PowerShellEditorServices.Protocol/MessageProtocol/RequestContext.cs b/src/PowerShellEditorServices.Protocol/MessageProtocol/RequestContext.cs index a578f4668..55c473f01 100644 --- a/src/PowerShellEditorServices.Protocol/MessageProtocol/RequestContext.cs +++ b/src/PowerShellEditorServices.Protocol/MessageProtocol/RequestContext.cs @@ -27,7 +27,7 @@ await this.messageWriter.WriteResponse( requestMessage.Id); } - public async Task SendEvent(EventType eventType, TParams eventParams) + public async Task SendEvent(NotificationType eventType, TParams eventParams) { await this.messageWriter.WriteEvent( eventType, diff --git a/src/PowerShellEditorServices.Protocol/MessageProtocol/RequestType.cs b/src/PowerShellEditorServices.Protocol/MessageProtocol/RequestType.cs index e5d0cea08..d7c5a6e8e 100644 --- a/src/PowerShellEditorServices.Protocol/MessageProtocol/RequestType.cs +++ b/src/PowerShellEditorServices.Protocol/MessageProtocol/RequestType.cs @@ -7,17 +7,28 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol { - [DebuggerDisplay("RequestType MethodName = {MethodName}")] - public class RequestType + [DebuggerDisplay("RequestType Method = {Method}")] + public class RequestType : AbstractMessageType { - public string MethodName { get; private set; } + private RequestType(string method) : base(method, 1) + { + + } - public static RequestType Create(string typeName) + public static RequestType ConvertToRequestType( + RequestType0 requestType0) { - return new RequestType() + return RequestType.Create(requestType0.Method); + } + + public static RequestType Create(string method) + { + if (method == null) { - MethodName = typeName - }; + throw new System.ArgumentNullException(nameof(method)); + } + + return new RequestType(method); } } } diff --git a/src/PowerShellEditorServices.Protocol/MessageProtocol/RequestType0.cs b/src/PowerShellEditorServices.Protocol/MessageProtocol/RequestType0.cs new file mode 100644 index 000000000..e8fc8da1c --- /dev/null +++ b/src/PowerShellEditorServices.Protocol/MessageProtocol/RequestType0.cs @@ -0,0 +1,22 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System.Diagnostics; + +namespace Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol +{ + [DebuggerDisplay("RequestType0 Method = {Method}")] + public class RequestType0 : AbstractMessageType + { + public RequestType0(string method) : base(method, 0) + { + } + + public static RequestType0 Create(string method) + { + return new RequestType0(method); + } + } +} diff --git a/src/PowerShellEditorServices.Protocol/Messages/PromptEvents.cs b/src/PowerShellEditorServices.Protocol/Messages/PromptEvents.cs index 031b996af..3a04eaf1e 100644 --- a/src/PowerShellEditorServices.Protocol/Messages/PromptEvents.cs +++ b/src/PowerShellEditorServices.Protocol/Messages/PromptEvents.cs @@ -10,8 +10,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Messages public class ShowChoicePromptRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/showChoicePrompt"); + RequestType Type = + RequestType.Create("powerShell/showChoicePrompt"); public bool IsMultiChoice { get; set; } @@ -34,8 +34,8 @@ public class ShowChoicePromptResponse public class ShowInputPromptRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/showInputPrompt"); + RequestType Type = + RequestType.Create("powerShell/showInputPrompt"); /// /// Gets or sets the name of the field. diff --git a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs index f82c316f3..cdc059e43 100644 --- a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs +++ b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs @@ -926,7 +926,7 @@ async void powerShellContext_RunspaceChanged(object sender, RunspaceChangedEvent // Exited the session while the debugger is stopped, // send a ContinuedEvent so that the client changes the // UI to appear to be running again - await this.SendEvent( + await this.SendEvent( ContinuedEvent.Type, new ContinuedEvent { diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 629d2f0bb..ede85beba 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -174,7 +174,7 @@ protected override async Task Shutdown() #region Built-in Message Handlers protected async Task HandleInitializeRequest( - InitializeRequest initializeParams, + InitializeParams initializeParams, RequestContext requestContext) { // Grab the workspace path from the parameters @@ -483,13 +483,13 @@ private async Task HandleFindModuleRequest( } protected Task HandleDidOpenTextDocumentNotification( - DidOpenTextDocumentNotification openParams, + DidOpenTextDocumentParams openParams, EventContext eventContext) { ScriptFile openedFile = editorSession.Workspace.GetFileBuffer( - openParams.Uri, - openParams.Text); + openParams.TextDocument.Uri, + openParams.TextDocument.Text); // TODO: Get all recently edited files in the workspace this.RunScriptDiagnostics( @@ -503,11 +503,11 @@ protected Task HandleDidOpenTextDocumentNotification( } protected async Task HandleDidCloseTextDocumentNotification( - TextDocumentIdentifier closeParams, + DidCloseTextDocumentParams closeParams, EventContext eventContext) { // Find and close the file in the current session - var fileToClose = editorSession.Workspace.GetFile(closeParams.Uri); + var fileToClose = editorSession.Workspace.GetFile(closeParams.TextDocument.Uri); if (fileToClose != null) { @@ -544,7 +544,7 @@ protected Task HandleDidChangeTextDocumentNotification( // A text change notification can batch multiple change requests foreach (var textChange in textChangeParams.ContentChanges) { - ScriptFile changedFile = editorSession.Workspace.GetFile(textChangeParams.Uri); + ScriptFile changedFile = editorSession.Workspace.GetFile(textChangeParams.TextDocument.Uri); changedFile.ApplyChange( GetFileChangeDetails( @@ -708,15 +708,15 @@ await editorSession.LanguageService.FindReferencesOfSymbol( } protected async Task HandleCompletionRequest( - TextDocumentPosition textDocumentPosition, + TextDocumentPositionParams textDocumentPositionParams, RequestContext requestContext) { - int cursorLine = textDocumentPosition.Position.Line + 1; - int cursorColumn = textDocumentPosition.Position.Character + 1; + int cursorLine = textDocumentPositionParams.Position.Line + 1; + int cursorColumn = textDocumentPositionParams.Position.Character + 1; ScriptFile scriptFile = editorSession.Workspace.GetFile( - textDocumentPosition.Uri); + textDocumentPositionParams.TextDocument.Uri); CompletionResults completionResults = await editorSession.LanguageService.GetCompletionsInFile( @@ -773,18 +773,18 @@ await CommandHelpers.GetCommandSynopsis( } protected async Task HandleSignatureHelpRequest( - TextDocumentPosition textDocumentPosition, + TextDocumentPositionParams textDocumentPositionParams, RequestContext requestContext) { ScriptFile scriptFile = editorSession.Workspace.GetFile( - textDocumentPosition.Uri); + textDocumentPositionParams.TextDocument.Uri); ParameterSetSignatures parameterSets = await editorSession.LanguageService.FindParameterSetsInFile( scriptFile, - textDocumentPosition.Position.Line + 1, - textDocumentPosition.Position.Character + 1); + textDocumentPositionParams.Position.Line + 1, + textDocumentPositionParams.Position.Character + 1); SignatureInformation[] signatures = null; int? activeParameter = null; @@ -824,18 +824,18 @@ await requestContext.SendResult( } protected async Task HandleDocumentHighlightRequest( - TextDocumentPosition textDocumentPosition, + TextDocumentPositionParams textDocumentPositionParams, RequestContext requestContext) { ScriptFile scriptFile = editorSession.Workspace.GetFile( - textDocumentPosition.Uri); + textDocumentPositionParams.TextDocument.Uri); FindOccurrencesResult occurrencesResult = editorSession.LanguageService.FindOccurrencesInFile( scriptFile, - textDocumentPosition.Position.Line + 1, - textDocumentPosition.Position.Character + 1); + textDocumentPositionParams.Position.Line + 1, + textDocumentPositionParams.Position.Character + 1); DocumentHighlight[] documentHighlights = null; @@ -863,20 +863,20 @@ protected async Task HandleDocumentHighlightRequest( } protected async Task HandleHoverRequest( - TextDocumentPosition textDocumentPosition, + TextDocumentPositionParams textDocumentPositionParams, RequestContext requestContext) { ScriptFile scriptFile = editorSession.Workspace.GetFile( - textDocumentPosition.Uri); + textDocumentPositionParams.TextDocument.Uri); SymbolDetails symbolDetails = await editorSession .LanguageService .FindSymbolDetailsAtLocation( scriptFile, - textDocumentPosition.Position.Line + 1, - textDocumentPosition.Position.Character + 1); + textDocumentPositionParams.Position.Line + 1, + textDocumentPositionParams.Position.Character + 1); List symbolInfo = new List(); Range? symbolRange = null; @@ -912,12 +912,12 @@ await requestContext.SendResult( } protected async Task HandleDocumentSymbolRequest( - TextDocumentIdentifier textDocumentIdentifier, + DocumentSymbolParams documentSymbolParams, RequestContext requestContext) { ScriptFile scriptFile = editorSession.Workspace.GetFile( - textDocumentIdentifier.Uri); + documentSymbolParams.TextDocument.Uri); FindOccurrencesResult foundSymbols = editorSession.LanguageService.FindSymbolsInFile( @@ -1078,7 +1078,7 @@ private bool IsQueryMatch(string query, string symbolName) } protected async Task HandleCodeActionRequest( - CodeActionRequest codeActionParams, + CodeActionParams codeActionParams, RequestContext requestContext) { MarkerCorrection correction = null; @@ -1249,7 +1249,7 @@ private Task RunScriptDiagnostics( private Task RunScriptDiagnostics( ScriptFile[] filesToAnalyze, EditorSession editorSession, - Func, PublishDiagnosticsNotification, Task> eventSender) + Func, PublishDiagnosticsNotification, Task> eventSender) { // If there's an existing task, attempt to cancel it try @@ -1327,7 +1327,7 @@ private static async Task DelayThenInvokeDiagnostics( bool isScriptAnalysisEnabled, Dictionary> correctionIndex, EditorSession editorSession, - Func, PublishDiagnosticsNotification, Task> eventSender, + Func, PublishDiagnosticsNotification, Task> eventSender, CancellationToken cancellationToken) { // First of all, wait for the desired delay period before @@ -1403,7 +1403,7 @@ private static async Task PublishScriptDiagnostics( ScriptFile scriptFile, ScriptFileMarker[] markers, Dictionary> correctionIndex, - Func, PublishDiagnosticsNotification, Task> eventSender) + Func, PublishDiagnosticsNotification, Task> eventSender) { List diagnostics = new List(); diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServerBase.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServerBase.cs index d23391785..7f912cfba 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServerBase.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServerBase.cs @@ -14,7 +14,7 @@ public abstract class LanguageServerBase : ProtocolEndpoint { private ChannelBase serverChannel; - public LanguageServerBase(ChannelBase serverChannel) : + public LanguageServerBase(ChannelBase serverChannel) : base(serverChannel, MessageProtocolType.LanguageServer) { this.serverChannel = serverChannel; @@ -55,7 +55,6 @@ protected virtual Task Shutdown() } private async Task HandleShutdownRequest( - object shutdownParams, RequestContext requestContext) { // Allow the implementor to shut down gracefully diff --git a/test/PowerShellEditorServices.Test.Channel.WebSocket/WebSocketChannelTest.cs b/test/PowerShellEditorServices.Test.Channel.WebSocket/WebSocketChannelTest.cs index 71d94c1a8..bfc74168d 100644 --- a/test/PowerShellEditorServices.Test.Channel.WebSocket/WebSocketChannelTest.cs +++ b/test/PowerShellEditorServices.Test.Channel.WebSocket/WebSocketChannelTest.cs @@ -50,7 +50,7 @@ await this.SendRequest( } private Task SendRequest( - RequestType requestType, + RequestType requestType, TParams requestParams) { return diff --git a/test/PowerShellEditorServices.Test.Host/LanguageServerTests.cs b/test/PowerShellEditorServices.Test.Host/LanguageServerTests.cs index 4b6c0e527..7ca874794 100644 --- a/test/PowerShellEditorServices.Test.Host/LanguageServerTests.cs +++ b/test/PowerShellEditorServices.Test.Host/LanguageServerTests.cs @@ -122,9 +122,12 @@ public async Task ServiceCompletesFunctionName() CompletionItem[] completions = await this.SendRequest( CompletionRequest.Type, - new TextDocumentPosition + new TextDocumentPositionParams { - Uri = "TestFiles\\CompleteFunctionName.ps1", + TextDocument = new TextDocumentIdentifier + { + Uri = "TestFiles\\CompleteFunctionName.ps1", + }, Position = new Position { Line = 4, @@ -146,9 +149,12 @@ public async Task CompletesDetailOnVariableSuggestion() CompletionItem[] completions = await this.SendRequest( CompletionRequest.Type, - new TextDocumentPosition + new TextDocumentPositionParams { - Uri = "TestFiles\\CompleteFunctionName.ps1", + TextDocument = new TextDocumentIdentifier + { + Uri = "TestFiles\\CompleteFunctionName.ps1" + }, Position = new Position { Line = 3, @@ -172,9 +178,12 @@ public async Task CompletesDetailOnVariableDocSuggestion() await this.SendRequest( CompletionRequest.Type, - new TextDocumentPosition + new TextDocumentPositionParams { - Uri = "TestFiles\\CompleteFunctionName.ps1", + TextDocument = new TextDocumentIdentifier + { + Uri = "TestFiles\\CompleteFunctionName.ps1" + }, Position = new Position { Line = 7, @@ -212,9 +221,12 @@ public async Task CompletesDetailOnCommandSuggestion() CompletionItem[] completions = await this.SendRequest( CompletionRequest.Type, - new TextDocumentPosition + new TextDocumentPositionParams { - Uri = "TestFiles\\CompleteFunctionName.ps1", + TextDocument = new TextDocumentIdentifier + { + Uri = "TestFiles\\CompleteFunctionName.ps1" + }, Position = new Position { Line = 5, @@ -430,9 +442,12 @@ public async Task FindsOccurencesOnFunctionDefinition() DocumentHighlight[] highlights = await this.SendRequest( DocumentHighlightRequest.Type, - new TextDocumentPosition + new TextDocumentPositionParams { - Uri = "TestFiles\\FindReferences.ps1", + TextDocument = new TextDocumentIdentifier + { + Uri = "TestFiles\\FindReferences.ps1" + }, Position = new Position { Line = 0, @@ -453,9 +468,12 @@ public async Task GetsParameterHintsOnCommand() SignatureHelp signatureHelp = await this.SendRequest( SignatureHelpRequest.Type, - new TextDocumentPosition + new TextDocumentPositionParams { - Uri = "TestFiles\\FindReferences.ps1", + TextDocument = new TextDocumentIdentifier + { + Uri = "TestFiles\\FindReferences.ps1" + }, Position = new Position { Line = 12, @@ -746,10 +764,15 @@ private async Task SendOpenFileEvent(string filePath, bool waitForDiagnostics = await this.SendEvent( DidOpenTextDocumentNotification.Type, - new DidOpenTextDocumentNotification() + new DidOpenTextDocumentParams { - Uri = filePath, - Text = fileContents + TextDocument = new TextDocumentItem + { + Uri = filePath, + Text = fileContents, + LanguageId = "PowerShell", + Version = 0 + } }); if (diagnosticWaitTask != null) @@ -758,4 +781,4 @@ await this.SendEvent( } } } -} \ No newline at end of file +} diff --git a/test/PowerShellEditorServices.Test.Host/ServerTestsBase.cs b/test/PowerShellEditorServices.Test.Host/ServerTestsBase.cs index d7e7f3e2a..e65983b1a 100644 --- a/test/PowerShellEditorServices.Test.Host/ServerTestsBase.cs +++ b/test/PowerShellEditorServices.Test.Host/ServerTestsBase.cs @@ -102,19 +102,16 @@ protected async Task> LaunchService( { // Must have read an error? Keep reading from error stream string errorString = completedRead.Result; + Task errorRead = this.serviceProcess.StandardError.ReadToEndAsync(); - while (true) + // Lets give the read operation 5 seconds to complete. Ideally, it shouldn't + // take that long at all, but just in case... + if (errorRead.Wait(5000)) { - Task errorRead = this.serviceProcess.StandardError.ReadLineAsync(); - if (!string.IsNullOrEmpty(errorRead.Result)) { errorString += errorRead.Result + Environment.NewLine; } - else - { - break; - } } throw new Exception("Could not launch powershell.exe:\r\n\r\n" + errorString); @@ -134,8 +131,8 @@ protected void KillService() } } - protected Task SendRequest( - RequestType requestType, + protected Task SendRequest( + RequestType requestType, TParams requestParams) { return @@ -144,7 +141,7 @@ protected Task SendRequest( requestParams); } - protected Task SendEvent(EventType eventType, TParams eventParams) + protected Task SendEvent(NotificationType eventType, TParams eventParams) { return this.protocolClient.SendEvent( @@ -152,11 +149,11 @@ protected Task SendEvent(EventType eventType, TParams eventPar eventParams); } - protected void QueueEventsForType(EventType eventType) + protected void QueueEventsForType(NotificationType eventType) { var eventQueue = this.eventQueuePerType.AddOrUpdate( - eventType.MethodName, + eventType.Method, new AsyncQueue(), (key, queue) => queue); @@ -168,15 +165,15 @@ protected void QueueEventsForType(EventType eventType) }); } - protected async Task WaitForEvent( - EventType eventType, + protected async Task WaitForEvent( + NotificationType eventType, int timeoutMilliseconds = 5000) { Task eventTask = null; // Use the event queue if one has been registered AsyncQueue eventQueue = null; - if (this.eventQueuePerType.TryGetValue(eventType.MethodName, out eventQueue)) + if (this.eventQueuePerType.TryGetValue(eventType.Method, out eventQueue)) { eventTask = eventQueue @@ -214,21 +211,21 @@ protected async Task WaitForEvent( throw new TimeoutException( string.Format( "Timed out waiting for '{0}' event!", - eventType.MethodName)); + eventType.Method)); } return await eventTask; } protected async Task>> WaitForRequest( - RequestType requestType, + RequestType requestType, int timeoutMilliseconds = 5000) { Task>> requestTask = null; // Use the request queue if one has been registered AsyncQueue requestQueue = null; - if (this.requestQueuePerType.TryGetValue(requestType.MethodName, out requestQueue)) + if (this.requestQueuePerType.TryGetValue(requestType.Method, out requestQueue)) { requestTask = requestQueue @@ -267,7 +264,7 @@ protected async Task>> WaitForRequest OutputEvents { get; } = new List(); - public Task SendEvent( - EventType eventType, + public Task SendEvent( + NotificationType eventType, TParams eventParams) { OutputEventBody outputEvent = eventParams as OutputEventBody; @@ -113,8 +113,8 @@ public Task SendEvent( return Task.FromResult(true); } - public Task SendRequest( - RequestType requestType, + public Task SendRequest( + RequestType requestType, TParams requestParams, bool waitForResponse) { // Legitimately not implemented for these tests.