From 15025cf21593cb4823c45461ca5c1930f0e6806e Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Thu, 6 Jun 2024 01:20:54 -0400 Subject: [PATCH 01/46] LSP Protocol: Implement WorkDoneProgress types --- .../Protocol/Protocol/IPartialResultParams.cs | 15 ++--- .../Protocol/IWorkDoneProgressOptions.cs | 11 +++- .../Protocol/IWorkDoneProgressParams.cs | 30 ++++++++++ .../VSInternalDocumentDiagnosticsParams.cs | 12 ++-- .../VSInternalWorkspaceDiagnosticsParams.cs | 10 +--- .../VSInternalDocumentSpellCheckableParams.cs | 4 +- ...VSInternalWorkspaceSpellCheckableParams.cs | 4 +- .../Protocol/Protocol/WorkDoneProgress.cs | 22 +++++++ .../Protocol/WorkDoneProgressBegin.cs | 58 +++++++++++++++++++ .../Protocol/Protocol/WorkDoneProgressEnd.cs | 26 +++++++++ .../Protocol/WorkDoneProgressReport.cs | 53 +++++++++++++++++ 11 files changed, 215 insertions(+), 30 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/IWorkDoneProgressParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WorkDoneProgress.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WorkDoneProgressBegin.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WorkDoneProgressEnd.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WorkDoneProgressReport.cs diff --git a/src/LanguageServer/Protocol/Protocol/IPartialResultParams.cs b/src/LanguageServer/Protocol/Protocol/IPartialResultParams.cs index 194dc57dc96cc..e21b13450804b 100644 --- a/src/LanguageServer/Protocol/Protocol/IPartialResultParams.cs +++ b/src/LanguageServer/Protocol/Protocol/IPartialResultParams.cs @@ -5,22 +5,23 @@ namespace Roslyn.LanguageServer.Protocol { using System; + using System.Text.Json.Serialization; /// /// Interface to describe parameters for requests that support streaming results. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// /// The type to be reported by . internal interface IPartialResultParams { /// - /// Gets or sets the value of the PartialResultToken instance. + /// An instance that can be used to report partial results + /// via the $/progress notification. /// - public IProgress? PartialResultToken - { - get; - set; - } + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressOptions.cs b/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressOptions.cs index 5ed79725eacb1..d130861d2488d 100644 --- a/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressOptions.cs @@ -2,18 +2,25 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Text.Json.Serialization; + namespace Roslyn.LanguageServer.Protocol { /// /// Options to signal work done progress support in server capabilities. /// + /// Since LSP 3.15 internal interface IWorkDoneProgressOptions { /// /// Gets or sets a value indicating whether work done progress is supported. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - bool WorkDoneProgress { get; init; } + /// Since LSP 3.15 + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressParams.cs b/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressParams.cs new file mode 100644 index 0000000000000..da39f9756df8e --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressParams.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Interface to describe parameters for requests that support reporting work done via the $/progress notification. +/// +/// +/// See the Language Server Protocol specification for additional information. +/// +/// Since LSP 3.15 +internal interface IWorkDoneProgressParams +{ + /// + /// An optional token that a server can use to report work done progress. + /// + /// The derived classes , and + /// are used to report the beginning, progression, and end of the operation. + /// + /// + /// Since LSP 3.15 + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDocumentDiagnosticsParams.cs b/src/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDocumentDiagnosticsParams.cs index 2a136bb3fab29..b717a780f70a3 100644 --- a/src/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDocumentDiagnosticsParams.cs +++ b/src/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalDocumentDiagnosticsParams.cs @@ -10,18 +10,14 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing a diagnostic pull request for a specific document. /// - internal class VSInternalDocumentDiagnosticsParams : VSInternalDiagnosticParams, IPartialResultParams + internal class VSInternalDocumentDiagnosticsParams : VSInternalDiagnosticParams, IPartialResultParams, IWorkDoneProgressParams { - /// - /// Gets or sets an optional token that a server can use to report work done progress. - /// + /// [JsonPropertyName(Methods.WorkDoneTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public IProgress? WorkDoneToken { get; set; } + public IProgress WorkDoneToken { get; set; } - /// - /// Gets or sets an optional token that a server can use to report partial results (e.g. streaming) to the client. - /// + /// [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken { get; set; } diff --git a/src/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalWorkspaceDiagnosticsParams.cs b/src/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalWorkspaceDiagnosticsParams.cs index 61d145c73c8bc..8dec2ac09d500 100644 --- a/src/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalWorkspaceDiagnosticsParams.cs +++ b/src/LanguageServer/Protocol/Protocol/Internal/Diagnostics/VSInternalWorkspaceDiagnosticsParams.cs @@ -19,16 +19,12 @@ internal class VSInternalWorkspaceDiagnosticsParams : IPartialResultParams - /// Gets or sets an optional token that a server can use to report work done progress. - /// + /// [JsonPropertyName(Methods.WorkDoneTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public IProgress? WorkDoneToken { get; set; } + public IProgress? WorkDoneToken { get; set; } - /// - /// Gets or sets an optional token that a server can use to report partial results (e.g. streaming) to the client. - /// + /// [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken { get; set; } diff --git a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentSpellCheckableParams.cs b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentSpellCheckableParams.cs index e3634b57d5e98..c1b456342f95e 100644 --- a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentSpellCheckableParams.cs +++ b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalDocumentSpellCheckableParams.cs @@ -12,9 +12,7 @@ namespace Roslyn.LanguageServer.Protocol /// internal class VSInternalDocumentSpellCheckableParams : VSInternalStreamingParams, IPartialResultParams { - /// - /// Gets or sets an optional token that a server can use to report partial results (e.g. streaming) to the client. - /// + /// [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken diff --git a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalWorkspaceSpellCheckableParams.cs b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalWorkspaceSpellCheckableParams.cs index 417638b7bd55d..a3e3577f9ae33 100644 --- a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalWorkspaceSpellCheckableParams.cs +++ b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalWorkspaceSpellCheckableParams.cs @@ -19,9 +19,7 @@ internal class VSInternalWorkspaceSpellCheckableParams : IPartialResultParams - /// Gets or sets an optional token that a server can use to report partial results (e.g. streaming) to the client. - /// + /// [JsonPropertyName("_vs_partialResultToken")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken diff --git a/src/LanguageServer/Protocol/Protocol/WorkDoneProgress.cs b/src/LanguageServer/Protocol/Protocol/WorkDoneProgress.cs new file mode 100644 index 0000000000000..7b4cfb2672a1f --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WorkDoneProgress.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// An IProgress<WorkDoneProgress> is used to report progress to the server via the $/progress notification. +/// +/// The derived classes , and +/// are used to report the beginning, progression, and end of the operation. +/// +/// +[JsonDerivedType(typeof(WorkDoneProgressBegin), "begin")] +[JsonDerivedType(typeof(WorkDoneProgressReport), "report")] +[JsonDerivedType(typeof(WorkDoneProgressEnd), "end")] +[JsonPolymorphic(TypeDiscriminatorPropertyName = "kind")] +internal abstract class WorkDoneProgress +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/WorkDoneProgressBegin.cs b/src/LanguageServer/Protocol/Protocol/WorkDoneProgressBegin.cs new file mode 100644 index 0000000000000..9d2ed3d1b50e1 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WorkDoneProgressBegin.cs @@ -0,0 +1,58 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Used to report the beginning of an operation to an IProgress<WorkDoneProgress>. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.15 +internal sealed class WorkDoneProgressBegin : WorkDoneProgress +{ + // NOTE: the kind property from the spec is used as a JsonPolymorphic discriminator on the base type + + /// + /// Title of the progress operation. Used to briefly inform about the kind of operation being performed. + /// Examples: "Indexing" or "Linking dependencies". + /// + [JsonPropertyName("title")] + [JsonRequired] + public string Title { get; init; } + + /// + /// Controls if a cancel button should show to allow the user to cancel the + /// long running operation. Clients that don't support cancellation are + /// allowed to ignore the setting. + /// + [JsonPropertyName("cancellable")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public bool? Cancellable { get; init; } + + /// + /// Optional, more detailed associated progress message. Contains + /// complementary information to the `title`. + /// + /// Examples: "3/25 files", "project/src/module2", "node_modules/some_dep". + /// + [JsonPropertyName("message")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Message { get; init; } + + /// + /// Optional progress percentage to display (value 100 is considered 100%). + /// If not provided infinite progress is assumed and clients are allowed + /// to ignore the `percentage` value in subsequent in report notifications. + /// + /// The value should be steadily rising. Clients are free to ignore values + /// that are not following this rule. The value range is [0, 100] + /// + [JsonPropertyName("percentage")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public int? Percentage { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/WorkDoneProgressEnd.cs b/src/LanguageServer/Protocol/Protocol/WorkDoneProgressEnd.cs new file mode 100644 index 0000000000000..4190436880f97 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WorkDoneProgressEnd.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Used to report the end of an operation to an IProgress<WorkDoneProgress>. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.15 +internal class WorkDoneProgressEnd : WorkDoneProgress +{ + // NOTE: the kind property from the spec is used as a JsonPolymorphic discriminator on the base type + + /// + /// Optional final message indicating for example the outcome of the operation. + /// + [JsonPropertyName("message")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Message { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/WorkDoneProgressReport.cs b/src/LanguageServer/Protocol/Protocol/WorkDoneProgressReport.cs new file mode 100644 index 0000000000000..7c00ddfe0f0b0 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WorkDoneProgressReport.cs @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Used to report progress of an operation to an IProgress<WorkDoneProgress>. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.15 +internal sealed class WorkDoneProgressReport : WorkDoneProgress +{ + // NOTE: the kind property from the spec is used as a JsonPolymorphic discriminator on the base type + + /// + /// Controls enablement state of a cancel button. This property is only valid + /// if a cancel button got requested in the payload. + /// Clients that don't support cancellation or don't support control the + /// button's enablement state are allowed to ignore the setting. + /// + [JsonPropertyName("cancellable")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public bool? Cancellable { get; init; } + + /// + /// Optional, more detailed associated progress message. Contains + /// complementary information to the `title`. + /// + /// Examples: "3/25 files", "project/src/module2", "node_modules/some_dep". + /// + /// If unset, the previous progress message (if any) is still valid. + /// + [JsonPropertyName("message")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Message { get; init; } + + /// + /// Optional progress percentage to display (value 100 is considered 100%). + /// If not provided infinite progress is assumed and clients are allowed + /// to ignore the `percentage` value in subsequent in report notifications. + /// + /// The value should be steadily rising. Clients are free to ignore values + /// that are not following this rule. The value range is [0, 100] + /// + [JsonPropertyName("percentage")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public int? Percentage { get; init; } +} From b3c3459e1387ca6a94db3ac4891f79c785e3d63f Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sat, 8 Jun 2024 23:22:31 -0400 Subject: [PATCH 02/46] LSP Protocol: Use spec ordering in capabilities types This makes it easier to update them --- .../Protocol/Protocol/ServerCapabilities.cs | 176 ++++-------------- .../TextDocumentClientCapabilities.cs | 144 +++----------- .../Protocol/WorkspaceClientCapabilities.cs | 91 +++------ 3 files changed, 91 insertions(+), 320 deletions(-) diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 840da00bb13b1..c78740a3de3ca 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -14,6 +14,8 @@ namespace Roslyn.LanguageServer.Protocol /// internal class ServerCapabilities { + // NOTE: these are kept in the same order as the spec to make them easier to update + /// /// Gets or sets the value which indicates how text document are synced. /// @@ -40,274 +42,174 @@ public TextDocumentSyncOptions? TextDocumentSync /// [JsonPropertyName("completionProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public CompletionOptions? CompletionProvider - { - get; - set; - } + public CompletionOptions? CompletionProvider { get; set; } /// /// Gets or sets a value indicating whether the server provides hover support. /// [JsonPropertyName("hoverProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? HoverProvider - { - get; - set; - } + public SumType? HoverProvider { get; set; } /// /// Gets or sets the value which indicates if signature help is supported. /// [JsonPropertyName("signatureHelpProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SignatureHelpOptions? SignatureHelpProvider - { - get; - set; - } + public SignatureHelpOptions? SignatureHelpProvider { get; set; } /// /// Gets or sets a value indicating whether go to definition is supported. /// [JsonPropertyName("definitionProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? DefinitionProvider - { - get; - set; - } + public SumType? DefinitionProvider { get; set; } /// /// Gets or sets a value indicating whether go to type definition is supported. /// [JsonPropertyName("typeDefinitionProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? TypeDefinitionProvider - { - get; - set; - } + public SumType? TypeDefinitionProvider { get; set; } /// /// Gets or sets a value indicating whether go to implementation is supported. /// [JsonPropertyName("implementationProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? ImplementationProvider - { - get; - set; - } + public SumType? ImplementationProvider { get; set; } /// /// Gets or sets a value indicating whether find all references is supported. /// [JsonPropertyName("referencesProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? ReferencesProvider - { - get; - set; - } + public SumType? ReferencesProvider { get; set; } /// /// Gets or sets a value indicating whether the server supports document highlight. /// [JsonPropertyName("documentHighlightProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? DocumentHighlightProvider - { - get; - set; - } + public SumType? DocumentHighlightProvider { get; set; } /// /// Gets or sets a value indicating whether document symbols are supported. /// [JsonPropertyName("documentSymbolProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? DocumentSymbolProvider - { - get; - set; - } + public SumType? DocumentSymbolProvider { get; set; } /// /// Gets or sets a value indicating whether code actions are supported. /// [JsonPropertyName("codeActionProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? CodeActionProvider - { - get; - set; - } + public SumType? CodeActionProvider { get; set; } /// /// Gets or sets the value which indicates if code lens is supported. /// [JsonPropertyName("codeLensProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public CodeLensOptions? CodeLensProvider - { - get; - set; - } + public CodeLensOptions? CodeLensProvider { get; set; } /// /// Gets or sets the value which indicates if document link is supported. /// [JsonPropertyName("documentLinkProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DocumentLinkOptions? DocumentLinkProvider - { - get; - set; - } + public DocumentLinkOptions? DocumentLinkProvider { get; set; } /// /// Gets or sets the value which indicates if document color is supported. /// [JsonPropertyName("colorProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? DocumentColorProvider - { - get; - set; - } + public SumType? DocumentColorProvider { get; set; } /// /// Gets or sets a value indicating whether document formatting is supported. /// [JsonPropertyName("documentFormattingProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? DocumentFormattingProvider - { - get; - set; - } + public SumType? DocumentFormattingProvider { get; set; } /// /// Gets or sets a value indicating whether document range formatting is supported. /// [JsonPropertyName("documentRangeFormattingProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? DocumentRangeFormattingProvider - { - get; - set; - } + public SumType? DocumentRangeFormattingProvider { get; set; } /// /// Gets or sets the value which indicates if document on type formatting is supported. /// [JsonPropertyName("documentOnTypeFormattingProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DocumentOnTypeFormattingOptions? DocumentOnTypeFormattingProvider - { - get; - set; - } + public DocumentOnTypeFormattingOptions? DocumentOnTypeFormattingProvider { get; set; } /// /// Gets or sets a value indicating whether rename is supported. /// [JsonPropertyName("renameProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? RenameProvider - { - get; - set; - } + public SumType? RenameProvider { get; set; } /// /// Gets or sets the value which indicates if folding range is supported. /// [JsonPropertyName("foldingRangeProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? FoldingRangeProvider - { - get; - set; - } + public SumType? FoldingRangeProvider { get; set; } /// /// Gets or sets the value which indicates if execute command is supported. /// [JsonPropertyName("executeCommandProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public ExecuteCommandOptions? ExecuteCommandProvider - { - get; - set; - } + public ExecuteCommandOptions? ExecuteCommandProvider { get; set; } /// - /// Gets or sets a value indicating whether workspace symbols are supported. + /// Gets or sets a value indicating whether the server supports linked editing range. /// - [JsonPropertyName("workspaceSymbolProvider")] + [JsonPropertyName("linkedEditingRangeProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? WorkspaceSymbolProvider - { - get; - set; - } + public SumType? LinkedEditingRangeProvider { get; set; } /// - /// Gets or sets experimental server capabilities. + /// Gets or sets the value which indicates if semantic tokens is supported. /// - [JsonPropertyName("experimental")] + [JsonPropertyName("semanticTokensProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public object? Experimental - { - get; - set; - } + public SemanticTokensOptions? SemanticTokensOptions { get; set; } /// - /// Gets or sets a value indicating whether the server supports linked editing range. + /// Gets or sets the value which indicates what support the server has for inlay hints. /// - [JsonPropertyName("linkedEditingRangeProvider")] + [JsonPropertyName("inlayHintProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? LinkedEditingRangeProvider - { - get; - set; - } + public SumType? InlayHintOptions { get; set; } /// - /// Gets or sets the value which indicates if semantic tokens is supported. + /// Gets or sets the value which indicates what support the server has for pull diagnostics. /// - [JsonPropertyName("semanticTokensProvider")] + [JsonPropertyName("diagnosticProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SemanticTokensOptions? SemanticTokensOptions - { - get; - set; - } + public DiagnosticOptions? DiagnosticOptions { get; set; } /// - /// Gets or sets the value which indicates what support the server has for pull diagnostics. + /// Gets or sets a value indicating whether workspace symbols are supported. /// - [JsonPropertyName("diagnosticProvider")] + [JsonPropertyName("workspaceSymbolProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DiagnosticOptions? DiagnosticOptions - { - get; - set; - } + public SumType? WorkspaceSymbolProvider { get; set; } /// - /// Gets or sets the value which indicates what support the server has for inlay hints. + /// Gets or sets experimental server capabilities. /// - [JsonPropertyName("inlayHintProvider")] + [JsonPropertyName("experimental")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? InlayHintOptions - { - get; - set; - } + public object? Experimental { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index ee1b4051ae3ea..ad4a7c4347338 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -13,256 +13,166 @@ namespace Roslyn.LanguageServer.Protocol /// internal class TextDocumentClientCapabilities { + // NOTE: these are kept in the same order as the spec to make them easier to update + /// /// Gets or sets the synchronization setting. /// [JsonPropertyName("synchronization")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SynchronizationSetting? Synchronization - { - get; - set; - } + public SynchronizationSetting? Synchronization { get; set; } /// /// Gets or sets the completion setting. /// [JsonPropertyName("completion")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public CompletionSetting? Completion - { - get; - set; - } + public CompletionSetting? Completion { get; set; } /// /// Gets or sets the setting which determines if hover can be dynamically registered. /// [JsonPropertyName("hover")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public HoverSetting? Hover - { - get; - set; - } + public HoverSetting? Hover { get; set; } /// /// Gets or sets the setting which determines if signature help can be dynamically registered. /// [JsonPropertyName("signatureHelp")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SignatureHelpSetting? SignatureHelp - { - get; - set; - } + public SignatureHelpSetting? SignatureHelp { get; set; } /// /// Gets or sets the setting which determines if definition can be dynamically registered. /// [JsonPropertyName("definition")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? Definition - { - get; - set; - } + public DynamicRegistrationSetting? Definition { get; set; } /// /// Gets or sets the settings which determines if type definition can be dynamically registered. /// [JsonPropertyName("typeDefinition")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? TypeDefinition - { - get; - set; - } + public DynamicRegistrationSetting? TypeDefinition { get; set; } /// /// Gets or sets the settings which determines if implementation can be dynamically registered. /// [JsonPropertyName("implementation")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? Implementation - { - get; - set; - } + public DynamicRegistrationSetting? Implementation { get; set; } /// /// Gets or sets the setting which determines if references can be dynamically registered. /// [JsonPropertyName("references")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? References - { - get; - set; - } + public DynamicRegistrationSetting? References { get; set; } /// /// Gets or sets the setting which determines if document highlight can be dynamically registered. /// [JsonPropertyName("documentHighlight")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? DocumentHighlight - { - get; - set; - } + public DynamicRegistrationSetting? DocumentHighlight { get; set; } /// /// Gets or sets the setting which determines if document symbol can be dynamically registered. /// [JsonPropertyName("documentSymbol")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DocumentSymbolSetting? DocumentSymbol - { - get; - set; - } + public DocumentSymbolSetting? DocumentSymbol { get; set; } /// /// Gets or sets the setting which determines if code action can be dynamically registered. /// [JsonPropertyName("codeAction")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public CodeActionSetting? CodeAction - { - get; - set; - } + public CodeActionSetting? CodeAction { get; set; } /// /// Gets or sets the setting which determines if code lens can be dynamically registered. /// [JsonPropertyName("codeLens")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? CodeLens - { - get; - set; - } + public DynamicRegistrationSetting? CodeLens { get; set; } /// /// Gets or sets the setting which determines if document link can be dynamically registered. /// [JsonPropertyName("documentLink")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? DocumentLink - { - get; - set; - } + public DynamicRegistrationSetting? DocumentLink { get; set; } /// /// Gets or sets the setting which determines if formatting can be dynamically registered. /// [JsonPropertyName("formatting")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? Formatting - { - get; - set; - } + public DynamicRegistrationSetting? Formatting { get; set; } /// /// Gets or sets the setting which determines if range formatting can be dynamically registered. /// [JsonPropertyName("rangeFormatting")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? RangeFormatting - { - get; - set; - } + public DynamicRegistrationSetting? RangeFormatting { get; set; } /// /// Gets or sets the setting which determines if on type formatting can be dynamically registered. /// [JsonPropertyName("onTypeFormatting")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? OnTypeFormatting - { - get; - set; - } + public DynamicRegistrationSetting? OnTypeFormatting { get; set; } /// /// Gets or sets the setting which determines if rename can be dynamically registered. /// [JsonPropertyName("rename")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public RenameClientCapabilities? Rename - { - get; - set; - } + public RenameClientCapabilities? Rename { get; set; } /// /// Gets or sets the setting publish diagnostics setting. /// [JsonPropertyName("publishDiagnostics")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public PublishDiagnosticsSetting? PublishDiagnostics - { - get; - set; - } + public PublishDiagnosticsSetting? PublishDiagnostics { get; set; } /// /// Gets or sets the setting which determines how folding range is supported. /// [JsonPropertyName("foldingRange")] - public FoldingRangeSetting? FoldingRange - { - get; - set; - } + public FoldingRangeSetting? FoldingRange { get; set; } /// /// Gets or sets the setting which determines if linked editing range can be dynamically registered. /// [JsonPropertyName("linkedEditingRange")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting LinkedEditingRange - { - get; - set; - } + public DynamicRegistrationSetting LinkedEditingRange { get; set; } /// /// Gets or sets a setting indicating whether semantic tokens is supported. /// [JsonPropertyName("semanticTokens")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SemanticTokensSetting? SemanticTokens - { - get; - set; - } + public SemanticTokensSetting? SemanticTokens { get; set; } /// /// Gets or sets the setting which determines what support the client has for pull diagnostics. /// - [JsonPropertyName("diagnostic")] + [JsonPropertyName("inlayHint")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DiagnosticSetting? Diagnostic - { - get; - set; - } + public InlayHintSetting? InlayHint { get; set; } /// /// Gets or sets the setting which determines what support the client has for pull diagnostics. /// - [JsonPropertyName("inlayHint")] + [JsonPropertyName("diagnostic")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public InlayHintSetting? InlayHint - { - get; - set; - } + public DiagnosticSetting? Diagnostic { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs index a045161ec3973..02083af20d7d6 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs @@ -8,130 +8,89 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents workspace capabilities. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class WorkspaceClientCapabilities { + // NOTE: these are kept in the same order as the spec to make them easier to update + /// /// Gets or sets a value indicating whether apply edit is supported. /// [JsonPropertyName("applyEdit")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool ApplyEdit - { - get; - set; - } + public bool ApplyEdit { get; set; } /// /// Gets or sets the workspace edit setting. /// [JsonPropertyName("workspaceEdit")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public WorkspaceEditSetting? WorkspaceEdit - { - get; - set; - } + public WorkspaceEditSetting? WorkspaceEdit { get; set; } /// /// Gets or sets the setting which determines if did change configuration can be dynamically registered. /// [JsonPropertyName("didChangeConfiguration")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? DidChangeConfiguration - { - get; - set; - } + public DynamicRegistrationSetting? DidChangeConfiguration { get; set; } /// /// Gets or sets the setting which determines if did change watched files can be dynamically registered. /// [JsonPropertyName("didChangeWatchedFiles")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? DidChangeWatchedFiles - { - get; - set; - } + public DynamicRegistrationSetting? DidChangeWatchedFiles { get; set; } /// /// Gets or sets the setting which determines if symbols can be dynamically registered. /// [JsonPropertyName("symbol")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SymbolSetting? Symbol - { - get; - set; - } + public SymbolSetting? Symbol { get; set; } /// /// Gets or sets the setting which determines if execute command can be dynamically registered. /// [JsonPropertyName("executeCommand")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? ExecuteCommand - { - get; - set; - } + public DynamicRegistrationSetting? ExecuteCommand { get; set; } /// - /// Gets or sets capabilities specific to the semantic token requests scoped to the workspace. + /// Gets or sets the capabilities if client support 'workspace/configuration' requests. /// - [JsonPropertyName("semanticTokens")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SemanticTokensWorkspaceSetting? SemanticTokens - { - get; - set; - } + [JsonPropertyName("configuration")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool Configuration { get; set; } /// - /// Gets or sets capabilities indicating what support the client has for workspace pull diagnostics. + /// Gets or sets capabilities specific to the semantic token requests scoped to the workspace. /// - [JsonPropertyName("diagnostics")] + [JsonPropertyName("semanticTokens")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DiagnosticWorkspaceSetting? Diagnostics - { - get; - set; - } + public SemanticTokensWorkspaceSetting? SemanticTokens { get; set; } /// - /// Gets or sets the capabilities if client support 'workspace/configuration' requests. + /// Gets of sets capabilities specific to the code lens requests scoped to the workspace. /// - [JsonPropertyName("configuration")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool Configuration - { - get; - set; - } + [JsonPropertyName("codeLens")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public CodeLensWorkspaceSetting? CodeLens { get; set; } /// /// Gets of sets capabilities specific to the inlay hint requests scoped to the workspace. /// [JsonPropertyName("inlayHint")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public InlayHintWorkspaceSetting? InlayHint - { - get; - set; - } + public InlayHintWorkspaceSetting? InlayHint { get; set; } /// - /// Gets of sets capabilities specific to the code lens requests scoped to the workspace. + /// Gets or sets capabilities indicating what support the client has for workspace pull diagnostics. /// - [JsonPropertyName("codeLens")] + [JsonPropertyName("diagnostics")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public CodeLensWorkspaceSetting? CodeLens - { - get; - set; - } + public DiagnosticWorkspaceSetting? Diagnostics { get; set; } } } From d1fdfed8aa58e95ab89bffbd60be81fcfb96b809 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Tue, 4 Jun 2024 21:57:11 -0400 Subject: [PATCH 03/46] LSP Protocol: Add window/general client capabilities --- .../Protocol/Protocol/ClientCapabilities.cs | 18 ++++- .../Protocol/GeneralClientCapabilities.cs | 66 +++++++++++++++++++ .../Protocol/MarkdownClientCapabilities.cs | 39 +++++++++++ .../MessageActionItemClientCapabilities.cs | 23 +++++++ .../Protocol/Protocol/PositionEncodingKind.cs | 42 ++++++++++++ .../RegularExpressionsClientCapabilities.cs | 31 +++++++++ .../ShowDocumentClientCapabilities.cs | 24 +++++++ .../ShowMessageRequestClientCapabilities.cs | 24 +++++++ .../Protocol/Protocol/StaleRequestSupport.cs | 28 ++++++++ .../Protocol/WindowClientCapabilities.cs | 45 +++++++++++++ 10 files changed, 339 insertions(+), 1 deletion(-) create mode 100644 src/LanguageServer/Protocol/Protocol/GeneralClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/MarkdownClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/MessageActionItemClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/PositionEncodingKind.cs create mode 100644 src/LanguageServer/Protocol/Protocol/RegularExpressionsClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/ShowDocumentClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/ShowMessageRequestClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/StaleRequestSupport.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WindowClientCapabilities.cs diff --git a/src/LanguageServer/Protocol/Protocol/ClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ClientCapabilities.cs index ba9367aea66dd..a2c69b9cc040d 100644 --- a/src/LanguageServer/Protocol/Protocol/ClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ClientCapabilities.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents client capabilities. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class ClientCapabilities { @@ -35,6 +36,21 @@ public TextDocumentClientCapabilities? TextDocument set; } + /// + /// Window specific client capabilities. + /// + [JsonPropertyName("window")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public WindowClientCapabilities? Window { get; init; } + + /// + /// Capabilities specific to the notebook document support. + /// + /// Since LSP 3.17 + [JsonPropertyName("general")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public GeneralClientCapabilities? General { get; init; } + /// /// Gets or sets the experimental capabilities. /// diff --git a/src/LanguageServer/Protocol/Protocol/GeneralClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/GeneralClientCapabilities.cs new file mode 100644 index 0000000000000..ef59c332a543b --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/GeneralClientCapabilities.cs @@ -0,0 +1,66 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Class which represents general client capabilities. +/// +/// Since LSP 3.16 +internal class GeneralClientCapabilities +{ + /// + /// Client capability that signals how the client + /// handles stale requests (e.g. a request + /// for which the client will not process the response + /// anymore since the information is outdated). + /// + /// Since LSP 3.17 + [JsonPropertyName("staleRequestSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public StaleRequestSupport? StaleRequestSupport { get; init; } + + /// + /// Client capabilities specific to regular expressions. + /// + [JsonPropertyName("regularExpressions")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public RegularExpressionsClientCapabilities? RegularExpressions { get; init; } + + /// + /// Client capabilities specific to the client's markdown parser. + /// + [JsonPropertyName("markdown")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public MarkdownClientCapabilities? Markdown { get; init; } + + /// + /// The position encodings supported by the client. Client and server + /// have to agree on the same position encoding to ensure that offsets + /// (e.g. character position in a line) are interpreted the same on both + /// side. + /// + /// To keep the protocol backwards compatible the following applies: if + /// the value 'utf-16' is missing from the array of position encodings + /// servers can assume that the client supports UTF-16. UTF-16 is + /// therefore a mandatory encoding. + /// + /// + /// If omitted it defaults to ['utf-16']. + /// + /// + /// Implementation considerations: since the conversion from one encoding + /// into another requires the content of the file / line the conversion + /// is best done where the file is read which is usually on the server + /// side. + /// + /// + /// Since LSP 3.17 + [JsonPropertyName("positionEncodings")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public PositionEncodingKind[]? PositionEncodings { get; init; } + +} diff --git a/src/LanguageServer/Protocol/Protocol/MarkdownClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/MarkdownClientCapabilities.cs new file mode 100644 index 0000000000000..9276f7c6f4eb2 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/MarkdownClientCapabilities.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Describes capabilities of the client's markdown parser +/// +/// +/// See the Language Server Protocol specification for additional information. +/// +/// Since LSP 3.16 +internal class MarkdownClientCapabilities +{ + /// + /// The name of the parser. + /// + [JsonPropertyName("parser")] + [JsonRequired] + public string Parser { get; init; } + + /// + /// The version of the parser. + /// + [JsonPropertyName("version")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Version { get; init; } + + /// + /// A list of HTML tags that the client allows/support in markdown + /// + /// Since LSP 3.17 + [JsonPropertyName("allowedTags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string[]? AllowedTags { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/MessageActionItemClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/MessageActionItemClientCapabilities.cs new file mode 100644 index 0000000000000..5f1dd17c821fa --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/MessageActionItemClientCapabilities.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `MessageActionItem` type +/// +/// Since LSP 3.16 +internal class MessageActionItemClientCapabilities +{ + /// + /// Whether the client supports additional attributes which + /// are preserved and sent back to the server in the + /// request's response. + /// + [JsonPropertyName("additionalPropertiesSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool AdditionalPropertiesSupport { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/PositionEncodingKind.cs b/src/LanguageServer/Protocol/Protocol/PositionEncodingKind.cs new file mode 100644 index 0000000000000..d433d2333ebeb --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/PositionEncodingKind.cs @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.ComponentModel; +using System.Text.Json.Serialization; + +/// +/// The encoding used for representing character offsets in documents +/// as negotiated between the client and server during initialization +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +[JsonConverter(typeof(StringEnumConverter))] +[TypeConverter(typeof(StringEnumConverter.TypeConverter))] +internal readonly record struct PositionEncodingKind(string Value) : IStringEnum +{ + /// + /// Character offsets count UTF-8 code units (e.g bytes). + /// + public static readonly PositionEncodingKind UTF8 = new("utf-8"); + + /// + /// Character offsets count UTF-16 code units. + /// + /// This is the default and must always be supported by servers + /// + /// + public static readonly PositionEncodingKind UTF16 = new("utf-16"); + + /// + /// Character offsets count UTF-32 code units. + /// + /// Implementation note: these are the same as Unicode code points, so + /// this may also be used for an encoding-agnostic + /// representation of character offsets. + /// + public static readonly PositionEncodingKind UTF32 = new("utf-32"); +} diff --git a/src/LanguageServer/Protocol/Protocol/RegularExpressionsClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/RegularExpressionsClientCapabilities.cs new file mode 100644 index 0000000000000..e0a4ee2e32893 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/RegularExpressionsClientCapabilities.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Describes the client's regular expression engine +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class RegularExpressionsClientCapabilities +{ + /// + /// The name of the regular expression engine. + /// + [JsonPropertyName("engine")] + [JsonRequired] + public string Engine { get; init; } + + /// + /// The version of the regular expression engine. + /// + [JsonPropertyName("version")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Version { get; init; } + +} diff --git a/src/LanguageServer/Protocol/Protocol/ShowDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ShowDocumentClientCapabilities.cs new file mode 100644 index 0000000000000..77e02ee12fb42 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ShowDocumentClientCapabilities.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Client capabilities for the 'window/showDocument' request +/// +/// +/// See the Language Server Protocol specification for additional information. +/// +/// Since LSP 3.16 +internal class ShowDocumentClientCapabilities +{ + /// + /// The client has support for the show document request. + /// + [JsonPropertyName("support")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool Support { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/ShowMessageRequestClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ShowMessageRequestClientCapabilities.cs new file mode 100644 index 0000000000000..6b03b48c5f284 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ShowMessageRequestClientCapabilities.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the 'window/showMessage' request +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class ShowMessageRequestClientCapabilities +{ + /// + /// Capabilities specific to the `MessageActionItem` type + /// + [JsonPropertyName("messageActionItem")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public MessageActionItemClientCapabilities? MessageActionItem { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/StaleRequestSupport.cs b/src/LanguageServer/Protocol/Protocol/StaleRequestSupport.cs new file mode 100644 index 0000000000000..70163d1c45787 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/StaleRequestSupport.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Describes how the client handles stale requests +/// +internal class StaleRequestSupport +{ + /// + /// The client will actively cancel the request. + /// + [JsonPropertyName("cancel")] + [JsonRequired] + public bool Cancel { get; init; } + + /// + /// The list of requests for which the client + /// will retry the request if it receives a + /// response with error code `ContentModified` + /// + [JsonPropertyName("retryOnContentModified")] + public string[] RetryOnContentModified { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/WindowClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WindowClientCapabilities.cs new file mode 100644 index 0000000000000..d20a7703ba35c --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WindowClientCapabilities.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Notebook specific client capabilities +/// +/// Since LSP 3.15 +internal class WindowClientCapabilities : IWorkDoneProgressOptions +{ + /// + /// Indicates whether the client supports server initiated + /// progress using the `window/workDoneProgress/create` request. + /// + /// The capability also controls Whether client supports handling + /// of progress notifications. If set, servers are allowed to report a + /// `workDoneProgress` property in the request specific server + /// capabilities. + /// + /// + /// Since LSP 3.15 + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } + + /// + /// The client supports sending execution summary data per cell. + /// + /// Since LSP 3.16 + [JsonPropertyName("showMessage")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ShowMessageRequestClientCapabilities? ShowMessage { get; init; } + + /// + /// Client capabilities for the show document request. + /// + /// Since LSP 3.16 + [JsonPropertyName("showDocument")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public ShowDocumentClientCapabilities? ShowDocument { get; init; } +} From 4a62b71c3de65c0d88b50ec25f960a825c7be720 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Wed, 5 Jun 2024 03:55:23 -0400 Subject: [PATCH 04/46] LSP Protocol: Update lifecycle messages --- .../Protocol/Protocol/ClientInfo.cs | 28 ++++ ...itializeParamsWorkspaceFoldersConverter.cs | 38 +++++ .../Protocol/Protocol/InitializeParams.cs | 44 +++++- .../Protocol/Protocol/InitializeResult.cs | 9 ++ .../Protocol/Protocol/LogTraceParams.cs | 30 ++++ .../Protocol/Protocol/Methods.Lifecyle.cs | 147 ++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 67 +------- .../Protocol/Protocol/Registration.cs | 2 + .../Protocol/Protocol/RegistrationParams.cs | 1 + .../Protocol/Protocol/ServerCapabilities.cs | 17 +- .../Protocol/Protocol/ServerInfo.cs | 31 ++++ .../Protocol/Protocol/SetTraceParams.cs | 23 +++ .../Protocol/Protocol/TraceValue.cs | 24 +++ .../Protocol/Protocol/Unregistration.cs | 2 + .../Protocol/Protocol/UnregistrationParams.cs | 4 +- .../Protocol/Protocol/WorkspaceFolder.cs | 28 ++++ 16 files changed, 421 insertions(+), 74 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/ClientInfo.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Converters/InitializeParamsWorkspaceFoldersConverter.cs create mode 100644 src/LanguageServer/Protocol/Protocol/LogTraceParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Methods.Lifecyle.cs create mode 100644 src/LanguageServer/Protocol/Protocol/ServerInfo.cs create mode 100644 src/LanguageServer/Protocol/Protocol/SetTraceParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/TraceValue.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WorkspaceFolder.cs diff --git a/src/LanguageServer/Protocol/Protocol/ClientInfo.cs b/src/LanguageServer/Protocol/Protocol/ClientInfo.cs new file mode 100644 index 0000000000000..6a79e0e0c72f4 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ClientInfo.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Information about the client +/// +/// Since LSP 3.16 +internal class ClientInfo +{ + /// + /// The client's name as defined by the client + /// + [JsonPropertyName("name")] + [JsonRequired] + public string Name { get; set; } + + /// + /// The client's version as defined by the client + /// + [JsonPropertyName("version")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Version { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Converters/InitializeParamsWorkspaceFoldersConverter.cs b/src/LanguageServer/Protocol/Protocol/Converters/InitializeParamsWorkspaceFoldersConverter.cs new file mode 100644 index 0000000000000..b9fbf0fe107b4 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Converters/InitializeParamsWorkspaceFoldersConverter.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// This is used to surface the distinction between "not supported" and "none open" for +/// +/// Per the LSP Spec: +/// +/// +/// If the property is NOT present, the client does not support workspace folders. +/// +/// +/// If the property is present but null, or an empty array, the client supports workspace folders but none are open. +/// +/// +/// +/// To represent this on , we use +/// to represent that the client does not support workspace folders, and use an empty array to represent that none are open. +/// +internal class InitializeParamsWorkspaceFoldersConverter : JsonConverter +{ + public override WorkspaceFolder[]? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return JsonSerializer.Deserialize(ref reader, options) ?? []; + } + + public override void Write(Utf8JsonWriter writer, WorkspaceFolder[]? value, JsonSerializerOptions options) + { + JsonSerializer.Serialize(writer, value, options); + } +} diff --git a/src/LanguageServer/Protocol/Protocol/InitializeParams.cs b/src/LanguageServer/Protocol/Protocol/InitializeParams.cs index f4a1f88cceb2b..1d6aa360525e3 100644 --- a/src/LanguageServer/Protocol/Protocol/InitializeParams.cs +++ b/src/LanguageServer/Protocol/Protocol/InitializeParams.cs @@ -10,10 +10,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents the parameter sent with an initialize method request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class InitializeParams + internal class InitializeParams : IWorkDoneProgressParams { /// /// Gets or sets the ID of the process which launched the language server. @@ -25,6 +26,13 @@ public int? ProcessId set; } + /// + /// Information about the client. + /// + /// Since LSP 3.15 + [JsonPropertyName("clientInfo")] + public ClientInfo? ClientInfo { get; set; } + /// /// Gets or sets the locale the client is currently showing the user interface in. /// This must not necessarily be the locale of the operating system. @@ -32,6 +40,7 @@ public int? ProcessId /// Uses IETF language tags as the value's syntax. /// (See https://en.wikipedia.org/wiki/IETF_language_tag) /// + /// Since LSP 3.16 [JsonPropertyName("locale")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Locale @@ -45,7 +54,7 @@ public string? Locale /// [JsonPropertyName("rootPath")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - [Obsolete("Deprecated in favour of RootUri")] + [Obsolete("Deprecated in favor of RootUri")] public string? RootPath { get; @@ -53,12 +62,10 @@ public string? RootPath } /// - /// Gets or sets the workspace root path. + /// Gets or sets the workspace root path. Take precedence over if both are set. /// - /// - /// This should be a string representation of an URI. - /// [JsonPropertyName("rootUri")] + [Obsolete("Deprecated in favor of WorkspaceFolders")] [JsonConverter(typeof(DocumentUriConverter))] public Uri? RootUri { @@ -100,5 +107,28 @@ public TraceSetting Trace #pragma warning disable SA1500, SA1513 // Braces for multi-line statements should not share line, Closing brace should be followed by blank line } = TraceSetting.Off; #pragma warning restore SA1500, SA1513 // Braces for multi-line statements should not share line, Closing brace should be followed by blank line + + /// + /// Workspace folders configured in the client when the server starts. + /// + /// An empty array indicates that the client supports workspace folders but none are open, + /// and indicates that the client does not support workspace folders. + /// + /// + /// Note that this is a minor change from the raw protocol, where if the property is present in JSON but , + /// it is equivalent to an empty array value. This distinction cannot easily be represented idiomatically in .NET, + /// but is not important to preserve. + /// + /// + /// Since LSP 3.6 + [JsonPropertyName("workspaceFolders")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonConverter(typeof(InitializeParamsWorkspaceFoldersConverter))] + public WorkspaceFolder[]? WorkspaceFolders { get; init; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/InitializeResult.cs b/src/LanguageServer/Protocol/Protocol/InitializeResult.cs index b3cf86842bdfd..6653657181d1c 100644 --- a/src/LanguageServer/Protocol/Protocol/InitializeResult.cs +++ b/src/LanguageServer/Protocol/Protocol/InitializeResult.cs @@ -17,10 +17,19 @@ internal class InitializeResult /// Gets or sets the server capabilities. /// [JsonPropertyName("capabilities")] + [JsonRequired] public ServerCapabilities Capabilities { get; set; } + + /// + /// Information about the server name and version + /// + /// Since LSP 3.15 + [JsonPropertyName("serverInfo")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ServerInfo? ServerInfo { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/LogTraceParams.cs b/src/LanguageServer/Protocol/Protocol/LogTraceParams.cs new file mode 100644 index 0000000000000..ba127418ecf2c --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/LogTraceParams.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Class representing the parameters for the notification. +/// +/// See the Language Server Protocol specification for additional information. +/// +internal class LogTraceParams +{ + /// + /// The message to be logged. + /// + [JsonPropertyName("message")] + [JsonRequired] + public string Message { get; init; } + + /// + /// Additional information that can be computed if the `trace` configuration + /// is set to . + /// + [JsonPropertyName("verbose")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Verbose { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Lifecyle.cs b/src/LanguageServer/Protocol/Protocol/Methods.Lifecyle.cs new file mode 100644 index 0000000000000..535f76eb920c9 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Methods.Lifecyle.cs @@ -0,0 +1,147 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#lifeCycleMessages +partial class Methods +{ + // NOTE: these are sorted/grouped in the order used by the spec + + /// + /// Method name for 'initialize'. + /// + /// The initialize request is sent as the first request from the client to the server and is used to exchange capabilities. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string InitializeName = "initialize"; + + /// + /// Strongly typed message object for 'initialize'. + /// + public static readonly LspRequest Initialize = new(InitializeName); + + /// + /// Method name for 'initialized'. + /// + /// The initialized notification is sent from the client to the server after the client received the + /// result of the initialize request but before the client is sending any other request or notification to the server. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string InitializedName = "initialized"; + + /// + /// Strongly typed message object for 'initialized'. + /// + public static readonly LspNotification Initialized = new(InitializedName); + + /// + /// Method name for 'client/registerCapability'. + /// + /// The client/registerCapability request is sent from the server to the client to register for a new capability on the client side. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string ClientRegisterCapabilityName = "client/registerCapability"; + + /// + /// Strongly typed message object for 'client/registerCapability'. + /// + public static readonly LspRequest ClientRegisterCapability = new(ClientRegisterCapabilityName); + + /// + /// Method name for 'client/unregisterCapability'. + /// + /// The client/unregisterCapability request is sent from the server to the client to unregister a previously registered capability. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string ClientUnregisterCapabilityName = "client/unregisterCapability"; + + /// + /// Strongly typed message object for 'client/unregisterCapability'. + /// + public static readonly LspRequest ClientUnregisterCapability = new(ClientUnregisterCapabilityName); + + /// + /// Method name for '$/setTrace' notifications. + /// + /// A notification that should be used by the client to modify the trace setting of the server. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string SetTraceName = "$/setTrace"; + + /// + /// Strongly typed message object for '$/setTrace'. + /// + public static readonly LspNotification SetTrace = new(SetTraceName); + + /// + /// Method name for '$/logTrace' notifications. + /// + /// A notification to log the trace of the server’s execution. This must + /// respect the current trace configuration set by the $/logTrace notification. + /// + /// + /// This should only be used for systematic trace reporting For single debugging messages, + /// the server should instead send window/logMessage notifications. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string LogTraceName = "$/logTrace"; + + /// + /// Strongly typed message object for '$/logTrace'. + /// + public static readonly LspNotification LogTrace = new(LogTraceName); + + /// + /// Method name for 'shutdown'. + /// + /// The shutdown request is sent from the client to the server. It asks the server to shut + /// down, but to not exit (otherwise the response might not be delivered correctly to the + /// client). There is a separate exit notification that asks the server to exit. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string ShutdownName = "shutdown"; + + /// + /// Strongly typed message object for 'shutdown'. + /// + public static readonly LspRequest Shutdown = new(ShutdownName); + + /// + /// Method name for 'exit'. + /// + /// A notification to ask the server to exit its process. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string ExitName = "exit"; + + /// + /// Strongly typed message object for 'exit'. + /// + public static readonly LspNotification Exit = new(ExitName); +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index 0bf3fd4109733..af71d249a9482 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -7,17 +7,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which contains the string values for all common language protocol methods. /// - internal static class Methods + internal static partial class Methods { - /// - /// Method name for 'initialize'. - /// - public const string InitializeName = "initialize"; - - /// - /// Method name for 'initialized'. - /// - public const string InitializedName = "initialized"; + // NOTE: these are sorted/grouped in the order used by the spec /// /// Method name for '$/progress' notifications. @@ -29,11 +21,6 @@ internal static class Methods /// public const string PartialResultTokenName = "partialResultToken"; - /// - /// Name of the progress token in the request. - /// - public const string PartialResultTokenPropertyName = "PartialResultToken"; - /// /// Name of the work done token in the request. /// @@ -299,41 +286,11 @@ internal static class Methods /// public const string WorkspaceInlayHintRefreshName = "workspace/inlayHint/refresh"; - /// - /// Method name for 'shutdown'. - /// - public const string ShutdownName = "shutdown"; - - /// - /// Method name for 'exit'. - /// - public const string ExitName = "exit"; - /// /// Method name for 'telemetry/event'. /// public const string TelemetryEventName = "telemetry/event"; - /// - /// Method name for 'client/registerCapability'. - /// - public const string ClientRegisterCapabilityName = "client/registerCapability"; - - /// - /// Method name for 'client/unregisterCapability'. - /// - public const string ClientUnregisterCapabilityName = "client/unregisterCapability"; - - /// - /// Strongly typed message object for 'initialize'. - /// - public static readonly LspRequest Initialize = new LspRequest(InitializeName); - - /// - /// Strongly typed message object for 'initialized'. - /// - public static readonly LspNotification Initialized = new LspNotification(InitializedName); - /// /// Strongly typed message object for 'textDocument/codeAction'. /// @@ -559,31 +516,11 @@ internal static class Methods /// public static readonly LspRequest WorkspaceInlayHintRefresh = new LspRequest(WorkspaceInlayHintRefreshName); - /// - /// Strongly typed message object for 'shutdown'. - /// - public static readonly LspRequest Shutdown = new LspRequest(ShutdownName); - - /// - /// Strongly typed message object for 'exit'. - /// - public static readonly LspNotification Exit = new LspNotification(ExitName); - /// /// Strongly typed message object for 'telemetry/event'. /// public static readonly LspNotification TelemetryEvent = new LspNotification(TelemetryEventName); - /// - /// Strongly typed message object for 'client/registerCapability'. - /// - public static readonly LspRequest ClientRegisterCapability = new LspRequest(ClientRegisterCapabilityName); - - /// - /// Strongly typed message object for 'client/unregisterCapability'. - /// - public static readonly LspRequest ClientUnregisterCapability = new LspRequest(ClientUnregisterCapabilityName); - /// /// Strongly typed message object for 'textDocument/semanticTokens/full'. /// diff --git a/src/LanguageServer/Protocol/Protocol/Registration.cs b/src/LanguageServer/Protocol/Protocol/Registration.cs index 906b4f4277d8e..d3b0e33e58b73 100644 --- a/src/LanguageServer/Protocol/Protocol/Registration.cs +++ b/src/LanguageServer/Protocol/Protocol/Registration.cs @@ -17,6 +17,7 @@ internal class Registration /// Gets or sets the id used to register the request. This can be used to deregister later. /// [JsonPropertyName("id")] + [JsonRequired] public string Id { get; @@ -27,6 +28,7 @@ public string Id /// Gets or sets the method / capability to register for. /// [JsonPropertyName("method")] + [JsonRequired] public string Method { get; diff --git a/src/LanguageServer/Protocol/Protocol/RegistrationParams.cs b/src/LanguageServer/Protocol/Protocol/RegistrationParams.cs index 4125036ab0e1f..25c68fca57c41 100644 --- a/src/LanguageServer/Protocol/Protocol/RegistrationParams.cs +++ b/src/LanguageServer/Protocol/Protocol/RegistrationParams.cs @@ -17,6 +17,7 @@ internal class RegistrationParams /// Gets or sets the set of capabilities that are being registered. /// [JsonPropertyName("registrations")] + [JsonRequired] public Registration[] Registrations { get; diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index c78740a3de3ca..68c83dfe4c233 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -9,13 +9,28 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents server capabilities. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class ServerCapabilities { // NOTE: these are kept in the same order as the spec to make them easier to update + /// + /// The position encoding the server picked from the encodings offered + /// by the client via the client capability `general.positionEncodings`. + /// + /// If the client didn't provide any position encodings the only valid + /// value that a server can return is 'utf-16'. + /// If omitted it defaults to 'utf-16'. + /// + /// + /// Since LSP 3.16 + [JsonPropertyName("positionEncoding")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public PositionEncodingKind? PositionEncoding { get; init; } + /// /// Gets or sets the value which indicates how text document are synced. /// diff --git a/src/LanguageServer/Protocol/Protocol/ServerInfo.cs b/src/LanguageServer/Protocol/Protocol/ServerInfo.cs new file mode 100644 index 0000000000000..1f2deef039f3e --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ServerInfo.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Information about the server name and version +/// +/// Since LSP 3.15 +internal class ServerInfo +{ + + /// + /// The server name + /// + [JsonPropertyName("name")] + [JsonRequired] + public string Name { get; init; } + + + + /// + /// The server version + /// + [JsonPropertyName("version")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Version { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/SetTraceParams.cs b/src/LanguageServer/Protocol/Protocol/SetTraceParams.cs new file mode 100644 index 0000000000000..3b3cbee100776 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/SetTraceParams.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Class representing the parameters for the $/setTrace notification. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class SetTraceParams +{ + /// + /// The new value that should be assigned to the trace setting. + /// + [JsonPropertyName("value")] + [JsonRequired] + public TraceValue Value { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/TraceValue.cs b/src/LanguageServer/Protocol/Protocol/TraceValue.cs new file mode 100644 index 0000000000000..6951508b62953 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/TraceValue.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A TraceValue represents the level of verbosity with which the server systematically reports its +/// execution trace using . The initial trace value is set by the +/// client at initialization and can be modified later using the notification. +/// +/// See the Language Server Protocol specification for additional information. +/// +[JsonConverter(typeof(StringEnumConverter))] +[TypeConverter(typeof(StringEnumConverter.TypeConverter))] +internal readonly record struct TraceValue(string Value) : IStringEnum +{ + public static readonly TraceValue Off = new("off"); + public static readonly TraceValue Messages = new("messages"); + public static readonly TraceValue Verbose = new("verbose"); +} diff --git a/src/LanguageServer/Protocol/Protocol/Unregistration.cs b/src/LanguageServer/Protocol/Protocol/Unregistration.cs index ea2c9e8efbea3..9e0b337de4a22 100644 --- a/src/LanguageServer/Protocol/Protocol/Unregistration.cs +++ b/src/LanguageServer/Protocol/Protocol/Unregistration.cs @@ -17,6 +17,7 @@ internal class Unregistration /// Gets or sets the id of the unregistration. /// [JsonPropertyName("id")] + [JsonRequired] public string Id { get; @@ -27,6 +28,7 @@ public string Id /// Gets or sets the method to unregister. /// [JsonPropertyName("method")] + [JsonRequired] public string Method { get; diff --git a/src/LanguageServer/Protocol/Protocol/UnregistrationParams.cs b/src/LanguageServer/Protocol/Protocol/UnregistrationParams.cs index 118084c82212d..ca7108dee7b93 100644 --- a/src/LanguageServer/Protocol/Protocol/UnregistrationParams.cs +++ b/src/LanguageServer/Protocol/Protocol/UnregistrationParams.cs @@ -16,7 +16,9 @@ internal class UnregistrationParams /// /// Gets or sets the capabilities to unregister. /// - [JsonPropertyName("unregistrations")] + // NOTE: the 'unregisterations' typo is noted in the spec but cannot be changed until LSP 4.x for compat reasons + [JsonPropertyName("unregisterations")] + [JsonRequired] public Unregistration[] Unregistrations { get; diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceFolder.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceFolder.cs new file mode 100644 index 0000000000000..8fb025fff24bc --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceFolder.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// Describes a workspace folder +/// Since LSP 3.6 +internal class WorkspaceFolder +{ + /// + /// The URI for this workspace folder. + /// + [JsonPropertyName("uri")] + [JsonConverter(typeof(Uri))] + [JsonRequired] + public Uri Uri { get; init; } + + /// + /// The name of the workspace folder used in the UI. + /// + [JsonPropertyName("name")] + [JsonRequired] + public string Name { get; init; } +} From 6bf6885525d647900e896fbdc41801aa9bb07b9d Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Wed, 5 Jun 2024 04:28:55 -0400 Subject: [PATCH 05/46] LSP Protocol: Update document sync messages --- .../Protocol/DidChangeTextDocumentParams.cs | 24 +++- .../Protocol/DidCloseTextDocumentParams.cs | 4 +- .../Protocol/DidOpenTextDocumentParams.cs | 4 +- .../Protocol/DidSaveTextDocumentParams.cs | 8 +- .../Methods.DocumentSynchronization.cs | 107 ++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 60 ---------- .../Protocol/Protocol/SaveOptions.cs | 3 +- .../Protocol/SynchronizationSetting.cs | 11 +- .../TextDocumentChangeRegistrationOptions.cs | 5 +- .../TextDocumentContentChangeEvent.cs | 3 +- .../TextDocumentSaveRegistrationOptions.cs | 23 ++++ .../Protocol/WillSaveTextDocumentParams.cs | 5 +- 12 files changed, 181 insertions(+), 76 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/Methods.DocumentSynchronization.cs create mode 100644 src/LanguageServer/Protocol/Protocol/TextDocumentSaveRegistrationOptions.cs diff --git a/src/LanguageServer/Protocol/Protocol/DidChangeTextDocumentParams.cs b/src/LanguageServer/Protocol/Protocol/DidChangeTextDocumentParams.cs index 78ac42a0491d8..24f6c768af88b 100644 --- a/src/LanguageServer/Protocol/Protocol/DidChangeTextDocumentParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DidChangeTextDocumentParams.cs @@ -8,15 +8,19 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents the parameter that is sent with textDocument/didChange message. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DidChangeTextDocumentParams : ITextDocumentParams { /// - /// Gets or sets the document that changed. + /// The document that did change. The version number points + /// to the version after all provided content changes have + /// been applied. /// [JsonPropertyName("textDocument")] + [JsonRequired] public VersionedTextDocumentIdentifier TextDocument { get; @@ -24,9 +28,23 @@ public VersionedTextDocumentIdentifier TextDocument } /// - /// Gets or sets the content changes. + /// The actual content changes. The content changes describe single state + /// changes to the document. So if there are two content changes c1 (at + /// array index 0) and c2(at array index 1) for a document in state S then + /// c1 moves the document from S to S' and c2 from S' to S''. So c1 is + /// computed on the state S and c2 is computed on the state S'. + /// + /// To mirror the content of a document using change events use the following + /// approach: + /// + /// Start with the same initial content + /// Apply the 'textDocument/didChange' notifications in the order you receive them. + /// Apply the `TextDocumentContentChangeEvent`s in a single notification in the order you receive them. + /// + /// /// [JsonPropertyName("contentChanges")] + [JsonRequired] public TextDocumentContentChangeEvent[] ContentChanges { get; diff --git a/src/LanguageServer/Protocol/Protocol/DidCloseTextDocumentParams.cs b/src/LanguageServer/Protocol/Protocol/DidCloseTextDocumentParams.cs index 15a1ccb176d6e..2cfcefc153255 100644 --- a/src/LanguageServer/Protocol/Protocol/DidCloseTextDocumentParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DidCloseTextDocumentParams.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents the parameter that is sent with textDocument/didClose message. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DidCloseTextDocumentParams : ITextDocumentParams { @@ -17,6 +18,7 @@ internal class DidCloseTextDocumentParams : ITextDocumentParams /// Gets or sets the text document identifier. /// [JsonPropertyName("textDocument")] + [JsonRequired] public TextDocumentIdentifier TextDocument { get; diff --git a/src/LanguageServer/Protocol/Protocol/DidOpenTextDocumentParams.cs b/src/LanguageServer/Protocol/Protocol/DidOpenTextDocumentParams.cs index ff6ecfacc3ccb..812f72c8bdd24 100644 --- a/src/LanguageServer/Protocol/Protocol/DidOpenTextDocumentParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DidOpenTextDocumentParams.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents the parameter that is sent with textDocument/didOpen message. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DidOpenTextDocumentParams { @@ -17,6 +18,7 @@ internal class DidOpenTextDocumentParams /// Gets or sets the which represents the text document that was opened. /// [JsonPropertyName("textDocument")] + [JsonRequired] public TextDocumentItem TextDocument { get; diff --git a/src/LanguageServer/Protocol/Protocol/DidSaveTextDocumentParams.cs b/src/LanguageServer/Protocol/Protocol/DidSaveTextDocumentParams.cs index b0c24f6e168c2..2c05d40d38946 100644 --- a/src/LanguageServer/Protocol/Protocol/DidSaveTextDocumentParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DidSaveTextDocumentParams.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents the parameter that is sent with a textDocument/didSave message. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DidSaveTextDocumentParams : ITextDocumentParams { @@ -17,6 +18,7 @@ internal class DidSaveTextDocumentParams : ITextDocumentParams /// Gets or sets the which represents the text document that was saved. /// [JsonPropertyName("textDocument")] + [JsonRequired] public TextDocumentIdentifier TextDocument { get; @@ -24,7 +26,9 @@ public TextDocumentIdentifier TextDocument } /// - /// Gets or sets the which represents the content of the text document when it was saved. + /// Optional the content when saved. Depends on the value + /// or the when the save + /// notification was requested. /// [JsonPropertyName("text")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/Methods.DocumentSynchronization.cs b/src/LanguageServer/Protocol/Protocol/Methods.DocumentSynchronization.cs new file mode 100644 index 0000000000000..37dbffb9a051f --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Methods.DocumentSynchronization.cs @@ -0,0 +1,107 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Roslyn.LanguageServer.Protocol; + +namespace Roslyn.LanguageServer.Protocol; + +// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_synchronization +partial class Methods +{ + // NOTE: these are sorted/grouped in the order used by the spec + + /// + /// Method name for 'textDocument/didOpen'. + /// + /// The document open notification is sent from the client to the server to signal newly opened text documents. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentDidOpenName = "textDocument/didOpen"; + + /// + /// Strongly typed message object for 'textDocument/didOpen'. + /// + public static readonly LspNotification TextDocumentDidOpen = new(TextDocumentDidOpenName); + + /// + /// Method name for 'textDocument/didChange'. + /// + /// The document change notification is sent from the client to the server to signal changes to a text document. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentDidChangeName = "textDocument/didChange"; + + /// + /// Strongly typed message object for 'textDocument/didChange'. + /// + public static readonly LspNotification TextDocumentDidChange = new(TextDocumentDidChangeName); + + /// + /// Method name for 'textDocument/willSave'. + /// + /// The document will save notification is sent from the client to the server before the document is actually saved. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentWillSaveName = "textDocument/willSave"; + + /// + /// Strongly typed message object for 'textDocument/willSave'. + /// + public static readonly LspNotification TextDocumentWillSave = new(TextDocumentWillSaveName); + + /// + /// Method name for 'textDocument/willSaveWaitUntil'. + /// + /// The document will save wait until request is sent from the client to the server before the document is actually saved. + /// The request can return an array of TextEdits which will be applied to the text document before it is saved. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentWillSaveWaitUntilName = "textDocument/willSaveWaitUntil"; + + /// + /// Strongly typed message object for 'textDocument/willSaveWaitUntil'. + /// + public static readonly LspRequest TextDocumentWillSaveWaitUntil = new(TextDocumentWillSaveWaitUntilName); + + /// + /// Method name for 'textDocument/didSave'. + /// + /// The document save notification is sent from the client to the server when the document was saved in the client. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentDidSaveName = "textDocument/didSave"; + + /// + /// Strongly typed message object for 'textDocument/didSave'. + /// + public static readonly LspNotification TextDocumentDidSave = new(TextDocumentDidSaveName); + + /// + /// Method name for 'textDocument/didClose'. + /// + /// The document close notification is sent from the client to the server when the document + /// got closed in the client. The document’s master now exists where the document’s Uri + /// points to (e.g. if the document’s Uri is a file Uri the master now exists on disk) + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentDidCloseName = "textDocument/didClose"; +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index af71d249a9482..807b28dd915fa 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -71,26 +71,6 @@ internal static partial class Methods /// public const string TextDocumentDiagnosticName = "textDocument/diagnostic"; - /// - /// Method name for 'textDocument/didOpen'. - /// - public const string TextDocumentDidOpenName = "textDocument/didOpen"; - - /// - /// Method name for 'textDocument/didClose'. - /// - public const string TextDocumentDidCloseName = "textDocument/didClose"; - - /// - /// Method name for 'textDocument/didChange'. - /// - public const string TextDocumentDidChangeName = "textDocument/didChange"; - - /// - /// Method name for 'textDocument/didSave'. - /// - public const string TextDocumentDidSaveName = "textDocument/didSave"; - /// /// Method name for 'textDocument/documentHighlight'. /// @@ -201,16 +181,6 @@ internal static partial class Methods /// public const string TextDocumentSignatureHelpName = "textDocument/signatureHelp"; - /// - /// Method name for 'textDocument/willSave'. - /// - public const string TextDocumentWillSaveName = "textDocument/willSave"; - - /// - /// Method name for 'textDocument/willSaveWaitUntil'. - /// - public const string TextDocumentWillSaveWaitUntilName = "textDocument/willSaveWaitUntil"; - /// /// Method name for 'textDocument/linkedEditingRange'. /// @@ -326,26 +296,6 @@ internal static partial class Methods /// public static readonly LspRequest?> TextDocumentDefinition = new LspRequest?>(TextDocumentDefinitionName); - /// - /// Strongly typed message object for 'textDocument/didOpen'. - /// - public static readonly LspNotification TextDocumentDidOpen = new LspNotification(TextDocumentDidOpenName); - - /// - /// Strongly typed message object for 'textDocument/didClose'. - /// - public static readonly LspNotification TextDocumentDidClose = new LspNotification(TextDocumentDidCloseName); - - /// - /// Strongly typed message object for 'textDocument/didChange'. - /// - public static readonly LspNotification TextDocumentDidChange = new LspNotification(TextDocumentDidChangeName); - - /// - /// Strongly typed message object for 'textDocument/didSave'. - /// - public static readonly LspNotification TextDocumentDidSave = new LspNotification(TextDocumentDidSaveName); - /// /// Strongly typed message object for 'textDocument/documentHighlight'. /// @@ -441,16 +391,6 @@ internal static partial class Methods /// public static readonly LspRequest TextDocumentSignatureHelp = new LspRequest(TextDocumentSignatureHelpName); - /// - /// Strongly typed message object for 'textDocument/willSave'. - /// - public static readonly LspNotification TextDocumentWillSave = new LspNotification(TextDocumentWillSaveName); - - /// - /// Strongly typed message object for 'textDocument/willSaveWaitUntil'. - /// - public static readonly LspRequest TextDocumentWillSaveWaitUntil = new LspRequest(TextDocumentWillSaveWaitUntilName); - /// /// Strongly typed message object for 'textDocument/linkedEditingRange'. /// diff --git a/src/LanguageServer/Protocol/Protocol/SaveOptions.cs b/src/LanguageServer/Protocol/Protocol/SaveOptions.cs index 9d04b661df742..5284b1bddb6cd 100644 --- a/src/LanguageServer/Protocol/Protocol/SaveOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/SaveOptions.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents save option configurations. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class SaveOptions { diff --git a/src/LanguageServer/Protocol/Protocol/SynchronizationSetting.cs b/src/LanguageServer/Protocol/Protocol/SynchronizationSetting.cs index 82e339cb5ea56..c8064d376dbf0 100644 --- a/src/LanguageServer/Protocol/Protocol/SynchronizationSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/SynchronizationSetting.cs @@ -8,13 +8,14 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents synchronization initialization setting. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class SynchronizationSetting : DynamicRegistrationSetting { /// - /// Gets or sets a value indicating whether WillSave event is supported. + /// Whether the client supports sending textDocument/willSave notifications. /// [JsonPropertyName("willSave")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -25,7 +26,9 @@ public bool WillSave } /// - /// Gets or sets a value indicating whether WillSaveWaitUntil event is supported. + /// Whether the client supports sending textDocument/willSaveWaitUntil + /// notifications and waits for a response providing text edits which will be + /// applied to the document before it is saved. /// [JsonPropertyName("willSaveWaitUntil")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -36,7 +39,7 @@ public bool WillSaveWaitUntil } /// - /// Gets or sets a value indicating whether DidSave event is supported. + /// Whether the client supports sending textDocument/didSave notifications. /// [JsonPropertyName("didSave")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentChangeRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentChangeRegistrationOptions.cs index fa152aa3d8140..4f5fbeb6a45c7 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentChangeRegistrationOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentChangeRegistrationOptions.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol { /// /// Class representing the registration options for didChange events. - /// - /// See the Language Server Protocol specification for additional information. + /// + /// See the Language Server Protocol specification for additional information. + /// /// internal class TextDocumentChangeRegistrationOptions : TextDocumentRegistrationOptions { diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentContentChangeEvent.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentContentChangeEvent.cs index 64568623fe4dc..2db2a3afb7fd8 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentContentChangeEvent.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentContentChangeEvent.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which encapsulates a text document changed event. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class TextDocumentContentChangeEvent { diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentSaveRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentSaveRegistrationOptions.cs new file mode 100644 index 0000000000000..18a4903a1944b --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentSaveRegistrationOptions.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Options when registering for document-specific 'textDocument/didSave' notifications +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class TextDocumentSaveRegistrationOptions : TextDocumentRegistrationOptions +{ + /// + /// The client is supposed to include the content on save. + /// + [JsonPropertyName("IncludeText")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool IncludeText { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/WillSaveTextDocumentParams.cs b/src/LanguageServer/Protocol/Protocol/WillSaveTextDocumentParams.cs index 46269ba196183..ba127c758fc73 100644 --- a/src/LanguageServer/Protocol/Protocol/WillSaveTextDocumentParams.cs +++ b/src/LanguageServer/Protocol/Protocol/WillSaveTextDocumentParams.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the parameters sent for the textDocument/willSave request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class WillSaveTextDocumentParams : ITextDocumentParams { @@ -17,6 +18,7 @@ internal class WillSaveTextDocumentParams : ITextDocumentParams /// Gets or sets the representing the document to be saved. /// [JsonPropertyName("textDocument")] + [JsonRequired] public TextDocumentIdentifier TextDocument { get; @@ -27,6 +29,7 @@ public TextDocumentIdentifier TextDocument /// Gets or sets the reason that the text document was saved. /// [JsonPropertyName("reason")] + [JsonRequired] public TextDocumentSaveReason Reason { get; From eccb0296da434ec1f9f89eb16f2b717592a24e1f Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Wed, 5 Jun 2024 20:24:33 -0400 Subject: [PATCH 06/46] LSP Protocol: Add notebook types/methods --- .../Protocol/Protocol/ClientCapabilities.cs | 8 ++ .../Protocol/DynamicRegistrationSetting.cs | 2 +- .../Protocol/IDynamicRegistrationSetting.cs | 20 +++++ .../Protocol/Protocol/Methods.Notebook.cs | 87 +++++++++++++++++++ .../DidChangeNotebookDocumentParams.cs | 45 ++++++++++ .../DidCloseNotebookDocumentParams.cs | 33 +++++++ .../Notebook/DidOpenNotebookDocumentParams.cs | 31 +++++++ .../Notebook/DidSaveNotebookDocumentParams.cs | 24 +++++ .../Protocol/Notebook/ExecutionSummary.cs | 32 +++++++ .../Protocol/Notebook/NotebookCell.cs | 49 +++++++++++ .../Notebook/NotebookCellArrayChange.cs | 38 ++++++++ .../Protocol/Notebook/NotebookCellKind.cs | 25 ++++++ .../NotebookCellTextDocumentFilter.cs | 37 ++++++++ .../Protocol/Notebook/NotebookDocument.cs | 53 +++++++++++ .../Notebook/NotebookDocumentChangeCells.cs | 39 +++++++++ .../NotebookDocumentChangeCellsStructure.cs | 38 ++++++++ .../NotebookDocumentChangeCellsText.cs | 31 +++++++ .../Notebook/NotebookDocumentChangeEvent.cs | 32 +++++++ .../NotebookDocumentClientCapabilities.cs | 24 +++++ .../Notebook/NotebookDocumentFilter.cs | 40 +++++++++ .../Notebook/NotebookDocumentIdentifier.cs | 25 ++++++ .../NotebookDocumentSyncCellSelector.cs | 21 +++++ .../NotebookDocumentSyncClientCapabilities.cs | 33 +++++++ .../Notebook/NotebookDocumentSyncOptions.cs | 42 +++++++++ ...NotebookDocumentSyncRegistrationOptions.cs | 26 ++++++ .../Notebook/NotebookDocumentSyncSelector.cs | 36 ++++++++ .../VersionedNotebookDocumentIdentifier.cs | 33 +++++++ .../Protocol/Protocol/ServerCapabilities.cs | 7 ++ 28 files changed, 910 insertions(+), 1 deletion(-) create mode 100644 src/LanguageServer/Protocol/Protocol/IDynamicRegistrationSetting.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Methods.Notebook.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/DidChangeNotebookDocumentParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/DidCloseNotebookDocumentParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/DidOpenNotebookDocumentParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/DidSaveNotebookDocumentParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/ExecutionSummary.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookCell.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookCellArrayChange.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookCellKind.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookCellTextDocumentFilter.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocument.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeCells.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeCellsStructure.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeCellsText.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeEvent.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentFilter.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentIdentifier.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncCellSelector.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncSelector.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Notebook/VersionedNotebookDocumentIdentifier.cs diff --git a/src/LanguageServer/Protocol/Protocol/ClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ClientCapabilities.cs index a2c69b9cc040d..1658f039aa594 100644 --- a/src/LanguageServer/Protocol/Protocol/ClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ClientCapabilities.cs @@ -36,6 +36,14 @@ public TextDocumentClientCapabilities? TextDocument set; } + /// + /// Capabilities specific to the notebook document support. + /// + /// Since LSP 3.17 + [JsonPropertyName("notebook")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public NotebookDocumentClientCapabilities? Notebook { get; init; } + /// /// Window specific client capabilities. /// diff --git a/src/LanguageServer/Protocol/Protocol/DynamicRegistrationSetting.cs b/src/LanguageServer/Protocol/Protocol/DynamicRegistrationSetting.cs index 9bc210064c78f..58a671f772169 100644 --- a/src/LanguageServer/Protocol/Protocol/DynamicRegistrationSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/DynamicRegistrationSetting.cs @@ -9,7 +9,7 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents a setting that can be dynamically registered. /// - internal class DynamicRegistrationSetting + internal class DynamicRegistrationSetting : IDynamicRegistrationSetting { /// /// Initializes a new instance of the class. diff --git a/src/LanguageServer/Protocol/Protocol/IDynamicRegistrationSetting.cs b/src/LanguageServer/Protocol/Protocol/IDynamicRegistrationSetting.cs new file mode 100644 index 0000000000000..581e5a957eac8 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/IDynamicRegistrationSetting.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// A setting that can be dynamically registered via the `client/registerCapability` method. +/// +internal interface IDynamicRegistrationSetting +{ + /// + /// Whether the implementation supports dynamic registration. + /// + [JsonPropertyName("dynamicRegistration")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool DynamicRegistration { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Notebook.cs b/src/LanguageServer/Protocol/Protocol/Methods.Notebook.cs new file mode 100644 index 0000000000000..5d67fa0bbe37c --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Methods.Notebook.cs @@ -0,0 +1,87 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notebookDocument_synchronization +partial class Methods +{ + // NOTE: these are sorted/grouped in the order used by the spec + + /// + /// Method name for 'notebookDocument/didOpen'. + /// + /// The open notification is sent from the client to the server when a notebook document is opened. It is only + /// sent by a client if the server specified a in its + /// capability. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string NotebookDidOpenName = "notebookDocument/didOpen"; + + /// + /// Strongly typed message object for 'notebookDocument/didOpen'. + /// + public static readonly LspNotification NotebookDidOpen = new(NotebookDidOpenName); + + /// + /// Method name for 'notebookDocument/didChange'. + /// + /// The change notification is sent from the client to the server when a notebook document changes. It is only + /// sent by a client if the server specified a in its + /// capability. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string NotebookDidChangeName = "notebookDocument/didChange"; + + /// + /// Strongly typed message object for 'notebookDocument/didChange'. + /// + public static readonly LspNotification NotebookDidChange = new(NotebookDidChangeName); + + /// + /// Method name for 'notebookDocument/didSave'. + /// + /// The change notification is sent from the client to the server when a notebook document is saved. It is only + /// sent by a client if the server specified a in its + /// capability. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string NotebookDidSaveName = "notebookDocument/didSave"; + + /// + /// Strongly typed message object for 'notebookDocument/didSave'. + /// + public static readonly LspNotification NotebookDidSave = new(NotebookDidSaveName); + + /// + /// Method name for 'notebookDocument/didClose'. + /// + /// The change notification is sent from the client to the server when a notebook document is closed. It is only + /// sent by a client if the server specified a in its + /// capability. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string NotebookDidCloseName = "notebookDocument/didClose"; + + /// + /// Strongly typed message object for 'notebookDocument/didClose'. + /// + public static readonly LspNotification NotebookDidClose = new(NotebookDidCloseName); +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/DidChangeNotebookDocumentParams.cs b/src/LanguageServer/Protocol/Protocol/Notebook/DidChangeNotebookDocumentParams.cs new file mode 100644 index 0000000000000..4870ca9f5b401 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/DidChangeNotebookDocumentParams.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a notebookDocument/didChange notification. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class DidChangeNotebookDocumentParams +{ + /// + /// The notebook document that did change. The version number points + /// to the version after all provided changes have been applied. + /// + [JsonPropertyName("notebookDocument")] + [JsonRequired] + public VersionedNotebookDocumentIdentifier NotebookDocument { get; init; } + + /// + /// The actual changes to the notebook document. + /// + /// The change describes single state change to the notebook document. + /// So it moves a notebook document, its cells and its cell text document + /// contents from state S to S'. + /// + /// + /// To mirror the content of a notebook using change events use the + /// following approach: + /// + /// start with the same initial content + /// apply the notebookDocument/didChange notifications in the order you receive them. + /// + /// + /// + [JsonPropertyName("change")] + [JsonRequired] + public NotebookDocumentChangeEvent Change { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/DidCloseNotebookDocumentParams.cs b/src/LanguageServer/Protocol/Protocol/Notebook/DidCloseNotebookDocumentParams.cs new file mode 100644 index 0000000000000..7bd04c8d90e1c --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/DidCloseNotebookDocumentParams.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a notebookDocument/didClose notification. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class DidCloseNotebookDocumentParams +{ + + /// + /// The notebook document that got closed. + /// + [JsonPropertyName("notebookDocument")] + [JsonRequired] + public NotebookDocumentIdentifier NotebookDocument { get; init; } + + /// + /// The text documents that represent the content + /// of a notebook cell that got closed. + /// + [JsonPropertyName("cellTextDocuments")] + [JsonRequired] + public TextDocumentIdentifier[] CellTextDocuments { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/DidOpenNotebookDocumentParams.cs b/src/LanguageServer/Protocol/Protocol/Notebook/DidOpenNotebookDocumentParams.cs new file mode 100644 index 0000000000000..4d9646d0d1813 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/DidOpenNotebookDocumentParams.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in notebookDocument/didOpen notification. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class DidOpenNotebookDocumentParams +{ + /// + /// The notebook document that got opened. + /// + [JsonPropertyName("notebookDocument")] + [JsonRequired] + public NotebookDocument NotebookDocument { get; init; } + + /// + /// The text documents that represent the content of a notebook cell. + /// + [JsonPropertyName("cellTextDocuments")] + [JsonRequired] + public TextDocumentItem[] CellTextDocuments { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/DidSaveNotebookDocumentParams.cs b/src/LanguageServer/Protocol/Protocol/Notebook/DidSaveNotebookDocumentParams.cs new file mode 100644 index 0000000000000..959cdadb248d7 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/DidSaveNotebookDocumentParams.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a notebookDocument/didSave notification. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class DidSaveNotebookDocumentParams +{ + /// + /// The notebook document that got saved. + /// + [JsonPropertyName("notebookDocument")] + [JsonRequired] + public NotebookDocumentIdentifier NotebookDocument { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/ExecutionSummary.cs b/src/LanguageServer/Protocol/Protocol/Notebook/ExecutionSummary.cs new file mode 100644 index 0000000000000..59411c815213a --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/ExecutionSummary.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Additional execution summary information +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class ExecutionSummary +{ + /// + /// A strict monotonically increasing value indicating the + /// execution order of a cell inside a notebook. + /// + [JsonPropertyName("executionOrder")] + [JsonRequired] + public int ExecutionOrder { get; init; } + + /// + /// Whether the execution was successful or not, if known by the client. + /// + [JsonPropertyName("success")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public bool? Success { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookCell.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookCell.cs new file mode 100644 index 0000000000000..a738797ac815b --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookCell.cs @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A notebook cell. +/// +/// A cell's document URI must be unique across ALL notebook +/// cells and can therefore be used to uniquely identify a +/// notebook cell or the cell's text document. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// Since LSP 3.17 +internal class NotebookCell +{ + + /// + /// The cell's kind + /// + [JsonPropertyName("kind")] + [JsonRequired] + public NotebookCellKind Kind { get; init; } + + /// + /// The URI of the cell's text document content. + /// + [JsonPropertyName("document")] + [JsonConverter(typeof(DocumentUriConverter))] + [JsonRequired] + public Uri Document { get; init; } + + /// + /// Additional metadata stored with the cell. + /// + [JsonPropertyName("metadata")] + public object? Metadata { get; init; } + + /// + /// Additional execution summary information if supported by the client. + /// + [JsonPropertyName("executionSummary")] + public ExecutionSummary? ExecutionSummary { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookCellArrayChange.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookCellArrayChange.cs new file mode 100644 index 0000000000000..7c743cac151b7 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookCellArrayChange.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A change describing how to move a array from state S to S'. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class NotebookCellArrayChange +{ + /// + /// The start offset of the cell that changed. + /// + [JsonPropertyName("start")] + [JsonRequired] + public int Start { get; set; } + + /// + /// The deleted cells + /// + [JsonPropertyName("deleteCount")] + [JsonRequired] + public int DeleteCount { get; init; } + + /// + /// The new cells, if any + /// + [JsonPropertyName("cells")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public NotebookCell[]? Cells { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookCellKind.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookCellKind.cs new file mode 100644 index 0000000000000..9be94fa10c2fc --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookCellKind.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A notebook cell kind. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal enum NotebookCellKind +{ + /// + /// A markup-cell is formatted source that is used for display. + /// + Markup = 1, + + /// + /// A code-cell is source code. + /// + Code = 2 +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookCellTextDocumentFilter.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookCellTextDocumentFilter.cs new file mode 100644 index 0000000000000..84bbb757511ee --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookCellTextDocumentFilter.cs @@ -0,0 +1,37 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A notebook cell text document filter denotes a cell text document by +/// different properties. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// Since LSP 3.17 +internal class NotebookCellTextDocumentFilter +{ + /// + /// A filter that matches against the notebook + /// containing the notebook cell. If a string + /// value is provided it matches against the + /// notebook type. '*' matches every notebook. + /// + [JsonPropertyName("notebook")] + [JsonRequired] + public SumType Notebook { get; init; } + + /// + /// A language id like `python`. + /// + /// Will be matched against the language id of the + /// notebook cell document. '*' matches every language. + /// + [JsonPropertyName("language")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Language { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocument.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocument.cs new file mode 100644 index 0000000000000..0ae70f36870a2 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocument.cs @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A notebook document. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class NotebookDocument +{ + /// + /// The notebook document's URI. + /// + [JsonPropertyName("uri")] + [JsonRequired] + // NOTE: not a DocumentURI + public Uri Uri { get; init; } + + /// + /// The type of the notebook. + /// + [JsonPropertyName("notebookType")] + [JsonRequired] + public string NotebookType { get; init; } + + /// + /// The version number of this document (it will increase after each change, including undo/redo). + /// + [JsonPropertyName("version")] + [JsonRequired] + public int Version { get; init; } + + /// + /// Additional metadata stored with the notebook document. + /// + [JsonPropertyName("metadata")] + public object? Metadata { get; init; } + + /// + /// The cells of a notebook. + /// + [JsonPropertyName("cells")] + [JsonRequired] + public NotebookCell[] Cells { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeCells.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeCells.cs new file mode 100644 index 0000000000000..43b748cf64057 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeCells.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Represents changes to the notebook cells in a +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class NotebookDocumentChangeCells +{ + /// + /// Changes to the cell structure to add or remove cells. + /// + [JsonPropertyName("structure")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public NotebookDocumentChangeCellsStructure? Structure { get; init; } + + /// + /// Changes to notebook cells properties like its + /// kind, execution summary or metadata. + /// + [JsonPropertyName("data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public NotebookCell[]? Data { get; init; } + + /// + /// Changes to the text content of notebook cells. + /// + [JsonPropertyName("textContent")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public NotebookDocumentChangeCellsText[]? TextContent { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeCellsStructure.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeCellsStructure.cs new file mode 100644 index 0000000000000..455d24f5fcf4b --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeCellsStructure.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Represents changes to the notebook structure to add or remove cells in a +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class NotebookDocumentChangeCellsStructure +{ + /// + /// The change to the cell array. + /// + [JsonPropertyName("array")] + [JsonRequired] + public NotebookCellArrayChange Array { get; init; } + + /// + /// Additional opened cell text documents. + /// + [JsonPropertyName("didOpen")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public TextDocumentItem[]? DidOpen { get; init; } + + /// + /// Additional closed cell text documents. + /// + [JsonPropertyName("didClose")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public TextDocumentIdentifier[]? DidClose { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeCellsText.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeCellsText.cs new file mode 100644 index 0000000000000..34c60f56b61f9 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeCellsText.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Changes to the text content of a notebook cell in a +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class NotebookDocumentChangeCellsText +{ + /// + /// Identifier for the document representing the cell + /// + [JsonPropertyName("document")] + [JsonRequired] + public VersionedTextDocumentIdentifier Document { get; init; } + + /// + /// The changes to the document representing the cell + /// + [JsonPropertyName("changes")] + [JsonRequired] + public TextDocumentContentChangeEvent[] Changes { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeEvent.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeEvent.cs new file mode 100644 index 0000000000000..f575097f0e478 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentChangeEvent.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A change event for a notebook document. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class NotebookDocumentChangeEvent +{ + /// + /// The changed metadata, if any. + /// + [JsonPropertyName("metadata")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IDictionary? Metadata { get; init; } + + /// + /// Changes to cells + /// + [JsonPropertyName("cells")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public NotebookDocumentChangeCells? Cells { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentClientCapabilities.cs new file mode 100644 index 0000000000000..ae0c62673d076 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentClientCapabilities.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the notebook document support +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class NotebookDocumentClientCapabilities +{ + /// + /// Capabilities specific to notebook document synchronization + /// + [JsonPropertyName("synchronization")] + [JsonRequired] + public NotebookDocumentSyncClientCapabilities Synchronization { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentFilter.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentFilter.cs new file mode 100644 index 0000000000000..23e68b0c90b43 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentFilter.cs @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A notebook document filter denotes a notebook document by +/// different properties. +/// +/// NOTE: One or more of the properties NotebookType, Scheme and Pattern must be non-null +/// +/// See the Language Server Protocol specification for additional information. +/// +/// Since LSP 3.17 +internal class NotebookDocumentFilter +{ + /// + /// The type of the enclosing notebook. */ + /// + [JsonPropertyName("notebookType")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? NotebookType { get; init; } + + /// + /// A Uri scheme () like file or untitled. + /// + [JsonPropertyName("scheme")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Scheme { get; init; } + + /// + /// A glob pattern. + /// + [JsonPropertyName("pattern")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Pattern { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentIdentifier.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentIdentifier.cs new file mode 100644 index 0000000000000..f7ec5f7dc9fa2 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentIdentifier.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A literal to identify a notebook document in the client. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class NotebookDocumentIdentifier +{ + /// + /// The notebook document's URI. + /// + [JsonPropertyName("uri")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public Uri Uri { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncCellSelector.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncCellSelector.cs new file mode 100644 index 0000000000000..a82fc5b937393 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncCellSelector.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Specifies languages of cells to be matched in a notebook sync. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// Since LSP 3.17 +/// +internal class NotebookDocumentSyncCellSelector +{ + [JsonPropertyName("language")] + [JsonRequired] + public string Language { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncClientCapabilities.cs new file mode 100644 index 0000000000000..aa51a0e356249 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncClientCapabilities.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Notebook specific client capabilities +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class NotebookDocumentSyncClientCapabilities : IDynamicRegistrationSetting +{ + /// + /// The client supports sending execution summary data per cell. + /// + [JsonPropertyName("executionSummarySupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool ExecutionSummarySupport { get; init; } + + /// + /// Whether the implementation supports dynamic registration. If this is set to + /// the client supports the new and + /// return values for the corresponding server capabilities. + /// + [JsonPropertyName("dynamicRegistration")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool DynamicRegistration { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncOptions.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncOptions.cs new file mode 100644 index 0000000000000..ecc8f8d6d73de --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncOptions.cs @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Options specific to a notebook plus its cells +/// to be synced to the server. +/// +/// If a selector provides a notebook document +/// filter but no cell selector all cells of a +/// matching notebook document will be synced. +/// +/// +/// If a selector provides no notebook document +/// filter but only a cell selector all notebook +/// documents that contain at least one matching +/// cell will be synced. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// Since LSP 3.17 +internal class NotebookDocumentSyncOptions +{ + /// + /// The notebooks to be synced + /// + [JsonPropertyName("notebookSelector")] + [JsonRequired] + public NotebookDocumentSyncSelector[] NotebookSelector { get; init; } + + /// + /// Whether save notification should be forwarded to + /// the server. Will only be honored if mode === `notebook`. + /// + [JsonPropertyName("save")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool Save { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncRegistrationOptions.cs new file mode 100644 index 0000000000000..2968e35aa4bf4 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncRegistrationOptions.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that implements +/// , allowing it to be registered +/// with an ID that can be used to unregister it later. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class NotebookDocumentSyncRegistrationOptions : NotebookDocumentSyncOptions, IStaticRegistrationOptions +{ + /// + /// The id used to register the request. The id can be used to deregister the request again. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncSelector.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncSelector.cs new file mode 100644 index 0000000000000..dd849cf2cac4f --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentSyncSelector.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Matches notebooks and cells to be synced +/// +/// NOTE: either one or both of the Notebook and Cells properties must be non-null. +/// +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class NotebookDocumentSyncSelector +{ + /// + /// The notebook to be synced. If a string + /// value is provided it matches against the + /// notebook type. '*' matches every notebook. + /// + [JsonPropertyName("notebook")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SumType? Notebook { get; init; } + + /// + /// The cells of the matching notebook to be synced. + /// + [JsonPropertyName("cells")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public NotebookDocumentSyncCellSelector[]? Cells { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/VersionedNotebookDocumentIdentifier.cs b/src/LanguageServer/Protocol/Protocol/Notebook/VersionedNotebookDocumentIdentifier.cs new file mode 100644 index 0000000000000..f28811a85e485 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Notebook/VersionedNotebookDocumentIdentifier.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A versioned notebook document identifier. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class VersionedNotebookDocumentIdentifier +{ + + /// + /// The version number of this notebook document. + /// + [JsonPropertyName("version")] + [JsonRequired] + public int Version { get; init; } + + /// + /// The notebook document's URI. + /// + [JsonPropertyName("uri")] + [JsonRequired] + public Uri Uri { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 68c83dfe4c233..a591f57710519 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -52,6 +52,13 @@ public TextDocumentSyncOptions? TextDocumentSync }, }; + /// + /// Defines how notebook documents are synced. + /// + /// Since LSP 3.17 + [JsonPropertyName("notebookDocumentSync")] + public SumType? NotebookDocumentSync { get; init; } + /// /// Gets or sets the value which indicates if completions are supported. /// From ceafc11535f68bf817a708622d23a079baaaa8ce Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Wed, 5 Jun 2024 22:02:44 -0400 Subject: [PATCH 07/46] LSP Protocol: Update navigation methods/types --- .../Protocol/Protocol/DefinitionOptions.cs | 23 -- .../Internal/VSInternalReferenceParams.cs | 9 +- .../Protocol/Protocol/LocationLink.cs | 71 ++++++ .../Protocol/Protocol/Methods.Navigation.cs | 224 ++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 40 ---- .../CallHierarchyClientCapabilities.cs | 16 ++ .../Navigation/CallHierarchyIncomingCall.cs | 33 +++ .../CallHierarchyIncomingCallsParams.cs | 38 +++ .../Protocol/Navigation/CallHierarchyItem.cs | 79 ++++++ .../Navigation/CallHierarchyOptions.cs | 24 ++ .../Navigation/CallHierarchyOutgoingCall.cs | 33 +++ .../CallHierarchyOutgoingCallsParams.cs | 38 +++ .../Navigation/CallHierarchyPrepareParams.cs | 23 ++ .../CallHierarchyRegistrationOptions.cs | 32 +++ .../DeclarationClientCapabilities.cs | 25 ++ .../Protocol/Navigation/DeclarationOptions.cs | 24 ++ .../Protocol/Navigation/DeclarationParams.cs | 30 +++ .../DeclarationRegistrationOptions.cs | 32 +++ .../DefinitionClientCapabilities.cs | 24 ++ .../Protocol/Navigation/DefinitionOptions.cs | 23 ++ .../Protocol/Navigation/DefinitionParams.cs | 30 +++ .../DefinitionRegistrationOptions.cs | 23 ++ .../ImplementationClientCapabilities.cs | 25 ++ .../{ => Navigation}/ImplementationOptions.cs | 2 +- .../Navigation/ImplementationParams.cs | 30 +++ .../ImplementationRegistrationOptions.cs | 31 +++ .../Navigation/ReferenceClientCapabilities.cs | 16 ++ .../Protocol/Navigation/ReferenceContext.cs | 22 ++ .../{ => Navigation}/ReferenceOptions.cs | 2 +- .../Protocol/Navigation/ReferenceParams.cs | 34 +++ .../ReferenceRegistrationOptions.cs | 24 ++ .../TypeDefinitionClientCapabilities.cs | 25 ++ .../Navigation/TypeDefinitionOptions.cs | 23 ++ .../Navigation/TypeDefinitionParams.cs | 30 +++ .../TypeDefinitionRegistrationOptions.cs | 31 +++ .../TypeHierarchyClientCapabilities.cs | 16 ++ .../Protocol/Navigation/TypeHierarchyItem.cs | 81 +++++++ .../Navigation/TypeHierarchyOptions.cs | 22 ++ .../Navigation/TypeHierarchyPrepareParams.cs | 23 ++ .../TypeHierarchyRegistrationOptions.cs | 30 +++ .../Navigation/TypeHierarchySubtypesParams.cs | 38 +++ .../TypeHierarchySupertypesParams.cs | 38 +++ .../Protocol/Protocol/ReferenceContext.cs | 26 -- .../Protocol/Protocol/ReferenceParams.cs | 41 ---- .../Protocol/Protocol/ServerCapabilities.cs | 38 ++- .../TextDocumentClientCapabilities.cs | 45 +++- .../Protocol/TypeDefinitionOptions.cs | 23 -- 47 files changed, 1439 insertions(+), 171 deletions(-) delete mode 100644 src/LanguageServer/Protocol/Protocol/DefinitionOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/LocationLink.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Methods.Navigation.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyIncomingCall.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyIncomingCallsParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyItem.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyOutgoingCall.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyOutgoingCallsParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyPrepareParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/DeclarationClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/DeclarationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/DeclarationParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/DeclarationRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/DefinitionClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/DefinitionOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/DefinitionParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/DefinitionRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/ImplementationClientCapabilities.cs rename src/LanguageServer/Protocol/Protocol/{ => Navigation}/ImplementationOptions.cs (93%) create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/ImplementationParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/ImplementationRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/ReferenceClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/ReferenceContext.cs rename src/LanguageServer/Protocol/Protocol/{ => Navigation}/ReferenceOptions.cs (93%) create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/ReferenceParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/ReferenceRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyItem.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyPrepareParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchySubtypesParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchySupertypesParams.cs delete mode 100644 src/LanguageServer/Protocol/Protocol/ReferenceContext.cs delete mode 100644 src/LanguageServer/Protocol/Protocol/ReferenceParams.cs delete mode 100644 src/LanguageServer/Protocol/Protocol/TypeDefinitionOptions.cs diff --git a/src/LanguageServer/Protocol/Protocol/DefinitionOptions.cs b/src/LanguageServer/Protocol/Protocol/DefinitionOptions.cs deleted file mode 100644 index b906658d84875..0000000000000 --- a/src/LanguageServer/Protocol/Protocol/DefinitionOptions.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace Roslyn.LanguageServer.Protocol -{ - using System.Text.Json.Serialization; - - /// - /// Class which represents workspace symbols capabilities. - /// - /// See the Language Server Protocol specification for additional information. - /// - internal class DefinitionOptions : IWorkDoneProgressOptions - { - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// - [JsonPropertyName("workDoneProgress")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool WorkDoneProgress { get; init; } - } -} diff --git a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceParams.cs b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceParams.cs index 790b9ef24d951..3c16e2c21afb9 100644 --- a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceParams.cs +++ b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceParams.cs @@ -4,12 +4,13 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// /// Class which represents extensions of passed as parameter of find reference requests. /// - internal class VSInternalReferenceParams : ReferenceParams + internal class VSInternalReferenceParams : ReferenceParams, IPartialResultParams> { /// /// Gets or sets a value indicating the scope of returned items. @@ -21,5 +22,11 @@ public VSInternalItemOrigin? Scope get; set; } + + // overrides the IPartialResultParams version on ReferenceParams + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public new IProgress>? PartialResultToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/LocationLink.cs b/src/LanguageServer/Protocol/Protocol/LocationLink.cs new file mode 100644 index 0000000000000..e3f8738c33629 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/LocationLink.cs @@ -0,0 +1,71 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Represents a link between a source and a target location. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.14 +internal class LocationLink : IEquatable +{ + /// + /// Span of the origin of this link. + /// + /// Used as the underlined span for mouse interaction. Defaults to the word + /// range at the mouse position. + /// + /// + [JsonPropertyName("originSelectionRange")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public Range? OriginSelectionRange { get; init; } + + /// + /// The URI for the target document. + /// + [JsonPropertyName("targetUri")] + [JsonRequired] + [JsonConverter(typeof(DocumentUriConverter))] + public Uri TargetUri { get; init; } + + /// + /// The full target range of the linked location in the target document, which includes + /// the and additional context such as comments (but + /// not leading/trailing whitespace). This information is typically used to highlight + /// the range in the editor. + /// + [JsonPropertyName("targetRange")] + [JsonRequired] + public Range TargetRange { get; init; } + + /// + /// Gets or sets the range to be selected and revealed in the target document e.g. the + /// name of the linked symbol. Must be contained by the . + /// + [JsonPropertyName("targetSelectionRange")] + [JsonRequired] + public Range TargetSelectionRange { get; init; } + + /// + public override bool Equals(object obj) => Equals(obj as LocationLink); + + /// + public bool Equals(LocationLink? other) => + other != null + && EqualityComparer.Default.Equals(this.OriginSelectionRange, other.OriginSelectionRange) + && this.TargetUri != null && other.TargetUri != null && this.TargetUri.Equals(other.TargetUri) + && EqualityComparer.Default.Equals(this.TargetRange, other.TargetRange) + && EqualityComparer.Default.Equals(this.TargetSelectionRange, other.TargetSelectionRange); + + /// + public override int GetHashCode() => + HashCode.Combine(OriginSelectionRange, TargetUri, TargetRange, TargetSelectionRange); +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Navigation.cs b/src/LanguageServer/Protocol/Protocol/Methods.Navigation.cs new file mode 100644 index 0000000000000..2031062a8ce84 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Methods.Navigation.cs @@ -0,0 +1,224 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +// navigation methods from https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#languageFeatures +partial class Methods +{ + // NOTE: these are sorted in the order used by the spec + + /// + /// Method name for 'textDocument/declaration'. + /// + /// The go to declaration request is sent from the client to the server to resolve the declaration location of a symbol at a given text document position. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.14 + public const string TextDocumentDeclarationName = "textDocument/declaration"; + + /// + /// Strongly typed message object for 'textDocument/declaration'. + /// + /// may only be returned if the client opts in via + /// + /// + /// Since LSP 3.14 + public static readonly LspRequest?> TextDocumentDeclaration = new(TextDocumentDeclarationName); + + /// + /// Method name for 'textDocument/definition'. + /// + /// The go to definition request is sent from the client to the server to resolve the definition location of a symbol at a given text document position. + /// + /// + /// may only be returned if the client opts in via + /// + /// + public const string TextDocumentDefinitionName = "textDocument/definition"; + + /// + /// Strongly typed message object for 'textDocument/definition'. + /// + /// may only be returned if the client opts in via + /// + /// + public static readonly LspRequest?> TextDocumentDefinition = new(TextDocumentDefinitionName); + + /// + /// Method name for 'textDocument/typeDefinition'. + /// + /// The go to type definition request is sent from the client to the server to resolve the type definition location of a symbol at a given text document position. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentTypeDefinitionName = "textDocument/typeDefinition"; + + /// + /// Strongly typed message object for 'textDocument/typeDefinition'. + /// + /// may only be returned if the client opts in via + /// + /// + public static readonly LspRequest?> TextDocumentTypeDefinition = new(TextDocumentTypeDefinitionName); + + /// + /// Method name for 'textDocument/implementation'. + /// + /// The go to implementation request is sent from the client to the server to resolve the implementation location of a symbol at a given text document position. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentImplementationName = "textDocument/implementation"; + + /// + /// Strongly typed message object for 'textDocument/implementation'. + /// + /// may only be returned if the client opts in via + /// + /// + public static readonly LspRequest?> TextDocumentImplementation = new(TextDocumentImplementationName); + + /// + /// Method name for 'textDocument/references'. + /// + /// The references request is sent from the client to the server to resolve project-wide references for the symbol denoted by the given text document position. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentReferencesName = "textDocument/references"; + + /// + /// Strongly typed message object for 'textDocument/references'. + /// + public static readonly LspRequest TextDocumentReferences = new(TextDocumentReferencesName); + + /// + /// Method name for 'textDocument/prepareCallHierarchy'. + /// + /// The call hierarchy request is sent from the client to the server to return a call hierarchy for the language element of given text document positions. The call hierarchy requests are executed in two steps: + /// + /// first a call hierarchy item is resolved for the given text document position + /// for a call hierarchy item the incoming or outgoing call hierarchy items are resolved. + /// + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string PrepareCallHierarchyName = "textDocument/prepareCallHierarchy"; + + /// + /// Strongly typed message object for 'textDocument/prepareCallHierarchy'. + /// + /// Since LSP 3.16 + public static readonly LspRequest PrepareCallHierarchy = new(PrepareCallHierarchyName); + + /// + /// Method name for 'callHierarchy/incomingCalls'. + /// + /// The request is sent from the client to the server to resolve incoming calls for a given call hierarchy item. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string CallHierarchyIncomingCallsName = "callHierarchy/incomingCalls"; + + /// + /// Strongly typed message object for 'callHierarchy/incomingCalls'. + /// + /// Since LSP 3.16 + public static readonly LspRequest CallHierarchyIncomingCalls = new(CallHierarchyIncomingCallsName); + + /// + /// Method name for 'callHierarchy/outgoingCalls'. + /// + /// The request is sent from the client to the server to resolve outgoing calls for a given call hierarchy item. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string CallHierarchyOutgoingCallsName = "callHierarchy/outgoingCalls"; + + /// + /// Strongly typed message object for 'callHierarchy/outgoingCalls'. + /// + /// Since LSP 3.16 + public static readonly LspRequest CallHierarchyOutgoingCalls = new(CallHierarchyOutgoingCallsName); + + /// + /// Method name for 'textDocument/prepareTypeHierarchy'. + /// + /// The type hierarchy request is sent from the client to the server to return a type hierarchy for the language element of given text + /// document positions. Will return null if the server couldn't infer a valid type from the position. + /// + /// + /// The type hierarchy requests are executed in two steps: + /// + /// first a type hierarchy item is prepared for the given text document position. + /// for a type hierarchy item the supertype or subtype type hierarchy items are resolved. + /// + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string PrepareTypeHierarchyName = "textDocument/prepareTypeHierarchy"; + + /// + /// Strongly typed message object for 'textDocument/prepareTypeHierarchy'. + /// + /// Since LSP 3.17 + public static readonly LspRequest PrepareTypeHierarchy = new(PrepareTypeHierarchyName); + + /// + /// Method name for 'typeHierarchy/supertypes'. + /// + /// The request is sent from the client to the server to resolve the supertypes for a given type hierarchy item. + /// Will return null if the server couldn't infer a valid type from item in the params. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string TypeHierarchySupertypesName = "typeHierarchy/supertypes"; + + /// + /// Strongly typed message object for 'typeHierarchy/supertypes'. + /// + /// Since LSP 3.17 + public static readonly LspRequest TypeHierarchySupertypes = new(TypeHierarchySupertypesName); + + /// + /// Method name for 'typeHierarchy/subtypes'. + /// + /// The request is sent from the client to the server to resolve outgoing calls for a given call hierarchy item. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TypeHierarchySubtypesName = "typeHierarchy/subtypes"; + + /// + /// Strongly typed message object for 'typeHierarchy/subtypes'. + /// + /// Since LSP 3.17 + public static readonly LspRequest TypeHierarchySubtypes = new(TypeHierarchySubtypesName); +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index 807b28dd915fa..c6e949638e18d 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -61,11 +61,6 @@ internal static partial class Methods /// public const string TextDocumentCompletionResolveName = "completionItem/resolve"; - /// - /// Method name for 'textDocument/definition'. - /// - public const string TextDocumentDefinitionName = "textDocument/definition"; - /// /// Method name for 'textDocument/diagnostic'. /// @@ -126,11 +121,6 @@ internal static partial class Methods /// public const string TextDocumentPublishDiagnosticsName = "textDocument/publishDiagnostics"; - /// - /// Method name for 'textDocument/implementation'. - /// - public const string TextDocumentImplementationName = "textDocument/implementation"; - /// /// Method name for 'textDocument/inlayHint'. /// @@ -141,16 +131,6 @@ internal static partial class Methods /// public const string InlayHintResolveName = "inlayHint/resolve"; - /// - /// Method name for 'textDocument/typeDefinition'. - /// - public const string TextDocumentTypeDefinitionName = "textDocument/typeDefinition"; - - /// - /// Method name for 'textDocument/references'. - /// - public const string TextDocumentReferencesName = "textDocument/references"; - /// /// Method name for 'textDocument/rename'. /// @@ -291,11 +271,6 @@ internal static partial class Methods /// public static readonly LspRequest TextDocumentCompletionResolve = new LspRequest(TextDocumentCompletionResolveName); - /// - /// Strongly typed message object for 'textDocument/definition'. - /// - public static readonly LspRequest?> TextDocumentDefinition = new LspRequest?>(TextDocumentDefinitionName); - /// /// Strongly typed message object for 'textDocument/documentHighlight'. /// @@ -351,11 +326,6 @@ internal static partial class Methods /// public static readonly LspNotification TextDocumentPublishDiagnostics = new LspNotification(TextDocumentPublishDiagnosticsName); - /// - /// Strongly typed message object for 'textDocument/implementation'. - /// - public static readonly LspRequest?> TextDocumentImplementation = new LspRequest?>(TextDocumentImplementationName); - /// /// Strongly typed message object for 'textDocument/inlayHint'. /// @@ -366,16 +336,6 @@ internal static partial class Methods /// public static readonly LspRequest InlayHintResolve = new LspRequest(InlayHintResolveName); - /// - /// Strongly typed message object for 'textDocument/typeDefinition'. - /// - public static readonly LspRequest?> TextDocumentTypeDefinition = new LspRequest?>(TextDocumentTypeDefinitionName); - - /// - /// Strongly typed message object for 'textDocument/references'. - /// - public static readonly LspRequest TextDocumentReferences = new LspRequest(TextDocumentReferencesName); - /// /// Strongly typed message object for 'textDocument/rename'. /// diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyClientCapabilities.cs new file mode 100644 index 0000000000000..9e6930b721fa2 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyClientCapabilities.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the various type hierarchy requests. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class CallHierarchyClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyIncomingCall.cs b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyIncomingCall.cs new file mode 100644 index 0000000000000..cfd4ef2e20d74 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyIncomingCall.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The item returned from a 'callHierarchy/incomingCalls' request +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class CallHierarchyIncomingCall +{ + /// + /// The for which to return incoming calls + /// + [JsonPropertyName("from")] + [JsonRequired] + public CallHierarchyItem From { get; init; } + + /// + /// The ranges at which the calls appear. This is relative to the caller + /// denoted by [`this.from`](#CallHierarchyIncomingCall.from). + /// + [JsonPropertyName("fromRanges")] + [JsonRequired] + + public Range[] FromRanges { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyIncomingCallsParams.cs b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyIncomingCallsParams.cs new file mode 100644 index 0000000000000..0569630a6b1ae --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyIncomingCallsParams.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a 'callHierarchy/incomingCalls' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class CallHierarchyIncomingCallsParams : TextDocumentPositionParams, IWorkDoneProgressParams, IPartialResultParams +{ + /// + /// The item returned from `textDocument/prepareCallHierarchy` + /// + [JsonPropertyName("item")] + [JsonRequired] + public CallHierarchyItem Item { get; init; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + /// + /// may only be used if the client opts in via + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyItem.cs b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyItem.cs new file mode 100644 index 0000000000000..384c225efa4cd --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyItem.cs @@ -0,0 +1,79 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Represents an item in the call hierarchy +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class CallHierarchyItem +{ + /// + /// The name of this item. + /// + [JsonPropertyName("name")] + [JsonRequired] + public string Name { get; init; } + + /// + /// The kind of this item. + /// + [JsonPropertyName("kind")] + [JsonRequired] + public SymbolKind Kind { get; init; } + + /// + /// Tags for this item. + /// + [JsonPropertyName("tags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SymbolTag[]? Tags { get; init; } + + /// + /// More detail for this item, e.g. the signature of a function. + /// + [JsonPropertyName("detail")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Detail { get; init; } + + /// + /// The resource identifier of this item. + /// + [JsonPropertyName("uri")] + [JsonRequired] + [JsonConverter(typeof(DocumentUriConverter))] + public Uri Uri { get; init; } + + /// + /// The range enclosing this symbol not including leading/trailing whitespace + /// but everything else, e.g. comments and code. + /// + [JsonPropertyName("range")] + [JsonRequired] + public Range Range { get; init; } + + /// + /// The range that should be selected and revealed when this symbol is being + /// picked, e.g. the name of a function. Must be contained by the + /// + /// + [JsonPropertyName("selectionRange")] + [JsonRequired] + public Range SelectionRange { get; init; } + + /// + /// A data field that is preserved between a call hierarchy prepare and + /// incoming calls or outgoing calls requests. + /// + [JsonPropertyName("data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public object? Data { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyOptions.cs new file mode 100644 index 0000000000000..28d0d339c8cd1 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyOptions.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Class which represents Call Hierarchy server capabilities. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class CallHierarchyOptions : IWorkDoneProgressOptions +{ + /// + /// Gets or sets a value indicating whether work done progress is supported. + /// + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyOutgoingCall.cs b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyOutgoingCall.cs new file mode 100644 index 0000000000000..f1f787e51fe77 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyOutgoingCall.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The item returned from a 'callHierarchy/outgoingCalls' request +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class CallHierarchyOutgoingCall +{ + /// + /// The for which to return outgoing calls + /// + [JsonPropertyName("to")] + [JsonRequired] + public CallHierarchyItem To { get; init; } + + /// + /// The range at which this item is called. This is the range relative to + /// the caller, e.g the item passed to the callHierarchy/outgoingCalls request. + /// + [JsonPropertyName("fromRanges")] + [JsonRequired] + public Range[] FromRanges { get; init; } +} + diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyOutgoingCallsParams.cs b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyOutgoingCallsParams.cs new file mode 100644 index 0000000000000..61863c4fe4f1b --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyOutgoingCallsParams.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a 'callHierarchy/incomingCalls' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class CallHierarchyOutgoingCallsParams : TextDocumentPositionParams, IWorkDoneProgressParams, IPartialResultParams +{ + /// + /// The item returned from `textDocument/prepareCallHierarchy` + /// + [JsonPropertyName("item")] + [JsonRequired] + public CallHierarchyItem Item { get; init; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + /// + /// may only be used if the client opts in via + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyPrepareParams.cs b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyPrepareParams.cs new file mode 100644 index 0000000000000..931bb20ae55e1 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyPrepareParams.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a 'textDocument/prepareCallHierarchy' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class CallHierarchyPrepareParams : TextDocumentPositionParams, IWorkDoneProgressParams +{ + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyRegistrationOptions.cs new file mode 100644 index 0000000000000..61aecb53647e2 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/CallHierarchyRegistrationOptions.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class CallHierarchyRegistrationOptions : CallHierarchyOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + + /// + /// The id used to register the request. The id can be used to deregister the request again. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/DeclarationClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/Navigation/DeclarationClientCapabilities.cs new file mode 100644 index 0000000000000..1e3df13871094 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/DeclarationClientCapabilities.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/declaration` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.14 +internal class DeclarationClientCapabilities : DynamicRegistrationSetting +{ + /// + /// Whether the client supports supports additional metadata in the form of definition links + /// + [JsonPropertyName("linkSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool LinkSupport { get; init; } +} + diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/DeclarationOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/DeclarationOptions.cs new file mode 100644 index 0000000000000..a45524997fc68 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/DeclarationOptions.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Server capabilities specific to Go to Declaration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.14 +internal class DeclarationOptions : IWorkDoneProgressOptions +{ + /// + /// Gets or sets a value indicating whether work done progress is supported. + /// + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/DeclarationParams.cs b/src/LanguageServer/Protocol/Protocol/Navigation/DeclarationParams.cs new file mode 100644 index 0000000000000..b68720b420d46 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/DeclarationParams.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a 'textDocument/declaration' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DeclarationParams : TextDocumentPositionParams, IWorkDoneProgressParams, IPartialResultParams> +{ + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + /// + /// may only be used if the client opts in via + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress>? PartialResultToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/DeclarationRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/DeclarationRegistrationOptions.cs new file mode 100644 index 0000000000000..81ec9e915f4de --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/DeclarationRegistrationOptions.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.14 +internal class DeclarationRegistrationOptions : DeclarationOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + + /// + /// The id used to register the request. The id can be used to deregister the request again. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/DefinitionClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/Navigation/DefinitionClientCapabilities.cs new file mode 100644 index 0000000000000..191d43b5aab67 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/DefinitionClientCapabilities.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/definition` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DefinitionClientCapabilities : DynamicRegistrationSetting +{ + /// + /// Whether the client supports supports additional metadata in the form of definition links + /// + /// Since LSP 3.14 + [JsonPropertyName("linkSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool LinkSupport { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/DefinitionOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/DefinitionOptions.cs new file mode 100644 index 0000000000000..6415053e4b0ed --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/DefinitionOptions.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Server capabilities specific to Go to Definition. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DefinitionOptions : IWorkDoneProgressOptions +{ + /// + /// Gets or sets a value indicating whether work done progress is supported. + /// + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/DefinitionParams.cs b/src/LanguageServer/Protocol/Protocol/Navigation/DefinitionParams.cs new file mode 100644 index 0000000000000..dc77005dd6543 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/DefinitionParams.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a 'textDocument/definition' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DefinitionParams : TextDocumentPositionParams, IWorkDoneProgressParams, IPartialResultParams> +{ + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + /// + /// may only be used if the client opts in via + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress>? PartialResultToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/DefinitionRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/DefinitionRegistrationOptions.cs new file mode 100644 index 0000000000000..1f6859fc5bd96 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/DefinitionRegistrationOptions.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +internal class DefinitionRegistrationOptions : DefinitionOptions, ITextDocumentRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/ImplementationClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/Navigation/ImplementationClientCapabilities.cs new file mode 100644 index 0000000000000..98ac0fd7d0c87 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/ImplementationClientCapabilities.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/implementation` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.6 +internal class ImplementationClientCapabilities : DynamicRegistrationSetting +{ + /// + /// Whether the client supports supports additional metadata in the form of definition links + /// + /// Since LSP 3.14 + [JsonPropertyName("linkSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool LinkSupport { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/ImplementationOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/ImplementationOptions.cs similarity index 93% rename from src/LanguageServer/Protocol/Protocol/ImplementationOptions.cs rename to src/LanguageServer/Protocol/Protocol/Navigation/ImplementationOptions.cs index afd33c2190764..14fe2999d1fd8 100644 --- a/src/LanguageServer/Protocol/Protocol/ImplementationOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/Navigation/ImplementationOptions.cs @@ -7,7 +7,7 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents workspace symbols capabilities. + /// Server capabilities specific to Go to Implementation. /// /// See the Language Server Protocol specification for additional information. /// diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/ImplementationParams.cs b/src/LanguageServer/Protocol/Protocol/Navigation/ImplementationParams.cs new file mode 100644 index 0000000000000..9e6c1f7be75ac --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/ImplementationParams.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a 'textDocument/implementation' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class ImplementationParams : TextDocumentPositionParams, IWorkDoneProgressParams, IPartialResultParams> +{ + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + /// + /// may only be used if the client opts in via + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress>? PartialResultToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/ImplementationRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/ImplementationRegistrationOptions.cs new file mode 100644 index 0000000000000..76602354149a5 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/ImplementationRegistrationOptions.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol +{ + using System.Text.Json.Serialization; + + /// + /// Subclass of that allows scoping the registration. + /// + /// See the Language Server Protocol specification for additional information. + /// + internal class ImplementationRegistrationOptions : ImplementationOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions + { + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + + /// + /// The id used to register the request. The id can be used to deregister the request again. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } + } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceClientCapabilities.cs new file mode 100644 index 0000000000000..92c201b84f0f4 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceClientCapabilities.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/references` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.6 +internal class ReferenceClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceContext.cs b/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceContext.cs new file mode 100644 index 0000000000000..e92832b883726 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceContext.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Class representing reference context information for find reference request parameter. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class ReferenceContext +{ + /// + /// Include the declaration of the current symbol. + /// + [JsonPropertyName("includeDeclaration")] + public bool IncludeDeclaration { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/ReferenceOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceOptions.cs similarity index 93% rename from src/LanguageServer/Protocol/Protocol/ReferenceOptions.cs rename to src/LanguageServer/Protocol/Protocol/Navigation/ReferenceOptions.cs index 2282473292523..389c0c37cb131 100644 --- a/src/LanguageServer/Protocol/Protocol/ReferenceOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceOptions.cs @@ -7,7 +7,7 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents workspace symbols capabilities. + /// Server capabilities specific to Find References. /// /// See the Language Server Protocol specification for additional information. /// diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceParams.cs b/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceParams.cs new file mode 100644 index 0000000000000..e6b3a42264302 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceParams.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a textDocument/references request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class ReferenceParams : TextDocumentPositionParams, IWorkDoneProgressParams, IPartialResultParams +{ + /// + /// Gets or sets the reference context. + /// + [JsonPropertyName("context")] + [JsonRequired] + public ReferenceContext Context { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceRegistrationOptions.cs new file mode 100644 index 0000000000000..85fb9087594cb --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/ReferenceRegistrationOptions.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol +{ + using System.Text.Json.Serialization; + + /// + /// Subclass of that allows scoping the registration. + /// + /// See the Language Server Protocol specification for additional information. + /// + internal class ReferenceRegistrationOptions : ReferenceOptions, ITextDocumentRegistrationOptions + { + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionClientCapabilities.cs new file mode 100644 index 0000000000000..04c6d63d749ab --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionClientCapabilities.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/typeDefinition` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.6 +internal class TypeDefinitionClientCapabilities : DynamicRegistrationSetting +{ + /// + /// Whether the client supports supports additional metadata in the form of definition links + /// + /// Since LSP 3.14 + [JsonPropertyName("linkSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool LinkSupport { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionOptions.cs new file mode 100644 index 0000000000000..24cd04ee611ce --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionOptions.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Server capabilities specific to Go to Type Declaration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class TypeDefinitionOptions : IWorkDoneProgressOptions +{ + /// + /// Gets or sets a value indicating whether work done progress is supported. + /// + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionParams.cs b/src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionParams.cs new file mode 100644 index 0000000000000..dfce5158d3e15 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionParams.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a 'textDocument/typeDefinition' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class TypeDefinitionParams : TextDocumentPositionParams, IWorkDoneProgressParams, IPartialResultParams> +{ + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + /// + /// may only be used if the client opts in via + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress>? PartialResultToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionRegistrationOptions.cs new file mode 100644 index 0000000000000..5b821d0cc78e3 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/TypeDefinitionRegistrationOptions.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class TypeDefinitionRegistrationOptions : TypeDefinitionOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + + /// + /// The id used to register the request. The id can be used to deregister the request again. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyClientCapabilities.cs new file mode 100644 index 0000000000000..28fd856c2b53c --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyClientCapabilities.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the various type hierarchy requests. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class TypeHierarchyClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyItem.cs b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyItem.cs new file mode 100644 index 0000000000000..860eba4cc1d1a --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyItem.cs @@ -0,0 +1,81 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Represents an item in the type hierarchy +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class TypeHierarchyItem +{ + /// + /// The name of this item. + /// + [JsonPropertyName("name")] + [JsonRequired] + public string Name { get; init; } + + /// + /// The kind of this item. + /// + [JsonPropertyName("kind")] + [JsonRequired] + public SymbolKind Kind { get; init; } + + /// + /// Tags for this item. + /// + [JsonPropertyName("tags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SymbolTag[]? Tags { get; init; } + + /// + /// More detail for this item, e.g. the signature of a function. + /// + [JsonPropertyName("detail")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Detail { get; init; } + + /// + /// The resource identifier of this item. + /// + [JsonPropertyName("uri")] + [JsonRequired] + [JsonConverter(typeof(DocumentUriConverter))] + public Uri Uri { get; init; } + + /// + /// The range enclosing this symbol not including leading/trailing whitespace + /// but everything else, e.g. comments and code. + /// + [JsonPropertyName("range")] + [JsonRequired] + public Range Range { get; init; } + + /// + /// The range that should be selected and revealed when this symbol is being + /// picked, e.g. the name of a function. Must be contained by the + /// + /// + [JsonPropertyName("selectionRange")] + [JsonRequired] + public Range SelectionRange { get; init; } + + /// + /// A data field that is preserved between a type hierarchy prepare and + /// supertypes or subtypes requests. It could also be used to identify the + /// type hierarchy in the server, helping improve the performance on + /// resolving supertypes and subtypes. + /// + [JsonPropertyName("data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public object? Data { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyOptions.cs new file mode 100644 index 0000000000000..43b02fadad74a --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyOptions.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Sever capabilities specific to Type Hierarchy. +/// +/// See the Language Server Protocol specification for additional information. +/// +internal class TypeHierarchyOptions : IWorkDoneProgressOptions +{ + /// + /// Gets or sets a value indicating whether work done progress is supported. + /// + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyPrepareParams.cs b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyPrepareParams.cs new file mode 100644 index 0000000000000..17c33d3c3ffb3 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyPrepareParams.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a 'textDocument/prepareTypeHierarchy' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class TypeHierarchyPrepareParams : TextDocumentPositionParams, IWorkDoneProgressParams +{ + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyRegistrationOptions.cs new file mode 100644 index 0000000000000..7b77860abd991 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchyRegistrationOptions.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +internal class TypeHierarchyRegistrationOptions : TypeHierarchyOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + + /// + /// The id used to register the request. The id can be used to deregister the request again. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchySubtypesParams.cs b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchySubtypesParams.cs new file mode 100644 index 0000000000000..dd7d5927dc23b --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchySubtypesParams.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a 'typeHierarchy/subtypes' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class TypeHierarchySubtypesParams : TextDocumentPositionParams, IWorkDoneProgressParams, IPartialResultParams +{ + /// + /// The for which to return subtypes + /// + [JsonPropertyName("item")] + [JsonRequired] + public TypeHierarchyItem Item { get; init; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + /// + /// may only be used if the client opts in via + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchySupertypesParams.cs b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchySupertypesParams.cs new file mode 100644 index 0000000000000..c356e0d6789c1 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Navigation/TypeHierarchySupertypesParams.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a 'typeHierarchy/supertypes' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class TypeHierarchySupertypesParams : TextDocumentPositionParams, IWorkDoneProgressParams, IPartialResultParams +{ + /// + /// The for which to return supertypes + /// + [JsonPropertyName("item")] + [JsonRequired] + public TypeHierarchyItem Item { get; init; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + /// + /// may only be used if the client opts in via + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/ReferenceContext.cs b/src/LanguageServer/Protocol/Protocol/ReferenceContext.cs deleted file mode 100644 index 2e7411b4411a0..0000000000000 --- a/src/LanguageServer/Protocol/Protocol/ReferenceContext.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace Roslyn.LanguageServer.Protocol -{ - using System.Text.Json.Serialization; - - /// - /// Class representing reference context information for find reference request parameter. - /// - /// See the Language Server Protocol specification for additional information. - /// - internal class ReferenceContext - { - /// - /// Gets or sets a value indicating whether declaration should be included. - /// - [JsonPropertyName("includeDeclaration")] - public bool IncludeDeclaration - { - get; - set; - } - } -} diff --git a/src/LanguageServer/Protocol/Protocol/ReferenceParams.cs b/src/LanguageServer/Protocol/Protocol/ReferenceParams.cs deleted file mode 100644 index 00a2106a75ddc..0000000000000 --- a/src/LanguageServer/Protocol/Protocol/ReferenceParams.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace Roslyn.LanguageServer.Protocol -{ - using System; - using System.Text.Json.Serialization; - - /// - /// Class representing find reference parameter for find reference request. - /// - /// See the Language Server Protocol specification for additional information. - /// - internal class ReferenceParams : TextDocumentPositionParams, IPartialResultParams - { - // Using IPartialResultParams instead of IPartialResultParams to - // allow the VS protocol extension to allow returning VSReferenceItem[] - - /// - /// Gets or sets the reference context. - /// - [JsonPropertyName("context")] - public ReferenceContext Context - { - get; - set; - } - - /// - /// Gets or sets the value of the PartialResultToken instance. - /// - [JsonPropertyName(Methods.PartialResultTokenName)] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public IProgress? PartialResultToken - { - get; - set; - } - } -} diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index a591f57710519..5a41ea5049f96 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -81,28 +81,38 @@ public TextDocumentSyncOptions? TextDocumentSync public SignatureHelpOptions? SignatureHelpProvider { get; set; } /// - /// Gets or sets a value indicating whether go to definition is supported. + /// The server provides Go to Declaration support. + /// + /// Since LSP 3.14 + [JsonPropertyName("declarationProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SumType? DeclarationProvider { get; init; } + + /// + /// The server provides Go to Definition support. /// [JsonPropertyName("definitionProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? DefinitionProvider { get; set; } /// - /// Gets or sets a value indicating whether go to type definition is supported. + /// The server provides Go to Type Definition support. /// + /// Since LSP 3.6 [JsonPropertyName("typeDefinitionProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? TypeDefinitionProvider { get; set; } + public SumType? TypeDefinitionProvider { get; set; } /// - /// Gets or sets a value indicating whether go to implementation is supported. + /// The server provides Go to Implementation support. /// + /// Since LSP 3.6 [JsonPropertyName("implementationProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? ImplementationProvider { get; set; } + public SumType? ImplementationProvider { get; set; } /// - /// Gets or sets a value indicating whether find all references is supported. + /// The server provides Find References support. /// [JsonPropertyName("referencesProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -199,6 +209,14 @@ public TextDocumentSyncOptions? TextDocumentSync [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? LinkedEditingRangeProvider { get; set; } + /// + /// The server provides call hierarchy support. + /// + /// Since LSP 3.16 + [JsonPropertyName("callHierarchyProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SumType? CallHierarchyProvider { get; init; } + /// /// Gets or sets the value which indicates if semantic tokens is supported. /// @@ -206,6 +224,14 @@ public TextDocumentSyncOptions? TextDocumentSync [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SemanticTokensOptions? SemanticTokensOptions { get; set; } + /// + /// The server provides type hierarchy support. + /// + /// Since LSP 3.17 + [JsonPropertyName("typeHierarchyProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SumType? TypeHierarchyProvider { get; init; } + /// /// Gets or sets the value which indicates what support the server has for inlay hints. /// diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index ad4a7c4347338..17c05849c6ee2 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents text document capabilities. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class TextDocumentClientCapabilities { @@ -44,32 +45,42 @@ internal class TextDocumentClientCapabilities public SignatureHelpSetting? SignatureHelp { get; set; } /// - /// Gets or sets the setting which determines if definition can be dynamically registered. + /// Capabilities specific to the `textDocument/declaration` request + /// + /// Since LSP 3.14 + [JsonPropertyName("declaration")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DeclarationClientCapabilities? Declaration { get; init; } + + /// + /// Capabilities specific to the `textDocument/definition` request /// [JsonPropertyName("definition")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? Definition { get; set; } + public DefinitionClientCapabilities? Definition { get; set; } /// - /// Gets or sets the settings which determines if type definition can be dynamically registered. + /// Capabilities specific to the `textDocument/typeDefinition` request. /// + /// Since LSP 3.6 [JsonPropertyName("typeDefinition")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? TypeDefinition { get; set; } + public TypeDefinitionClientCapabilities? TypeDefinition { get; set; } /// - /// Gets or sets the settings which determines if implementation can be dynamically registered. + /// Capabilities specific to the `textDocument/implementation` request. /// + /// Since LSP 3.6 [JsonPropertyName("implementation")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? Implementation { get; set; } + public ImplementationClientCapabilities? Implementation { get; set; } /// - /// Gets or sets the setting which determines if references can be dynamically registered. + /// Capabilities specific to the `textDocument/references` request. /// [JsonPropertyName("references")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? References { get; set; } + public ReferenceClientCapabilities? References { get; set; } /// /// Gets or sets the setting which determines if document highlight can be dynamically registered. @@ -154,6 +165,14 @@ internal class TextDocumentClientCapabilities [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting LinkedEditingRange { get; set; } + /// + /// Capabilities specific to the various call hierarchy requests. + /// + /// Since LSP 3.16 + [JsonPropertyName("callHierarchy")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public CallHierarchyClientCapabilities CallHierarchy { get; init; } + /// /// Gets or sets a setting indicating whether semantic tokens is supported. /// @@ -161,6 +180,14 @@ internal class TextDocumentClientCapabilities [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SemanticTokensSetting? SemanticTokens { get; set; } + /// + /// Capabilities specific to the various type hierarchy requests. + /// + /// Since LSP 3.17 + [JsonPropertyName("typeHierarchy")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public TypeHierarchyClientCapabilities? TypeHierarchy { get; init; } + /// /// Gets or sets the setting which determines what support the client has for pull diagnostics. /// diff --git a/src/LanguageServer/Protocol/Protocol/TypeDefinitionOptions.cs b/src/LanguageServer/Protocol/Protocol/TypeDefinitionOptions.cs deleted file mode 100644 index b17c3bec86600..0000000000000 --- a/src/LanguageServer/Protocol/Protocol/TypeDefinitionOptions.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace Roslyn.LanguageServer.Protocol -{ - using System.Text.Json.Serialization; - - /// - /// Class which represents workspace symbols capabilities. - /// - /// See the Language Server Protocol specification for additional information. - /// - internal class TypeDefinitionOptions : IWorkDoneProgressOptions - { - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// - [JsonPropertyName("workDoneProgress")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool WorkDoneProgress { get; init; } - } -} From 6dceb2e70a6d0dd8d175811187d845ecdc363b0b Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Thu, 6 Jun 2024 01:54:56 -0400 Subject: [PATCH 08/46] LSP Protocol: Update documentLink & documentHighlight --- .../Protocol/Protocol/DocumentHighlight.cs | 7 ++- .../DocumentHighlightClientCapabilities.cs | 15 ++++++ .../Protocol/DocumentHighlightOptions.cs | 2 +- .../Protocol/DocumentHighlightParams.cs | 24 ++++----- .../DocumentHighlightRegistrationOptions.cs | 24 +++++++++ .../Protocol/Protocol/DocumentLink.cs | 31 +++++++++-- .../DocumentLinkClientCapabilities.cs | 24 +++++++++ .../Protocol/Protocol/DocumentLinkOptions.cs | 11 ++-- .../Protocol/Protocol/DocumentLinkParams.cs | 18 +++++-- .../DocumentLinkRegistrationOptions.cs | 24 +++++++++ .../Protocol/Protocol/Methods.Navigation.cs | 54 +++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 30 ----------- .../Protocol/Protocol/ServerCapabilities.cs | 2 +- .../TextDocumentClientCapabilities.cs | 8 +-- 14 files changed, 209 insertions(+), 65 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/DocumentHighlightClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/DocumentHighlightRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/DocumentLinkClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/DocumentLinkRegistrationOptions.cs diff --git a/src/LanguageServer/Protocol/Protocol/DocumentHighlight.cs b/src/LanguageServer/Protocol/Protocol/DocumentHighlight.cs index ee7ab022fea0f..c90c401795fdb 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentHighlight.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentHighlight.cs @@ -9,9 +9,12 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing the response from a textDocument/documentHighlight request. - /// + /// A document highlight is a range inside a text document which deserves + /// special attention.Usually a document highlight is visualized by changing + /// the background color of its range. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DocumentHighlight { diff --git a/src/LanguageServer/Protocol/Protocol/DocumentHighlightClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/DocumentHighlightClientCapabilities.cs new file mode 100644 index 0000000000000..a045bf5b730d6 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DocumentHighlightClientCapabilities.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/documentHighlight` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DocumentHighlightClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/DocumentHighlightOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentHighlightOptions.cs index c01c7eb95adb7..6c3abfc614bc3 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentHighlightOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentHighlightOptions.cs @@ -7,7 +7,7 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents workspace symbols capabilities. + /// Server capabilities specific to Document Highlight. /// /// See the Language Server Protocol specification for additional information. /// diff --git a/src/LanguageServer/Protocol/Protocol/DocumentHighlightParams.cs b/src/LanguageServer/Protocol/Protocol/DocumentHighlightParams.cs index 9fed8bdcc35fe..4933d02d3dd54 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentHighlightParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentHighlightParams.cs @@ -9,22 +9,20 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the parameters sent for a textDocument/documentHighlight request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class DocumentHighlightParams - : TextDocumentPositionParams, - IPartialResultParams + internal class DocumentHighlightParams : TextDocumentPositionParams, IWorkDoneProgressParams, IPartialResultParams { - /// - /// Gets or sets the value of the PartialResultToken instance. - /// - [JsonPropertyName("partialResultToken")] + /// + [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public IProgress? PartialResultToken - { - get; - set; - } + public IProgress? PartialResultToken { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/DocumentHighlightRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentHighlightRegistrationOptions.cs new file mode 100644 index 0000000000000..601c22ac19e69 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DocumentHighlightRegistrationOptions.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DocumentHighlightRegistrationOptions : DocumentHighlightOptions, ITextDocumentRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/DocumentLink.cs b/src/LanguageServer/Protocol/Protocol/DocumentLink.cs index a4fe991aef507..f060bec505004 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentLink.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentLink.cs @@ -8,14 +8,16 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing the response of a textDocument/documentLink request. - /// + /// A document link is a range in a text document that links to an internal or + /// external resource, like another text document or a web site. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DocumentLink { /// - /// Gets or sets the range the link applies to. + /// The range this link applies to. /// [JsonPropertyName("range")] public Range Range @@ -25,7 +27,7 @@ public Range Range } /// - /// Gets or sets the uri that the link points to. + /// The uri this link points to. If missing a resolve request is sent later. /// [JsonPropertyName("target")] [JsonConverter(typeof(DocumentUriConverter))] @@ -35,5 +37,26 @@ public Uri? Target get; set; } + + /// + /// The tooltip text when you hover over this link. + /// + /// If a tooltip is provided, it will be displayed in a string that includes + /// instructions on how to trigger the link, such as {0} (ctrl + click). + /// The specific instructions vary depending on OS, user settings, and localization. + /// + /// + /// Since LSP 3.15 + [JsonPropertyName("tooltip")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Tooltip { get; init; } + + /// + /// A data entry field that is preserved on a document link between a + /// DocumentLinkRequest and a DocumentLinkResolveRequest. + /// + [JsonPropertyName("data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public object? Data { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/DocumentLinkClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/DocumentLinkClientCapabilities.cs new file mode 100644 index 0000000000000..6cef7742f0095 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DocumentLinkClientCapabilities.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/documentLink` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DocumentLinkClientCapabilities : DynamicRegistrationSetting +{ + /// + /// Whether the client supports the property. + /// + /// Since LSP 3.15 + [JsonPropertyName("tooltipSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool TooltipSupport { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/DocumentLinkOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentLinkOptions.cs index c01515f8ae949..42dea0909a2cb 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentLinkOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentLinkOptions.cs @@ -8,21 +8,18 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the document link options for server capabilities. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DocumentLinkOptions : IWorkDoneProgressOptions { /// - /// Gets or sets a value indicating whether or not the server supports resolve providers. + /// Whether or not the server has a resolve provider for document links. /// [JsonPropertyName("resolveProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool ResolveProvider - { - get; - set; - } + public bool ResolveProvider { get; set; } /// /// Gets or sets a value indicating whether work done progress is supported. diff --git a/src/LanguageServer/Protocol/Protocol/DocumentLinkParams.cs b/src/LanguageServer/Protocol/Protocol/DocumentLinkParams.cs index 780a15fceded5..b69ec733fc76d 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentLinkParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentLinkParams.cs @@ -4,17 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// /// Class representing the parameters sent for a textDocument/documentLink request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class DocumentLinkParams : ITextDocumentParams + internal class DocumentLinkParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams { /// - /// Gets or sets the to provide links for. + /// The to provide links for. /// [JsonPropertyName("textDocument")] public TextDocumentIdentifier TextDocument @@ -22,5 +24,15 @@ public TextDocumentIdentifier TextDocument get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/DocumentLinkRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentLinkRegistrationOptions.cs new file mode 100644 index 0000000000000..9be4a9d90e132 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DocumentLinkRegistrationOptions.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DocumentLinkRegistrationOptions : DocumentLinkOptions, ITextDocumentRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Navigation.cs b/src/LanguageServer/Protocol/Protocol/Methods.Navigation.cs index 2031062a8ce84..55ead1428fef7 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Navigation.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Navigation.cs @@ -221,4 +221,58 @@ partial class Methods /// /// Since LSP 3.17 public static readonly LspRequest TypeHierarchySubtypes = new(TypeHierarchySubtypesName); + + /// + /// Method name for 'textDocument/documentHighlight'. + /// + /// The document highlight request is sent from the client to the server to resolve document highlights for a given text document position. + /// For programming languages this usually highlights all references to the symbol scoped to this file. + /// + /// + /// However, we kept ‘textDocument/documentHighlight’ and ‘textDocument/references’ separate requests since the first one is allowed to be + /// more fuzzy. Symbol matches usually have a of or + /// whereas fuzzy or textual matches use as the kind. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentDocumentHighlightName = "textDocument/documentHighlight"; + + /// + /// Strongly typed message object for 'textDocument/documentHighlight'. + /// + public static readonly LspRequest TextDocumentDocumentHighlight = new(TextDocumentDocumentHighlightName); + + /// + /// Method name for 'textDocument/documentLink'. + /// + /// The document links request is sent from the client to the server to request the location of links in a document. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentDocumentLinkName = "textDocument/documentLink"; + + /// + /// Strongly typed message object for 'textDocument/documentLink'. + /// + public static readonly LspRequest TextDocumentDocumentLink = new(TextDocumentDocumentLinkName); + + /// + /// Method name for 'documentLink/resolve'. + /// + /// The document link resolve request is sent from the client to the server to resolve the target of a given document link. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string DocumentLinkResolveName = "documentLink/resolve"; + + /// + /// Strongly typed message object for 'documentLink/resolve'. + /// + public static readonly LspRequest DocumentLinkResolve = new(DocumentLinkResolveName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index c6e949638e18d..71bf231f84aa4 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -66,21 +66,6 @@ internal static partial class Methods /// public const string TextDocumentDiagnosticName = "textDocument/diagnostic"; - /// - /// Method name for 'textDocument/documentHighlight'. - /// - public const string TextDocumentDocumentHighlightName = "textDocument/documentHighlight"; - - /// - /// Method name for 'textDocument/documentLink'. - /// - public const string TextDocumentDocumentLinkName = "textDocument/documentLink"; - - /// - /// Method name for 'documentLink/resolve'. - /// - public const string DocumentLinkResolveName = "documentLink/resolve"; - /// /// Method name for 'textDocument/documentColor'. /// @@ -271,21 +256,6 @@ internal static partial class Methods /// public static readonly LspRequest TextDocumentCompletionResolve = new LspRequest(TextDocumentCompletionResolveName); - /// - /// Strongly typed message object for 'textDocument/documentHighlight'. - /// - public static readonly LspRequest TextDocumentDocumentHighlight = new LspRequest(TextDocumentDocumentHighlightName); - - /// - /// Strongly typed message object for 'textDocument/documentLink'. - /// - public static readonly LspRequest TextDocumentDocumentLink = new LspRequest(TextDocumentDocumentLinkName); - - /// - /// Strongly typed message object for 'documentLink/resolve'. - /// - public static readonly LspRequest DocumentLinkResolve = new LspRequest(DocumentLinkResolveName); - /// /// Strongly typed message object for 'textDocument/documentColor'. /// diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 5a41ea5049f96..16a997bd59ade 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -119,7 +119,7 @@ public TextDocumentSyncOptions? TextDocumentSync public SumType? ReferencesProvider { get; set; } /// - /// Gets or sets a value indicating whether the server supports document highlight. + /// The server provides Document Highlight support. /// [JsonPropertyName("documentHighlightProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index 17c05849c6ee2..e60878c7fe79a 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -83,11 +83,11 @@ internal class TextDocumentClientCapabilities public ReferenceClientCapabilities? References { get; set; } /// - /// Gets or sets the setting which determines if document highlight can be dynamically registered. + /// Capabilities specific to the `textDocument/documentHighlight` request. /// [JsonPropertyName("documentHighlight")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? DocumentHighlight { get; set; } + public DocumentHighlightClientCapabilities? DocumentHighlight { get; set; } /// /// Gets or sets the setting which determines if document symbol can be dynamically registered. @@ -111,11 +111,11 @@ internal class TextDocumentClientCapabilities public DynamicRegistrationSetting? CodeLens { get; set; } /// - /// Gets or sets the setting which determines if document link can be dynamically registered. + /// Capabilities specific to the `textDocument/documentLink` request. /// [JsonPropertyName("documentLink")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? DocumentLink { get; set; } + public DocumentLinkClientCapabilities? DocumentLink { get; set; } /// /// Gets or sets the setting which determines if formatting can be dynamically registered. From 71dfa3c8750c10d7d18ab12abfa43d0c7cc5cdb8 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Fri, 7 Jun 2024 20:02:29 -0400 Subject: [PATCH 09/46] LSP Protocol: Update Hover & CodeLens --- .../Protocol/Protocol/CodeLens.cs | 14 +++- .../Protocol/CodeLensClientCapabilities.cs | 15 ++++ .../Protocol/Protocol/CodeLensOptions.cs | 3 +- .../Protocol/Protocol/CodeLensParams.cs | 16 +++- .../Protocol/CodeLensRegistrationOptions.cs | 24 ++++++ .../Protocol/CodeLensWorkspaceSetting.cs | 16 +++- src/LanguageServer/Protocol/Protocol/Hover.cs | 26 ++---- .../Protocol/Protocol/HoverOptions.cs | 3 +- .../Protocol/Protocol/HoverParams.cs | 22 +++++ .../Protocol/HoverRegistrationOptions.cs | 24 ++++++ .../Protocol/Protocol/HoverSetting.cs | 11 ++- .../Protocol/Internal/VSInternalHover.cs | 16 ++-- .../Protocol/Protocol/MarkedString.cs | 21 ++++- .../Protocol/Protocol/Methods.Document.cs | 83 +++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 50 ----------- .../Protocol/Protocol/ServerCapabilities.cs | 2 +- .../TextDocumentClientCapabilities.cs | 6 +- .../Protocol/WorkspaceClientCapabilities.cs | 3 +- 18 files changed, 262 insertions(+), 93 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/CodeLensClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/CodeLensRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/HoverParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/HoverRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Methods.Document.cs diff --git a/src/LanguageServer/Protocol/Protocol/CodeLens.cs b/src/LanguageServer/Protocol/Protocol/CodeLens.cs index 4bec557ca0a10..0eed0ebdb61ac 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeLens.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeLens.cs @@ -7,16 +7,24 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// A class representing a code lens command that should be shown alongside source code. - /// + /// A code lens represents a command that should be shown along with + /// source text, like the number of references, a way to run tests, etc. + /// + /// A code lens is _unresolved_ when no command is associated to it. For + /// performance reasons the creation of a code lens and resolving should be done + /// in two stages. + /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CodeLens { /// - /// Gets or sets the range that the code lens applies to. + /// The range in which this code lens is valid. Should only span a single line. /// [JsonPropertyName("range")] + [JsonRequired] public Range Range { get; diff --git a/src/LanguageServer/Protocol/Protocol/CodeLensClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/CodeLensClientCapabilities.cs new file mode 100644 index 0000000000000..44155ed3ecb03 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/CodeLensClientCapabilities.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/codeLens` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class CodeLensClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/CodeLensOptions.cs b/src/LanguageServer/Protocol/Protocol/CodeLensOptions.cs index 22ac4b4cbfb1c..828344451bcb2 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeLensOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeLensOptions.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the options for code lens support. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CodeLensOptions : IWorkDoneProgressOptions { diff --git a/src/LanguageServer/Protocol/Protocol/CodeLensParams.cs b/src/LanguageServer/Protocol/Protocol/CodeLensParams.cs index a2ee3f149fbc2..0ae8e41263b34 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeLensParams.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeLensParams.cs @@ -4,14 +4,16 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// /// Class representing the parameters sent from the client to the server for a textDocument/codeLens request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class CodeLensParams : ITextDocumentParams + internal class CodeLensParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams { /// /// Gets or sets the document identifier to fetch code lens results for. @@ -22,5 +24,15 @@ public TextDocumentIdentifier TextDocument get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/CodeLensRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/CodeLensRegistrationOptions.cs new file mode 100644 index 0000000000000..e3c824ff2708d --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/CodeLensRegistrationOptions.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class CodeLensRegistrationOptions : CodeLensOptions, ITextDocumentRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/CodeLensWorkspaceSetting.cs b/src/LanguageServer/Protocol/Protocol/CodeLensWorkspaceSetting.cs index 444bf3390dabe..2a2c6ab47cdbe 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeLensWorkspaceSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeLensWorkspaceSetting.cs @@ -7,14 +7,22 @@ namespace Roslyn.LanguageServer.Protocol { /// - /// Class representing the workspace code lens client capabilities. - /// - /// See the Language Server Protocol specification for additional information. + /// Client capabilities specific to the code lens requests scoped to the workspace. + /// + /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class CodeLensWorkspaceSetting { /// - /// Gets or sets a value indicating whether the client supports a refresh request sent from the server to the client. + /// Whether the client implementation supports a refresh request sent from the + /// server to the client. + /// + /// Note that this event is global and will force the client to refresh all + /// code lenses currently shown. It should be used with absolute care and is + /// useful for situation where a server for example detect a project wide + /// change that requires such a calculation. /// [JsonPropertyName("refreshSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] diff --git a/src/LanguageServer/Protocol/Protocol/Hover.cs b/src/LanguageServer/Protocol/Protocol/Hover.cs index 27c8399906956..82874f9c10149 100644 --- a/src/LanguageServer/Protocol/Protocol/Hover.cs +++ b/src/LanguageServer/Protocol/Protocol/Hover.cs @@ -7,34 +7,26 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing the data returned by a textDocument/hover request. - /// + /// Class representing the data returned by a textDocument/hover request. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class Hover { /// - /// Gets or sets the content for the hover. Object can either be an array or a single object. - /// If the object is an array the array can contain objects of type and . - /// If the object is not an array it can be of type , , or . + /// The hover's content /// - // This is nullable because in VS we allow null when VSInternalHover.RawContent is specified instead of Contents [JsonPropertyName("contents")] - public SumType[], MarkupContent>? Contents - { - get; - set; - } + [JsonRequired] + public SumType[], MarkupContent> Contents { get; set; } /// - /// Gets or sets the range over which the hover applies. + /// An optional range inside a text document that is used to visualize the applicable + /// range of the hover, e.g. by changing the background color. /// [JsonPropertyName("range")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public Range? Range - { - get; - set; - } + public Range? Range { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/HoverOptions.cs b/src/LanguageServer/Protocol/Protocol/HoverOptions.cs index 51c8a83658f0d..18de3820c7048 100644 --- a/src/LanguageServer/Protocol/Protocol/HoverOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/HoverOptions.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents the server hover support. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class HoverOptions : IWorkDoneProgressOptions { diff --git a/src/LanguageServer/Protocol/Protocol/HoverParams.cs b/src/LanguageServer/Protocol/Protocol/HoverParams.cs new file mode 100644 index 0000000000000..57bd0c85a5fd5 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/HoverParams.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The params sent in a 'textDocument/hover' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class HoverParams : TextDocumentPositionParams, IWorkDoneProgressParams +{ + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/HoverRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/HoverRegistrationOptions.cs new file mode 100644 index 0000000000000..d2f278aaf9fd9 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/HoverRegistrationOptions.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class HoverRegistrationOptions : HoverOptions, ITextDocumentRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/HoverSetting.cs b/src/LanguageServer/Protocol/Protocol/HoverSetting.cs index e19b54f371fe0..d5af4e8609a2a 100644 --- a/src/LanguageServer/Protocol/Protocol/HoverSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/HoverSetting.cs @@ -7,14 +7,19 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents the initialization setting for hover. - /// + /// Client capabilities specific to the `textDocument/hover` request. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class HoverSetting : DynamicRegistrationSetting { /// - /// Gets or sets the values supported. + /// The client supports the following content formats in a + /// instance in . + /// + /// The order describes the preferred format of the client. + /// /// [JsonPropertyName("contentFormat")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs index 54c83f2ebf742..44fa7428eb2d4 100644 --- a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs +++ b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs @@ -19,10 +19,16 @@ internal class VSInternalHover : Hover [JsonPropertyName("_vs_rawContent")] [JsonConverter(typeof(ObjectContentConverter))] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public object? RawContent - { - get; - set; - } + public object? RawContent { get; set; } + + /// + /// The hover's content + /// + /// + /// This may only be null when is specified instead of . + /// + [JsonPropertyName("contents")] + [JsonRequired] + public new SumType, SumType[], MarkupContent>? Contents { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/MarkedString.cs b/src/LanguageServer/Protocol/Protocol/MarkedString.cs index 3ca516d0589ab..3b878bcb1b941 100644 --- a/src/LanguageServer/Protocol/Protocol/MarkedString.cs +++ b/src/LanguageServer/Protocol/Protocol/MarkedString.cs @@ -4,13 +4,30 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// - /// Class representing human readable text that should be rendered. - /// + /// MarkedString can be used to render human readable text. It is either a + /// markdown string or a code-block that provides a language and a code snippet. + /// + /// The language identifier is semantically equal to the optional language + /// identifier in fenced code blocks in GitHub issues. + /// + /// The pair of a language and a value is an equivalent to markdown: + /// + /// ```${language} + /// ${value} + /// ``` + /// + /// + /// Note that markdown strings will be sanitized - that means html will be escaped. + /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + [Obsolete("Use MarkupContent instead")] internal class MarkedString { /// diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs new file mode 100644 index 0000000000000..136bf3187f7ab --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -0,0 +1,83 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +// non-navigation methods from https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#languageFeatures +partial class Methods +{ + // NOTE: these are sorted in the order used by the spec + + /// + /// Method name for 'textDocument/hover'. + /// + /// The hover request is sent from the client to the server to request hover information at a given text document position. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentHoverName = "textDocument/hover"; + + /// + /// Strongly typed message object for 'textDocument/hover'. + /// + public static readonly LspRequest TextDocumentHover = new(TextDocumentHoverName); + + /// + /// Method name for 'textDocument/codeLens'. + /// + /// The code lens request is sent from the client to the server to compute code lenses for a given text document. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentCodeLensName = "textDocument/codeLens"; + + /// + /// Strongly typed message object for 'textDocument/codeLens'. + /// + public static readonly LspRequest TextDocumentCodeLens = new(TextDocumentCodeLensName); + + /// + /// Method name for 'codeLens/resolve'. + /// + /// The code lens resolve request is sent from the client to the server to resolve the command for a given code lens item. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string CodeLensResolveName = "codeLens/resolve"; + + /// + /// Strongly typed message object for 'codeLens/resolve'. + /// + public static readonly LspRequest CodeLensResolve = new(CodeLensResolveName); + + /// + /// Method name for 'workspace/codeLens/refresh'. + /// + /// The workspace/codeLens/refresh request is sent from the server to the client. Servers can use it to ask clients to + /// refresh the code lenses currently shown in editors. As a result the client should ask the server to recompute the + /// code lenses for these editors. + /// + /// This is useful if a server detects a configuration change which requires a re-calculation of all code lenses. Note + /// that the client still has the freedom to delay the re-calculation of the code lenses if for example an editor + /// is currently not visible. + /// + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string WorkspaceCodeLensRefreshName = "workspace/codeLens/refresh"; + + /// + /// Strongly typed message object for 'workspace/codeLens/refresh'. + /// + public static readonly LspRequest WorkspaceCodeLensRefresh = new(WorkspaceCodeLensRefreshName); +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index 71bf231f84aa4..261bb9a0909ff 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -36,21 +36,11 @@ internal static partial class Methods /// public const string TextDocumentCodeActionName = "textDocument/codeAction"; - /// - /// Method name for 'textDocument/codeLens'. - /// - public const string TextDocumentCodeLensName = "textDocument/codeLens"; - /// /// Method name for 'codeAction/resolve'. /// public const string CodeActionResolveName = "codeAction/resolve"; - /// - /// Method name for 'codeLens/resolve'. - /// - public const string CodeLensResolveName = "codeLens/resolve"; - /// /// Method name for 'textDocument/completion'. /// @@ -76,21 +66,11 @@ internal static partial class Methods /// public const string TextDocumentDocumentSymbolName = "textDocument/documentSymbol"; - /// - /// Method name for 'textDocument/foldingRange'. - /// - public const string TextDocumentFoldingRangeName = "textDocument/foldingRange"; - /// /// Method name for 'textDocument/formatting'. /// public const string TextDocumentFormattingName = "textDocument/formatting"; - /// - /// Method name for 'textDocument/hover'. - /// - public const string TextDocumentHoverName = "textDocument/hover"; - /// /// Method name for 'textDocument/onTypeFormatting'. /// @@ -211,11 +191,6 @@ internal static partial class Methods /// public const string WorkspaceDidChangeWatchedFilesName = "workspace/didChangeWatchedFiles"; - /// - /// Method name for 'workspace/codeLens/refresh'. - /// - public const string WorkspaceCodeLensRefreshName = "workspace/codeLens/refresh"; - /// /// Method name for 'workspace/inlayHint/refresh'. /// @@ -231,21 +206,11 @@ internal static partial class Methods /// public static readonly LspRequest[]?> TextDocumentCodeAction = new LspRequest[]?>(TextDocumentCodeActionName); - /// - /// Strongly typed message object for 'textDocument/codeLens'. - /// - public static readonly LspRequest TextDocumentCodeLens = new LspRequest(TextDocumentCodeLensName); - /// /// Strongly typed message object for 'codeAction/resolve'. /// public static readonly LspRequest CodeActionResolve = new LspRequest(CodeActionResolveName); - /// - /// Strongly typed message object for 'codeLens/resolve'. - /// - public static readonly LspRequest CodeLensResolve = new LspRequest(CodeLensResolveName); - /// /// Strongly typed message object for 'textDocument/completion'. /// @@ -266,21 +231,11 @@ internal static partial class Methods /// public static readonly LspRequest TextDocumentDocumentSymbol = new LspRequest(TextDocumentDocumentSymbolName); - /// - /// Stronly typed message object for 'textDocument/foldingRange'. - /// - public static readonly LspRequest TextDocumentFoldingRange = new LspRequest(TextDocumentFoldingRangeName); - /// /// Strongly typed message object for 'textDocument/formatting'. /// public static readonly LspRequest TextDocumentFormatting = new LspRequest(TextDocumentFormattingName); - /// - /// Strongly typed message object for 'textDocument/hover'. - /// - public static readonly LspRequest TextDocumentHover = new LspRequest(TextDocumentHoverName); - /// /// Strongly typed message object for 'textDocument/onTypeFormatting'. /// @@ -376,11 +331,6 @@ internal static partial class Methods /// public static readonly LspNotification WorkspaceDidChangeWatchedFiles = new LspNotification(WorkspaceDidChangeWatchedFilesName); - /// - /// Strongly typed message object for 'workspace/codeLens/refresh'. - /// - public static readonly LspRequest WorkspaceCodeLensRefresh = new LspRequest(WorkspaceCodeLensRefreshName); - /// /// Strongly typed message object for 'workspace/inlayHint/refresh'. /// diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 16a997bd59ade..f5ee44a42acf3 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -67,7 +67,7 @@ public TextDocumentSyncOptions? TextDocumentSync public CompletionOptions? CompletionProvider { get; set; } /// - /// Gets or sets a value indicating whether the server provides hover support. + /// The server provides hover support. /// [JsonPropertyName("hoverProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index e60878c7fe79a..efd3fcbafe203 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -31,7 +31,7 @@ internal class TextDocumentClientCapabilities public CompletionSetting? Completion { get; set; } /// - /// Gets or sets the setting which determines if hover can be dynamically registered. + /// Capabilities specific to the `textDocument/hover` request /// [JsonPropertyName("hover")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -104,11 +104,11 @@ internal class TextDocumentClientCapabilities public CodeActionSetting? CodeAction { get; set; } /// - /// Gets or sets the setting which determines if code lens can be dynamically registered. + /// Capabilities specific to the `textDocument/codeLens` request. /// [JsonPropertyName("codeLens")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? CodeLens { get; set; } + public CodeLensClientCapabilities? CodeLens { get; set; } /// /// Capabilities specific to the `textDocument/documentLink` request. diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs index 02083af20d7d6..6be16b126fd7c 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs @@ -73,8 +73,9 @@ internal class WorkspaceClientCapabilities public SemanticTokensWorkspaceSetting? SemanticTokens { get; set; } /// - /// Gets of sets capabilities specific to the code lens requests scoped to the workspace. + /// Capabilities specific to the code lens requests scoped to the workspace. /// + /// Since LSP 3.16 [JsonPropertyName("codeLens")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeLensWorkspaceSetting? CodeLens { get; set; } From 1e09482b5b91a9c8d1544682217ae1f1df347830 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Fri, 7 Jun 2024 20:38:45 -0400 Subject: [PATCH 10/46] LSP Protocol: Update FoldingRange, add SelectionRange --- .../Protocol/Protocol/FoldingRange.cs | 51 ++++++++++++++++--- .../Protocol/Protocol/FoldingRangeKind.cs | 6 ++- .../Protocol/Protocol/FoldingRangeKindSet.cs | 26 ++++++++++ .../Protocol/Protocol/FoldingRangeParams.cs | 26 +++++++--- .../FoldingRangeRegistrationOptions.cs | 32 ++++++++++++ .../Protocol/Protocol/FoldingRangeSetting.cs | 28 ++++++---- .../Protocol/FoldingRangeSettingOptions.cs | 11 ++-- .../Protocol/Protocol/Methods.Document.cs | 37 ++++++++++++++ .../Protocol/Protocol/SelectionRange.cs | 34 +++++++++++++ .../SelectionRangeClientCapabilities.cs | 16 ++++++ .../Protocol/SelectionRangeOptions.cs | 24 +++++++++ .../Protocol/Protocol/SelectionRangeParams.cs | 42 +++++++++++++++ .../SelectionRangeRegistrationOptions.cs | 32 ++++++++++++ .../Protocol/Protocol/ServerCapabilities.cs | 9 ++++ .../TextDocumentClientCapabilities.cs | 12 ++++- 15 files changed, 354 insertions(+), 32 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/FoldingRangeKindSet.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FoldingRangeRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/SelectionRange.cs create mode 100644 src/LanguageServer/Protocol/Protocol/SelectionRangeClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/SelectionRangeOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/SelectionRangeParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/SelectionRangeRegistrationOptions.cs diff --git a/src/LanguageServer/Protocol/Protocol/FoldingRange.cs b/src/LanguageServer/Protocol/Protocol/FoldingRange.cs index 78f0c975a205d..d2ec8c52d55b5 100644 --- a/src/LanguageServer/Protocol/Protocol/FoldingRange.cs +++ b/src/LanguageServer/Protocol/Protocol/FoldingRange.cs @@ -7,16 +7,28 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing a folding range in a document. - /// + /// Represents a folding range in a document. + /// + /// To be valid, start and end line must be bigger than zero and smaller than + /// the number of lines in the document. Clients are free to ignore invalid ranges. + /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 internal class FoldingRange { /// - /// Gets or sets the start line value. + /// The zero-based start line of the range to fold. + /// + /// The folded area starts after the line's last character. To be + /// valid, the end must be zero or larger and smaller than the + /// number of lines in the document. + /// /// [JsonPropertyName("startLine")] + [JsonRequired] public int StartLine { get; @@ -24,7 +36,10 @@ public int StartLine } /// - /// Gets or sets the start character value. + /// The zero-based character offset from where the folded range starts. + /// + /// If not defined, defaults to the length of the start line. + /// /// [JsonPropertyName("startCharacter")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -35,9 +50,15 @@ public int? StartCharacter } /// - /// Gets or sets the end line value. + /// The zero-based end line of the range to fold. + /// + /// The folded area ends with the line's last character. To be valid, + /// the end must be zero or larger and smaller than the number of + /// lines in the document. + /// /// [JsonPropertyName("endLine")] + [JsonRequired] public int EndLine { get; @@ -45,7 +66,10 @@ public int EndLine } /// - /// Gets or sets the end character value. + /// The zero-based character offset before the folded range ends. + /// + /// If not defined, defaults to the length of the end line. + /// /// [JsonPropertyName("endCharacter")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -56,7 +80,13 @@ public int? EndCharacter } /// - /// Gets or sets the folding range kind. + /// Describes the kind of the folding range such as + /// or . + /// + /// The kind is used to categorize folding ranges and used by commands like + /// 'Fold all comments'. See for an + /// enumeration of standardized kinds. + /// /// [JsonPropertyName("kind")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -67,8 +97,13 @@ public FoldingRangeKind? Kind } /// - /// Gets or sets the collapsedText. + /// The text that the client should show when the specified range is + /// collapsed. + /// + /// If not defined or not supported by the client, a default will be chosen by the client + /// /// + /// Since LSP 3.17 [JsonPropertyName("collapsedText")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? CollapsedText diff --git a/src/LanguageServer/Protocol/Protocol/FoldingRangeKind.cs b/src/LanguageServer/Protocol/Protocol/FoldingRangeKind.cs index bf807c451becf..2b5447072329b 100644 --- a/src/LanguageServer/Protocol/Protocol/FoldingRangeKind.cs +++ b/src/LanguageServer/Protocol/Protocol/FoldingRangeKind.cs @@ -8,10 +8,12 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Value representing various code action kinds. - /// + /// Value representing kinds of folding range. + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 [JsonConverter(typeof(StringEnumConverter))] [TypeConverter(typeof(StringEnumConverter.TypeConverter))] internal readonly record struct FoldingRangeKind(string Value) : IStringEnum diff --git a/src/LanguageServer/Protocol/Protocol/FoldingRangeKindSet.cs b/src/LanguageServer/Protocol/Protocol/FoldingRangeKindSet.cs new file mode 100644 index 0000000000000..a6b20278f41e6 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FoldingRangeKindSet.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A set of values +/// +/// Since LSP 3.17 +internal class FoldingRangeKindSet +{ + /// + /// The folding range kind values the client supports. + /// + /// When this property exists the client also guarantees that it will + /// handle values outside its set gracefully and falls back + /// to a default value when unknown. + /// + /// + [JsonPropertyName("valueSet")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public FoldingRangeKind[]? ValueSet { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FoldingRangeParams.cs b/src/LanguageServer/Protocol/Protocol/FoldingRangeParams.cs index fed7123c0cb67..bb36a5c01fb56 100644 --- a/src/LanguageServer/Protocol/Protocol/FoldingRangeParams.cs +++ b/src/LanguageServer/Protocol/Protocol/FoldingRangeParams.cs @@ -4,23 +4,33 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// - /// Class representing the folding range request parameter. - /// + /// Class representing the parameter for the 'textDocument/foldingRange' request. + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class FoldingRangeParams : ITextDocumentParams + /// Since LSP 3.17 + internal class FoldingRangeParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams { /// /// Gets or sets the text document associated with the folding range request. /// [JsonPropertyName("textDocument")] - public TextDocumentIdentifier TextDocument - { - get; - set; - } + [JsonRequired] + public TextDocumentIdentifier TextDocument { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/FoldingRangeRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/FoldingRangeRegistrationOptions.cs new file mode 100644 index 0000000000000..b62a9ff9b0abc --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FoldingRangeRegistrationOptions.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class FoldingRangeRegistrationOptions : FoldingRangeOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + + /// + /// The id used to register the request. The id can be used to deregister the request again. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FoldingRangeSetting.cs b/src/LanguageServer/Protocol/Protocol/FoldingRangeSetting.cs index e57fde0b348aa..c5cb807ded664 100644 --- a/src/LanguageServer/Protocol/Protocol/FoldingRangeSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/FoldingRangeSetting.cs @@ -7,14 +7,17 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing the folding range setting for initialization. - /// + /// Client capabilities specific to the textDocument/foldingRange request. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class FoldingRangeSetting : DynamicRegistrationSetting { /// - /// Gets or sets the range limit for folding ranges. + /// The maximum number of folding ranges that the client prefers to receive + /// per document. The value serves as a hint, servers are free to follow the + /// limit. /// [JsonPropertyName("rangeLimit")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -25,7 +28,9 @@ public int? RangeLimit } /// - /// Gets or sets a value indicating whether if client only supports entire line folding only. + /// If set, the client signals that it only supports folding complete lines, + /// and will ignore and + /// properties. /// [JsonPropertyName("lineFoldingOnly")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -35,15 +40,20 @@ public bool LineFoldingOnly set; } + /// + /// Client capabilities specific to + /// + /// Since 3.17 + [JsonPropertyName("foldingRangeKind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public FoldingRangeKindSet? FoldingRangeKind { get; init; } + /// /// Gets or sets a value indicating the specific options for the folding range. /// + /// Since 3.17 [JsonPropertyName("foldingRange")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public FoldingRangeSettingOptions? FoldingRange - { - get; - set; - } + public FoldingRangeSettingOptions? FoldingRange { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/FoldingRangeSettingOptions.cs b/src/LanguageServer/Protocol/Protocol/FoldingRangeSettingOptions.cs index 35b524fd67379..d211b60683682 100644 --- a/src/LanguageServer/Protocol/Protocol/FoldingRangeSettingOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/FoldingRangeSettingOptions.cs @@ -7,14 +7,17 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing the specific options for the folding range. - /// + /// Client capabilities specific to + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class FoldingRangeSettingOptions : DynamicRegistrationSetting + /// Since LSP 3.17 + internal class FoldingRangeSettingOptions { /// - /// Gets or sets a value indicating whether if client supports collapsedText on folding ranges. + /// If set, the client signals that it supports setting + /// to display custom labels instead of the default text. /// [JsonPropertyName("collapsedText")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index 136bf3187f7ab..88e965100f359 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -80,4 +80,41 @@ partial class Methods /// Strongly typed message object for 'workspace/codeLens/refresh'. /// public static readonly LspRequest WorkspaceCodeLensRefresh = new(WorkspaceCodeLensRefreshName); + + /// + /// Method name for 'textDocument/foldingRange'. + /// + /// The folding range request is sent from the client to the server to return all folding ranges found in a given text document. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.10 + public const string TextDocumentFoldingRangeName = "textDocument/foldingRange"; + + /// + /// Strongly typed message object for 'textDocument/foldingRange'. + /// + public static readonly LspRequest TextDocumentFoldingRange = new(TextDocumentFoldingRangeName); + + /// + /// Method name for 'textDocument/selectionRange'. + /// + /// The selection range request is sent from the client to the server to return suggested selection ranges at an array of given positions. + /// + /// + /// A selection range is a range around the cursor position which the user might be interested in selecting. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.15 + public const string TextDocumentSelectionRangeName = "textDocument/selectionRange"; + + /// + /// Strongly typed message object for 'textDocument/selectionRange'. + /// + public static readonly LspRequest TextDocumentSelectionRange = new(TextDocumentSelectionRangeName); } diff --git a/src/LanguageServer/Protocol/Protocol/SelectionRange.cs b/src/LanguageServer/Protocol/Protocol/SelectionRange.cs new file mode 100644 index 0000000000000..904eea68d1f6a --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/SelectionRange.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A selection range is a range around the cursor position which the user might be interested in selecting. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.15 +internal class SelectionRange +{ + /// + /// The range of the selection range + /// + [JsonPropertyName("range")] + [JsonRequired] + public Range Range { get; init; } + + /// + /// The parent selection range containing this range. + /// + /// Parent.Range must contain this.Range. + /// + /// + [JsonPropertyName("parent")] + [JsonRequired] + public SelectionRange Parent { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/SelectionRangeClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/SelectionRangeClientCapabilities.cs new file mode 100644 index 0000000000000..9519bc9ce202a --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/SelectionRangeClientCapabilities.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/selectionRange` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.15 +internal class SelectionRangeClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/SelectionRangeOptions.cs b/src/LanguageServer/Protocol/Protocol/SelectionRangeOptions.cs new file mode 100644 index 0000000000000..a16f0719437ba --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/SelectionRangeOptions.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Server capabilities specific to Selection Range. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.15 +internal class SelectionRangeOptions : IWorkDoneProgressOptions +{ + /// + /// Gets or sets a value indicating whether work done progress is supported. + /// + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/SelectionRangeParams.cs b/src/LanguageServer/Protocol/Protocol/SelectionRangeParams.cs new file mode 100644 index 0000000000000..68f235894251f --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/SelectionRangeParams.cs @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Class representing the parameter for the 'textDocument/selectionRange' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.15 +internal class SelectionRangeParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams +{ + /// + /// The text document. + /// + [JsonPropertyName("textDocument")] + [JsonRequired] + public TextDocumentIdentifier TextDocument { get; init; } + + /// + /// The positions inside the text document. + /// + [JsonPropertyName("textDocument")] + [JsonRequired] + public Position[] Positions { get; init; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/SelectionRangeRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/SelectionRangeRegistrationOptions.cs new file mode 100644 index 0000000000000..ae53aa276c1e9 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/SelectionRangeRegistrationOptions.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.15 +internal class SelectionRangeRegistrationOptions : DeclarationOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + + /// + /// The id used to register the request. The id can be used to deregister the request again. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index f5ee44a42acf3..2c0c971d3c71b 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -191,6 +191,7 @@ public TextDocumentSyncOptions? TextDocumentSync /// /// Gets or sets the value which indicates if folding range is supported. /// + /// Since LSP 3.10 [JsonPropertyName("foldingRangeProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? FoldingRangeProvider { get; set; } @@ -202,6 +203,14 @@ public TextDocumentSyncOptions? TextDocumentSync [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ExecuteCommandOptions? ExecuteCommandProvider { get; set; } + /// + /// The server provides selection range support. + /// + /// Since LSP 3.15 + [JsonPropertyName("selectionRangeProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SumType? SelectionRangeProvider { get; init; } + /// /// Gets or sets a value indicating whether the server supports linked editing range. /// diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index efd3fcbafe203..88f5ce6d4baf5 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -153,11 +153,21 @@ internal class TextDocumentClientCapabilities public PublishDiagnosticsSetting? PublishDiagnostics { get; set; } /// - /// Gets or sets the setting which determines how folding range is supported. + /// Capabilities specific to the `textDocument/foldingRange` request. /// + /// Since LSP 3.10 [JsonPropertyName("foldingRange")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public FoldingRangeSetting? FoldingRange { get; set; } + /// + /// Capabilities specific to the `textDocument/selectionRange` request. + /// + /// Since LSP 3.15 + [JsonPropertyName("selectionRange")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SelectionRangeClientCapabilities? SelectionRange { get; set; } + /// /// Gets or sets the setting which determines if linked editing range can be dynamically registered. /// From 11cf35184d0bd52770e256fc31e9ccdc31e73958 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sat, 8 Jun 2024 00:17:55 -0400 Subject: [PATCH 11/46] LSP Protocol: Update DocumentSymbol classes --- .../Protocol/Protocol/DocumentSymbol.cs | 30 ++++++--- .../Protocol/DocumentSymbolOptions.cs | 14 +++- .../Protocol/Protocol/DocumentSymbolParams.cs | 43 ++++++++----- .../DocumentSymbolRegistrationOptions.cs | 24 +++++++ .../Protocol/DocumentSymbolSetting.cs | 31 +++++++-- .../Protocol/Protocol/Methods.Document.cs | 28 ++++++++ .../Protocol/Protocol/Methods.cs | 10 --- .../Protocol/Protocol/ServerCapabilities.cs | 2 +- .../Protocol/Protocol/SymbolInformation.cs | 64 ++++++++++++++----- .../Protocol/Protocol/SymbolKindSetting.cs | 17 +++-- .../Protocol/Protocol/SymbolTag.cs | 17 +++++ .../Protocol/Protocol/SymbolTagSupport.cs | 20 ++++++ .../TextDocumentClientCapabilities.cs | 2 +- 13 files changed, 237 insertions(+), 65 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/DocumentSymbolRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/SymbolTag.cs create mode 100644 src/LanguageServer/Protocol/Protocol/SymbolTagSupport.cs diff --git a/src/LanguageServer/Protocol/Protocol/DocumentSymbol.cs b/src/LanguageServer/Protocol/Protocol/DocumentSymbol.cs index e9110e2f82bc0..83b1b775eb408 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentSymbol.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentSymbol.cs @@ -4,19 +4,22 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// /// Represents programming constructs like variables, classes, interfaces etc. that appear in a document. Document symbols can be /// hierarchical and they have two ranges: one that encloses its definition and one that points to its most interesting range, /// e.g. the range of an identifier. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DocumentSymbol { /// - /// Gets or sets the name of this symbol. + /// The name of this symbol. Will be displayed in the user interface and + /// therefore must not be an empty string or a string consisting only of whitespace. /// [JsonPropertyName("name")] [JsonRequired] @@ -27,7 +30,7 @@ public string Name } /// - /// Gets or sets more detail for this symbol, e.g the signature of a function. + /// More detail for this symbol, e.g the signature of a function. /// [JsonPropertyName("detail")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -38,7 +41,7 @@ public string? Detail } /// - /// Gets or sets the of this symbol. + /// The of this symbol. /// [JsonPropertyName("kind")] public SymbolKind Kind @@ -48,10 +51,19 @@ public SymbolKind Kind } /// - /// Gets or sets a value indicating whether this symbol is deprecated. + /// Tags for this document symbol. + /// + /// Since 3.16 + [JsonPropertyName("tags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SymbolTag[]? Tags { get; init; } + + /// + /// Indicates whether this symbol is deprecated. /// [JsonPropertyName("deprecated")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [Obsolete("Use Tags instead")] public bool Deprecated { get; @@ -59,9 +71,9 @@ public bool Deprecated } /// - /// Gets or sets the range enclosing this symbol not including leading/trailing whitespace but everything else - /// like comments.This information is typically used to determine if the clients cursor is - /// inside the symbol to reveal in the symbol in the UI. + /// Gets or sets the range enclosing this symbol not including leading/trailing whitespace + /// but everything else like comments. This information is typically used to determine + /// if the client's cursor is inside the symbol to reveal in the symbol in the UI. /// [JsonPropertyName("range")] [JsonRequired] @@ -73,7 +85,7 @@ public Range Range /// /// Gets or sets the range that should be selected and revealed when this symbol is being picked, e.g the name of a function. - /// Must be contained by the `range`. + /// Must be contained by the . /// [JsonPropertyName("selectionRange")] [JsonRequired] diff --git a/src/LanguageServer/Protocol/Protocol/DocumentSymbolOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentSymbolOptions.cs index 9298ac3d94632..021dd0c3cd78c 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentSymbolOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentSymbolOptions.cs @@ -7,9 +7,10 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents workspace symbols capabilities. - /// + /// Server capabilities specific to Document Symbols. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DocumentSymbolOptions : IWorkDoneProgressOptions { @@ -19,5 +20,14 @@ internal class DocumentSymbolOptions : IWorkDoneProgressOptions [JsonPropertyName("workDoneProgress")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } + + /// + /// A human-readable string that is shown when multiple outlines trees + /// are shown for the same document. + /// + /// Sicne LSP 3.16 + [JsonPropertyName("label")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Label { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/DocumentSymbolParams.cs b/src/LanguageServer/Protocol/Protocol/DocumentSymbolParams.cs index b12f359aec536..4a4669cfd66c3 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentSymbolParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentSymbolParams.cs @@ -2,25 +2,36 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Roslyn.LanguageServer.Protocol -{ - using System.Text.Json.Serialization; +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; +/// +/// Class which represents the parameter sent with textDocument/documentSymbol requests. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DocumentSymbolParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams> +{ /// - /// Class which represents the parameter sent with textDocument/documentSymbol requests. - /// - /// See the Language Server Protocol specification for additional information. + /// Gets or sets the text document. /// - internal class DocumentSymbolParams : ITextDocumentParams + [JsonPropertyName("textDocument")] + public TextDocumentIdentifier TextDocument { - /// - /// Gets or sets the text document. - /// - [JsonPropertyName("textDocument")] - public TextDocumentIdentifier TextDocument - { - get; - set; - } + get; + set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress>? PartialResultToken { get; set; } } diff --git a/src/LanguageServer/Protocol/Protocol/DocumentSymbolRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentSymbolRegistrationOptions.cs new file mode 100644 index 0000000000000..0d907db48ce29 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DocumentSymbolRegistrationOptions.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DocumentSymbolRegistrationOptions : DocumentSymbolOptions, ITextDocumentRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/DocumentSymbolSetting.cs b/src/LanguageServer/Protocol/Protocol/DocumentSymbolSetting.cs index 6b4274a7d9fdc..d00d8f8626e5e 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentSymbolSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentSymbolSetting.cs @@ -7,14 +7,15 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing the initialization setting for document symbols. - /// + /// Client capabilities specific to the textDocument/documentSymbol request. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DocumentSymbolSetting : DynamicRegistrationSetting { /// - /// Gets or sets the capabilities. + /// Specific capabilities for in textDocument/documentSymbol requests /// [JsonPropertyName("symbolKind")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -34,5 +35,27 @@ public bool HierarchicalDocumentSymbolSupport get; set; } + + /// + /// The client supports tags on . Tags are supported on + /// if is + /// set to . + /// + /// Clients supporting tags have to handle unknown tags gracefully. + /// + /// + /// Since LSP 3.16 + [JsonPropertyName("tagSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SymbolTagSupport? TagSupport { get; init; } + + /// + /// The client supports an additional label presented in the UI when + /// registering a document symbol provider. + /// + /// Since LSP 3.16 + [JsonPropertyName("labelSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool LabelSupport { get; init; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index 88e965100f359..ba962de5d7cbe 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -117,4 +117,32 @@ partial class Methods /// Strongly typed message object for 'textDocument/selectionRange'. /// public static readonly LspRequest TextDocumentSelectionRange = new(TextDocumentSelectionRangeName); + + /// + /// Method name for 'textDocument/documentSymbol'. + /// + /// + /// The document symbol request is sent from the client to the server to return a collection of symbols in the document. + /// + /// The returned result is either: + /// + /// + /// An array of , which is a flat list of all symbols found in a given text document. Neither the symbol’s location range nor the symbol’s container name should be used to infer a hierarchy. + /// + /// + /// An array of , which is a hierarchy of symbols found in a given text document. + /// + /// + /// Servers should whenever possible return since it is the richer data structure. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentDocumentSymbolName = "textDocument/documentSymbol"; + + /// + /// Strongly typed message object for 'textDocument/documentSymbol'. + /// + public static readonly LspRequest?> TextDocumentDocumentSymbol = new(TextDocumentDocumentSymbolName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index 261bb9a0909ff..f3a894c6ce89f 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -61,11 +61,6 @@ internal static partial class Methods /// public const string TextDocumentDocumentColorName = "textDocument/documentColor"; - /// - /// Method name for 'textDocument/documentSymbol'. - /// - public const string TextDocumentDocumentSymbolName = "textDocument/documentSymbol"; - /// /// Method name for 'textDocument/formatting'. /// @@ -226,11 +221,6 @@ internal static partial class Methods /// public static readonly LspRequest DocumentColorRequest = new LspRequest(TextDocumentDocumentColorName); - /// - /// Strongly typed message object for 'textDocument/documentSymbol'. - /// - public static readonly LspRequest TextDocumentDocumentSymbol = new LspRequest(TextDocumentDocumentSymbolName); - /// /// Strongly typed message object for 'textDocument/formatting'. /// diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 2c0c971d3c71b..dcc5105b9d253 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -126,7 +126,7 @@ public TextDocumentSyncOptions? TextDocumentSync public SumType? DocumentHighlightProvider { get; set; } /// - /// Gets or sets a value indicating whether document symbols are supported. + /// The server provides Document Symbols support. /// [JsonPropertyName("documentSymbolProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/SymbolInformation.cs b/src/LanguageServer/Protocol/Protocol/SymbolInformation.cs index c35871bdaef2b..12f9676f5e7f7 100644 --- a/src/LanguageServer/Protocol/Protocol/SymbolInformation.cs +++ b/src/LanguageServer/Protocol/Protocol/SymbolInformation.cs @@ -10,9 +10,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing information about programming constructs like variables, classes, interfaces, etc. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + [Obsolete("Use DocumentSymbol or WorkspaceSymbol instead")] internal class SymbolInformation : IEquatable { /// @@ -36,7 +38,33 @@ public SymbolKind Kind } /// - /// Gets or sets the of this symbol. + /// Tags for this document symbol. + /// + /// Since 3.16 + [JsonPropertyName("tags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SymbolTag[]? Tags { get; init; } + + /// + /// Indicates whether this symbol is deprecated. + /// + [JsonPropertyName("deprecated")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [Obsolete("Use Tags instead")] + public bool Deprecated { get; init; } + + /// + /// The location of this symbol, used by a tool to reveal the location in the editor. + /// + /// If the symbol is selected in the tool the range's start information is used to + /// position the cursor. So the range usually spans more then the actual symbol's + /// name and does normally include things like visibility modifiers. + /// + /// + /// The range doesn't have to denote a node range in the sense of an abstract + /// syntax tree. It can therefore not be used to re-construct a hierarchy of + /// the symbols. + /// /// [JsonPropertyName("location")] public Location Location @@ -46,7 +74,12 @@ public Location Location } /// - /// Gets or sets the name of the symbol containing this symbol. + /// + /// The name of the symbol containing this symbol. + /// + /// This information is for user interface purposes (e.g. to render a qualifier in + /// the user interface if necessary). It can't be used to re-infer a hierarchy for + /// the document symbols. /// [JsonPropertyName("containerName")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -65,22 +98,19 @@ public override bool Equals(object obj) /// public bool Equals(SymbolInformation? other) { - return other != null && - this.Name == other.Name && - this.Kind == other.Kind && - EqualityComparer.Default.Equals(this.Location, other.Location) && - this.ContainerName == other.ContainerName; + return other != null + && this.Name == other.Name + && this.Kind == other.Kind + && (this.Tags == null + ? other.Tags == null + : (this.Tags.Equals(other.Tags) || this.Tags.SequenceEqual(other.Tags))) + && this.Deprecated == other.Deprecated + && EqualityComparer.Default.Equals(this.Location, other.Location) + && this.ContainerName == other.ContainerName; } /// - public override int GetHashCode() - { - var hashCode = 1633890234; - hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(this.Name); - hashCode = (hashCode * -1521134295) + (int)this.Kind; - hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(this.Location); - hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(this.ContainerName); - return hashCode; - } + public override int GetHashCode() => + HashCode.Combine(Name, Kind, Utilities.Hash.CombineValues(Tags), Deprecated, Location, ContainerName); } } diff --git a/src/LanguageServer/Protocol/Protocol/SymbolKindSetting.cs b/src/LanguageServer/Protocol/Protocol/SymbolKindSetting.cs index 3b9f98a15aad2..a8b5a19aec5e9 100644 --- a/src/LanguageServer/Protocol/Protocol/SymbolKindSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/SymbolKindSetting.cs @@ -7,14 +7,21 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing the symbol kind setting in initialization. - /// - /// See the Language Server Protocol specification for additional information. + /// Represents the values that the client supports. /// internal class SymbolKindSetting { /// - /// Gets or sets the types of symbol kind the client supports. + /// The symbol kind values the client supports. + /// + /// When this property exists the client also guarantees that it will handle values outside + /// its set gracefully and falls back to a default value when unknown. + /// + /// + /// If this property is not present the client only supports the symbol kinds + /// from to as + /// defined in the initial version of the protocol. + /// /// [JsonPropertyName("valueSet")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -24,4 +31,4 @@ public SymbolKind[]? ValueSet set; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/SymbolTag.cs b/src/LanguageServer/Protocol/Protocol/SymbolTag.cs new file mode 100644 index 0000000000000..d5299fca50ab2 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/SymbolTag.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Symbol tags are extra annotations that tweak the rendering of a symbol. +/// +/// Since LSP 3.16 +internal enum SymbolTag +{ + /// + /// Render a symbol as obsolete, usually using a strike-out. + /// + Deprecated = 1 +} diff --git a/src/LanguageServer/Protocol/Protocol/SymbolTagSupport.cs b/src/LanguageServer/Protocol/Protocol/SymbolTagSupport.cs new file mode 100644 index 0000000000000..cbce90915e312 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/SymbolTagSupport.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Describes the tags supported by the client on and . +/// +/// Since LSP 3.16 +internal class SymbolTagSupport +{ + /// + /// The tags supported by the client. + /// + [JsonPropertyName("valueSet")] + public SymbolTag[] ValueSet { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index 88f5ce6d4baf5..87bbe0bd1a708 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -90,7 +90,7 @@ internal class TextDocumentClientCapabilities public DocumentHighlightClientCapabilities? DocumentHighlight { get; set; } /// - /// Gets or sets the setting which determines if document symbol can be dynamically registered. + /// Capabilities specific to the `textDocument/documentSymbol` request. /// [JsonPropertyName("documentSymbol")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] From a3204921ab4a4adb9d860d121bf894f4f706e2b6 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sat, 8 Jun 2024 01:15:56 -0400 Subject: [PATCH 12/46] LSP Protocol: Update semantic token types --- .../Protocol/Protocol/Methods.Document.cs | 97 +++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 41 -------- .../SemanticTokens/SemanticTokenFormat.cs | 4 +- .../SemanticTokens/SemanticTokenModifiers.cs | 4 + .../SemanticTokens/SemanticTokenTypes.cs | 14 ++- .../Protocol/SemanticTokens/SemanticTokens.cs | 11 ++- .../SemanticTokens/SemanticTokensDelta.cs | 7 +- .../SemanticTokensDeltaParams.cs | 29 +++--- .../SemanticTokensDeltaPartialResult.cs | 7 +- .../SemanticTokens/SemanticTokensEdit.cs | 6 +- .../SemanticTokensFullOptions.cs | 4 +- .../SemanticTokens/SemanticTokensLegend.cs | 14 ++- .../SemanticTokens/SemanticTokensOptions.cs | 9 +- .../SemanticTokens/SemanticTokensParams.cs | 24 ++--- .../SemanticTokensPartialResult.cs | 4 +- .../SemanticTokensRangeParams.cs | 27 +++++- .../SemanticTokensRegistrationOptions.cs | 31 ++++++ .../SemanticTokensRequestsFullSetting.cs | 7 +- .../SemanticTokensRequestsSetting.cs | 16 +-- .../SemanticTokens/SemanticTokensSetting.cs | 51 +++++++++- .../SemanticTokensWorkspaceSetting.cs | 8 +- .../Protocol/Protocol/ServerCapabilities.cs | 3 +- .../TextDocumentClientCapabilities.cs | 3 +- .../Protocol/WorkspaceClientCapabilities.cs | 3 +- 24 files changed, 313 insertions(+), 111 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRegistrationOptions.cs diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index ba962de5d7cbe..116e5bc2087d9 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -145,4 +145,101 @@ partial class Methods /// Strongly typed message object for 'textDocument/documentSymbol'. /// public static readonly LspRequest?> TextDocumentDocumentSymbol = new(TextDocumentDocumentSymbolName); + + /// + /// Method name for 'textDocument/semanticTokens'. + /// + /// This method name is used only for registering for semantic tokens requests. + /// + /// + /// For actual requests, the specific methods textDocument/semanticTokens/{full,full/delta,range} are used. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string TextDocumentSemanticTokensName = "textDocument/semanticTokens"; + + /// + /// Method name for 'textDocument/semanticTokens/full'. + /// + /// Returns semantic tokens for the full document. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string TextDocumentSemanticTokensFullName = "textDocument/semanticTokens/full"; + + /// + /// Strongly typed message object for 'textDocument/semanticTokens/full'. + /// + /// Since LSP 3.16 + public static readonly LspRequest TextDocumentSemanticTokensFull = new(TextDocumentSemanticTokensFullName); + + /// + /// Method name for 'textDocument/semanticTokens/full/delta'. + /// + /// Returns a delta against a previous set of semantic tokens for the full document. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string TextDocumentSemanticTokensFullDeltaName = "textDocument/semanticTokens/full/delta"; + + /// + /// Strongly typed message object for 'textDocument/semanticTokens/full/delta'. + /// + /// Since LSP 3.16 + public static readonly LspRequest?> TextDocumentSemanticTokensFullDelta = new(TextDocumentSemanticTokensFullDeltaName); + + /// + /// Method name for 'textDocument/semanticTokens/range'. + /// + /// Returns semantic tokens for a visible range of the document. + /// + /// + /// This allows clients to improved rendering performance when opening files + /// and allow rendering documents that are too large for full semantic coloring. + /// + /// + /// A server is allowed to compute the semantic tokens for a broader range than + /// requested by the client. However if the server does the semantic tokens + /// for the broader range must be complete and correct. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string TextDocumentSemanticTokensRangeName = "textDocument/semanticTokens/range"; + + /// + /// Strongly typed message object for 'textDocument/semanticTokens/range'. + /// + /// Since LSP 3.16 + public static readonly LspRequest TextDocumentSemanticTokensRange = new(TextDocumentSemanticTokensRangeName); + + /// + /// Method name for 'workspace/semanticTokens/refresh'. + /// + /// This request is sent from the server to the client. Servers can use it to ask clients to refresh the editors for + /// which this server provides semantic tokens. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string WorkspaceSemanticTokensRefreshName = "workspace/semanticTokens/refresh"; + + /// + /// Strongly typed message object for 'workspace/semanticTokens/refresh'. + /// + /// Since LSP 3.16 + public static readonly LspRequest WorkspaceSemanticTokensRefresh = new(WorkspaceSemanticTokensRefreshName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index f3a894c6ce89f..58ce689207669 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -101,21 +101,6 @@ internal static partial class Methods /// public const string TextDocumentPrepareRenameName = "textDocument/prepareRename"; - /// - /// Method name for 'textDocument/semanticTokens/full'. - /// - public const string TextDocumentSemanticTokensFullName = "textDocument/semanticTokens/full"; - - /// - /// Method name for 'textDocument/semanticTokens/range'. - /// - public const string TextDocumentSemanticTokensRangeName = "textDocument/semanticTokens/range"; - - /// - /// Method name for 'textDocument/semanticTokens/full/delta'. - /// - public const string TextDocumentSemanticTokensFullDeltaName = "textDocument/semanticTokens/full/delta"; - /// /// Method name for 'textDocument/signatureHelp'. /// @@ -146,11 +131,6 @@ internal static partial class Methods /// public const string WorkspaceApplyEditName = "workspace/applyEdit"; - /// - /// Method name for 'workspace/semanticTokens/refresh'. - /// - public const string WorkspaceSemanticTokensRefreshName = "workspace/semanticTokens/refresh"; - /// /// Method name for 'workspace/configuration'. /// @@ -291,11 +271,6 @@ internal static partial class Methods /// public static readonly LspRequest WorkspaceApplyEdit = new LspRequest(WorkspaceApplyEditName); - /// - /// Strongly typed message object for 'workspace/semanticTokens/refresh'. - /// - public static readonly LspRequest WorkspaceSemanticTokensRefresh = new LspRequest(WorkspaceSemanticTokensRefreshName); - /// /// Strongly typed message object for 'workspace/configuration'. /// @@ -330,21 +305,5 @@ internal static partial class Methods /// Strongly typed message object for 'telemetry/event'. /// public static readonly LspNotification TelemetryEvent = new LspNotification(TelemetryEventName); - - /// - /// Strongly typed message object for 'textDocument/semanticTokens/full'. - /// - public static readonly LspRequest TextDocumentSemanticTokensFull = new LspRequest(TextDocumentSemanticTokensFullName); - - /// - /// Strongly typed message object for 'textDocument/semanticTokens/range'. - /// - public static readonly LspRequest TextDocumentSemanticTokensRange = new LspRequest(TextDocumentSemanticTokensRangeName); - - /// - /// Strongly typed message object for 'textDocument/semanticTokens/full/delta'. - /// - public static readonly LspRequest?> TextDocumentSemanticTokensFullDelta - = new LspRequest?>(TextDocumentSemanticTokensFullDeltaName); } } diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenFormat.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenFormat.cs index 5a75e425e946b..997b024e78813 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenFormat.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenFormat.cs @@ -9,9 +9,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Value representing the format used to describe semantic tokens. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 [JsonConverter(typeof(StringEnumConverter))] [TypeConverter(typeof(StringEnumConverter.TypeConverter))] internal readonly record struct SemanticTokenFormat(string Value) : IStringEnum diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenModifiers.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenModifiers.cs index 2c96ef5b846ce..146c847484b25 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenModifiers.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenModifiers.cs @@ -8,7 +8,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Well-known semantic token modifiers. + /// + /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal static class SemanticTokenModifiers { /// diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenTypes.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenTypes.cs index 835e5d708cf35..93d003ff703f9 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenTypes.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokenTypes.cs @@ -8,7 +8,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Well-known semantic tokens types. + /// + /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal static class SemanticTokenTypes { /// @@ -17,7 +21,8 @@ internal static class SemanticTokenTypes public const string Namespace = "namespace"; /// - /// Semantic token modifier for 'type'. + /// Represents a generic type. Acts as a fallback for types which + /// can't be mapped to a specific type like class or enum /// public const string Type = "type"; @@ -122,6 +127,12 @@ internal static class SemanticTokenTypes /// public const string Operator = "operator"; + /// + /// Semantic token modifier for 'decorator'. + /// + /// Sicne LSP 3.17 + public const string Decorator = "decorator"; + /// /// Collection containing all well-known semantic tokens types. /// @@ -149,6 +160,7 @@ internal static class SemanticTokenTypes Number, Regexp, Operator, + Decorator ]; } } diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokens.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokens.cs index bd467fbf475d6..7fa8d682bb75c 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokens.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokens.cs @@ -8,13 +8,20 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing response to semantic tokens messages. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class SemanticTokens { /// - /// Gets or sets a property that identifies this version of the document's semantic tokens. + /// An optional result id. + /// + /// If provided and clients support delta updating the client will include the + /// result id in the next semantic token request. A server can then instead of + /// computing all semantic tokens again simply send a delta. + /// /// [JsonPropertyName("resultId")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDelta.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDelta.cs index f1697e0ac4939..6e756534a5a45 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDelta.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDelta.cs @@ -8,14 +8,15 @@ namespace Roslyn.LanguageServer.Protocol /// /// Represents a response from a semantic tokens Document provider Edits request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class SemanticTokensDelta { /// - /// Gets or sets the Id for the client's new version after applying all - /// edits to their current semantic tokens data. + /// The ID of this result, which can then be used as a base for future deltas. /// [JsonPropertyName("resultId")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaParams.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaParams.cs index aded0c9dd957b..c04e4ee5647d5 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaParams.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaParams.cs @@ -8,12 +8,13 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Parameters for a request for Edits that can be applied to a previous response - /// from a semantic tokens Document provider. - /// + /// Parameters for 'textDocument/semanticTokens/full/delta' request. + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class SemanticTokensDeltaParams : ITextDocumentParams, IPartialResultParams + /// Since LSP 3.16 + internal class SemanticTokensDeltaParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams { /// /// Gets or sets an identifier for the document to fetch semantic tokens from. @@ -22,21 +23,21 @@ internal class SemanticTokensDeltaParams : ITextDocumentParams, IPartialResultPa public TextDocumentIdentifier TextDocument { get; set; } /// - /// Gets or sets a property indicating the version of the semantic - /// tokens Document provider response that the edits will be applied to. + /// The result id of a previous response. The result Id can either point to + /// a full response or a delta response depending on what was received last. + /// The delta should be relative to this previous response. /// [JsonPropertyName("previousResultId")] public string PreviousResultId { get; set; } - /// - /// Gets or sets the value of the Progress instance. - /// + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public IProgress? PartialResultToken - { - get; - set; - } + public IProgress? PartialResultToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaPartialResult.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaPartialResult.cs index dadc783ce447f..d75e29bb5b796 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaPartialResult.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensDeltaPartialResult.cs @@ -8,14 +8,15 @@ namespace Roslyn.LanguageServer.Protocol /// /// Represents a response from a semantic tokens Document provider Edits request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class SemanticTokensDeltaPartialResult { /// - /// Gets or sets an array of edits to apply to a previous response from a - /// semantic tokens Document provider. + /// The semantic token edits to transform a previous result into a new result. /// [JsonPropertyName("edits")] [JsonRequired] diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensEdit.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensEdit.cs index c06932c59a9f7..3f7751745f705 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensEdit.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensEdit.cs @@ -10,9 +10,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing an individual edit incrementally applied to a previous /// semantic tokens response from the Document provider. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1036:Override methods on comparable types", Justification = "Pending implementation of IComparable")] internal class SemanticTokensEdit : IComparable { @@ -21,6 +23,7 @@ internal class SemanticTokensEdit : IComparable /// to begin the edit. /// [JsonPropertyName("start")] + [JsonRequired] public int Start { get; set; } /// @@ -28,6 +31,7 @@ internal class SemanticTokensEdit : IComparable /// from the previous response. /// [JsonPropertyName("deleteCount")] + [JsonRequired] public int DeleteCount { get; set; } /// diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensFullOptions.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensFullOptions.cs index ff7dcdf3e4970..cf34aa147515f 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensFullOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensFullOptions.cs @@ -8,9 +8,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Options for the full document semantic tokens classification provider. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class SemanticTokensFullOptions { /// diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensLegend.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensLegend.cs index 394c0d45c8f68..c0c00826c889c 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensLegend.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensLegend.cs @@ -7,16 +7,19 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Legend used to encode semantic token types in . - /// + /// Legend used by the server to describe how it encodes semantic token types in . + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class SemanticTokensLegend { - /// - /// Gets or sets an array of token types that can be encoded in semantic tokens responses. + /// . + /// The semantic token types the server uses. Indices into this array are used to encode token types in semantic tokens responses. /// [JsonPropertyName("tokenTypes")] + [JsonRequired] public string[] TokenTypes { get; @@ -24,9 +27,10 @@ public string[] TokenTypes } /// - /// Gets or sets an array of token modfiers that can be encoded in semantic tokens responses. + /// The semantic token modifiers the server uses. Indices into this array are used to encode modifiers in semantic tokens responses. /// [JsonPropertyName("tokenModifiers")] + [JsonRequired] public string[] TokenModifiers { get; diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensOptions.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensOptions.cs index 30fce0f5efaa6..081a47960fc69 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensOptions.cs @@ -8,15 +8,18 @@ namespace Roslyn.LanguageServer.Protocol /// /// Initialization options for semantic tokens support. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class SemanticTokensOptions : IWorkDoneProgressOptions { /// /// Gets or sets a legend describing how semantic token types and modifiers are encoded in responses. /// [JsonPropertyName("legend")] + [JsonRequired] public SemanticTokensLegend Legend { get; set; } /// @@ -33,9 +36,7 @@ internal class SemanticTokensOptions : IWorkDoneProgressOptions [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? Full { get; set; } - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// + /// [JsonPropertyName("workDoneProgress")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensParams.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensParams.cs index 5cf3738c12b6b..76a60692b2b43 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensParams.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensParams.cs @@ -8,27 +8,29 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Parameters for semantic tokens full Document request. - /// + /// Parameters for 'textDocument/semanticTokens/full' request. + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class SemanticTokensParams : ITextDocumentParams, IPartialResultParams + /// Since LSP 3.16 + internal class SemanticTokensParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams { /// /// Gets or sets an identifier for the document to fetch semantic tokens from. /// [JsonPropertyName("textDocument")] + [JsonRequired] public TextDocumentIdentifier TextDocument { get; set; } - /// - /// Gets or sets the value of the Progress instance. - /// + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public IProgress? PartialResultToken - { - get; - set; - } + public IProgress? PartialResultToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensPartialResult.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensPartialResult.cs index 3307b392e936a..538869edd5bae 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensPartialResult.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensPartialResult.cs @@ -8,9 +8,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing response to semantic tokens messages. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class SemanticTokensPartialResult { /// diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRangeParams.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRangeParams.cs index 0523c2e25293f..62f2248286ca7 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRangeParams.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRangeParams.cs @@ -4,19 +4,40 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// - /// Parameters for the semantic tokens Range request. - /// + /// Parameters for 'textDocument/semanticTokens/range' request. + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class SemanticTokensRangeParams : SemanticTokensParams + /// Since LSP 3.16 + internal class SemanticTokensRangeParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams { + /// + /// Gets or sets an identifier for the document to fetch semantic tokens from. + /// + [JsonPropertyName("textDocument")] + [JsonRequired] + public TextDocumentIdentifier TextDocument { get; set; } + /// /// Gets or sets the range within the document to fetch semantic tokens for. /// [JsonPropertyName("range")] + [JsonRequired] public Range Range { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRegistrationOptions.cs new file mode 100644 index 0000000000000..b3789e270eec2 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRegistrationOptions.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// Since LSP 3.16 +internal class SemanticTokensRegistrationOptions : SemanticTokensOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + + /// + /// The id used to register the request. The id can be used to deregister the request again. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsFullSetting.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsFullSetting.cs index ce6ad7de1e5d6..e3667324f7cda 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsFullSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsFullSetting.cs @@ -7,11 +7,12 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Client settings for semantic tokens related to the - /// `textDocument/semanticTokens/full` message. - /// + /// Client capabilities specific to the textDocument/semanticTokens/full request. + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class SemanticTokensRequestsFullSetting { /// diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsSetting.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsSetting.cs index 7c9dbd73769b9..c3110ddad1898 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensRequestsSetting.cs @@ -7,25 +7,25 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Requests client settings for semantic tokens. - /// + /// Represents which semantic token requests are supported by the client. + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class SemanticTokensRequestsSetting { /// - /// Gets or sets a value indicating whether the client will send the - /// `textDocument/semanticTokens/range` request if the server provides a - /// corresponding handler. + /// The client will send the textDocument/semanticTokens/range request + /// if the server provides a corresponding handler. /// [JsonPropertyName("range")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? Range { get; set; } /// - /// Gets or sets a value indicating whether the client will send the - /// `textDocument/semanticTokens/full` request if the server provides a - /// corresponding handler. + /// The client will send the textDocument/semanticTokens/full request + /// if the server provides a corresponding handler. /// [JsonPropertyName("full")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensSetting.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensSetting.cs index 85e34d5680f9f..c93f244723338 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensSetting.cs @@ -7,17 +7,30 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Client settings for semantic tokens. - /// + /// Client capabilities for semantic tokens. + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class SemanticTokensSetting : DynamicRegistrationSetting { /// - /// Gets or sets a value indicating which requests the client supports and might send to the server + /// Which requests the client supports and might send to the server /// depending on the server's capability. /// + /// + /// Please note that clients might not + /// show semantic tokens or degrade some of the user experience if a range + /// or full request is advertised by the client but not provided by the + /// server. If for example the client capability + /// and are both set to true + /// but the server only provides a range provider the client might not + /// render a minimap correctly or might even decide to not show any + /// semantic tokens at all. + /// [JsonPropertyName("requests")] + [JsonRequired] public SemanticTokensRequestsSetting Requests { get; set; } /// @@ -25,6 +38,7 @@ internal class SemanticTokensSetting : DynamicRegistrationSetting /// semantic tokens. /// [JsonPropertyName("tokenTypes")] + [JsonRequired] public string[] TokenTypes { get; set; } /// @@ -32,12 +46,14 @@ internal class SemanticTokensSetting : DynamicRegistrationSetting /// semantic tokens. /// [JsonPropertyName("tokenModifiers")] + [JsonRequired] public string[] TokenModifiers { get; set; } /// /// Gets or sets an array of formats the clients supports. /// [JsonPropertyName("formats")] + [JsonRequired] public SemanticTokenFormat[] Formats { get; set; } /// @@ -53,5 +69,34 @@ internal class SemanticTokensSetting : DynamicRegistrationSetting [JsonPropertyName("multilineTokenSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool MultilineTokenSupport { get; set; } + + /// + /// Whether the client allows the server to actively cancel a + /// semantic token request, e.g. supports returning + /// ErrorCodes.ServerCancelled. + /// + /// If a server does the client needs to retrigger the request. + /// + /// + /// Since LSP 3.17 + [JsonPropertyName("serverCancelSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool ServerCancelSupport { get; init; } + + /// + /// Whether the client uses semantic tokens to augment existing + /// syntax tokens. If set to client side created syntax + /// tokens and semantic tokens are both used for colorization. If + /// set to the client only uses the returned semantic tokens + /// for colorization. + /// + /// If the value is then the client behavior is not + /// specified. + /// + /// + /// Since LSP 3.17 + [JsonPropertyName("augmentsSyntaxTokens")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public bool? AugmentsSyntaxTokens { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensWorkspaceSetting.cs b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensWorkspaceSetting.cs index d560f44d6c5c2..3f76963721e9e 100644 --- a/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensWorkspaceSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/SemanticTokens/SemanticTokensWorkspaceSetting.cs @@ -8,9 +8,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Capabilities specific to the semantic token requests scoped to the workspace. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class SemanticTokensWorkspaceSetting { /// @@ -19,7 +21,7 @@ internal class SemanticTokensWorkspaceSetting /// /// /// Note that this event is global and will force the client to refresh all - /// semantic tokens currently shown.It should be used with absolute care + /// semantic tokens currently shown. It should be used with absolute care /// and is useful for situation where a server for example detect a project /// wide change that requires such a calculation. /// @@ -27,4 +29,4 @@ internal class SemanticTokensWorkspaceSetting [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool RefreshSupport { get; set; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index dcc5105b9d253..08f23a148cec4 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -229,9 +229,10 @@ public TextDocumentSyncOptions? TextDocumentSync /// /// Gets or sets the value which indicates if semantic tokens is supported. /// + /// Since LSP 3.16 [JsonPropertyName("semanticTokensProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SemanticTokensOptions? SemanticTokensOptions { get; set; } + public SumType? SemanticTokensOptions { get; set; } /// /// The server provides type hierarchy support. diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index 87bbe0bd1a708..dfc188e9d355b 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -184,8 +184,9 @@ internal class TextDocumentClientCapabilities public CallHierarchyClientCapabilities CallHierarchy { get; init; } /// - /// Gets or sets a setting indicating whether semantic tokens is supported. + /// Capabilities specific to the various semantic token requests. /// + /// Since LSP 3.16 [JsonPropertyName("semanticTokens")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SemanticTokensSetting? SemanticTokens { get; set; } diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs index 6be16b126fd7c..944850af85c7b 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs @@ -66,8 +66,9 @@ internal class WorkspaceClientCapabilities public bool Configuration { get; set; } /// - /// Gets or sets capabilities specific to the semantic token requests scoped to the workspace. + /// Capabilities specific to the semantic token requests scoped to the workspace. /// + /// Since LSP 3.16 [JsonPropertyName("semanticTokens")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SemanticTokensWorkspaceSetting? SemanticTokens { get; set; } From 5c451b589630df2e83970c57554c5e33f9fad196 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sat, 8 Jun 2024 01:55:00 -0400 Subject: [PATCH 13/46] LSP Protocol: Update Inlay Hint types --- .../Protocol/Protocol/InlayHint.cs | 55 ++++++++++++++--- .../Protocol/Protocol/InlayHintKind.cs | 8 ++- .../Protocol/Protocol/InlayHintLabelPart.cs | 31 ++++++++-- .../Protocol/Protocol/InlayHintOptions.cs | 8 ++- .../Protocol/Protocol/InlayHintParams.cs | 26 ++++---- .../Protocol/InlayHintRegistrationOptions.cs | 27 +++----- .../InlayHintResolveSupportSetting.cs | 8 ++- .../Protocol/Protocol/InlayHintSetting.cs | 9 +-- .../Protocol/InlayHintWorkspaceSetting.cs | 6 +- .../Protocol/Protocol/Methods.Document.cs | 61 +++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 30 --------- .../Protocol/Protocol/ServerCapabilities.cs | 3 +- .../TextDocumentClientCapabilities.cs | 3 +- .../Protocol/WorkspaceClientCapabilities.cs | 1 + 14 files changed, 185 insertions(+), 91 deletions(-) diff --git a/src/LanguageServer/Protocol/Protocol/InlayHint.cs b/src/LanguageServer/Protocol/Protocol/InlayHint.cs index 3b934f479d901..3baccb3001f60 100644 --- a/src/LanguageServer/Protocol/Protocol/InlayHint.cs +++ b/src/LanguageServer/Protocol/Protocol/InlayHint.cs @@ -8,15 +8,22 @@ namespace Roslyn.LanguageServer.Protocol /// /// A class representing inlay hints that appear next to parameters or types. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 internal class InlayHint { /// - /// Gets or sets the position that the inlay hint applies to. + /// The position of this hint. + /// + /// If multiple hints have the same position, they will be shown in the order + /// they appear in the response. + /// /// [JsonPropertyName("position")] + [JsonRequired] public Position Position { get; @@ -24,9 +31,14 @@ public Position Position } /// - /// Gets or sets the label associated with this inlay hint. + /// The label of this hint. A human readable string or an array of + /// label parts. + /// + /// Note that neither the string nor the label part can be empty. + /// /// [JsonPropertyName("label")] + [JsonRequired] public SumType Label { get; @@ -34,7 +46,8 @@ public SumType Label } /// - /// Gets or sets the InlayHintKind associated with this inlay hint. + /// The kind of this hint. Can be omitted in which case the client + /// should fall back to a reasonable default. /// [JsonPropertyName("kind")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -45,7 +58,16 @@ public InlayHintKind? Kind } /// - /// Gets or sets the TextEdits associated with this inlay hint. + /// Optional text edits that are performed when accepting this inlay hint. + /// + /// Note* that edits are expected to change the document so that the inlay + /// hint(or its nearest variant) is now part of the document and the inlay + /// hint itself is now obsolete. + /// + /// + /// Depending on the client capability clients + /// might resolve this property late using the resolve request. + /// /// [JsonPropertyName("textEdits")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -56,7 +78,11 @@ public TextEdit[]? TextEdits } /// - /// Gets or sets the tooltip of this inlay hint. + /// The tooltip text when you hover over this item. + /// + /// Depending on the client capability clients + /// might resolve this property late using the resolve request. + /// /// [JsonPropertyName("tooltip")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -67,7 +93,12 @@ public SumType? ToolTip } /// - /// Gets or sets the padding before this inlay hint. + /// Render padding before the hint. + /// + /// Note: Padding should use the editor's background color, not the + /// background color of the hint itself. That means padding can be used + /// to visually align/separate an inlay hint. + /// /// [JsonPropertyName("paddingLeft")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -78,7 +109,12 @@ public bool PaddingLeft } /// - /// Gets or sets the padding after this inlay hint. + /// Render padding after the hint. + /// + /// Note: Padding should use the editor's background color, not the + /// background color of the hint itself.That means padding can be used + /// to visually align/separate an inlay hint. + /// /// [JsonPropertyName("paddingRight")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -89,7 +125,8 @@ public bool PaddingRight } /// - /// Gets or sets the data that should be preserved between a textDocument/inlayHint request and a inlayHint/resolve request. + /// Gets or sets the data that should be preserved between a + /// textDocument/inlayHint request and a inlayHint/resolve request. /// [JsonPropertyName("data")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/InlayHintKind.cs b/src/LanguageServer/Protocol/Protocol/InlayHintKind.cs index 9e8ccb1548903..bfdd221883fc6 100644 --- a/src/LanguageServer/Protocol/Protocol/InlayHintKind.cs +++ b/src/LanguageServer/Protocol/Protocol/InlayHintKind.cs @@ -6,18 +6,20 @@ namespace Roslyn.LanguageServer.Protocol { /// /// Enum values for inlay hint kinds. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 internal enum InlayHintKind { /// - /// Type. + /// An inlay hint that for a type annotation /// Type = 1, /// - /// Parameter. + /// An inlay hint that is for a parameter /// Parameter = 2, } diff --git a/src/LanguageServer/Protocol/Protocol/InlayHintLabelPart.cs b/src/LanguageServer/Protocol/Protocol/InlayHintLabelPart.cs index 1946a23322ced..dcb07d48583b8 100644 --- a/src/LanguageServer/Protocol/Protocol/InlayHintLabelPart.cs +++ b/src/LanguageServer/Protocol/Protocol/InlayHintLabelPart.cs @@ -8,13 +8,15 @@ namespace Roslyn.LanguageServer.Protocol /// /// A class representing inlay hint label parts. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 internal class InlayHintLabelPart { /// - /// Gets or sets the value associated with this label part. + /// The value of this label part. /// [JsonPropertyName("value")] public string Value @@ -24,7 +26,11 @@ public string Value } /// - /// Gets or sets the tooltip of this label part. + /// The tooltip text when you hover over this label part. + /// + /// Depending on the client capability clients + /// might resolve this property late using the resolve request. + /// /// [JsonPropertyName("tooltip")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -35,7 +41,18 @@ public SumType? ToolTip } /// - /// Gets or sets the location of this label part. + /// An optional source code location that represents this label part. + /// + /// The editor will use this location for the hover and for code navigation + /// features. This part will become a clickable link that resolves to the + /// definition of the symbol at the given location (not necessarily the + /// location itself), it shows the hover that shows at the given location, + /// and it shows a context menu with further code navigation commands. + /// + /// + /// Depending on the client capability clients + /// might resolve this property late using the resolve request. + /// /// [JsonPropertyName("location")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -46,7 +63,11 @@ public Location? Location } /// - /// Gets or sets the command of this label part. + /// An optional command for this label part. + /// + /// Depending on the client capability clients + /// might resolve this property late using the resolve request. + /// /// [JsonPropertyName("command")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/InlayHintOptions.cs b/src/LanguageServer/Protocol/Protocol/InlayHintOptions.cs index ce9e1c5aef33a..fb24530ce5980 100644 --- a/src/LanguageServer/Protocol/Protocol/InlayHintOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/InlayHintOptions.cs @@ -8,9 +8,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Server capabilities for inlay hints. - /// - /// See the Language Server Protocol specification for additional information. + /// + /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 internal class InlayHintOptions : IWorkDoneProgressOptions { /// @@ -21,7 +23,7 @@ internal class InlayHintOptions : IWorkDoneProgressOptions public bool WorkDoneProgress { get; init; } /// - /// Gets or sets a value indicating whether or not the inlay hints support has a resolve provider. + /// The server provides support to resolve additional information for an inlay hint item. /// [JsonPropertyName("resolveProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] diff --git a/src/LanguageServer/Protocol/Protocol/InlayHintParams.cs b/src/LanguageServer/Protocol/Protocol/InlayHintParams.cs index 9761b7c09c83d..0db0d373aaa6a 100644 --- a/src/LanguageServer/Protocol/Protocol/InlayHintParams.cs +++ b/src/LanguageServer/Protocol/Protocol/InlayHintParams.cs @@ -4,33 +4,35 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// /// Class representing the parameters sent from the client to the server for a textDocument/inlayHint request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class InlayHintParams : ITextDocumentParams + /// Since LSP 3.17 + internal class InlayHintParams : ITextDocumentParams, IWorkDoneProgressParams { /// /// Gets or sets the document identifier to fetch inlay hints results for. /// [JsonPropertyName("textDocument")] - public TextDocumentIdentifier TextDocument - { - get; - set; - } + [JsonRequired] + public TextDocumentIdentifier TextDocument { get; set; } /// /// Gets or sets the range to fetch inlay hints results for. /// [JsonPropertyName("range")] - public Range Range - { - get; - set; - } + [JsonRequired] + public Range Range { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/InlayHintRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/InlayHintRegistrationOptions.cs index 614eb9d3f459d..9a973b526507d 100644 --- a/src/LanguageServer/Protocol/Protocol/InlayHintRegistrationOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/InlayHintRegistrationOptions.cs @@ -8,30 +8,21 @@ namespace Roslyn.LanguageServer.Protocol /// /// Inlay hint registration options. - /// - /// See the Language Server Protocol specification for additional information. + /// + /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 internal class InlayHintRegistrationOptions : InlayHintOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions { - /// - /// Gets or sets the document filters for this registration option. - /// + /// [JsonPropertyName("documentSelector")] - public DocumentFilter[]? DocumentSelector - { - get; - set; - } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// + /// [JsonPropertyName("id")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string? Id - { - get; - set; - } + public string? Id { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/InlayHintResolveSupportSetting.cs b/src/LanguageServer/Protocol/Protocol/InlayHintResolveSupportSetting.cs index 25d1c6a154cc3..f5852d7c6e246 100644 --- a/src/LanguageServer/Protocol/Protocol/InlayHintResolveSupportSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/InlayHintResolveSupportSetting.cs @@ -7,14 +7,16 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing settings for inlayHint/resolve support. - /// + /// Client capabilities specific to the `inlayHint/resolve` request. + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 internal class InlayHintResolveSupportSetting { /// - /// Gets or sets a value indicating the properties that a client can resolve lazily. + /// The names of the properties that the client can resolve lazily. /// [JsonPropertyName("properties")] public string[] Properties diff --git a/src/LanguageServer/Protocol/Protocol/InlayHintSetting.cs b/src/LanguageServer/Protocol/Protocol/InlayHintSetting.cs index d6f8008ba47b6..2b418db0e0607 100644 --- a/src/LanguageServer/Protocol/Protocol/InlayHintSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/InlayHintSetting.cs @@ -7,15 +7,16 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing settings for inlay hint support. - /// + /// Inlay hint client capabilities. + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 internal class InlayHintSetting : DynamicRegistrationSetting { /// - /// Gets or sets a value indicating whether the client supports - /// resolving lazily on an inlay hint. + /// Indicates which properties a client can resolve lazily on an inlay hint. /// [JsonPropertyName("resolveSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/InlayHintWorkspaceSetting.cs b/src/LanguageServer/Protocol/Protocol/InlayHintWorkspaceSetting.cs index 7308f9b3d2ec5..92e9c682df3b4 100644 --- a/src/LanguageServer/Protocol/Protocol/InlayHintWorkspaceSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/InlayHintWorkspaceSetting.cs @@ -8,9 +8,11 @@ namespace Roslyn.LanguageServer.Protocol { /// /// Class representing the workspace inlay hint client capabilities. - /// - /// See the Language Server Protocol specification for additional information. + /// + /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 internal class InlayHintWorkspaceSetting { /// diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index 116e5bc2087d9..6012c1bf2fb37 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -242,4 +242,65 @@ partial class Methods /// /// Since LSP 3.16 public static readonly LspRequest WorkspaceSemanticTokensRefresh = new(WorkspaceSemanticTokensRefreshName); + + /// + /// Method name for 'textDocument/inlayHint'. + /// + /// The inlay hints request is sent from the client to the server to compute inlay hints + /// for a given [text document, range] tuple that may be rendered in the editor in place with other text. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string TextDocumentInlayHintName = "textDocument/inlayHint"; + + /// + /// Strongly typed message object for 'textDocument/inlayHint'. + /// + /// Since LSP 3.17 + public static readonly LspRequest TextDocumentInlayHint = new(TextDocumentInlayHintName); + + /// + /// Method name for 'inlayHint/resolve'. + /// + /// The request is sent from the client to the server to resolve additional information for + /// a given inlay hint. + /// + /// + /// This is usually used to compute the tooltip, location or command + /// properties of an inlay hint’s label part to avoid its unnecessary computation during + /// the textDocument/inlayHint request. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string InlayHintResolveName = "inlayHint/resolve"; + + /// + /// Strongly typed message object for 'inlayHint/resolve'. + /// + /// Since LSP 3.17 + public static readonly LspRequest InlayHintResolve = new(InlayHintResolveName); + + /// + /// Method name for 'workspace/inlayHint/refresh'. + /// + /// This request is sent from the server to ask the client to refresh the inlay hints currently shown in editors. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string WorkspaceInlayHintRefreshName = "workspace/inlayHint/refresh"; + + /// + /// Strongly typed message object for 'workspace/inlayHint/refresh'. + /// + /// Since LSP 3.17 + public static readonly LspRequest WorkspaceInlayHintRefresh = new(WorkspaceInlayHintRefreshName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index 58ce689207669..c038abe45ad61 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -81,16 +81,6 @@ internal static partial class Methods /// public const string TextDocumentPublishDiagnosticsName = "textDocument/publishDiagnostics"; - /// - /// Method name for 'textDocument/inlayHint'. - /// - public const string TextDocumentInlayHintName = "textDocument/inlayHint"; - - /// - /// Method name for 'inlayHint/resolve'. - /// - public const string InlayHintResolveName = "inlayHint/resolve"; - /// /// Method name for 'textDocument/rename'. /// @@ -166,11 +156,6 @@ internal static partial class Methods /// public const string WorkspaceDidChangeWatchedFilesName = "workspace/didChangeWatchedFiles"; - /// - /// Method name for 'workspace/inlayHint/refresh'. - /// - public const string WorkspaceInlayHintRefreshName = "workspace/inlayHint/refresh"; - /// /// Method name for 'telemetry/event'. /// @@ -221,16 +206,6 @@ internal static partial class Methods /// public static readonly LspNotification TextDocumentPublishDiagnostics = new LspNotification(TextDocumentPublishDiagnosticsName); - /// - /// Strongly typed message object for 'textDocument/inlayHint'. - /// - public static readonly LspRequest TextDocumentInlayHint = new LspRequest(TextDocumentInlayHintName); - - /// - /// Strongly typed message object for 'inlayHint/resolve'. - /// - public static readonly LspRequest InlayHintResolve = new LspRequest(InlayHintResolveName); - /// /// Strongly typed message object for 'textDocument/rename'. /// @@ -296,11 +271,6 @@ internal static partial class Methods /// public static readonly LspNotification WorkspaceDidChangeWatchedFiles = new LspNotification(WorkspaceDidChangeWatchedFilesName); - /// - /// Strongly typed message object for 'workspace/inlayHint/refresh'. - /// - public static readonly LspRequest WorkspaceInlayHintRefresh = new LspRequest(WorkspaceInlayHintRefreshName); - /// /// Strongly typed message object for 'telemetry/event'. /// diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 08f23a148cec4..352ded3c4c147 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -245,9 +245,10 @@ public TextDocumentSyncOptions? TextDocumentSync /// /// Gets or sets the value which indicates what support the server has for inlay hints. /// + /// Since LSP 3.17 [JsonPropertyName("inlayHintProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? InlayHintOptions { get; set; } + public SumType? InlayHintOptions { get; set; } /// /// Gets or sets the value which indicates what support the server has for pull diagnostics. diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index dfc188e9d355b..1f01604a3f6ef 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -200,8 +200,9 @@ internal class TextDocumentClientCapabilities public TypeHierarchyClientCapabilities? TypeHierarchy { get; init; } /// - /// Gets or sets the setting which determines what support the client has for pull diagnostics. + /// Capabilities specific to the `textDocument/inlayHint` request. /// + /// Since LSP 3.17 [JsonPropertyName("inlayHint")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public InlayHintSetting? InlayHint { get; set; } diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs index 944850af85c7b..c29c864ff9627 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs @@ -84,6 +84,7 @@ internal class WorkspaceClientCapabilities /// /// Gets of sets capabilities specific to the inlay hint requests scoped to the workspace. /// + /// Since LSP 3.17 [JsonPropertyName("inlayHint")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public InlayHintWorkspaceSetting? InlayHint { get; set; } From 71d11085fbf0089ec97a5319495988c6286ed240 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sat, 8 Jun 2024 02:21:47 -0400 Subject: [PATCH 14/46] LSP Protocol: Add Inline Value types/methods --- .../InlineValueClientCapability.cs | 16 +++++++ .../InlineValues/InlineValueContext.cs | 32 +++++++++++++ .../InlineValueEvaluatableExpression.cs | 39 ++++++++++++++++ .../InlineValues/InlineValueOptions.cs | 22 +++++++++ .../InlineValues/InlineValueParams.cs | 45 +++++++++++++++++++ .../InlineValueRegistrationOptions.cs | 27 +++++++++++ .../Protocol/InlineValues/InlineValueText.cs | 28 ++++++++++++ .../InlineValues/InlineValueVariableLookup.cs | 45 +++++++++++++++++++ .../InlineValueWorkspaceClientCapabilities.cs | 31 +++++++++++++ .../Protocol/Protocol/Methods.Document.cs | 37 +++++++++++++++ .../Protocol/Protocol/ServerCapabilities.cs | 8 ++++ .../TextDocumentClientCapabilities.cs | 8 ++++ .../Protocol/WorkspaceClientCapabilities.cs | 8 ++++ 13 files changed, 346 insertions(+) create mode 100644 src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueClientCapability.cs create mode 100644 src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueContext.cs create mode 100644 src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueEvaluatableExpression.cs create mode 100644 src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueText.cs create mode 100644 src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueVariableLookup.cs create mode 100644 src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueWorkspaceClientCapabilities.cs diff --git a/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueClientCapability.cs b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueClientCapability.cs new file mode 100644 index 0000000000000..28a6da214db57 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueClientCapability.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/inlineValue` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class InlineValueClientCapability : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueContext.cs b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueContext.cs new file mode 100644 index 0000000000000..7dd094a53a762 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueContext.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Additional information about the context in which inline values were requested. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class InlineValueContext +{ + /// + /// The stack frame (as a DAP Id) where the execution has stopped. + /// + [JsonPropertyName("frameId")] + [JsonRequired] + public int FrameId { get; set; } + + /// + /// The document range where execution has stopped. Typically the end + /// position of the range denotes the line where the inline values are shown + /// + [JsonPropertyName("stoppedLocation")] + [JsonRequired] + public Range StoppedLocation { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueEvaluatableExpression.cs b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueEvaluatableExpression.cs new file mode 100644 index 0000000000000..c56509b4d03e2 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueEvaluatableExpression.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Provide an inline value through an expression evaluation. +/// +/// If only a range is specified, the expression will be extracted from the +/// underlying document. +/// +/// +/// An optional expression can be used to override the extracted expression. +/// +/// +/// Since LSP 3.17 +internal class InlineValueEvaluatableExpression +{ + /// + /// The document range for which the inline value applies. + /// + /// The range is used to extract the evaluatable expression from the + /// underlying document. + /// + /// + [JsonPropertyName("range")] + [JsonRequired] + public Range Range { get; init; } + + /// + /// If specified the expression overrides the extracted expression. + /// + [JsonPropertyName("expression")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Expression { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueOptions.cs b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueOptions.cs new file mode 100644 index 0000000000000..3dc248ac311b2 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueOptions.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Server capabilities specific to Inline Values. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class InlineValueOptions : IWorkDoneProgressOptions +{ + /// + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueParams.cs b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueParams.cs new file mode 100644 index 0000000000000..1d105d755e6cc --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueParams.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System; +using System.Text.Json.Serialization; + +/// +/// Class representing the parameters sent from the client to the server for a textDocument/inlineValue request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class InlineValueParams : ITextDocumentParams, IWorkDoneProgressParams +{ + /// + /// The text document. + /// + [JsonPropertyName("textDocument")] + [JsonRequired] + public TextDocumentIdentifier TextDocument { get; set; } + + /// + /// The document range for which inline values should be computed. + /// + [JsonPropertyName("range")] + [JsonRequired] + public Range Range { get; set; } + + /// + /// Additional information about the context in which inline values were + /// requested. + /// + [JsonPropertyName("context")] + [JsonRequired] + public InlineValueContext Context { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueRegistrationOptions.cs new file mode 100644 index 0000000000000..0eeea40bc2a60 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueRegistrationOptions.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class InlineValueRegistrationOptions : InlineValueOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions +{ + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueText.cs b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueText.cs new file mode 100644 index 0000000000000..7ac60bacf0825 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueText.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Provide inline value as text. +/// +/// Since LSP 3.17 +internal class InlineValueText +{ + /// + /// The document range for which the inline value applies. + /// + [JsonPropertyName("range")] + [JsonRequired] + public Range Range { get; init; } + + /// + /// The text of the inline value. + /// + [JsonPropertyName("text")] + [JsonRequired] + public string Text { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueVariableLookup.cs b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueVariableLookup.cs new file mode 100644 index 0000000000000..e8b84bb39d42d --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueVariableLookup.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Provide inline value through a variable lookup. +/// +/// If only a range is specified, the variable name will be extracted from +/// the underlying document. +/// +/// +/// An optional variable name can be used to override the extracted name. +/// +/// +/// Since LSP 3.17 +internal class InlineValueVariableLookup +{ + /// + /// The document range for which the inline value applies. + /// + /// The range is used to extract the variable name from the underlying document. + /// + /// + [JsonPropertyName("range")] + [JsonRequired] + public Range Range { get; init; } + + /// + /// If specified the name of the variable to look up. + /// + [JsonPropertyName("variableName")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? VariableName { get; init; } + + /// + /// How to perform the lookup. + /// + [JsonPropertyName("caseSensitiveLookup")] + [JsonRequired] + public bool CaseSensitiveLookup { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueWorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueWorkspaceClientCapabilities.cs new file mode 100644 index 0000000000000..8ad1cc84c3d39 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/InlineValues/InlineValueWorkspaceClientCapabilities.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Client workspace capabilities specific to inline values. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class InlineValueWorkspaceClientCapabilities +{ + /// + /// Whether the client implementation supports a refresh request sent from + /// the server to the client. + /// + /// Note that this event is global and will force the client to refresh all + /// inline values currently shown. It should be used with absolute care and + /// is useful for situation where a server for example detect a project wide + /// change that requires such a calculation. + /// + /// + [JsonPropertyName("refreshSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool RefreshSupport { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index 6012c1bf2fb37..eb450469fa095 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -303,4 +303,41 @@ partial class Methods /// /// Since LSP 3.17 public static readonly LspRequest WorkspaceInlayHintRefresh = new(WorkspaceInlayHintRefreshName); + + /// + /// Method name for 'textDocument/inlineValue'. + /// + /// The inline value request is sent from the client to the server to compute inline values for + /// a given text document that may be rendered in the editor at the end of lines.. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string TextDocumentInlineValueName = "textDocument/inlineValue"; + + /// + /// Strongly typed message object for 'textDocument/inlineValue'. + /// + /// Since LSP 3.17 + public static readonly LspRequest[]?> TextDocumentInlineValue = new(TextDocumentInlineValueName); + + /// + /// Method name for 'workspace/inlineValue/refresh'. + /// + /// This request is sent from the server to ask the client to refresh the inline values currently shown in editors. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string WorkspaceInlineValueRefreshName = "workspace/inlineValue/refresh"; + + /// + /// Strongly typed message object for 'workspace/inlineValue/refresh'. + /// + /// Since LSP 3.17 + public static readonly LspRequest WorkspaceInlineValueRefresh = new(WorkspaceInlineValueRefreshName); } diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 352ded3c4c147..814f7794e0871 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -242,6 +242,14 @@ public TextDocumentSyncOptions? TextDocumentSync [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? TypeHierarchyProvider { get; init; } + /// + /// The server provides inline values. + /// + /// Since LSP 3.17 + [JsonPropertyName("inlineValueProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SumType? InlineValueProvider { get; init; } + /// /// Gets or sets the value which indicates what support the server has for inlay hints. /// diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index 1f01604a3f6ef..0e150c9424940 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -199,6 +199,14 @@ internal class TextDocumentClientCapabilities [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public TypeHierarchyClientCapabilities? TypeHierarchy { get; init; } + /// + /// Capabilities specific to the `textDocument/inlineValue` request. + /// + /// Since LSP 3.17 + [JsonPropertyName("inlineValue")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public InlineValueClientCapability? InlineValue { get; set; } + /// /// Capabilities specific to the `textDocument/inlayHint` request. /// diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs index c29c864ff9627..07a1707d6511c 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs @@ -81,6 +81,14 @@ internal class WorkspaceClientCapabilities [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeLensWorkspaceSetting? CodeLens { get; set; } + /// + /// Client workspace capabilities specific to inline values. + /// + /// Since LSP 3.17 + [JsonPropertyName("inlineValue")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public InlineValueWorkspaceClientCapabilities? InlineValue { get; init; } + /// /// Gets of sets capabilities specific to the inlay hint requests scoped to the workspace. /// From f13f458970cab20558723da7bfdb6aaffa08b37e Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sat, 8 Jun 2024 18:24:18 -0400 Subject: [PATCH 15/46] LSP Protocol: Add Moniker types --- .../Protocol/Protocol/Methods.Document.cs | 22 +++++++++ .../Protocol/Protocol/Moniker/Moniker.cs | 46 +++++++++++++++++++ .../Moniker/MonikerClientCapabilities.cs | 16 +++++++ .../Protocol/Protocol/Moniker/MonikerKind.cs | 36 +++++++++++++++ .../Protocol/Moniker/MonikerOptions.cs | 23 ++++++++++ .../Protocol/Moniker/MonikerParams.cs | 28 +++++++++++ .../Moniker/MonikerRegistrationOptions.cs | 31 +++++++++++++ .../Protocol/Moniker/UniquenessLevel.cs | 46 +++++++++++++++++++ .../Protocol/Protocol/ServerCapabilities.cs | 8 ++++ .../TextDocumentClientCapabilities.cs | 8 ++++ 10 files changed, 264 insertions(+) create mode 100644 src/LanguageServer/Protocol/Protocol/Moniker/Moniker.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Moniker/MonikerClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Moniker/MonikerKind.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Moniker/MonikerOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Moniker/MonikerParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Moniker/MonikerRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Moniker/UniquenessLevel.cs diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index eb450469fa095..26e8225ad5c95 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -340,4 +340,26 @@ partial class Methods /// /// Since LSP 3.17 public static readonly LspRequest WorkspaceInlineValueRefresh = new(WorkspaceInlineValueRefreshName); + + /// + /// Method name for 'textDocument/moniker'. + /// + /// Provide the same symbol moniker information used by Language Server Index Format (LSIF) given a text document position. + /// + /// + /// Clients can utilize this method to get the moniker at the current location in a file user is editing and do + /// further code navigation queries in other services that rely on LSIF indexes and link symbols together. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string TextDocumentMonikerName = "textDocument/moniker"; + + /// + /// Strongly typed message object for 'textDocument/moniker'. + /// + /// Since LSP 3.17 + public static readonly LspRequest TextDocumentMoniker = new(TextDocumentMonikerName); } diff --git a/src/LanguageServer/Protocol/Protocol/Moniker/Moniker.cs b/src/LanguageServer/Protocol/Protocol/Moniker/Moniker.cs new file mode 100644 index 0000000000000..120bfdcbb759d --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Moniker/Moniker.cs @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Moniker definition to match LSIF 0.5 moniker definition. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class Moniker +{ + /// + /// The scheme of the moniker. For example tsc or .Net + /// + [JsonPropertyName("scheme")] + [JsonRequired] + public string Scheme { get; init; } + + /// + /// The identifier of the moniker. The value is opaque in LSIF however + /// schema owners are allowed to define the structure if they want. + /// + [JsonPropertyName("identifier")] + [JsonRequired] + public string Identifier { get; init; } + + /// + /// The scope in which the moniker is unique + /// + [JsonPropertyName("unique")] + [JsonRequired] + public UniquenessLevel Unique { get; init; } + + /// + /// The moniker kind if known. + /// + [JsonPropertyName("kind")] + [JsonIgnore(Condition =JsonIgnoreCondition.WhenWritingNull)] + public MonikerKind? Kind { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Moniker/MonikerClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/Moniker/MonikerClientCapabilities.cs new file mode 100644 index 0000000000000..55c91437ce62a --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Moniker/MonikerClientCapabilities.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/moniker` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class MonikerClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/Moniker/MonikerKind.cs b/src/LanguageServer/Protocol/Protocol/Moniker/MonikerKind.cs new file mode 100644 index 0000000000000..7f90f07b89535 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Moniker/MonikerKind.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.ComponentModel; +using System.Text.Json.Serialization; + +/// +/// The kind of a . +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +[JsonConverter(typeof(StringEnumConverter))] +[TypeConverter(typeof(StringEnumConverter.TypeConverter))] +internal readonly record struct MonikerKind(string Value) : IStringEnum +{ + /// + /// The moniker represent a symbol that is imported into a project + /// + public static readonly MonikerKind Import = new("import"); + + /// + /// The moniker represents a symbol that is exported from a project + /// + public static readonly MonikerKind Export = new("export"); + + /// + /// The moniker represents a symbol that is local to a project (e.g. a local + /// variable of a function, a class not visible outside the project, ...) + /// + public static readonly MonikerKind Local = new("local"); +} diff --git a/src/LanguageServer/Protocol/Protocol/Moniker/MonikerOptions.cs b/src/LanguageServer/Protocol/Protocol/Moniker/MonikerOptions.cs new file mode 100644 index 0000000000000..3d3a51b7103a7 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Moniker/MonikerOptions.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Class which represents Moniker capabilities. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class MonikerOptions : IWorkDoneProgressOptions +{ + /// + /// Gets or sets a value indicating whether work done progress is supported. + /// + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Moniker/MonikerParams.cs b/src/LanguageServer/Protocol/Protocol/Moniker/MonikerParams.cs new file mode 100644 index 0000000000000..1f385a972b10f --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Moniker/MonikerParams.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System; +using System.Text.Json.Serialization; + +/// +/// Class representing the parameters sent from the client to the server for a textDocument/moniker request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class MonikerParams : TextDocumentPositionParams, IWorkDoneProgressParams, IPartialResultParams +{ + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Moniker/MonikerRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/Moniker/MonikerRegistrationOptions.cs new file mode 100644 index 0000000000000..c51dd950d0ea3 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Moniker/MonikerRegistrationOptions.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class MonikerRegistrationOptions : CallHierarchyOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + + /// + /// The id used to register the request. The id can be used to deregister the request again. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Moniker/UniquenessLevel.cs b/src/LanguageServer/Protocol/Protocol/Moniker/UniquenessLevel.cs new file mode 100644 index 0000000000000..82896bc5a1e38 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Moniker/UniquenessLevel.cs @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.ComponentModel; +using System.Text.Json.Serialization; + +/// +/// Moniker uniqueness level to define scope of a . +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +/// +[JsonConverter(typeof(StringEnumConverter))] +[TypeConverter(typeof(StringEnumConverter.TypeConverter))] +internal readonly record struct UniquenessLevel(string Value) : IStringEnum +{ + /// + /// The moniker is only unique inside a document + /// + public static readonly UniquenessLevel Document = new("document"); + + /// + /// The moniker is unique inside a project for which a dump got created + /// + public static readonly UniquenessLevel Project = new("project"); + + /// + /// The moniker is unique inside the group to which a project belongs + /// + public static readonly UniquenessLevel Group = new("group"); + + /// + /// The moniker is unique inside the moniker scheme. + /// + public static readonly UniquenessLevel Scheme = new("scheme"); + + /// + /// The moniker is globally unique + /// + public static readonly UniquenessLevel Global = new("global"); +} diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 814f7794e0871..6e7ad42f9eff7 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -234,6 +234,14 @@ public TextDocumentSyncOptions? TextDocumentSync [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? SemanticTokensOptions { get; set; } + /// + /// Whether server provides moniker support. + /// + /// Since LSP 3.16 + [JsonPropertyName("monikerProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SumType? MonikerProvider { get; init; } + /// /// The server provides type hierarchy support. /// diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index 0e150c9424940..b0e1fa94e09b2 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -191,6 +191,14 @@ internal class TextDocumentClientCapabilities [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SemanticTokensSetting? SemanticTokens { get; set; } + /// + /// Capabilities specific to the `textDocument/moniker` request. + /// + /// Since LSP 3.16 + [JsonPropertyName("moniker")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public MonikerClientCapabilities? Moniker { get; set; } + /// /// Capabilities specific to the various type hierarchy requests. /// From a466e0208d26cf896526bf7012d4be914a7323f9 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Wed, 5 Jun 2024 02:57:14 -0400 Subject: [PATCH 16/46] LSP Protocol: Update completion types --- .../Protocol/Protocol/CompletionContext.cs | 9 +- .../Protocol/Protocol/CompletionItem.cs | 143 +++++++++++++++--- .../Protocol/Protocol/CompletionItemKind.cs | 14 +- .../Protocol/CompletionItemKindSetting.cs | 18 ++- .../Protocol/CompletionItemLabelDetails.cs | 14 +- .../Protocol/CompletionItemOptions.cs | 6 +- .../Protocol/CompletionItemSetting.cs | 51 +++++-- .../Protocol/Protocol/CompletionItemTag.cs | 4 +- .../CompletionItemTagSupportSetting.cs | 6 +- .../Protocol/Protocol/CompletionList.cs | 38 +++-- .../Protocol/CompletionListItemDefaults.cs | 14 +- .../Protocol/CompletionListSetting.cs | 5 +- .../Protocol/Protocol/CompletionOptions.cs | 48 ++++-- .../Protocol/Protocol/CompletionParams.cs | 10 +- .../Protocol/CompletionRegistrationOptions.cs | 21 +++ .../Protocol/Protocol/CompletionSetting.cs | 19 ++- .../Protocol/CompletionTriggerKind.cs | 9 +- .../Protocol/Protocol/InsertReplaceEdit.cs | 4 +- .../Protocol/Protocol/InsertTextFormat.cs | 16 +- .../Protocol/Protocol/InsertTextMode.cs | 20 ++- .../Protocol/InsertTextModeSupportSetting.cs | 8 +- .../Protocol/Protocol/Methods.Document.cs | 36 +++++ .../Protocol/Protocol/Methods.cs | 20 --- .../Protocol/ResolveSupportSetting.cs | 6 +- .../Protocol/Protocol/ServerCapabilities.cs | 2 +- .../TextDocumentClientCapabilities.cs | 2 +- 26 files changed, 412 insertions(+), 131 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/CompletionRegistrationOptions.cs diff --git a/src/LanguageServer/Protocol/Protocol/CompletionContext.cs b/src/LanguageServer/Protocol/Protocol/CompletionContext.cs index 6c674e6b35b65..912477d1aa16b 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionContext.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionContext.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing additional information about the content in which a completion request is triggered. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CompletionContext { @@ -17,6 +18,7 @@ internal class CompletionContext /// Gets or sets the indicating how the completion was triggered. /// [JsonPropertyName("triggerKind")] + [JsonRequired] public CompletionTriggerKind TriggerKind { get; @@ -24,7 +26,8 @@ public CompletionTriggerKind TriggerKind } /// - /// Gets or sets the character that triggered code completion. + /// The trigger character (a single character) that has triggered code completion. + /// Undefined when is not /// [JsonPropertyName("triggerCharacter")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -34,4 +37,4 @@ public string? TriggerCharacter set; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/CompletionItem.cs b/src/LanguageServer/Protocol/Protocol/CompletionItem.cs index d795c27940feb..44c5b6e04bf3d 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionItem.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionItem.cs @@ -4,19 +4,29 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization; /// /// Class which represents an IntelliSense completion item. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CompletionItem { /// - /// Gets or sets the label value, i.e. display text to users. + /// The label of this completion item. + /// + /// The label property is also by default the text that + /// is inserted when selecting this completion. + /// + /// + /// If label details are provided the label itself should + /// be an unqualified name of the completion item. + /// /// [JsonPropertyName("label")] [JsonRequired] @@ -27,8 +37,9 @@ public string Label } /// - /// Gets or sets additional details for the label. + /// Additional details for the label. /// + /// Since LSP 3.17 [JsonPropertyName("labelDetails")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionItemLabelDetails? LabelDetails @@ -38,7 +49,8 @@ public CompletionItemLabelDetails? LabelDetails } /// - /// Gets or sets the completion kind. + /// The kind of this completion item. Based on the kind + /// an icon is chosen by the editor. /// [JsonPropertyName("kind")] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")] @@ -52,8 +64,9 @@ public CompletionItemKind Kind } = CompletionItemKind.None; /// - /// Tags for this completion item. + /// Tags for this completion item, which tweak the rendering of the item. /// + /// Since LSP 3.15 [JsonPropertyName("tags")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public CompletionItemTag[]? Tags @@ -63,7 +76,8 @@ public CompletionItemTag[]? Tags } /// - /// Gets or sets the completion detail. + /// A human-readable string with additional information + /// about this item, like type or symbol information /// [JsonPropertyName("detail")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -74,7 +88,7 @@ public string? Detail } /// - /// Gets or sets the documentation comment. + /// A human-readable string that represents a documentation comment /// [JsonPropertyName("documentation")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -85,7 +99,20 @@ public SumType? Documentation } /// - /// Gets or sets a value indicating whether this should be the selected item when showing. + /// Indicates whether this item is deprecated. + /// + [Obsolete("Use Tags instead if supported")] + [JsonPropertyName("deprecated")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool? Deprecated { get; set; } + + /// + /// Select this item when showing. + /// + /// Note that only one completion item can be selected and that the + /// tool / client decides which item that is. The rule is that the *first* + /// item of those that match best is selected + /// /// [JsonPropertyName("preselect")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -96,7 +123,9 @@ public bool Preselect } /// - /// Gets or sets the custom sort text. + /// A string that should be used when comparing this item + /// with other items. When omitted the label is used + /// as the sort text for this item. /// [JsonPropertyName("sortText")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -107,7 +136,9 @@ public string? SortText } /// - /// Gets or sets the custom filter text. + /// A string that should be used when filtering a set of + /// completion items. When omitted the label is used as the + /// filter text for this item. /// [JsonPropertyName("filterText")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -118,7 +149,19 @@ public string? FilterText } /// - /// Gets or sets the insert text. + /// A string that should be inserted into a document when selecting + /// this completion. When omitted the label is used as the insert text + /// for this item. + /// + /// The is subject to interpretation by the client side, + /// so it is recommended to use instead which avoids + /// client side interpretation. + /// + /// + /// For example in VS Code when code complete is requested for + /// con<cursor position> and an item with + /// console is selected, it will only insert sole. + /// /// [JsonPropertyName("insertText")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -129,7 +172,14 @@ public string? InsertText } /// - /// Gets or sets the insert text format. + /// The format of the insert text. If omitted, defaults to + /// + /// The format applies to both and the + /// property on . + /// + /// + /// Note that this does not apply to + /// /// [JsonPropertyName("insertTextFormat")] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")] @@ -143,7 +193,34 @@ public InsertTextFormat InsertTextFormat } = InsertTextFormat.Plaintext; /// - /// Gets or sets the text edit. + /// How whitespace and indentation is handled during completion + /// item insertion. If not provided the client's default value depends on + /// the client capability. + /// + /// Since LSP 3.16 + [JsonPropertyName("insertTextMode")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public InsertTextMode? InsertTextMode { get; init; } + + /// + /// An edit which is applied to a document when selecting this completion. + /// When an edit is provided the value of is ignored. + /// + /// The must be single-line and must contain the position at which completion was requested. + /// + /// + /// Most editors support two different commit operations: insert completion text, + /// or replace existing text with completion text. This cannot usually be predetermined + /// by a server, so it can report both ranges using + /// if the client signals support via the + /// capability. + /// + /// + /// The + /// must be a prefix of the i.e. same start + /// position and contained within it. They must be single-line and must contain the + /// position at which completion was requested. + /// /// [JsonPropertyName("textEdit")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -154,8 +231,17 @@ public SumType? TextEdit } /// - /// Gets or sets the text edit text. + /// The edit text used if the completion item is part of a + /// that defines a default . + /// + /// Clients will only honor this property if they opt into completion list + /// item defaults using the capability . + /// + /// + /// If not provided, the is used. + /// /// + /// Since LSP 3.17 [JsonPropertyName("textEditText")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? TextEditText @@ -165,11 +251,18 @@ public string? TextEditText } /// - /// Gets or sets any additional text edits. + /// An optional array of additional text edits that are applied when + /// selecting this completion. + /// + /// Edits must not overlap (including the same + /// insert position) with the main edit nor with themselves. + /// + /// + /// Additional text edits should be used to change text unrelated to the + /// current cursor position (for example adding an import statement at the + /// top of the file). + /// /// - /// - /// Additional text edits must not interfere with the main text edit. - /// [JsonPropertyName("additionalTextEdits")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public TextEdit[]? AdditionalTextEdits @@ -179,7 +272,10 @@ public TextEdit[]? AdditionalTextEdits } /// - /// Gets or sets the set of characters that will commit completion when this is selected + /// An optional set of characters that will commit this item if typed while this completion is active. + /// The completion will be committed before inserting the typed character. + /// + /// /// If present, this will override . /// If absent, will be used instead. /// @@ -192,7 +288,11 @@ public string[]? CommitCharacters } /// - /// Gets or sets any optional command that will be executed after completion item insertion. + /// An optional command that is executed after inserting this completion. + /// + /// Note that additional modifications to the current document should instead be + /// described with . + /// /// /// /// This feature is not supported in VS. @@ -206,7 +306,8 @@ public Command? Command } /// - /// Gets or sets any additional data that links the unresolve completion item and the resolved completion item. + /// A data field that is preserved on a completion item between a completion + /// request and and a completion resolve request. /// [JsonPropertyName("data")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/CompletionItemKind.cs b/src/LanguageServer/Protocol/Protocol/CompletionItemKind.cs index 24a46531e3b3c..7fc57e37de689 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionItemKind.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionItemKind.cs @@ -6,8 +6,9 @@ namespace Roslyn.LanguageServer.Protocol { /// /// Enum values for completion item kinds. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal enum CompletionItemKind { @@ -148,26 +149,31 @@ internal enum CompletionItemKind /// /// Macro. /// + /// Specific to VS Macro = 118115 + 0, /// /// Namespace. /// + /// Specific to VS Namespace = 118115 + 1, /// /// Template. /// + /// Specific to VS Template = 118115 + 2, /// /// TypeDefinition. /// + /// Specific to VS TypeDefinition = 118115 + 3, /// /// Union. /// + /// Specific to VS Union = 118115 + 4, /// @@ -178,31 +184,37 @@ internal enum CompletionItemKind /// /// TagHelper. /// + /// Specific to VS TagHelper = 118115 + 6, /// /// ExtensionMethod. /// + /// Specific to VS ExtensionMethod = 118115 + 7, /// /// Element. /// + /// Specific to VS Element = 118115 + 8, /// /// LocalResource. /// + /// Specific to VS LocalResource = 118115 + 9, /// /// SystemResource. /// + /// Specific to VS SystemResource = 118115 + 10, /// /// CloseElement. /// + /// Specific to VS CloseElement = 118115 + 11, } } diff --git a/src/LanguageServer/Protocol/Protocol/CompletionItemKindSetting.cs b/src/LanguageServer/Protocol/Protocol/CompletionItemKindSetting.cs index b80c3219ce3fa..3c8992c63905d 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionItemKindSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionItemKindSetting.cs @@ -7,14 +7,26 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents the initialization setting for completion item kind - /// + /// Describes the values supported by the client + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CompletionItemKindSetting { /// /// Gets or sets the values that the client supports. + /// + /// The completion item kind values the client supports. When this + /// property exists the client also guarantees that it will + /// handle values outside its set gracefully and falls back + /// to a default value when unknown. + /// + /// + /// If this property is not present the client only supports the completion item + /// kinds from to + /// as defined in the initial version of the protocol. + /// /// [JsonPropertyName("valueSet")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -24,4 +36,4 @@ public CompletionItemKind[]? ValueSet set; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/CompletionItemLabelDetails.cs b/src/LanguageServer/Protocol/Protocol/CompletionItemLabelDetails.cs index 9bac8f809f335..a14e8b8fc4463 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionItemLabelDetails.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionItemLabelDetails.cs @@ -8,13 +8,17 @@ namespace Roslyn.LanguageServer.Protocol /// /// Additional details for a completion item label. - /// - /// See the Language Server Protocol specification for additional information. + /// + /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 internal class CompletionItemLabelDetails { /// - /// Gets or sets an optional string which is rendered less prominently directly after label, without any spacing. + /// An optional string which is rendered less prominently directly after + /// , without any spacing. Should be + /// used for function signatures or type annotations. /// [JsonPropertyName("detail")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -25,7 +29,9 @@ public string? Detail } /// - /// Gets or sets an optional string which is rendered less prominently after detail. + /// Gets or sets an optional string which is rendered less prominently after + /// . Should be used for fully qualified + /// names or file path. /// [JsonPropertyName("description")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/CompletionItemOptions.cs b/src/LanguageServer/Protocol/Protocol/CompletionItemOptions.cs index 11d0c8cd77ad1..82f32140a15a8 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionItemOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionItemOptions.cs @@ -7,10 +7,12 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents completion item capabilities. - /// + /// Class which represents completion item server capabilities. + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 internal class CompletionItemOptions { /// diff --git a/src/LanguageServer/Protocol/Protocol/CompletionItemSetting.cs b/src/LanguageServer/Protocol/Protocol/CompletionItemSetting.cs index e5ca68bae6da4..4d2b552bd2f08 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionItemSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionItemSetting.cs @@ -4,17 +4,26 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// - /// Class which represents initialization setting for completion item. - /// + /// Client capabilities specific to . + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CompletionItemSetting { /// - /// Gets or sets a value indicating whether completion items can contain snippets. + /// The client supports treating as a snippet + /// when is set to . + /// + /// A snippet can define tab stops and placeholders with $1, $2 + /// and ${3:foo}. $0 defines the final tab stop and defaults to + /// the end of the snippet. Placeholders with equal identifiers are + /// linked, such that typing in one will update others too. + /// /// [JsonPropertyName("snippetSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -25,7 +34,7 @@ public bool SnippetSupport } /// - /// Gets or sets a value indicating whether the client supports commit characters. + /// The client supports the property. /// [JsonPropertyName("commitCharactersSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -36,7 +45,8 @@ public bool CommitCharactersSupport } /// - /// Gets or sets the content formats supported for documentation. + /// The client supports the following content formats for the + /// property. The order describes the preferred format of the client. /// [JsonPropertyName("documentationFormat")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -47,8 +57,9 @@ public MarkupKind[]? DocumentationFormat } /// - /// Gets or sets the a value indicating whether the client supports the deprecated property on a completion item. + /// The client supports the property on a completion item. /// + [Obsolete("Use Tags instead if supported")] [JsonPropertyName("deprecatedSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool DeprecatedSupport @@ -58,7 +69,7 @@ public bool DeprecatedSupport } /// - /// Gets or sets the a value indicating whether the client supports the preselect property on a completion item. + /// The client supports the property. /// [JsonPropertyName("preselectSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -69,8 +80,14 @@ public bool PreselectSupport } /// - /// Gets or sets the a value indicating whether the client supports the tag property on a completion item. + /// The tags that the client supports on the property. + /// + /// Clients supporting tags have to handle unknown tags gracefully. Clients + /// especially need to preserve unknown tags when sending a completion + /// item back to the server in a resolve call. + /// /// + /// Since LSP 3.15 [JsonPropertyName("tagSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionItemTagSupportSetting? TagSupport @@ -80,8 +97,10 @@ public CompletionItemTagSupportSetting? TagSupport } /// - /// Gets or sets the a value indicating whether the client supports insert replace edit. + /// Whether the client supports values on the + /// property. /// + /// Since 3.16 [JsonPropertyName("insertReplaceSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool InsertReplaceSupport @@ -91,8 +110,13 @@ public bool InsertReplaceSupport } /// - /// Gets or sets the a value indicating which properties a client can resolve lazily on a completion item. + /// Indicates which properties a client can resolve lazily on a completion item. + /// + /// Before version 3.16 only the predefined properties + /// and could be resolved lazily. + /// /// + /// Since 3.16 [JsonPropertyName("resolveSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ResolveSupportSetting? ResolveSupport @@ -102,8 +126,10 @@ public ResolveSupportSetting? ResolveSupport } /// - /// Gets or sets the a value indicating whether the client supports the `insertTextMode` property on a completion item to override the whitespace handling mode as defined by the client. + /// Indicates whether the client supports the + /// property and which values it supports. /// + /// Since 3.16 [JsonPropertyName("insertTextModeSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public InsertTextModeSupportSetting? InsertTextModeSupport @@ -113,8 +139,9 @@ public InsertTextModeSupportSetting? InsertTextModeSupport } /// - /// Gets or sets the a value indicating whether the client supports completion item label details. + /// Indicates whether the client supports the property. /// + /// Since 3.17 [JsonPropertyName("labelDetailsSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool LabelDetailsSupport diff --git a/src/LanguageServer/Protocol/Protocol/CompletionItemTag.cs b/src/LanguageServer/Protocol/Protocol/CompletionItemTag.cs index 349e188ce5087..95fb411bf5e77 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionItemTag.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionItemTag.cs @@ -6,9 +6,11 @@ namespace Roslyn.LanguageServer.Protocol { /// /// Completion item tags are extra annotations that tweak the rendering of a completion item. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.15 internal enum CompletionItemTag { /// diff --git a/src/LanguageServer/Protocol/Protocol/CompletionItemTagSupportSetting.cs b/src/LanguageServer/Protocol/Protocol/CompletionItemTagSupportSetting.cs index 0b79975a7393a..538dd72ce6d3b 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionItemTagSupportSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionItemTagSupportSetting.cs @@ -7,10 +7,12 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents initialization setting for the tag property on a completion item. - /// + /// Represents the tags supported by the client on the property. + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.15 internal class CompletionItemTagSupportSetting { /// diff --git a/src/LanguageServer/Protocol/Protocol/CompletionList.cs b/src/LanguageServer/Protocol/Protocol/CompletionList.cs index 122fcb04d4e64..4eaa0af430204 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionList.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionList.cs @@ -8,16 +8,20 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents a completion list. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CompletionList { /// - /// Gets or sets a value indicating whether Items is the complete list of items or not. If incomplete is true, then - /// filtering should ask the server again for completion item. + /// This list is not complete. Further typing should result in recomputing this list. + /// + /// Recomputed lists have all their items replaced (not appended) in the incomplete completion sessions. + /// /// [JsonPropertyName("isIncomplete")] + [JsonRequired] public bool IsIncomplete { get; @@ -25,24 +29,36 @@ public bool IsIncomplete } /// - /// Gets or sets the list of completion items. + /// Default values of properties for items + /// that do not provide a value for those properties. + /// + /// If a completion list specifies a default value and a completion item + /// also specifies a corresponding value the one from the item is used. + /// + /// + /// Servers are only allowed to return default values if the client + /// signals support for this via the + /// capability. + /// /// - [JsonPropertyName("items")] - public CompletionItem[] Items + /// Since LSP 3.17 + [JsonPropertyName("itemDefaults")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public CompletionListItemDefaults? ItemDefaults { get; set; } /// - /// Gets or sets the completion list item defaults. + /// The completion items. /// - [JsonPropertyName("itemDefaults")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public CompletionListItemDefaults? ItemDefaults + [JsonPropertyName("items")] + [JsonRequired] + public CompletionItem[] Items { get; set; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/CompletionListItemDefaults.cs b/src/LanguageServer/Protocol/Protocol/CompletionListItemDefaults.cs index 4487a31a0f843..2d9ec548a6a6a 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionListItemDefaults.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionListItemDefaults.cs @@ -7,12 +7,14 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents default properties associated with the entire completion list. + /// Represents default values of properties for items + /// is the completion list that do not provide a value for those properties. /// + /// Since LSP 3.17 internal class CompletionListItemDefaults { /// - /// Gets or sets the default commit character set. + /// A default commit character set. /// [JsonPropertyName("commitCharacters")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -23,7 +25,7 @@ public string[]? CommitCharacters } /// - /// Gets or sets the default edit range. + /// A default edit range. /// [JsonPropertyName("editRange")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -34,7 +36,7 @@ public SumType? EditRange } /// - /// Gets or sets the default . + /// A default . /// [JsonPropertyName("insertTextFormat")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -45,7 +47,7 @@ public InsertTextFormat? InsertTextFormat } /// - /// Gets or sets the default . + /// A default . /// [JsonPropertyName("insertTextMode")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -56,7 +58,7 @@ public InsertTextMode? InsertTextMode } /// - /// Gets or sets the default completion item data. + /// A completion item data value. /// [JsonPropertyName("data")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/CompletionListSetting.cs b/src/LanguageServer/Protocol/Protocol/CompletionListSetting.cs index ee4a5d56d6e8e..6939dcfffe9b9 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionListSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionListSetting.cs @@ -7,12 +7,13 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents capabilites for the completion list type. + /// Client capabilities specific to /// + /// Since 3.17 internal class CompletionListSetting { /// - /// Gets or sets a value containing the supported property names of the object. + /// The supported property names of the object. /// If omitted, no properties are supported. /// [JsonPropertyName("itemDefaults")] diff --git a/src/LanguageServer/Protocol/Protocol/CompletionOptions.cs b/src/LanguageServer/Protocol/Protocol/CompletionOptions.cs index bdfa14e9507da..5d3ef67a729e7 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionOptions.cs @@ -8,13 +8,29 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents completion capabilities. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CompletionOptions : IWorkDoneProgressOptions { /// - /// Gets or sets the trigger characters. + /// The additional characters, beyond the defaults provided by the client (typically + /// [a-zA-Z]), that should automatically trigger a completion request. + /// + /// For example . JavaScript represents the beginning of an object property + /// or method and is thus a good candidate for triggering a completion request. + /// + /// + /// Most tools trigger a completion request automatically without explicitly + /// requesting it using a keyboard shortcut (e.g.Ctrl+Space). Typically they + /// do so when the user starts to type an identifier. + /// + /// + /// For example if the user types c in a JavaScript file code complete will + /// automatically pop up present console besides others as a completion item. + /// Characters that make up identifiers don't need to be listed here. + /// /// [JsonPropertyName("triggerCharacters")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -25,8 +41,17 @@ public string[]? TriggerCharacters } /// - /// Gets or sets a value indicating all the possible commit characters associated with the language server. + /// The list of all possible characters that commit a completion. + /// + /// This field can be used if clients don't support individual commit characters per + /// completion item. See client capability . + /// + /// + /// If a server provides both and commit characters on + /// an individual completion item the ones on the completion item win. + /// /// + /// Since LSP 3.2 [JsonPropertyName("allCommitCharacters")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? AllCommitCharacters @@ -36,7 +61,7 @@ public string[]? AllCommitCharacters } /// - /// Gets or sets a value indicating whether server provides completion item resolve capabilities. + /// The server provides support to resolve additional information for a completion item. /// [JsonPropertyName("resolveProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -46,16 +71,10 @@ public bool ResolveProvider set; } - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// - [JsonPropertyName("workDoneProgress")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool WorkDoneProgress { get; init; } - /// /// Gets or sets completion item setting. /// + /// Since LSP 3.17 [JsonPropertyName("completionItem")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionItemOptions? CompletionItemOptions @@ -63,5 +82,12 @@ public CompletionItemOptions? CompletionItemOptions get; set; } + + /// + /// Gets or sets a value indicating whether work done progress is supported. + /// + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/CompletionParams.cs b/src/LanguageServer/Protocol/Protocol/CompletionParams.cs index 0c1626b6c3395..a0550ecd41e21 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionParams.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionParams.cs @@ -9,13 +9,15 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the parameters for the textDocument/completion request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CompletionParams : TextDocumentPositionParams, IPartialResultParams?> { /// - /// Gets or sets the completion context. + /// The completion context. This is only available if the client specifies the + /// client capability . /// [JsonPropertyName("context")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -25,9 +27,7 @@ public CompletionContext? Context set; } - /// - /// Gets or sets the value of the PartialResultToken instance. - /// + /// [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress?>? PartialResultToken diff --git a/src/LanguageServer/Protocol/Protocol/CompletionRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/CompletionRegistrationOptions.cs new file mode 100644 index 0000000000000..1e136762a8a95 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/CompletionRegistrationOptions.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class CompletionRegistrationOptions : CompletionOptions, ITextDocumentRegistrationOptions +{ + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/CompletionSetting.cs b/src/LanguageServer/Protocol/Protocol/CompletionSetting.cs index 30a5228668a92..3888b8d997de0 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionSetting.cs @@ -7,14 +7,15 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents initialization setting for completion. - /// + /// Client capabilities specific to completion. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CompletionSetting : DynamicRegistrationSetting { /// - /// Gets or sets completion item setting. + /// The client supports the following specific capabilities. /// [JsonPropertyName("completionItem")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -25,7 +26,7 @@ public CompletionItemSetting? CompletionItem } /// - /// Gets or sets specific settings. + /// The client supports the following values. /// [JsonPropertyName("completionItemKind")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -36,7 +37,8 @@ public CompletionItemKindSetting? CompletionItemKind } /// - /// Gets or sets a value indicating whether the client supports sending additional context. + /// The client supports sending additional context information for + /// a textDocument/completion request. /// [JsonPropertyName("contextSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -47,8 +49,10 @@ public bool ContextSupport } /// - /// Gets or sets a value indicating client's default when the completion item doesn't provide an `insertTextMode` property. + /// The client's default insertion behavior when a completion item doesn't + /// provide a value for the property. /// + /// Since 3.17 [JsonPropertyName("insertTextMode")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public InsertTextMode? InsertTextMode @@ -58,8 +62,9 @@ public InsertTextMode? InsertTextMode } /// - /// Gets or sets a value indicating whether the client supports capabilities on the completion list. + /// The client supports the following specific capabilities. /// + /// Since 3.17 [JsonPropertyName("completionList")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CompletionListSetting? CompletionListSetting diff --git a/src/LanguageServer/Protocol/Protocol/CompletionTriggerKind.cs b/src/LanguageServer/Protocol/Protocol/CompletionTriggerKind.cs index 4154beeb6fa7f..de988596cd333 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionTriggerKind.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionTriggerKind.cs @@ -6,18 +6,19 @@ namespace Roslyn.LanguageServer.Protocol { /// /// Enum which represents the various ways in which completion can be triggered. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal enum CompletionTriggerKind { /// - /// Completion was triggered by typing an identifier. + /// Completion was triggered by typing an identifier, manual invocation (e.g Ctrl+Space) or via API. /// Invoked = 1, /// - /// Completion was triggered by typing a trigger character. + /// Completion was triggered by a trigger character specified in /// TriggerCharacter = 2, @@ -26,4 +27,4 @@ internal enum CompletionTriggerKind /// TriggerForIncompleteCompletions = 3, } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/InsertReplaceEdit.cs b/src/LanguageServer/Protocol/Protocol/InsertReplaceEdit.cs index 44c06ee7f3aef..067a0d240ba04 100644 --- a/src/LanguageServer/Protocol/Protocol/InsertReplaceEdit.cs +++ b/src/LanguageServer/Protocol/Protocol/InsertReplaceEdit.cs @@ -8,9 +8,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// A special text edit to provide an insert and a replace operation. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class InsertReplaceEdit { /// diff --git a/src/LanguageServer/Protocol/Protocol/InsertTextFormat.cs b/src/LanguageServer/Protocol/Protocol/InsertTextFormat.cs index 537c41b695637..5cca5cbf13299 100644 --- a/src/LanguageServer/Protocol/Protocol/InsertTextFormat.cs +++ b/src/LanguageServer/Protocol/Protocol/InsertTextFormat.cs @@ -5,19 +5,27 @@ namespace Roslyn.LanguageServer.Protocol { /// - /// Enum representing insert text format for completion items. - /// + /// Defines whether the insert text in a completion item should be + /// interpreted as plain text or as a snippet. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal enum InsertTextFormat { /// - /// Completion item insertion is plaintext. + /// The primary text to be inserted is treated as a plain string. /// Plaintext = 1, /// - /// Completion item insertion is snippet. + /// The primary text to be inserted is treated as a snippet. + /// + /// A snippet can define tab stops and placeholders with $1, $2 + /// and ${3:foo}. $0 defines the final tab stop and defaults to + /// the end of the snippet. Placeholders with equal identifiers are + /// linked, such that typing in one will update others too. + /// /// Snippet = 2, } diff --git a/src/LanguageServer/Protocol/Protocol/InsertTextMode.cs b/src/LanguageServer/Protocol/Protocol/InsertTextMode.cs index 68d7be59e0c45..73ac303b4785a 100644 --- a/src/LanguageServer/Protocol/Protocol/InsertTextMode.cs +++ b/src/LanguageServer/Protocol/Protocol/InsertTextMode.cs @@ -6,18 +6,32 @@ namespace Roslyn.LanguageServer.Protocol { /// /// How whitespace and indentation is handled during completion item insertion. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal enum InsertTextMode { /// - /// The insertion or replace strings is taken as it is. + /// The insertion or replace string is taken as-is. + /// + /// If the value is multi-line the lines below the cursor will be + /// inserted using the indentation defined in the string value. + /// The client will not apply any kind of adjustments to the string. + /// /// AsIs = 1, /// - /// The editor adjusts leading whitespace of new lines so that they match the indentation up to the cursor of the line for which the item is accepted. + /// The editor adjusts leading whitespace of new lines so that + /// they match the indentation up to the cursor of the line for + /// which the item is accepted. + /// + /// Consider a line like this: <2tabs><cursor><3tabs>foo. Accepting a + /// multi line completion item is indented using 2 tabs and all + /// following lines inserted will be indented using 2 tabs as well. + /// /// AdjustIndentation = 2, } diff --git a/src/LanguageServer/Protocol/Protocol/InsertTextModeSupportSetting.cs b/src/LanguageServer/Protocol/Protocol/InsertTextModeSupportSetting.cs index 7b7e24c261a79..81bde42941994 100644 --- a/src/LanguageServer/Protocol/Protocol/InsertTextModeSupportSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/InsertTextModeSupportSetting.cs @@ -7,14 +7,14 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents initialization setting for the tag property on a completion item. - /// - /// See the Language Server Protocol specification for additional information. + /// The client's capabilities specific to the property. /// + /// Since 3.16 internal class InsertTextModeSupportSetting { /// - /// Gets or sets a value indicating the client supports the `insertTextMode` property on a completion item to override the whitespace handling mode as defined by the client. + /// The values that the client supports + /// onf the the property. /// [JsonPropertyName("valueSet")] [JsonRequired] diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index 26e8225ad5c95..87737eaff3ae1 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -362,4 +362,40 @@ partial class Methods /// /// Since LSP 3.17 public static readonly LspRequest TextDocumentMoniker = new(TextDocumentMonikerName); + + /// + /// Method name for 'textDocument/completion'. + /// + /// The Completion request is sent from the client to the server to compute completion items at a given cursor position. + /// + /// + /// If computing full completion items is expensive, servers can additionally provide a handler for the completion + /// item resolve request (‘completionItem/resolve’), which is sent when a completion item is selected in the user interface. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentCompletionName = "textDocument/completion"; + + /// + /// Strongly typed message object for 'textDocument/completion'. + /// + public static readonly LspRequest?> TextDocumentCompletion = new(TextDocumentCompletionName); + + /// + /// Method name for 'completionItem/resolve'. + /// + /// The request is sent from the client to the server to resolve additional information for a given completion item. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentCompletionResolveName = "completionItem/resolve"; + + /// + /// Strongly typed message object for 'completionItem/resolve'. + /// + public static readonly LspRequest TextDocumentCompletionResolve = new(TextDocumentCompletionResolveName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index c038abe45ad61..86606367a0dbc 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -41,16 +41,6 @@ internal static partial class Methods /// public const string CodeActionResolveName = "codeAction/resolve"; - /// - /// Method name for 'textDocument/completion'. - /// - public const string TextDocumentCompletionName = "textDocument/completion"; - - /// - /// Method name for 'completionItem/resolve'. - /// - public const string TextDocumentCompletionResolveName = "completionItem/resolve"; - /// /// Method name for 'textDocument/diagnostic'. /// @@ -171,16 +161,6 @@ internal static partial class Methods /// public static readonly LspRequest CodeActionResolve = new LspRequest(CodeActionResolveName); - /// - /// Strongly typed message object for 'textDocument/completion'. - /// - public static readonly LspRequest?> TextDocumentCompletion = new LspRequest?>(TextDocumentCompletionName); - - /// - /// Strongly typed message object for 'completionItem/resolve'. - /// - public static readonly LspRequest TextDocumentCompletionResolve = new LspRequest(TextDocumentCompletionResolveName); - /// /// Strongly typed message object for 'textDocument/documentColor'. /// diff --git a/src/LanguageServer/Protocol/Protocol/ResolveSupportSetting.cs b/src/LanguageServer/Protocol/Protocol/ResolveSupportSetting.cs index 6ff560bb95808..a9a1fc88afa0a 100644 --- a/src/LanguageServer/Protocol/Protocol/ResolveSupportSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/ResolveSupportSetting.cs @@ -7,10 +7,12 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents initialization setting for properties a client can resolve lazily on a completion item. - /// + /// Indicates which properties a client can resolve lazily on a . + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since 3.16 internal class ResolveSupportSetting { /// diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 6e7ad42f9eff7..7e0cd369fc564 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -60,7 +60,7 @@ public TextDocumentSyncOptions? TextDocumentSync public SumType? NotebookDocumentSync { get; init; } /// - /// Gets or sets the value which indicates if completions are supported. + /// The server provides completion support. /// [JsonPropertyName("completionProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index b0e1fa94e09b2..aefb849276476 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -24,7 +24,7 @@ internal class TextDocumentClientCapabilities public SynchronizationSetting? Synchronization { get; set; } /// - /// Gets or sets the completion setting. + /// Capabilities specific to the `textDocument/completion` request. /// [JsonPropertyName("completion")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] From ccd8d177581ba2b7773561409e4931303b221e3d Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sat, 8 Jun 2024 23:03:22 -0400 Subject: [PATCH 17/46] LSP Protocol: Update Diagnostic types/methods --- .../Protocol/Protocol/CodeDescription.cs | 6 +- .../Protocol/Protocol/Diagnostic.cs | 29 +++-- .../Protocol/Protocol/DiagnosticOptions.cs | 18 ++- .../Protocol/DiagnosticRegistrationOptions.cs | 27 ++--- .../Protocol/DiagnosticRelatedInformation.cs | 2 +- .../DiagnosticServerCancellationData.cs | 8 +- .../Protocol/Protocol/DiagnosticSetting.cs | 10 +- .../Protocol/Protocol/DiagnosticTag.cs | 4 +- .../Protocol/Protocol/DiagnosticTagSupport.cs | 23 ++++ .../Protocol/DiagnosticWorkspaceSetting.cs | 16 ++- .../Protocol/DocumentDiagnosticParams.cs | 22 ++-- .../Protocol/DocumentDiagnosticReportKind.cs | 6 +- .../DocumentDiagnosticReportPartialResult.cs | 8 +- .../Protocol/FullDocumentDiagnosticReport.cs | 10 +- .../Protocol/Protocol/Methods.Diagnostics.cs | 103 ++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 24 ---- .../Protocol/Protocol/PreviousResultId.cs | 10 +- .../Protocol/PublishDiagnosticParams.cs | 8 ++ .../Protocol/PublishDiagnosticsSetting.cs | 43 +++++++- .../RelatedFullDocumentDiagnosticReport.cs | 16 ++- ...elatedUnchangedDocumentDiagnosticReport.cs | 16 ++- .../Protocol/Protocol/ServerCapabilities.cs | 3 +- .../Protocol/Protocol/TagSupport.cs | 26 ----- .../TextDocumentClientCapabilities.cs | 5 +- .../UnchangedDocumentDiagnosticReport.cs | 14 ++- .../Protocol/WorkspaceClientCapabilities.cs | 1 + .../Protocol/WorkspaceDiagnosticParams.cs | 36 +++--- .../Protocol/WorkspaceDiagnosticReport.cs | 9 +- .../WorkspaceDiagnosticReportPartialResult.cs | 9 +- .../WorkspaceFullDocumentDiagnosticReport.cs | 8 +- ...kspaceUnchangedDocumentDiagnosticReport.cs | 8 +- 31 files changed, 361 insertions(+), 167 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/DiagnosticTagSupport.cs create mode 100644 src/LanguageServer/Protocol/Protocol/Methods.Diagnostics.cs delete mode 100644 src/LanguageServer/Protocol/Protocol/TagSupport.cs diff --git a/src/LanguageServer/Protocol/Protocol/CodeDescription.cs b/src/LanguageServer/Protocol/Protocol/CodeDescription.cs index d7c414285753e..4ff525a766ad9 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeDescription.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeDescription.cs @@ -8,10 +8,12 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing a description for an error code. - /// + /// Class representing a description for an error code in a . + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class CodeDescription : IEquatable { /// diff --git a/src/LanguageServer/Protocol/Protocol/Diagnostic.cs b/src/LanguageServer/Protocol/Protocol/Diagnostic.cs index 57def31e7cee4..bd899f1dcb804 100644 --- a/src/LanguageServer/Protocol/Protocol/Diagnostic.cs +++ b/src/LanguageServer/Protocol/Protocol/Diagnostic.cs @@ -53,6 +53,7 @@ public SumType? Code /// /// Gets or sets an optional value that describes the error code. /// + /// Since LSP 3.16 [JsonPropertyName("codeDescription")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeDescription? CodeDescription @@ -84,8 +85,9 @@ public string Message } /// - /// Gets or sets the diagnostic's tags. + /// Additional metadata about the diagnostic. /// + /// Since 3.16 [JsonPropertyName("tags")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DiagnosticTag[]? Tags @@ -105,6 +107,14 @@ public DiagnosticRelatedInformation[]? RelatedInformation set; } + /// + /// Data that is preserved for a textDocument/codeAction request + /// + /// Since 3.16 + [JsonPropertyName("data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public object? Data { get; init; } + public static bool operator ==(Diagnostic? value1, Diagnostic? value2) { if (ReferenceEquals(value1, value2)) @@ -138,7 +148,10 @@ public bool Equals(Diagnostic other) && string.Equals(this.Message, other.Message, StringComparison.Ordinal) && (this.Tags == null ? other.Tags == null - : this.Tags.Equals(other.Tags) || this.Tags.SequenceEqual(other.Tags)); + : this.Tags.Equals(other.Tags) || this.Tags.SequenceEqual(other.Tags)) + && (this.Data is null + ? other.Data is null + : this.Data.Equals(other.Data)); } /// @@ -155,15 +168,7 @@ public override bool Equals(object obj) } /// - public override int GetHashCode() - { - return (this.Range == null ? 53 : this.Range.GetHashCode() * 13) - ^ (this.Severity.GetHashCode() * 17) - ^ (this.Code == null ? 47 : this.Code.GetHashCode() * 19) - ^ (this.Source == null ? 61 : this.Source.GetHashCode() * 79) - ^ (this.Message == null ? 83 : this.Message.GetHashCode() * 23) - ^ (this.Tags == null ? 89 : this.Tags.Sum(t => (int)t) * 73) - ^ (this.CodeDescription == null ? 23 : this.CodeDescription.GetHashCode() * 29); - } + public override int GetHashCode() => + HashCode.Combine(Range, Severity, Code, Source, Message, Utilities.Hash.CombineValues(Tags), CodeDescription, Data); } } diff --git a/src/LanguageServer/Protocol/Protocol/DiagnosticOptions.cs b/src/LanguageServer/Protocol/Protocol/DiagnosticOptions.cs index 4d51c1b96d201..62fdf966dce4c 100644 --- a/src/LanguageServer/Protocol/Protocol/DiagnosticOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/DiagnosticOptions.cs @@ -8,14 +8,14 @@ namespace Roslyn.LanguageServer.Protocol; /// /// Server capabilities for pull diagnostics. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 internal class DiagnosticOptions : IWorkDoneProgressOptions { - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// + /// [JsonPropertyName("workDoneProgress")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } @@ -32,7 +32,13 @@ public string? Identifier } /// - /// Gets or sets a value indicating whether the language has inter file dependencies. + /// Whether the language has inter-file dependencies meaning that + /// editing code in one file can result in a different diagnostic + /// set in another file. + /// + /// Inter file dependencies are common for most programming + /// languages and typically uncommon for linters. + /// /// [JsonPropertyName("interFileDependencies")] public bool InterFileDependencies diff --git a/src/LanguageServer/Protocol/Protocol/DiagnosticRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/DiagnosticRegistrationOptions.cs index f41e6490d1766..30364dab17779 100644 --- a/src/LanguageServer/Protocol/Protocol/DiagnosticRegistrationOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/DiagnosticRegistrationOptions.cs @@ -8,29 +8,20 @@ namespace Roslyn.LanguageServer.Protocol; /// /// Diagnostic registration options. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 internal class DiagnosticRegistrationOptions : DiagnosticOptions, IStaticRegistrationOptions, ITextDocumentRegistrationOptions { - /// - /// Gets or sets the document filters for this registration option. - /// + /// [JsonPropertyName("documentSelector")] - public DocumentFilter[]? DocumentSelector - { - get; - set; - } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// + /// [JsonPropertyName("id")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string? Id - { - get; - set; - } + public string? Id { get; set; } } diff --git a/src/LanguageServer/Protocol/Protocol/DiagnosticRelatedInformation.cs b/src/LanguageServer/Protocol/Protocol/DiagnosticRelatedInformation.cs index cc3099afe6976..4a0866a073658 100644 --- a/src/LanguageServer/Protocol/Protocol/DiagnosticRelatedInformation.cs +++ b/src/LanguageServer/Protocol/Protocol/DiagnosticRelatedInformation.cs @@ -11,7 +11,7 @@ namespace Roslyn.LanguageServer.Protocol /// This should be used to point to code locations that cause or are related to /// a diagnostics, e.g when duplicating a symbol in a scope. /// - /// See the Language Server Protocol specification for additional information. + /// See the Language Server Protocol specification for additional information. /// internal class DiagnosticRelatedInformation { diff --git a/src/LanguageServer/Protocol/Protocol/DiagnosticServerCancellationData.cs b/src/LanguageServer/Protocol/Protocol/DiagnosticServerCancellationData.cs index 0ee406d772ae8..efff6f7331cb9 100644 --- a/src/LanguageServer/Protocol/Protocol/DiagnosticServerCancellationData.cs +++ b/src/LanguageServer/Protocol/Protocol/DiagnosticServerCancellationData.cs @@ -8,9 +8,11 @@ namespace Roslyn.LanguageServer.Protocol; /// /// Class representing the cancellation data returned from a diagnostic request. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 internal class DiagnosticServerCancellationData { /// @@ -22,4 +24,4 @@ public bool RetriggerRequest get; set; } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/DiagnosticSetting.cs b/src/LanguageServer/Protocol/Protocol/DiagnosticSetting.cs index b5d623d11f2c9..e416751dd382a 100644 --- a/src/LanguageServer/Protocol/Protocol/DiagnosticSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/DiagnosticSetting.cs @@ -7,10 +7,12 @@ namespace Roslyn.LanguageServer.Protocol; using System.Text.Json.Serialization; /// -/// Client settings for pull diagnostics. -/// -/// See the Language Server Protocol specification for additional information. +/// Client capabilities specific to pull diagnostics. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 internal class DiagnosticSetting : DynamicRegistrationSetting { /// @@ -19,4 +21,4 @@ internal class DiagnosticSetting : DynamicRegistrationSetting [JsonPropertyName("relatedDocumentSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool RelatedDocumentSupport { get; set; } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/DiagnosticTag.cs b/src/LanguageServer/Protocol/Protocol/DiagnosticTag.cs index 1b2662066ffea..6c648f8b3b29c 100644 --- a/src/LanguageServer/Protocol/Protocol/DiagnosticTag.cs +++ b/src/LanguageServer/Protocol/Protocol/DiagnosticTag.cs @@ -14,13 +14,13 @@ internal enum DiagnosticTag { /// /// Unused or unnecessary code. - /// Diagnostics with this tag are rendered faded out. + /// Clients are allowed to render diagnostics with this tag faded out. /// Unnecessary = 1, /// /// Deprecated or obsolete code. - /// Clients are allowed to rendered diagnostics with this tag strike through. + /// Clients are allowed to render diagnostics with this tag strike through. /// Deprecated = 2, } diff --git a/src/LanguageServer/Protocol/Protocol/DiagnosticTagSupport.cs b/src/LanguageServer/Protocol/Protocol/DiagnosticTagSupport.cs new file mode 100644 index 0000000000000..e8c631ab0505d --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DiagnosticTagSupport.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Represent the client's support for the property to provide metadata about a diagnostic. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.15 +internal class DiagnosticTagSupport +{ + /// + /// Gets or sets a value indicating the tags supported by the client. + /// + [JsonPropertyName("valueSet")] + public DiagnosticTag[] ValueSet { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/DiagnosticWorkspaceSetting.cs b/src/LanguageServer/Protocol/Protocol/DiagnosticWorkspaceSetting.cs index 5aee040d2afc3..cda41f08b7950 100644 --- a/src/LanguageServer/Protocol/Protocol/DiagnosticWorkspaceSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/DiagnosticWorkspaceSetting.cs @@ -8,15 +8,23 @@ namespace Roslyn.LanguageServer.Protocol; /// /// Class representing the workspace diagnostic client capabilities. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 internal class DiagnosticWorkspaceSetting { /// - /// Gets or sets a value indicating whether the client supports a refresh request sent from the server to the client. + /// Whether the client supports a refresh request sent from the server to the client. + /// + /// Note that this event is global and will force the client to refresh all + /// pulled diagnostics currently shown. It should be used with absolute care + /// and is useful for situation where a server for example detects a project + /// wide change that requires such a calculation. + /// /// [JsonPropertyName("refreshSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool RefreshSupport { get; set; } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/DocumentDiagnosticParams.cs b/src/LanguageServer/Protocol/Protocol/DocumentDiagnosticParams.cs index 348274675e055..3ba3b8dcc7a6e 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentDiagnosticParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentDiagnosticParams.cs @@ -9,14 +9,14 @@ namespace Roslyn.LanguageServer.Protocol; /// /// Class representing the document diagnostic request parameters -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// -internal class DocumentDiagnosticParams : ITextDocumentParams, IPartialResultParams> +/// Since LSP 3.17 +internal class DocumentDiagnosticParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams> { - /// - /// Gets or sets the value of the Progress instance. - /// + /// /// /// Note that the first literal send needs to be either the or /// followed by n literals. @@ -25,10 +25,14 @@ internal class DocumentDiagnosticParams : ITextDocumentParams, IPartialResultPar [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress>? PartialResultToken { - get; - set; + get; set; } + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + /// /// Gets or sets the to provide diagnostics for. /// @@ -40,7 +44,7 @@ public TextDocumentIdentifier TextDocument } /// - /// Gets or sets the identifier for which the client is requesting diagnostics for. + /// The additional identifier provided during registration /// [JsonPropertyName("identifier")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/DocumentDiagnosticReportKind.cs b/src/LanguageServer/Protocol/Protocol/DocumentDiagnosticReportKind.cs index 30efcc8483aa7..ce76ef7d9db2c 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentDiagnosticReportKind.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentDiagnosticReportKind.cs @@ -6,8 +6,10 @@ namespace Roslyn.LanguageServer.Protocol; /// /// Value representing the kind of the document diagnostic report. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// Since LSP 3.17 /// internal static class DocumentDiagnosticReportKind { diff --git a/src/LanguageServer/Protocol/Protocol/DocumentDiagnosticReportPartialResult.cs b/src/LanguageServer/Protocol/Protocol/DocumentDiagnosticReportPartialResult.cs index 9e2c17cb63aef..65f92997293a2 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentDiagnosticReportPartialResult.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentDiagnosticReportPartialResult.cs @@ -10,9 +10,11 @@ namespace Roslyn.LanguageServer.Protocol; /// /// Class representing a partial document diagnostic report for a set of related documents. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 internal class DocumentDiagnosticReportPartialResult { /// @@ -24,4 +26,4 @@ public Dictionary /// Class representing a diagnostic report with a full set of problems. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 [Kind(DocumentDiagnosticReportKind.Full)] internal class FullDocumentDiagnosticReport { @@ -23,7 +25,9 @@ internal class FullDocumentDiagnosticReport #pragma warning restore CA1822 // Mark members as static /// - /// Gets or sets the optional result id. + /// An optional result id. If provided it will + /// be sent on the next diagnostic request for the + /// same document. /// [JsonPropertyName("resultId")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Diagnostics.cs b/src/LanguageServer/Protocol/Protocol/Methods.Diagnostics.cs new file mode 100644 index 0000000000000..41caa8cf3f0f4 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Methods.Diagnostics.cs @@ -0,0 +1,103 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +// diagnostics methods from https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#languageFeatures +partial class Methods +{ + // NOTE: these are sorted in the order used by the spec + + /// + /// Method name for 'textDocument/publishDiagnostics'. + /// + /// Diagnostics notifications are sent from the server to the client to signal results of validation runs. + /// + /// + /// Diagnostics are “owned” by the server so it is the server’s responsibility to clear them if necessary. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentPublishDiagnosticsName = "textDocument/publishDiagnostics"; + + /// + /// Strongly typed message object for 'textDocument/publishDiagnostics'. + /// + public static readonly LspNotification TextDocumentPublishDiagnostics = new(TextDocumentPublishDiagnosticsName); + + /// + /// Method name for 'textDocument/diagnostic'. + /// + /// Pull diagnostics are a preferred alternative to 'textDocument/publishDiagnostics' push diagnostics that give + /// the client more control over the documents for which diagnostics should be computed and at which point in time. + /// + /// + /// The text document diagnostic request is sent from the client to the server to ask the server to compute the + /// diagnostics for a given document. As with other pull requests the server is asked to compute the diagnostics + /// for the currently synced version of the document. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string TextDocumentDiagnosticName = "textDocument/diagnostic"; + + /// + /// Strongly typed message object for 'textDocument/diagnostic'. + /// + /// Since LSP 3.17 + public static readonly LspNotification TextDocumentDiagnostic = new(TextDocumentDiagnosticName); + + /// + /// Method name for 'workspace/diagnostic'. + /// + /// The workspace diagnostic request is sent from the client to the server to ask the server to compute workspace + /// wide diagnostics which previously were pushed from the server to the client. + /// + /// + /// In contrast to the document diagnostic request the workspace request can be long running and is not bound + /// to a specific workspace or document state. + /// + /// + /// If the client supports streaming for the workspace diagnostic pull it is legal to provide a document diagnostic + /// report multiple times for the same document URI. The last one reported will win over previous reports. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string WorkspaceDiagnosticName = "workspace/diagnostic"; + + /// + /// Strongly typed message object for 'workspace/diagnostic'. + /// + /// Since LSP 3.17 + public static readonly LspRequest WorkspaceDiagnostic = new(WorkspaceDiagnosticName); + + /// + /// Method name for 'workspace/diagnostic/refresh'. + /// + /// The workspace/diagnostic/refresh request is sent from the server to the client. Servers can use it to ask clients + /// to refresh all needed document and workspace diagnostics. + /// + /// + /// This is useful if a server detects a project wide configuration change which requires a re-calculation of all diagnostics. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.17 + public const string WorkspaceDiagnosticRefreshName = "workspace/diagnostic/refresh"; + + /// + /// Strongly typed message object for 'workspace/diagnostic/refresh'. + /// + /// Since LSP 3.17 + public static readonly LspNotification WorkspaceDiagnosticRefresh = new(WorkspaceDiagnosticRefreshName); +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index 86606367a0dbc..58e293b43319b 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -41,11 +41,6 @@ internal static partial class Methods /// public const string CodeActionResolveName = "codeAction/resolve"; - /// - /// Method name for 'textDocument/diagnostic'. - /// - public const string TextDocumentDiagnosticName = "textDocument/diagnostic"; - /// /// Method name for 'textDocument/documentColor'. /// @@ -66,11 +61,6 @@ internal static partial class Methods /// public const string TextDocumentRangeFormattingName = "textDocument/rangeFormatting"; - /// - /// Method name for 'textDocument/publishDiagnostics'. - /// - public const string TextDocumentPublishDiagnosticsName = "textDocument/publishDiagnostics"; - /// /// Method name for 'textDocument/rename'. /// @@ -116,15 +106,6 @@ internal static partial class Methods /// public const string WorkspaceConfigurationName = "workspace/configuration"; - /// - /// Method name for 'workspace/diagnostic'. - /// - public const string WorkspaceDiagnosticName = "workspace/diagnostic"; - - /// - /// Method name for 'workspace/diagnostic/refresh'. - /// - public const string WorkspaceDiagnosticRefreshName = "workspace/diagnostic/refresh"; /// /// Method name for 'workspace/didChangeConfiguration'. @@ -181,11 +162,6 @@ internal static partial class Methods /// public static readonly LspRequest TextDocumentRangeFormatting = new LspRequest(TextDocumentRangeFormattingName); - /// - /// Strongly typed message object for 'textDocument/publishDiagnostics'. - /// - public static readonly LspNotification TextDocumentPublishDiagnostics = new LspNotification(TextDocumentPublishDiagnosticsName); - /// /// Strongly typed message object for 'textDocument/rename'. /// diff --git a/src/LanguageServer/Protocol/Protocol/PreviousResultId.cs b/src/LanguageServer/Protocol/Protocol/PreviousResultId.cs index e8ae0c7e4e6bc..610de39552d7c 100644 --- a/src/LanguageServer/Protocol/Protocol/PreviousResultId.cs +++ b/src/LanguageServer/Protocol/Protocol/PreviousResultId.cs @@ -8,10 +8,12 @@ namespace Roslyn.LanguageServer.Protocol; using System.Text.Json.Serialization; /// -/// Class representing a previous result id in a workspace pull request. -/// -/// See the Language Server Protocol specification for additional information. +/// Class representing a previous result id in a 'workspace/diagnostic' request. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 internal class PreviousResultId { /// @@ -34,4 +36,4 @@ public string Value get; set; } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/PublishDiagnosticParams.cs b/src/LanguageServer/Protocol/Protocol/PublishDiagnosticParams.cs index 5b759a01c9aa3..4656113a54618 100644 --- a/src/LanguageServer/Protocol/Protocol/PublishDiagnosticParams.cs +++ b/src/LanguageServer/Protocol/Protocol/PublishDiagnosticParams.cs @@ -25,6 +25,14 @@ public Uri Uri set; } + /// + /// Optional version number of the document for which the diagnostics are published + /// + /// Since LSP 3.15 + [JsonPropertyName("version")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public int? Version { get; init; } + /// /// Gets or sets the collection of diagnostics. /// diff --git a/src/LanguageServer/Protocol/Protocol/PublishDiagnosticsSetting.cs b/src/LanguageServer/Protocol/Protocol/PublishDiagnosticsSetting.cs index 63f44c94aabbf..ddfb07c089ca7 100644 --- a/src/LanguageServer/Protocol/Protocol/PublishDiagnosticsSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/PublishDiagnosticsSetting.cs @@ -7,21 +7,56 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing the initialization setting for publish diagnostics. - /// + /// Client capabilities specific to the textDocument/publishDiagnostics notification + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class PublishDiagnosticsSetting { /// - /// Gets or sets a value indicating whether gets or sets the capabilities. + /// Whether the client supports the property. + /// + public bool RelatedInformation { get; init; } + + /// + /// Client supports the property to provide meta data about a diagnostic. + /// + /// Clients supporting tags have to handle unknown tags gracefully. + /// /// [JsonPropertyName("tagSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public TagSupport? TagSupport + public DiagnosticTagSupport? TagSupport { get; set; } + + /// + /// Whether the client interprets the property + /// of the textDocument/publishDiagnostics notification's parameter. + /// + /// Since LSP 3.15 + [JsonPropertyName("versionSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool VersionSupport { get; init; } + + /// + /// Whether the client supports the property. + /// + /// Since LSP 3.15 + [JsonPropertyName("codeDescriptionSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool CodeDescriptionSupport { get; init; } + + /// + /// Whether the client supports propagating the property from + /// a textDocument/publishDiagnostics notification to a textDocument/codeAction request. + /// + /// Since LSP 3.16 + [JsonPropertyName("dataSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool DataSupport { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/RelatedFullDocumentDiagnosticReport.cs b/src/LanguageServer/Protocol/Protocol/RelatedFullDocumentDiagnosticReport.cs index 7b6fbc77a4210..7468d207b9b13 100644 --- a/src/LanguageServer/Protocol/Protocol/RelatedFullDocumentDiagnosticReport.cs +++ b/src/LanguageServer/Protocol/Protocol/RelatedFullDocumentDiagnosticReport.cs @@ -10,14 +10,22 @@ namespace Roslyn.LanguageServer.Protocol; /// /// Class representing a full diagnostic report with a set of related documents. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 [Kind(DocumentDiagnosticReportKind.Full)] internal class RelatedFullDocumentDiagnosticReport : FullDocumentDiagnosticReport { /// - /// Gets or sets the map of related document diagnostic reports. + /// Diagnostics of related documents. + /// + /// + /// This information is useful in programming languages where code in a + /// file A can generate diagnostics in a file B which A depends on. An + /// example of such a language is C/C++ where macro definitions in a file + /// a.cpp can result in errors in a header file b.hpp. /// [JsonPropertyName("relatedDocuments")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -26,4 +34,4 @@ public Dictionary /// Class representing an unchanged diagnostic report with a set of related documents. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 [Kind(DocumentDiagnosticReportKind.Unchanged)] internal class RelatedUnchangedDocumentDiagnosticReport : UnchangedDocumentDiagnosticReport { /// - /// Gets or sets the map of related document diagnostic reports. + /// Diagnostics of related documents. + /// + /// + /// This information is useful in programming languages where code in a + /// file A can generate diagnostics in a file B which A depends on. An + /// example of such a language is C/C++ where macro definitions in a file + /// a.cpp can result in errors in a header file b.hpp. /// [JsonPropertyName("relatedDocuments")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -26,4 +34,4 @@ public Dictionary /// Gets or sets the value which indicates what support the server has for pull diagnostics. /// + /// Since LSP 3.17 [JsonPropertyName("diagnosticProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DiagnosticOptions? DiagnosticOptions { get; set; } + public SumType? DiagnosticOptions { get; set; } /// /// Gets or sets a value indicating whether workspace symbols are supported. diff --git a/src/LanguageServer/Protocol/Protocol/TagSupport.cs b/src/LanguageServer/Protocol/Protocol/TagSupport.cs deleted file mode 100644 index 2f27a28e442e8..0000000000000 --- a/src/LanguageServer/Protocol/Protocol/TagSupport.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace Roslyn.LanguageServer.Protocol -{ - using System.Text.Json.Serialization; - - /// - /// Class representing the capabilities. - /// - /// See the Language Server Protocol specification for additional information. - /// - internal class TagSupport - { - /// - /// Gets or sets a value indicating the tags supported by the client. - /// - [JsonPropertyName("valueSet")] - public DiagnosticTag[] ValueSet - { - get; - set; - } - } -} diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index aefb849276476..5c6fb6e3c62ed 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -146,7 +146,7 @@ internal class TextDocumentClientCapabilities public RenameClientCapabilities? Rename { get; set; } /// - /// Gets or sets the setting publish diagnostics setting. + /// Capabilities specific to the `textDocument/publishDiagnostics` notification. /// [JsonPropertyName("publishDiagnostics")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -224,8 +224,9 @@ internal class TextDocumentClientCapabilities public InlayHintSetting? InlayHint { get; set; } /// - /// Gets or sets the setting which determines what support the client has for pull diagnostics. + /// Capabilities specific to the diagnostic pull model. /// + /// Since LSP 3.17 [JsonPropertyName("diagnostic")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DiagnosticSetting? Diagnostic { get; set; } diff --git a/src/LanguageServer/Protocol/Protocol/UnchangedDocumentDiagnosticReport.cs b/src/LanguageServer/Protocol/Protocol/UnchangedDocumentDiagnosticReport.cs index 238da08d40af5..f99d560b1b687 100644 --- a/src/LanguageServer/Protocol/Protocol/UnchangedDocumentDiagnosticReport.cs +++ b/src/LanguageServer/Protocol/Protocol/UnchangedDocumentDiagnosticReport.cs @@ -7,10 +7,13 @@ namespace Roslyn.LanguageServer.Protocol; using System.Text.Json.Serialization; /// -/// Class representing a diagnostic report indicating that the last returned report is still accurate. -/// -/// See the Language Server Protocol specification for additional information. +/// A diagnostic report indicating that the last returned report is still accurate. +/// A server can only return this if result ids are provided. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 [Kind(DocumentDiagnosticReportKind.Unchanged)] internal class UnchangedDocumentDiagnosticReport { @@ -18,14 +21,17 @@ internal class UnchangedDocumentDiagnosticReport /// Gets the kind of this report. /// [JsonPropertyName("kind")] + [JsonRequired] #pragma warning disable CA1822 // Mark members as static public string Kind => DocumentDiagnosticReportKind.Unchanged; #pragma warning restore CA1822 // Mark members as static /// - /// Gets or sets the optional result id. + /// A result id which will be sent on the next + /// diagnostic request for the same document. /// [JsonPropertyName("resultId")] + [JsonRequired] public string ResultId { get; diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs index 07a1707d6511c..b697665723efd 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs @@ -100,6 +100,7 @@ internal class WorkspaceClientCapabilities /// /// Gets or sets capabilities indicating what support the client has for workspace pull diagnostics. /// + /// Since LSP 3.17 [JsonPropertyName("diagnostics")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DiagnosticWorkspaceSetting? Diagnostics { get; set; } diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticParams.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticParams.cs index 850f8c4fa31ab..1dd136bc0148f 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticParams.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticParams.cs @@ -8,29 +8,35 @@ namespace Roslyn.LanguageServer.Protocol; using System.Text.Json.Serialization; /// -/// Class representing the workspace diagnostic request parameters -/// -/// See the Language Server Protocol specification for additional information. +/// Parameters of the 'workspace/diagnostic' request +/// +/// See the Language Server Protocol specification for additional information. +/// /// /// -/// Note that the first literal send needs to be a -/// followed by n literals. +/// Since LSP 3.17 /// -internal class WorkspaceDiagnosticParams : IPartialResultParams> +internal class WorkspaceDiagnosticParams : IWorkDoneProgressParams, IPartialResultParams> { /// - /// Gets or sets the value of the Progress instance. + /// An instance that can be used to report partial results + /// via the $/progress notification. + /// + /// Note that the first literal sent needs to be a + /// followed by n literals. + /// /// [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public IProgress>? PartialResultToken - { - get; - set; - } + public IProgress>? PartialResultToken { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } /// - /// Gets or sets the identifier for which the client is requesting diagnostics for. + /// The additional identifier provided during registration. /// [JsonPropertyName("identifier")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -41,7 +47,7 @@ public string? Identifier } /// - /// Gets or sets the result id of a previous diagnostics response if provided. + /// The currently known diagnostic reports with their previous result ids. /// [JsonPropertyName("previousResultIds")] public PreviousResultId[] PreviousResultId @@ -49,4 +55,4 @@ public PreviousResultId[] PreviousResultId get; set; } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReport.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReport.cs index 49b33e63f135a..189a27aa11f8f 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReport.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReport.cs @@ -7,18 +7,21 @@ namespace Roslyn.LanguageServer.Protocol; /// /// Class representing a workspace diagnostic report. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 internal class WorkspaceDiagnosticReport { /// /// Gets or sets the items in this diagnostic report. /// [JsonPropertyName("items")] + [JsonRequired] public SumType[] Items { get; set; } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReportPartialResult.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReportPartialResult.cs index 1c29c40074e81..ba3a7d8be4262 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReportPartialResult.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceDiagnosticReportPartialResult.cs @@ -7,18 +7,21 @@ namespace Roslyn.LanguageServer.Protocol; /// /// Class representing a partial result for a workspace diagnostic report. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 internal class WorkspaceDiagnosticReportPartialResult { /// /// Gets or sets the items in this diagnostic report. /// [JsonPropertyName("items")] + [JsonRequired] public SumType[] Items { get; set; } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceFullDocumentDiagnosticReport.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceFullDocumentDiagnosticReport.cs index 95ec1cad08b96..a034368bf8bda 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceFullDocumentDiagnosticReport.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceFullDocumentDiagnosticReport.cs @@ -9,9 +9,11 @@ namespace Roslyn.LanguageServer.Protocol; /// /// Class representing a full document diagnostic report for workspace diagnostic result. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 [Kind(DocumentDiagnosticReportKind.Full)] internal class WorkspaceFullDocumentDiagnosticReport : FullDocumentDiagnosticReport { @@ -19,6 +21,7 @@ internal class WorkspaceFullDocumentDiagnosticReport : FullDocumentDiagnosticRep /// Gets or sets the URI associated with this diagnostic report. /// [JsonPropertyName("uri")] + [JsonRequired] [JsonConverter(typeof(DocumentUriConverter))] public Uri Uri { @@ -31,6 +34,7 @@ public Uri Uri /// If the document is not marked as open 'null' can be provided. /// [JsonPropertyName("version")] + [JsonRequired] public int? Version { get; diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceUnchangedDocumentDiagnosticReport.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceUnchangedDocumentDiagnosticReport.cs index 1fc1bd8cda697..84316ebaacbfa 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceUnchangedDocumentDiagnosticReport.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceUnchangedDocumentDiagnosticReport.cs @@ -9,9 +9,11 @@ namespace Roslyn.LanguageServer.Protocol; /// /// Class representing a unchanged document diagnostic report for workspace diagnostic result. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// +/// Since LSP 3.17 [Kind(DocumentDiagnosticReportKind.Unchanged)] internal class WorkspaceUnchangedDocumentDiagnosticReport : UnchangedDocumentDiagnosticReport { @@ -19,6 +21,7 @@ internal class WorkspaceUnchangedDocumentDiagnosticReport : UnchangedDocumentDia /// Gets or sets the URI associated with this diagnostic report. /// [JsonPropertyName("uri")] + [JsonRequired] [JsonConverter(typeof(DocumentUriConverter))] public Uri Uri { @@ -31,6 +34,7 @@ public Uri Uri /// If the document is not marked as open 'null' can be provided. /// [JsonPropertyName("version")] + [JsonRequired] public int? Version { get; From e611615d6622b7c0889597feda28519b56f9172c Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 9 Jun 2024 00:39:07 -0400 Subject: [PATCH 18/46] LSP Protocol: Update Signature Help types --- .../Protocol/Protocol/Methods.Document.cs | 16 +++++++++ .../Protocol/Protocol/Methods.cs | 10 ------ .../Protocol/Protocol/ParameterInformation.cs | 21 ++++++++--- .../Protocol/ParameterInformationSetting.cs | 11 +++--- .../Protocol/Protocol/ServerCapabilities.cs | 2 +- .../Protocol/Protocol/SignatureHelp.cs | 35 ++++++++++++++++--- .../Protocol/Protocol/SignatureHelpContext.cs | 22 +++++++++--- .../Protocol/Protocol/SignatureHelpOptions.cs | 8 ++--- .../Protocol/Protocol/SignatureHelpParams.cs | 23 +++++++----- .../SignatureHelpRegistrationOptions.cs | 21 +++++++++++ .../Protocol/Protocol/SignatureHelpSetting.cs | 17 +++++---- .../Protocol/SignatureHelpTriggerKind.cs | 6 ++-- .../Protocol/Protocol/SignatureInformation.cs | 19 ++++++++-- .../Protocol/SignatureInformationSetting.cs | 18 +++++++--- .../TextDocumentClientCapabilities.cs | 2 +- 15 files changed, 176 insertions(+), 55 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/SignatureHelpRegistrationOptions.cs diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index 87737eaff3ae1..c845604eaf47a 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -398,4 +398,20 @@ partial class Methods /// Strongly typed message object for 'completionItem/resolve'. /// public static readonly LspRequest TextDocumentCompletionResolve = new(TextDocumentCompletionResolveName); + + /// + /// Method name for 'textDocument/signatureHelp'. + /// + /// The signature help request is sent from the client to the server to request signature information at a given cursor position. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentSignatureHelpName = "textDocument/signatureHelp"; + + /// + /// Strongly typed message object for 'textDocument/signatureHelp'. + /// + public static readonly LspRequest TextDocumentSignatureHelp = new(TextDocumentSignatureHelpName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index 58e293b43319b..e79359bd617b0 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -71,11 +71,6 @@ internal static partial class Methods /// public const string TextDocumentPrepareRenameName = "textDocument/prepareRename"; - /// - /// Method name for 'textDocument/signatureHelp'. - /// - public const string TextDocumentSignatureHelpName = "textDocument/signatureHelp"; - /// /// Method name for 'textDocument/linkedEditingRange'. /// @@ -172,11 +167,6 @@ internal static partial class Methods /// public static readonly LspRequest?> TextDocumentPrepareRename = new LspRequest?>(TextDocumentPrepareRenameName); - /// - /// Strongly typed message object for 'textDocument/signatureHelp'. - /// - public static readonly LspRequest TextDocumentSignatureHelp = new LspRequest(TextDocumentSignatureHelpName); - /// /// Strongly typed message object for 'textDocument/linkedEditingRange'. /// diff --git a/src/LanguageServer/Protocol/Protocol/ParameterInformation.cs b/src/LanguageServer/Protocol/Protocol/ParameterInformation.cs index e92aeb737af31..9967582e52d8c 100644 --- a/src/LanguageServer/Protocol/Protocol/ParameterInformation.cs +++ b/src/LanguageServer/Protocol/Protocol/ParameterInformation.cs @@ -8,15 +8,28 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing a parameter of a callable signature. - /// + /// Represents a parameter of a callable-signature. A parameter can + /// have a label and documentation. + /// /// See the Language Server Protocol specification for additional information. + /// /// [JsonConverter(typeof(ParameterInformationConverter))] internal class ParameterInformation { /// - /// Gets or sets the label of the parameter. + /// The label of this parameter information. + /// + /// Either a string or an inclusive start and exclusive end offsets within + /// its containing signature label (see ). + /// The offsets are based on a UTF-16 string representation, like and + /// . + /// + /// + /// Note*: a label of type should be a substring of its containing + /// signature label. Its intended use case is to highlight the parameter + /// label part in the . + /// /// [JsonPropertyName("label")] public SumType> Label @@ -26,7 +39,7 @@ public SumType> Label } /// - /// Gets or sets the human-readable documentation of the parameter. + /// Human-readable documentation of the parameter. Will be shown in the UI but can be omitted. /// [JsonPropertyName("documentation")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/ParameterInformationSetting.cs b/src/LanguageServer/Protocol/Protocol/ParameterInformationSetting.cs index a392f4102186d..1733e9fbb0a0c 100644 --- a/src/LanguageServer/Protocol/Protocol/ParameterInformationSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/ParameterInformationSetting.cs @@ -7,15 +7,18 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing the parameter information initialization setting. - /// + /// Client capabilities specific to + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.14 internal class ParameterInformationSetting { /// - /// Gets or sets a value indicating whether the client supports label offset. + /// The client supports processing label offsets instead of a simple label string. /// + /// Since LSP 3.14 [JsonPropertyName("labelOffsetSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool LabelOffsetSupport @@ -24,4 +27,4 @@ public bool LabelOffsetSupport set; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 0109d5a50eaac..790dbbfe542ed 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -74,7 +74,7 @@ public TextDocumentSyncOptions? TextDocumentSync public SumType? HoverProvider { get; set; } /// - /// Gets or sets the value which indicates if signature help is supported. + /// The server provides signature help support. /// [JsonPropertyName("signatureHelpProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/SignatureHelp.cs b/src/LanguageServer/Protocol/Protocol/SignatureHelp.cs index fbc02b0b71901..892cfca3fa794 100644 --- a/src/LanguageServer/Protocol/Protocol/SignatureHelp.cs +++ b/src/LanguageServer/Protocol/Protocol/SignatureHelp.cs @@ -8,13 +8,18 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the signature of something callable. This class is returned from the textDocument/signatureHelp request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class SignatureHelp { /// - /// Gets or sets an array of signatures associated with the callable item. + /// One or more signatures. + /// + /// If no signatures are available the signature help + /// request should return . + /// /// [JsonPropertyName("signatures")] [JsonRequired] @@ -25,7 +30,19 @@ public SignatureInformation[] Signatures } /// - /// Gets or sets the active signature. If the value is omitted or falls outside the range of Signatures it defaults to zero. + /// The active signature. + /// + /// + /// If omitted or the value lies outside the range of the + /// value defaults to zero or is ignored if the has no signatures. + /// + /// Whenever possible implementors should make an active decision about + /// the active signature and shouldn't rely on a default value. + /// + /// + /// In a future version of the protocol this property might become + /// mandatory to better express this. + /// /// [JsonPropertyName("activeSignature")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -36,7 +53,17 @@ public int? ActiveSignature } /// - /// Gets or sets the active parameter. If the value is omitted or falls outside the range of Signatures[ActiveSignature].Parameters it defaults to zero. + /// The active parameter of the active signature. + /// + /// If omitted or the value lies outside the range of Signatures[ActiveSignature].Parameters + /// it defaults to 0 if the active signature has parameters. + /// If the active signature has no parameters it is ignored. + /// + /// + /// In a future version of the protocol this property might become + /// mandatory to better express the active parameter if the active + /// signature has any parameters. + /// /// [JsonPropertyName("activeParameter")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/SignatureHelpContext.cs b/src/LanguageServer/Protocol/Protocol/SignatureHelpContext.cs index 7d3a42675c951..562dbb0fdcb11 100644 --- a/src/LanguageServer/Protocol/Protocol/SignatureHelpContext.cs +++ b/src/LanguageServer/Protocol/Protocol/SignatureHelpContext.cs @@ -8,9 +8,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing additional information about the context in which a signature help request is triggered. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.15 internal class SignatureHelpContext { /// @@ -25,7 +27,10 @@ public SignatureHelpTriggerKind TriggerKind /// /// Gets or sets the character that caused signature help to be triggered. - /// This value is null when triggerKind is not TriggerCharacter. + /// + /// This is defined when when is not + /// . + /// /// [JsonPropertyName("triggerCharacter")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -37,6 +42,11 @@ public string? TriggerCharacter /// /// Gets or sets a value indicating whether signature help was already showing when it was triggered. + /// + /// Retriggers occur when the signature help is already active and can be + /// caused by actions such as typing a trigger character, a cursor move, or + /// document content changes. + /// /// [JsonPropertyName("isRetrigger")] public bool IsRetrigger @@ -46,7 +56,11 @@ public bool IsRetrigger } /// - /// Gets or sets the currently active . + /// The currently active . + /// + /// The has its + /// updated based on the user navigating through available signatures. + /// /// [JsonPropertyName("activeSignatureHelp")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -56,4 +70,4 @@ public SignatureHelp? ActiveSignatureHelp set; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/SignatureHelpOptions.cs b/src/LanguageServer/Protocol/Protocol/SignatureHelpOptions.cs index 102ef229035f9..ecc68b5ad15fd 100644 --- a/src/LanguageServer/Protocol/Protocol/SignatureHelpOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/SignatureHelpOptions.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the options for signature help support. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class SignatureHelpOptions : IWorkDoneProgressOptions { @@ -28,6 +29,7 @@ public string[]? TriggerCharacters /// Gets or sets the characters that re-trigger signature help /// when signature help is already showing. /// + /// Since LSP 3.15 [JsonPropertyName("retriggerCharacters")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string[]? RetriggerCharacters @@ -36,9 +38,7 @@ public string[]? RetriggerCharacters set; } - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// + /// [JsonPropertyName("workDoneProgress")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } diff --git a/src/LanguageServer/Protocol/Protocol/SignatureHelpParams.cs b/src/LanguageServer/Protocol/Protocol/SignatureHelpParams.cs index 52fbd2f43e10a..f68a1c87c94d7 100644 --- a/src/LanguageServer/Protocol/Protocol/SignatureHelpParams.cs +++ b/src/LanguageServer/Protocol/Protocol/SignatureHelpParams.cs @@ -4,24 +4,31 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// /// Class representing the parameters for the textDocument/signatureHelp request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class SignatureHelpParams : TextDocumentPositionParams + internal class SignatureHelpParams : TextDocumentPositionParams, IWorkDoneProgressParams { /// - /// Gets or sets the signature help context. + /// The signature help context. + /// + /// This is only available if the client specifies the client + /// capability + /// /// [JsonPropertyName("context")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SignatureHelpContext? Context - { - get; - set; - } + public SignatureHelpContext? Context { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/SignatureHelpRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/SignatureHelpRegistrationOptions.cs new file mode 100644 index 0000000000000..31b9e4f7fd83d --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/SignatureHelpRegistrationOptions.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class SignatureHelpRegistrationOptions : SignatureHelpOptions, ITextDocumentRegistrationOptions +{ + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/SignatureHelpSetting.cs b/src/LanguageServer/Protocol/Protocol/SignatureHelpSetting.cs index 447b91419344d..7aba3296d7859 100644 --- a/src/LanguageServer/Protocol/Protocol/SignatureHelpSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/SignatureHelpSetting.cs @@ -7,14 +7,15 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing the signature help initialization setting. - /// + /// Client capabilities specific to the `textDocument/signatureHelp` request. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class SignatureHelpSetting : DynamicRegistrationSetting { /// - /// Gets or sets the information. + /// Client capabilities specific to . /// [JsonPropertyName("signatureInformation")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -25,9 +26,13 @@ public SignatureInformationSetting? SignatureInformation } /// - /// Gets or sets a value indicating whether additional context information - /// is supported for the `textDocument/signatureHelp` request. + /// The client supports sending additional context information for + /// the textDocument/signatureHelp request. + /// + /// A client that opts into this will also support . + /// /// + /// Since LSP 3.15 [JsonPropertyName("contextSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool ContextSupport @@ -36,4 +41,4 @@ public bool ContextSupport set; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/SignatureHelpTriggerKind.cs b/src/LanguageServer/Protocol/Protocol/SignatureHelpTriggerKind.cs index 00ba1f6410d50..d029c0e97c9a6 100644 --- a/src/LanguageServer/Protocol/Protocol/SignatureHelpTriggerKind.cs +++ b/src/LanguageServer/Protocol/Protocol/SignatureHelpTriggerKind.cs @@ -6,9 +6,11 @@ namespace Roslyn.LanguageServer.Protocol { /// /// Enum which represents the various ways in which completion can be triggered. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.15 internal enum SignatureHelpTriggerKind { /// @@ -26,4 +28,4 @@ internal enum SignatureHelpTriggerKind /// ContentChange = 3, } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/SignatureInformation.cs b/src/LanguageServer/Protocol/Protocol/SignatureInformation.cs index 462bd9c6e2b4a..8efea2b31091d 100644 --- a/src/LanguageServer/Protocol/Protocol/SignatureInformation.cs +++ b/src/LanguageServer/Protocol/Protocol/SignatureInformation.cs @@ -8,13 +8,14 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing a single signature of a callable item. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class SignatureInformation { /// - /// Gets or sets the label of this signature. + /// The label of this signature. Will be shown in the UI. /// [JsonPropertyName("label")] public string Label @@ -24,7 +25,8 @@ public string Label } /// - /// Gets or sets the human-readable documentation of this signature. + /// The human-readable documentation of this signature. + /// Will be shown in the UI but can be omitted. /// [JsonPropertyName("documentation")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -44,5 +46,16 @@ public ParameterInformation[]? Parameters get; set; } + + /// + /// The index of the active parameter. + /// + /// If provided, this is used in place of . + /// + /// + /// Since LSP 3.16 + [JsonPropertyName("activeParameter")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public int? ActiveParameter { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/SignatureInformationSetting.cs b/src/LanguageServer/Protocol/Protocol/SignatureInformationSetting.cs index efb21c658a425..16017694639d7 100644 --- a/src/LanguageServer/Protocol/Protocol/SignatureInformationSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/SignatureInformationSetting.cs @@ -8,13 +8,15 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the signature information initialization setting. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class SignatureInformationSetting { /// - /// Gets or sets the set of documentation formats the client supports. + /// The client supports the following content formats for the + /// property. The order describes the preferred format of the client. /// [JsonPropertyName("documentationFormat")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -25,7 +27,7 @@ public MarkupKind[]? DocumentationFormat } /// - /// Gets or sets the parameter information the client supports. + /// Client capabilities specific to /// [JsonPropertyName("parameterInformation")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -34,5 +36,13 @@ public ParameterInformationSetting? ParameterInformation get; set; } + + /// + /// The client supports the property + /// + /// Since LSP 3.16 + [JsonPropertyName("activeParameterSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool ActiveParameterSupport { get; init; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index 5c6fb6e3c62ed..b4c16cef2a4e6 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -38,7 +38,7 @@ internal class TextDocumentClientCapabilities public HoverSetting? Hover { get; set; } /// - /// Gets or sets the setting which determines if signature help can be dynamically registered. + /// Capabilities specific to the `textDocument/signatureHelp` request /// [JsonPropertyName("signatureHelp")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] From d489f1404ec22de1c66abf9adc73dfd453393ca1 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Wed, 5 Jun 2024 01:18:18 -0400 Subject: [PATCH 19/46] LSP Protocol: Update CodeAction types --- .../Protocol/Protocol/CodeAction.cs | 60 +++++++++++++++++-- .../Protocol/Protocol/CodeActionContext.cs | 20 ++++++- .../Protocol/CodeActionDisabledReason.cs | 25 ++++++++ .../Protocol/Protocol/CodeActionKind.cs | 10 +++- .../Protocol/CodeActionKindSetting.cs | 7 ++- .../Protocol/CodeActionLiteralSetting.cs | 7 ++- .../Protocol/Protocol/CodeActionOptions.cs | 20 ++++--- .../Protocol/Protocol/CodeActionParams.cs | 19 +++++- .../Protocol/CodeActionRegistrationOptions.cs | 21 +++++++ .../CodeActionResolveSupportSetting.cs | 6 +- .../Protocol/Protocol/CodeActionSetting.cs | 58 ++++++++++++++---- .../Protocol/CodeActionTriggerKind.cs | 8 ++- .../Protocol/Protocol/Methods.Document.cs | 39 ++++++++++++ .../Protocol/Protocol/Methods.cs | 20 ------- .../Protocol/Protocol/ServerCapabilities.cs | 4 +- .../TextDocumentClientCapabilities.cs | 2 +- 16 files changed, 260 insertions(+), 66 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/CodeActionDisabledReason.cs create mode 100644 src/LanguageServer/Protocol/Protocol/CodeActionRegistrationOptions.cs diff --git a/src/LanguageServer/Protocol/Protocol/CodeAction.cs b/src/LanguageServer/Protocol/Protocol/CodeAction.cs index 9ac8ab11410e9..30a9e29ba7720 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeAction.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeAction.cs @@ -10,15 +10,17 @@ namespace Roslyn.LanguageServer.Protocol /// A class representing a change that can be performed in code. A CodeAction must either set /// or . If both are supplied, /// the edit will be applied first, then the command will be executed. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CodeAction { /// - /// Gets or sets the human readable title for this code action. + /// A short human readable title for this code action. /// [JsonPropertyName("title")] + [JsonRequired] public string Title { get; @@ -26,7 +28,7 @@ public string Title } /// - /// Gets or sets the kind of code action this instance represents. + /// The kind of the code action, used to filter code actions. /// [JsonPropertyName("kind")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -37,7 +39,7 @@ public CodeActionKind? Kind } /// - /// Gets or sets the diagnostics that this code action resolves. + /// The diagnostics that this code action resolves. /// [JsonPropertyName("diagnostics")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -47,6 +49,48 @@ public Diagnostic[]? Diagnostics set; } + /// + /// Marks this as a preferred action. Preferred actions are used by the + /// Auto Fix command and can be targeted by keybindings. + /// + /// A quick fix should be marked preferred if it properly addresses the + /// underlying error. A refactoring should be marked preferred if it is the + /// most reasonable choice of actions to take. + /// + /// + /// Since LSP 3.15 + [JsonPropertyName("preferred")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool IsPreferred { get; init; } + + /// + /// Marks that the code action cannot currently be applied. + /// + /// Clients should follow the following guidelines regarding disabled code + /// actions: + /// + /// + /// Disabled code actions are not shown in automatic lightbulbs code + /// action menus. + /// + /// + /// Disabled actions are shown as faded out in the code action menu when + /// the user request a more specific type of code action, such as + /// refactorings. + /// + /// + /// If the user has a keybinding that auto applies a code action and only + /// a disabled code actions are returned, the client should show the user + /// an error message with in the editor. + /// + /// + /// + /// + /// Since LSP 3.16 + [JsonPropertyName("disabled")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public CodeActionDisabledReason? Disabled { get; init; } + /// /// Gets or sets the workspace edit that this code action performs. /// @@ -59,7 +103,9 @@ public WorkspaceEdit? Edit } /// - /// Gets or sets the command that this code action executes. + /// A command this code action executes. If a code action + /// provides an edit and a command, first the edit is + /// executed and then the command. /// [JsonPropertyName("command")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -70,8 +116,10 @@ public Command? Command } /// - /// Gets or sets the data that will be resend to the server if the code action is selected to be resolved. + /// Data field that is preserved on a code action between a textDocument/codeAction request + /// and a codeAction/resolve request. /// + /// Since LSP 3.16 [JsonPropertyName("data")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? Data diff --git a/src/LanguageServer/Protocol/Protocol/CodeActionContext.cs b/src/LanguageServer/Protocol/Protocol/CodeActionContext.cs index e40c24c7a3bd6..f5a142522b6ca 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeActionContext.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeActionContext.cs @@ -8,15 +8,24 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing diagnostic information about the context of a code action - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CodeActionContext { /// - /// Gets or sets an array of diagnostics relevant to a code action. + /// An array of diagnostics known on the client side overlapping the range + /// provided to the textDocument/codeAction request. + /// + /// They are provided so that the server knows which errors are currently + /// presented to the user for the given range. There is no guarantee that + /// these accurately reflect the error state of the resource. The primary + /// parameter to compute code actions is the provided range. + /// /// [JsonPropertyName("diagnostics")] + [JsonRequired] public Diagnostic[] Diagnostics { get; @@ -24,7 +33,11 @@ public Diagnostic[] Diagnostics } /// - /// Gets or sets an array of code action kinds to filter for. + /// Requested kinds of actions to return. + /// + /// Actions not of this kind are filtered out by the client before being + /// shown, so servers can omit computing them. + /// /// [JsonPropertyName("only")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -37,6 +50,7 @@ public CodeActionKind[]? Only /// /// Gets or sets the indicating how the code action was triggered.. /// + /// Since LSP 3.17 [JsonPropertyName("triggerKind")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeActionTriggerKind? TriggerKind diff --git a/src/LanguageServer/Protocol/Protocol/CodeActionDisabledReason.cs b/src/LanguageServer/Protocol/Protocol/CodeActionDisabledReason.cs new file mode 100644 index 0000000000000..7ae88a629cb98 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/CodeActionDisabledReason.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Indicates why a code action is disabled +/// +class CodeActionDisabledReason +{ + + /// + /// Human readable description of why the code action is currently + /// disabled. + /// + /// This is displayed in the code actions UI. + /// + /// + [JsonPropertyName("reason")] + [JsonRequired] + public string Reason { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/CodeActionKind.cs b/src/LanguageServer/Protocol/Protocol/CodeActionKind.cs index c6c8663e284b2..30b31542d4c09 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeActionKind.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeActionKind.cs @@ -9,8 +9,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Value representing the kind of a code action. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// [JsonConverter(typeof(StringEnumConverter))] [TypeConverter(typeof(StringEnumConverter.TypeConverter))] @@ -62,10 +63,13 @@ internal readonly record struct CodeActionKind(string Value) : IStringEnum /// /// Base kind for a fix all source action, which automatically fixes errors that have a clear /// fix that do not require user input. - /// - /// + /// /// They should not suppress errors or perform unsafe fixes such as generating new /// types or classes. + /// + /// + /// + /// Since LSP 3.17 /// public static readonly CodeActionKind SourceFixAll = new("source.fixAll"); } diff --git a/src/LanguageServer/Protocol/Protocol/CodeActionKindSetting.cs b/src/LanguageServer/Protocol/Protocol/CodeActionKindSetting.cs index 03806a7c4c696..fc4bdf623f4cf 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeActionKindSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeActionKindSetting.cs @@ -7,16 +7,19 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class containing the set of code action kinds that are supported. - /// + /// Represents the code action kinds that are supported by the client. + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.8 internal class CodeActionKindSetting { /// /// Gets or sets the code actions kinds the client supports. /// [JsonPropertyName("valueSet")] + [JsonRequired] public CodeActionKind[] ValueSet { get; diff --git a/src/LanguageServer/Protocol/Protocol/CodeActionLiteralSetting.cs b/src/LanguageServer/Protocol/Protocol/CodeActionLiteralSetting.cs index adc2cf397db90..9926693d1efc5 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeActionLiteralSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeActionLiteralSetting.cs @@ -7,16 +7,19 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing support for code action literals. - /// + /// Represents the client's support for code action literals in the response of the textDocument/codeAction request + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.8 internal class CodeActionLiteralSetting { /// /// Gets or sets a value indicating what code action kinds are supported. /// [JsonPropertyName("codeActionKind")] + [JsonRequired] public CodeActionKindSetting CodeActionKind { get; diff --git a/src/LanguageServer/Protocol/Protocol/CodeActionOptions.cs b/src/LanguageServer/Protocol/Protocol/CodeActionOptions.cs index e63a4852b80e8..7c1a6fda7106e 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeActionOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeActionOptions.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the registration options for code actions support. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CodeActionOptions : IWorkDoneProgressOptions { @@ -17,7 +18,7 @@ internal class CodeActionOptions : IWorkDoneProgressOptions /// Gets or sets the kinds of code action that this server may return. /// /// - /// The list of kinds may be generic, such as `CodeActionKind.Refactor`, or the server + /// The list of kinds may be generic, such as , or the server /// may list out every specific kind they provide. /// [JsonPropertyName("codeActionKinds")] @@ -28,17 +29,11 @@ public CodeActionKind[]? CodeActionKinds set; } - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// - [JsonPropertyName("workDoneProgress")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool WorkDoneProgress { get; init; } - /// /// Gets or sets a value indicating whether the server provides support to resolve /// additional information for a code action. /// + /// Since LSP 3.16 [JsonPropertyName("resolveProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool ResolveProvider @@ -46,5 +41,12 @@ public bool ResolveProvider get; set; } + + /// + /// Gets or sets a value indicating whether work done progress is supported. + /// + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/CodeActionParams.cs b/src/LanguageServer/Protocol/Protocol/CodeActionParams.cs index 70e9f70d93c4a..dbdd86bf00a2f 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeActionParams.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeActionParams.cs @@ -4,19 +4,22 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// /// Class representing the parameters sent from the client to the server for the textDocument/codeAction request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class CodeActionParams : ITextDocumentParams + internal class CodeActionParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams[]> { /// /// Gets or sets the document identifier indicating where the command was invoked. /// [JsonPropertyName("textDocument")] + [JsonRequired] public TextDocumentIdentifier TextDocument { get; @@ -27,6 +30,7 @@ public TextDocumentIdentifier TextDocument /// Gets or sets the range in the document for which the command was invoked. /// [JsonPropertyName("range")] + [JsonRequired] public Range Range { get; @@ -37,10 +41,21 @@ public Range Range /// Gets or sets the additional diagnostic information about the code action context. /// [JsonPropertyName("context")] + [JsonRequired] public CodeActionContext Context { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress[]>? PartialResultToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/CodeActionRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/CodeActionRegistrationOptions.cs new file mode 100644 index 0000000000000..39c26e4b66c20 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/CodeActionRegistrationOptions.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class CodeActionRegistrationOptions : CodeActionOptions, ITextDocumentRegistrationOptions +{ + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/CodeActionResolveSupportSetting.cs b/src/LanguageServer/Protocol/Protocol/CodeActionResolveSupportSetting.cs index 1d1280be4d074..40c9f18014529 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeActionResolveSupportSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeActionResolveSupportSetting.cs @@ -7,9 +7,10 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing settings for codeAction/resolve support. - /// + /// Client capabilities specific to the codeAction/resolve request. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CodeActionResolveSupportSetting { @@ -17,6 +18,7 @@ internal class CodeActionResolveSupportSetting /// Gets or sets a value indicating the properties that a client can resolve lazily. /// [JsonPropertyName("properties")] + [JsonRequired] public string[] Properties { get; diff --git a/src/LanguageServer/Protocol/Protocol/CodeActionSetting.cs b/src/LanguageServer/Protocol/Protocol/CodeActionSetting.cs index eba4e7a023559..a57146027e17b 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeActionSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeActionSetting.cs @@ -7,15 +7,18 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing settings for code action support. - /// + /// Client capabilities specific to code actions. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class CodeActionSetting : DynamicRegistrationSetting { /// - /// Gets or sets a value indicating the client supports code action literals. + /// The client supports code action literals as a valid response of + /// the textDocument/codeAction request. /// + /// Since LSP 3.8 [JsonPropertyName("codeActionLiteralSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeActionLiteralSetting? CodeActionLiteralSupport @@ -24,11 +27,42 @@ public CodeActionLiteralSetting? CodeActionLiteralSupport set; } + /// + /// Whether code action supports the property. + /// + /// Since LSP 3.15 + [JsonPropertyName("isPreferredSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool IsPreferredSupport { get; init; } + + /// + /// Whether code action supports the property. + /// + /// Since LSP 3.16 + [JsonPropertyName("disabledSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool DisabledSupport { get; init; } + + /// + /// Gets or sets a value indicating whether code action supports the + /// property which is preserved between a `textDocument/codeAction` request and a + /// `codeAction/resolve` request. + /// + /// Since LSP 3.16 + [JsonPropertyName("dataSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool DataSupport + { + get; + set; + } + /// /// Gets or sets a value indicating whether the client supports resolving - /// additional code action properties via a separate `codeAction/resolve` + /// additional code action properties via a separate codeAction/resolve /// request. /// + /// Since LSP 3.16 [JsonPropertyName("resolveSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeActionResolveSupportSetting? ResolveSupport @@ -38,16 +72,14 @@ public CodeActionResolveSupportSetting? ResolveSupport } /// - /// Gets or sets a value indicating whether code action supports the `data` - /// property which is preserved between a `textDocument/codeAction` and a - /// `codeAction/resolve` request. + /// Whether the client honors the change annotations in text edits and + /// resource operations returned via the property by + /// for example presenting the workspace edit in the user interface and asking + /// for confirmation. /// - [JsonPropertyName("dataSupport")] + /// Since LSP 3.16 + [JsonPropertyName("honorsChangeAnnotations")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool DataSupport - { - get; - set; - } + public bool HonorsChangeAnnotations { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/CodeActionTriggerKind.cs b/src/LanguageServer/Protocol/Protocol/CodeActionTriggerKind.cs index ed48b55932d33..b1fb8c8276036 100644 --- a/src/LanguageServer/Protocol/Protocol/CodeActionTriggerKind.cs +++ b/src/LanguageServer/Protocol/Protocol/CodeActionTriggerKind.cs @@ -6,9 +6,11 @@ namespace Roslyn.LanguageServer.Protocol { /// /// Enum which represents the various reason why code actions were requested. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.17 internal enum CodeActionTriggerKind { /// @@ -18,8 +20,10 @@ internal enum CodeActionTriggerKind /// /// Code actions were requested automatically. + /// /// This typically happens when current selection in a file changes, but can also be triggered when file content changes. + /// /// Automatic = 2, } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index c845604eaf47a..6963a2d6d1afe 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -414,4 +414,43 @@ partial class Methods /// Strongly typed message object for 'textDocument/signatureHelp'. /// public static readonly LspRequest TextDocumentSignatureHelp = new(TextDocumentSignatureHelpName); + + /// + /// Method name for 'textDocument/codeAction'. + /// + public const string TextDocumentCodeActionName = "textDocument/codeAction"; + + /// + /// Strongly typed message object for 'textDocument/codeAction'. + /// + /// The code action request is sent from the client to the server to compute commands for a + /// given text document and range. These commands are typically code fixes to either fix + /// problems or to beautify/refactor code. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public static readonly LspRequest[]?> TextDocumentCodeAction = new(TextDocumentCodeActionName); + + /// + /// Method name for 'codeAction/resolve'. + /// + /// The request is sent from the client to the server to resolve additional information + /// for a given code action. + /// + /// + /// This is usually used to compute the edit property of a code action to avoid its + /// unnecessary computation during the textDocument/codeAction request. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string CodeActionResolveName = "codeAction/resolve"; + + /// + /// Strongly typed message object for 'codeAction/resolve'. + /// + public static readonly LspRequest CodeActionResolve = new(CodeActionResolveName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index e79359bd617b0..9f7b421a0ec25 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -31,16 +31,6 @@ internal static partial class Methods /// public const string ProgressNotificationTokenName = "token"; - /// - /// Method name for 'textDocument/codeAction'. - /// - public const string TextDocumentCodeActionName = "textDocument/codeAction"; - - /// - /// Method name for 'codeAction/resolve'. - /// - public const string CodeActionResolveName = "codeAction/resolve"; - /// /// Method name for 'textDocument/documentColor'. /// @@ -127,16 +117,6 @@ internal static partial class Methods /// public const string TelemetryEventName = "telemetry/event"; - /// - /// Strongly typed message object for 'textDocument/codeAction'. - /// - public static readonly LspRequest[]?> TextDocumentCodeAction = new LspRequest[]?>(TextDocumentCodeActionName); - - /// - /// Strongly typed message object for 'codeAction/resolve'. - /// - public static readonly LspRequest CodeActionResolve = new LspRequest(CodeActionResolveName); - /// /// Strongly typed message object for 'textDocument/documentColor'. /// diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 790dbbfe542ed..aafe261a8649c 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -133,7 +133,9 @@ public TextDocumentSyncOptions? TextDocumentSync public SumType? DocumentSymbolProvider { get; set; } /// - /// Gets or sets a value indicating whether code actions are supported. + /// The server provides code actions. The return type is + /// only valid if the client signals code action literal support via the + /// property . /// [JsonPropertyName("codeActionProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index b4c16cef2a4e6..abdd397e7b5a0 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -97,7 +97,7 @@ internal class TextDocumentClientCapabilities public DocumentSymbolSetting? DocumentSymbol { get; set; } /// - /// Gets or sets the setting which determines if code action can be dynamically registered. + /// Capabilities specific to the `textDocument/codeAction` request. /// [JsonPropertyName("codeAction")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] From 6393717231039d828c1e5524df8baf8e3b0e735e Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 9 Jun 2024 01:11:55 -0400 Subject: [PATCH 20/46] LSP Protocol: Update DocumentColor types/methods --- src/LanguageServer/Protocol/Protocol/Color.cs | 4 +- .../Protocol/Protocol/ColorInformation.cs | 4 +- .../Protocol/Protocol/ColorPresentation.cs | 49 +++++++++++++++ .../Protocol/ColorPresentationParams.cs | 49 +++++++++++++++ .../DocumentColorClientCapabilities.cs | 16 +++++ .../Protocol/Protocol/DocumentColorOptions.cs | 6 +- .../Protocol/Protocol/DocumentColorParams.cs | 25 +++++--- .../DocumentColorRegistrationOptions.cs | 27 +++++++++ .../Protocol/Protocol/Methods.Document.cs | 59 +++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 10 ---- .../Protocol/Protocol/ServerCapabilities.cs | 3 +- .../TextDocumentClientCapabilities.cs | 8 +++ 12 files changed, 237 insertions(+), 23 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/ColorPresentation.cs create mode 100644 src/LanguageServer/Protocol/Protocol/ColorPresentationParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/DocumentColorClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/DocumentColorRegistrationOptions.cs diff --git a/src/LanguageServer/Protocol/Protocol/Color.cs b/src/LanguageServer/Protocol/Protocol/Color.cs index 319d60cf17462..e6773cc7fa16a 100644 --- a/src/LanguageServer/Protocol/Protocol/Color.cs +++ b/src/LanguageServer/Protocol/Protocol/Color.cs @@ -8,9 +8,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents a color. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.6 internal class Color { /// diff --git a/src/LanguageServer/Protocol/Protocol/ColorInformation.cs b/src/LanguageServer/Protocol/Protocol/ColorInformation.cs index a55e45f655455..3a9bca5c7ec44 100644 --- a/src/LanguageServer/Protocol/Protocol/ColorInformation.cs +++ b/src/LanguageServer/Protocol/Protocol/ColorInformation.cs @@ -8,9 +8,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents color information. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.6 internal class ColorInformation { /// diff --git a/src/LanguageServer/Protocol/Protocol/ColorPresentation.cs b/src/LanguageServer/Protocol/Protocol/ColorPresentation.cs new file mode 100644 index 0000000000000..9e25164639dfd --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ColorPresentation.cs @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A color presentation for a textDocument/colorPresentation response. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.6 +internal class ColorPresentation +{ + /// + /// The label of this color presentation. It will be shown on the color picker header. + /// + /// By default this is also the text that is inserted when selecting this color presentation. + /// + /// + [JsonPropertyName("label")] + [JsonRequired] + public string Label { get; init; } + + /// + /// A which is applied to a document when selecting this presentation for the color. + /// + /// When omitted the [label](#ColorPresentation.label) is used. + /// + /// + [JsonPropertyName("textEdit")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public TextEdit? TextEdit { get; init; } + + /// + /// An optional array of additional that are applied + /// when selecting this color presentation. + /// + /// Edits must not overlap with the main nor with themselves. + /// + /// + [JsonPropertyName("additionalTextEdits")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public TextEdit[]? AdditionalTextEdits { get; init; } + +} diff --git a/src/LanguageServer/Protocol/Protocol/ColorPresentationParams.cs b/src/LanguageServer/Protocol/Protocol/ColorPresentationParams.cs new file mode 100644 index 0000000000000..995bb06e90a56 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ColorPresentationParams.cs @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Class representing the parameters sent for a textDocument/colorPresentation request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.6 +internal class ColorPresentationParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams +{ + /// + /// The text document. + /// + [JsonPropertyName("textDocument")] + [JsonRequired] + public TextDocumentIdentifier TextDocument { get; set; } + + /// + /// The color information to request presentations for. + /// + [JsonPropertyName("color")] + [JsonRequired] + public Color Color { get; init; } + + /// + /// The range where the color would be inserted. Serves as a context. + /// + [JsonPropertyName("range")] + [JsonRequired] + public Range Range { get; init; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/DocumentColorClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/DocumentColorClientCapabilities.cs new file mode 100644 index 0000000000000..c04b402eeb054 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DocumentColorClientCapabilities.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/documentColor` and the `textDocument/colorPresentation` requests. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.6 +internal class DocumentColorClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/DocumentColorOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentColorOptions.cs index 96cf410caca2e..499e3d070c5e6 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentColorOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentColorOptions.cs @@ -7,10 +7,12 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents workspace symbols capabilities. - /// + /// Server capabilities specific to DocumentColor. + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.6 internal class DocumentColorOptions : IWorkDoneProgressOptions { /// diff --git a/src/LanguageServer/Protocol/Protocol/DocumentColorParams.cs b/src/LanguageServer/Protocol/Protocol/DocumentColorParams.cs index 6e5b7506a718b..5e2c738acca9e 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentColorParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentColorParams.cs @@ -4,23 +4,32 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// /// Class representing the parameters sent for a textDocument/documentColor request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class DocumentColorParams : ITextDocumentParams + /// Since LSP 3.6 + internal class DocumentColorParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams { /// - /// Gets or sets the to provide links for. + /// The to provide color information for. /// [JsonPropertyName("textDocument")] - public TextDocumentIdentifier TextDocument - { - get; - set; - } + public TextDocumentIdentifier TextDocument { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } + + /// + [JsonPropertyName(Methods.PartialResultTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? PartialResultToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/DocumentColorRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentColorRegistrationOptions.cs new file mode 100644 index 0000000000000..645ffd2b647fc --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DocumentColorRegistrationOptions.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.6 +internal class DocumentColorRegistrationOptions : DocumentColorOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions +{ + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index 6963a2d6d1afe..77adea5e6ad7e 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -453,4 +453,63 @@ partial class Methods /// Strongly typed message object for 'codeAction/resolve'. /// public static readonly LspRequest CodeActionResolve = new(CodeActionResolveName); + + /// + /// Method name for 'textDocument/documentColor'. + /// + /// The document color request is sent from the client to the server to list all color references + /// found in a given text document. Along with the range, a color value in RGB is returned. + /// + /// + /// Clients can use the result to decorate color references in an editor. For example: + /// + /// + /// Color boxes showing the actual color next to the reference + /// + /// + /// Show a color picker when a color reference is edited + /// + /// + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.6 + public const string TextDocumentDocumentColorName = "textDocument/documentColor"; + + /// + /// Strongly typed message object for 'textDocument/documentColor'. + /// + /// Since LSP 3.6 + public static readonly LspRequest TextDocumentDocumentColor = new(TextDocumentDocumentColorName); + + /// + /// Method name for 'textDocument/colorPresentation'. + /// + /// The color presentation request is sent from the client to the server to obtain a list of presentations for a color value at a given location. + /// + /// + /// Clients can use the result to: + /// + /// + /// modify a color reference. + /// + /// + /// show in a color picker and let users pick one of the presentations + /// + /// + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.6 + public const string TextDocumentColorPresentationName = "textDocument/colorPresentation"; + + /// + /// Strongly typed message object for 'textDocument/colorPresentation'. + /// + /// Since LSP 3.6 + public static readonly LspRequest TextDocumentColorPresentation = new(TextDocumentColorPresentationName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index 9f7b421a0ec25..a01f7a2e9f8f6 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -31,11 +31,6 @@ internal static partial class Methods /// public const string ProgressNotificationTokenName = "token"; - /// - /// Method name for 'textDocument/documentColor'. - /// - public const string TextDocumentDocumentColorName = "textDocument/documentColor"; - /// /// Method name for 'textDocument/formatting'. /// @@ -117,11 +112,6 @@ internal static partial class Methods /// public const string TelemetryEventName = "telemetry/event"; - /// - /// Strongly typed message object for 'textDocument/documentColor'. - /// - public static readonly LspRequest DocumentColorRequest = new LspRequest(TextDocumentDocumentColorName); - /// /// Strongly typed message object for 'textDocument/formatting'. /// diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index aafe261a8649c..f508245ff9e30 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -158,9 +158,10 @@ public TextDocumentSyncOptions? TextDocumentSync /// /// Gets or sets the value which indicates if document color is supported. /// + /// Since LSP 3.6 [JsonPropertyName("colorProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType? DocumentColorProvider { get; set; } + public SumType? DocumentColorProvider { get; set; } /// /// Gets or sets a value indicating whether document formatting is supported. diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index abdd397e7b5a0..bc6122cf57c8c 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -117,6 +117,14 @@ internal class TextDocumentClientCapabilities [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DocumentLinkClientCapabilities? DocumentLink { get; set; } + /// + /// Capabilities specific to the `textDocument/documentColor` and the `textDocument/colorPresentation` request. + /// + /// Since LSP 3.6 + [JsonPropertyName("colorProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentColorClientCapabilities? ColorProvider { get; set; } + /// /// Gets or sets the setting which determines if formatting can be dynamically registered. /// From 7b7b3f86a2dc3717c0b6ace3849a2fe61334137e Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 9 Jun 2024 01:47:23 -0400 Subject: [PATCH 21/46] LSP Protocol: Update formatting types/methods --- .../DocumentFormattingClientCapabilities.cs | 15 ++++++ .../Protocol/DocumentFormattingOptions.cs | 4 +- .../Protocol/DocumentFormattingParams.cs | 15 ++++-- .../DocumentFormattingRegistrationOptions.cs | 21 ++++++++ .../DocumentOnTypeFormattingOptions.cs | 10 ++-- .../DocumentOnTypeFormattingParams.cs | 43 ++++++++++----- ...mentOnTypeFormattingRegistrationOptions.cs | 24 +++++++++ .../DocumentRangeFormattingOptions.cs | 7 ++- .../Protocol/DocumentRangeFormattingParams.cs | 6 ++- ...umentRangeFormattingRegistrationOptions.cs | 21 ++++++++ .../Protocol/Protocol/FormattingOptions.cs | 53 ++++++++++++------- .../Protocol/Protocol/Methods.Document.cs | 48 +++++++++++++++++ .../Protocol/Protocol/Methods.cs | 30 ----------- .../OnTypeFormattingClientCapabilities.cs | 15 ++++++ .../RangeFormattingClientCapabilities.cs | 15 ++++++ .../TextDocumentClientCapabilities.cs | 12 ++--- 16 files changed, 256 insertions(+), 83 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/DocumentFormattingClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/DocumentFormattingRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/DocumentRangeFormattingRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/OnTypeFormattingClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/RangeFormattingClientCapabilities.cs diff --git a/src/LanguageServer/Protocol/Protocol/DocumentFormattingClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/DocumentFormattingClientCapabilities.cs new file mode 100644 index 0000000000000..450eacbd74e36 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DocumentFormattingClientCapabilities.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/formatting` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DocumentFormattingClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/DocumentFormattingOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentFormattingOptions.cs index 144e53f17087c..5304dc376759e 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentFormattingOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentFormattingOptions.cs @@ -13,9 +13,7 @@ namespace Roslyn.LanguageServer.Protocol /// internal class DocumentFormattingOptions : IWorkDoneProgressOptions { - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// + /// [JsonPropertyName("workDoneProgress")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } diff --git a/src/LanguageServer/Protocol/Protocol/DocumentFormattingParams.cs b/src/LanguageServer/Protocol/Protocol/DocumentFormattingParams.cs index 35f814d3ff9b9..478b3405479ae 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentFormattingParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentFormattingParams.cs @@ -4,19 +4,22 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// - /// Class which represents the parameter that is sent with textDocument/formatting message. - /// + /// Parameter for the 'textDocument/formatting' request. + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class DocumentFormattingParams : ITextDocumentParams + internal class DocumentFormattingParams : ITextDocumentParams, IWorkDoneProgressParams { /// /// Gets or sets the identifier for the text document to be formatted. /// [JsonPropertyName("textDocument")] + [JsonRequired] public TextDocumentIdentifier TextDocument { get; @@ -27,10 +30,16 @@ public TextDocumentIdentifier TextDocument /// Gets or sets the formatting options. /// [JsonPropertyName("options")] + [JsonRequired] public FormattingOptions Options { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/DocumentFormattingRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentFormattingRegistrationOptions.cs new file mode 100644 index 0000000000000..5a757d5e30e70 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DocumentFormattingRegistrationOptions.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DocumentFormattingRegistrationOptions : DocumentFormattingOptions, ITextDocumentRegistrationOptions +{ + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingOptions.cs index 13105e53003d7..499f65841100b 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingOptions.cs @@ -8,15 +8,17 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the options for on type formatting. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DocumentOnTypeFormattingOptions { /// - /// Gets or sets the first trigger character. + /// A character on which formatting should be triggered, like {. /// [JsonPropertyName("firstTriggerCharacter")] + [JsonRequired] public string FirstTriggerCharacter { get; @@ -24,7 +26,7 @@ public string FirstTriggerCharacter } /// - /// Gets or sets additional trigger characters. + /// Optional additional trigger characters. /// [JsonPropertyName("moreTriggerCharacter")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -34,4 +36,4 @@ public string[]? MoreTriggerCharacter set; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingParams.cs b/src/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingParams.cs index 919c36c1275ae..988496d36acf9 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingParams.cs @@ -8,29 +8,46 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the parameters sent for a textDocument/onTypeFormatting request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class DocumentOnTypeFormattingParams : TextDocumentPositionParams + internal class DocumentOnTypeFormattingParams : ITextDocumentPositionParams { /// - /// Gets or sets the character that was typed. + /// The document to format. + /// + [JsonPropertyName("textDocument")] + public TextDocumentIdentifier TextDocument { get; set; } + + /// + /// The position around which the on type formatting should happen. + /// + /// This is not necessarily the exact position where the character denoted + /// by the property got typed. + /// + /// + [JsonPropertyName("position")] + public Position Position { get; set; } + + /// + /// The character that has been typed that triggered the formatting + /// on type request. + /// + /// That is not necessarily the last character that + /// got inserted into the document since the client could auto insert + /// characters as well (e.g. like automatic brace completion). + /// /// [JsonPropertyName("ch")] - public string Character - { - get; - set; - } + [JsonRequired] + public string Character { get; set; } /// /// Gets or sets the for the request. /// [JsonPropertyName("options")] - public FormattingOptions Options - { - get; - set; - } + [JsonRequired] + public FormattingOptions Options { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingRegistrationOptions.cs new file mode 100644 index 0000000000000..73267582a2aec --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DocumentOnTypeFormattingRegistrationOptions.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DocumentOnTypeFormattingRegistrationOptions : DocumentOnTypeFormattingOptions, ITextDocumentRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/DocumentRangeFormattingOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentRangeFormattingOptions.cs index 1c4cbe2ce2c7c..28ae43959d26b 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentRangeFormattingOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentRangeFormattingOptions.cs @@ -8,14 +8,13 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the document range formatting options for server capabilities. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DocumentRangeFormattingOptions : IWorkDoneProgressOptions { - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// + /// [JsonPropertyName("workDoneProgress")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } diff --git a/src/LanguageServer/Protocol/Protocol/DocumentRangeFormattingParams.cs b/src/LanguageServer/Protocol/Protocol/DocumentRangeFormattingParams.cs index 104830b737a1b..8977dbd117016 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentRangeFormattingParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentRangeFormattingParams.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents the parameter that is sent with textDocument/rangeFormatting message. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DocumentRangeFormattingParams : ITextDocumentParams { @@ -17,6 +18,7 @@ internal class DocumentRangeFormattingParams : ITextDocumentParams /// Gets or sets the identifier for the text document to be formatted. /// [JsonPropertyName("textDocument")] + [JsonRequired] public TextDocumentIdentifier TextDocument { get; @@ -27,6 +29,7 @@ public TextDocumentIdentifier TextDocument /// Gets or sets the selection range to be formatted. /// [JsonPropertyName("range")] + [JsonRequired] public Range Range { get; @@ -37,6 +40,7 @@ public Range Range /// Gets or sets the formatting options. /// [JsonPropertyName("options")] + [JsonRequired] public FormattingOptions Options { get; diff --git a/src/LanguageServer/Protocol/Protocol/DocumentRangeFormattingRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/DocumentRangeFormattingRegistrationOptions.cs new file mode 100644 index 0000000000000..1872ee874d632 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DocumentRangeFormattingRegistrationOptions.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DocumentRangeFormattingRegistrationOptions : DocumentRangeFormattingOptions, ITextDocumentRegistrationOptions +{ + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FormattingOptions.cs b/src/LanguageServer/Protocol/Protocol/FormattingOptions.cs index c7385acedce78..c8f5b5e36f8d5 100644 --- a/src/LanguageServer/Protocol/Protocol/FormattingOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/FormattingOptions.cs @@ -9,39 +9,54 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents formatting options. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class FormattingOptions { /// - /// Gets or sets the number of spaces to be inserted per tab. + /// Size of a tab in spaces. /// [JsonPropertyName("tabSize")] - public int TabSize - { - get; - set; - } + [JsonRequired] + public int TabSize { get; set; } /// - /// Gets or sets a value indicating whether tabs should be spaces. + /// Whether tabs should be spaces. /// [JsonPropertyName("insertSpaces")] - public bool InsertSpaces - { - get; - set; - } + [JsonRequired] + public bool InsertSpaces { get; set; } /// - /// Gets or sets the other potential formatting options. + /// Trim trailing whitespace on a line. + /// + /// Since LSP 3.15 + [JsonPropertyName("trimTrailingWhitespace")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool TrimTrailingWhitespace { get; init; } + + /// + /// Insert a newline character at the end of the file if one does not exist. + /// + /// Since LSP 3.15 + [JsonPropertyName("insertFinalNewline")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool InsertFinalNewline { get; init; } + + /// + /// Trim all newlines after the final newline at the end of the file. + /// + /// Since LSP 3.15 + [JsonPropertyName("trimFinalNewlines")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool TrimFinalNewlines { get; init; } + + /// + /// Other potential formatting options. /// [JsonExtensionData] - public Dictionary? OtherOptions - { - get; - set; - } + public Dictionary>? OtherOptions { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index 77adea5e6ad7e..e2c52fd5ebd20 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -512,4 +512,52 @@ partial class Methods /// /// Since LSP 3.6 public static readonly LspRequest TextDocumentColorPresentation = new(TextDocumentColorPresentationName); + + /// + /// Method name for 'textDocument/formatting'. + /// + /// The document formatting request is sent from the client to the server to format a whole document. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentFormattingName = "textDocument/formatting"; + + /// + /// Strongly typed message object for 'textDocument/formatting'. + /// + public static readonly LspRequest TextDocumentFormatting = new(TextDocumentFormattingName); + + /// + /// Method name for 'textDocument/rangeFormatting'. + /// + /// The document range formatting request is sent from the client to the server to format a given range in a document. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentRangeFormattingName = "textDocument/rangeFormatting"; + + /// + /// Strongly typed message object for 'textDocument/rangeFormatting'. + /// + public static readonly LspRequest TextDocumentRangeFormatting = new(TextDocumentRangeFormattingName); + + /// + /// Method name for 'textDocument/onTypeFormatting'. + /// + /// The document on type formatting request is sent from the client to the server to format parts of the document during typing. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentOnTypeFormattingName = "textDocument/onTypeFormatting"; + + /// + /// Strongly typed message object for 'textDocument/onTypeFormatting'. + /// + public static readonly LspRequest TextDocumentOnTypeFormatting = new(TextDocumentOnTypeFormattingName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index a01f7a2e9f8f6..a26a94cb98564 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -31,21 +31,6 @@ internal static partial class Methods /// public const string ProgressNotificationTokenName = "token"; - /// - /// Method name for 'textDocument/formatting'. - /// - public const string TextDocumentFormattingName = "textDocument/formatting"; - - /// - /// Method name for 'textDocument/onTypeFormatting'. - /// - public const string TextDocumentOnTypeFormattingName = "textDocument/onTypeFormatting"; - - /// - /// Method name for 'textDocument/rangeFormatting'. - /// - public const string TextDocumentRangeFormattingName = "textDocument/rangeFormatting"; - /// /// Method name for 'textDocument/rename'. /// @@ -112,21 +97,6 @@ internal static partial class Methods /// public const string TelemetryEventName = "telemetry/event"; - /// - /// Strongly typed message object for 'textDocument/formatting'. - /// - public static readonly LspRequest TextDocumentFormatting = new LspRequest(TextDocumentFormattingName); - - /// - /// Strongly typed message object for 'textDocument/onTypeFormatting'. - /// - public static readonly LspRequest TextDocumentOnTypeFormatting = new LspRequest(TextDocumentOnTypeFormattingName); - - /// - /// Strongly typed message object for 'textDocument/rangeFormatting'. - /// - public static readonly LspRequest TextDocumentRangeFormatting = new LspRequest(TextDocumentRangeFormattingName); - /// /// Strongly typed message object for 'textDocument/rename'. /// diff --git a/src/LanguageServer/Protocol/Protocol/OnTypeFormattingClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/OnTypeFormattingClientCapabilities.cs new file mode 100644 index 0000000000000..6d5f5414b19b5 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/OnTypeFormattingClientCapabilities.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/onTypeFormatting` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class OnTypeFormattingClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/RangeFormattingClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/RangeFormattingClientCapabilities.cs new file mode 100644 index 0000000000000..4d0c885a15d6b --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/RangeFormattingClientCapabilities.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/rangeFormatting` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class RangeFormattingClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index bc6122cf57c8c..f310fde9957f7 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -126,25 +126,25 @@ internal class TextDocumentClientCapabilities public DocumentColorClientCapabilities? ColorProvider { get; set; } /// - /// Gets or sets the setting which determines if formatting can be dynamically registered. + /// Capabilities specific to the `textDocument/formatting` request. /// [JsonPropertyName("formatting")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? Formatting { get; set; } + public DocumentFormattingClientCapabilities? Formatting { get; set; } /// - /// Gets or sets the setting which determines if range formatting can be dynamically registered. + /// Capabilities specific to the `textDocument/rangeFormatting` request. /// [JsonPropertyName("rangeFormatting")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? RangeFormatting { get; set; } + public RangeFormattingClientCapabilities? RangeFormatting { get; set; } /// - /// Gets or sets the setting which determines if on type formatting can be dynamically registered. + /// Capabilities specific to the `textDocument/onTypeFormatting` request. /// [JsonPropertyName("onTypeFormatting")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? OnTypeFormatting { get; set; } + public OnTypeFormattingClientCapabilities? OnTypeFormatting { get; set; } /// /// Gets or sets the setting which determines if rename can be dynamically registered. From 8a46f2c284d6102cd77e9b1aa977cbc2da73a178 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 9 Jun 2024 02:01:12 -0400 Subject: [PATCH 22/46] LSP Protocol: Update rename types/methods --- .../Protocol/DefaultBehaviorPrepareRename.cs | 4 ++- .../Protocol/Protocol/Methods.Document.cs | 36 +++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 20 ----------- .../Protocol/Protocol/PrepareRenameParams.cs | 34 +++++++++--------- .../Protocol/PrepareSupportDefaultBehavior.cs | 4 ++- .../Protocol/RenameClientCapabilities.cs | 12 ++++--- .../Protocol/Protocol/RenameOptions.cs | 7 ++-- .../Protocol/Protocol/RenameParams.cs | 22 +++++++----- .../Protocol/Protocol/RenameRange.cs | 4 ++- .../Protocol/RenameRegistrationOptions.cs | 21 +++++++++++ .../TextDocumentClientCapabilities.cs | 2 +- 11 files changed, 109 insertions(+), 57 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/RenameRegistrationOptions.cs diff --git a/src/LanguageServer/Protocol/Protocol/DefaultBehaviorPrepareRename.cs b/src/LanguageServer/Protocol/Protocol/DefaultBehaviorPrepareRename.cs index d221861d3f169..6623df023bc13 100644 --- a/src/LanguageServer/Protocol/Protocol/DefaultBehaviorPrepareRename.cs +++ b/src/LanguageServer/Protocol/Protocol/DefaultBehaviorPrepareRename.cs @@ -8,9 +8,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents a possible result value of the 'textDocument/prepareRename' request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class DefaultBehaviorPrepareRename { /// diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index e2c52fd5ebd20..edf6d72595b12 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -560,4 +560,40 @@ partial class Methods /// Strongly typed message object for 'textDocument/onTypeFormatting'. /// public static readonly LspRequest TextDocumentOnTypeFormatting = new(TextDocumentOnTypeFormattingName); + + /// + /// Method name for 'textDocument/rename'. + /// + /// The rename request is sent from the client to the server to ask the server to compute + /// a workspace change so that the client can perform a workspace-wide rename of a symbol. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TextDocumentRenameName = "textDocument/rename"; + + /// + /// Strongly typed message object for 'textDocument/rename'. + /// + public static readonly LspRequest TextDocumentRename = new(TextDocumentRenameName); + + /// + /// Method name for 'textDocument/prepareRename'. + /// + /// The prepare rename request is sent from the client to the server to setup and test the + /// validity of a rename operation at a given location. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.12 + public const string TextDocumentPrepareRenameName = "textDocument/prepareRename"; + + /// + /// Strongly typed message object for 'textDocument/prepareRename'. + /// + /// Since LSP 3.12 + public static readonly LspRequest?> TextDocumentPrepareRename = new(TextDocumentPrepareRenameName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index a26a94cb98564..358ccb558d9a9 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -31,16 +31,6 @@ internal static partial class Methods /// public const string ProgressNotificationTokenName = "token"; - /// - /// Method name for 'textDocument/rename'. - /// - public const string TextDocumentRenameName = "textDocument/rename"; - - /// - /// Method name for 'textDocument/prepareRename'. - /// - public const string TextDocumentPrepareRenameName = "textDocument/prepareRename"; - /// /// Method name for 'textDocument/linkedEditingRange'. /// @@ -97,16 +87,6 @@ internal static partial class Methods /// public const string TelemetryEventName = "telemetry/event"; - /// - /// Strongly typed message object for 'textDocument/rename'. - /// - public static readonly LspRequest TextDocumentRename = new LspRequest(TextDocumentRenameName); - - /// - /// Strongly typed message object for 'textDocument/prepareRename'. - /// - public static readonly LspRequest?> TextDocumentPrepareRename = new LspRequest?>(TextDocumentPrepareRenameName); - /// /// Strongly typed message object for 'textDocument/linkedEditingRange'. /// diff --git a/src/LanguageServer/Protocol/Protocol/PrepareRenameParams.cs b/src/LanguageServer/Protocol/Protocol/PrepareRenameParams.cs index 2ef5c34b6eb05..3e9e051756d3b 100644 --- a/src/LanguageServer/Protocol/Protocol/PrepareRenameParams.cs +++ b/src/LanguageServer/Protocol/Protocol/PrepareRenameParams.cs @@ -4,33 +4,33 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// - /// Class representing the parameters for the 'textDocument/prepare' request. - /// + /// Class representing the parameters for the 'textDocument/prepareRename' request. + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class PrepareRenameParams : ITextDocumentPositionParams + /// Since LSP 3.12 + internal class PrepareRenameParams : ITextDocumentPositionParams, IWorkDoneProgressParams { - /// - /// Gets or sets the value which identifies the document. - /// + /// [JsonPropertyName("textDocument")] - public TextDocumentIdentifier TextDocument - { - get; - set; - } + [JsonRequired] + public TextDocumentIdentifier TextDocument { get; set; } /// - /// Gets or sets the position in which the rename is requested. + /// The position in which the rename is requested. /// [JsonPropertyName("position")] - public Position Position - { - get; - set; - } + [JsonRequired] + public Position Position { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/PrepareSupportDefaultBehavior.cs b/src/LanguageServer/Protocol/Protocol/PrepareSupportDefaultBehavior.cs index fb4a1319a87e1..3b4e76f26745d 100644 --- a/src/LanguageServer/Protocol/Protocol/PrepareSupportDefaultBehavior.cs +++ b/src/LanguageServer/Protocol/Protocol/PrepareSupportDefaultBehavior.cs @@ -6,9 +6,11 @@ namespace Roslyn.LanguageServer.Protocol { /// /// Enum representing the default behavior used by the client for computing a rename range. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal enum PrepareSupportDefaultBehavior { /// diff --git a/src/LanguageServer/Protocol/Protocol/RenameClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/RenameClientCapabilities.cs index bea10606988cb..9283f7bafa79c 100644 --- a/src/LanguageServer/Protocol/Protocol/RenameClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/RenameClientCapabilities.cs @@ -8,14 +8,16 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents renaming client capabilities. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class RenameClientCapabilities : DynamicRegistrationSetting { /// /// Gets or sets a value indicating whether the client supports testing for validity of rename operations before execution. /// + /// Since LSP 3.12 [JsonPropertyName("prepareSupport")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool PrepareSupport @@ -25,9 +27,10 @@ public bool PrepareSupport } /// - /// Gets or sets the value indicating the default behavior used by the client when the (`{ defaultBehavior: boolean }`) - /// result is used in the 'textDocument/prepareRename' request. + /// Gets or sets the value indicating the default behavior used by the client when the + /// result is used in the 'textDocument/prepareRename' request. /// + /// Since LSP 3.16 [JsonPropertyName("prepareSupportDefaultBehavior")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public PrepareSupportDefaultBehavior? PrepareSupportDefaultBehavior @@ -37,10 +40,11 @@ public PrepareSupportDefaultBehavior? PrepareSupportDefaultBehavior } /// - /// Gets or sets a value indicating whether the client honors the change annotations in text edits and resource + /// Whether the client honors the change annotations in text edits and resource /// operations returned via the rename request's workspace edit, by for example presenting the workspace edit in /// the user interface and asking for confirmation. /// + /// Since LSP 3.16 [JsonPropertyName("honorsChangeAnnotations")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool HonorsChangeAnnotations diff --git a/src/LanguageServer/Protocol/Protocol/RenameOptions.cs b/src/LanguageServer/Protocol/Protocol/RenameOptions.cs index 841b679e2e005..cd98eac650b7d 100644 --- a/src/LanguageServer/Protocol/Protocol/RenameOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/RenameOptions.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the rename options for server capabilities. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class RenameOptions : IWorkDoneProgressOptions { @@ -24,9 +25,7 @@ public bool PrepareProvider set; } - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// + /// [JsonPropertyName("workDoneProgress")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } diff --git a/src/LanguageServer/Protocol/Protocol/RenameParams.cs b/src/LanguageServer/Protocol/Protocol/RenameParams.cs index 3c95b96d9393e..ec271e314e866 100644 --- a/src/LanguageServer/Protocol/Protocol/RenameParams.cs +++ b/src/LanguageServer/Protocol/Protocol/RenameParams.cs @@ -4,23 +4,29 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// /// Class representing the rename parameters for the textDocument/rename request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class RenameParams : TextDocumentPositionParams + internal class RenameParams : TextDocumentPositionParams, IWorkDoneProgressParams { /// - /// Gets or sets the new name of the renamed symbol. + /// The new name of the symbol. If the given name is not valid the + /// request must return a ResponseError with an + /// appropriate message set. /// [JsonPropertyName("newName")] - public string NewName - { - get; - set; - } + [JsonRequired] + public string NewName { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/RenameRange.cs b/src/LanguageServer/Protocol/Protocol/RenameRange.cs index 984b50dc823a0..b74641538d752 100644 --- a/src/LanguageServer/Protocol/Protocol/RenameRange.cs +++ b/src/LanguageServer/Protocol/Protocol/RenameRange.cs @@ -8,9 +8,11 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents a possible result value of the 'textDocument/prepareRename' request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.12 internal class RenameRange { /// diff --git a/src/LanguageServer/Protocol/Protocol/RenameRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/RenameRegistrationOptions.cs new file mode 100644 index 0000000000000..5f8876947fc0e --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/RenameRegistrationOptions.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class RenameRegistrationOptions : RenameOptions, ITextDocumentRegistrationOptions +{ + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index f310fde9957f7..4074bf21eb10f 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -147,7 +147,7 @@ internal class TextDocumentClientCapabilities public OnTypeFormattingClientCapabilities? OnTypeFormatting { get; set; } /// - /// Gets or sets the setting which determines if rename can be dynamically registered. + /// Capabilities specific to the `textDocument/rename` request. /// [JsonPropertyName("rename")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] From c5a1e56e87476016336afe953b60f741ba8a56ef Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 9 Jun 2024 02:21:41 -0400 Subject: [PATCH 23/46] LSP Protocol: Update TextDocumentEdit/WorkspaceEdit --- .../Protocol/Protocol/AnnotatedTextEdit.cs | 24 ++++++++++ .../Protocol/Protocol/ChangeAnnotation.cs | 40 ++++++++++++++++ .../Protocol/ChangeAnnotationIdentifier.cs | 23 ++++++++++ .../Protocol/ChangeAnnotationSupport.cs | 23 ++++++++++ .../Protocol/Protocol/CreateFile.cs | 13 ++++-- .../Protocol/Protocol/CreateFileOptions.cs | 12 ++++- .../Protocol/Protocol/DeleteFile.cs | 11 ++++- .../Protocol/Protocol/FailureHandlingKind.cs | 46 +++++++++++++++++++ .../Protocol/Protocol/IAnnotatedChange.cs | 21 +++++++++ .../Protocol/Protocol/RenameFile.cs | 13 ++++-- .../Protocol/Protocol/RenameFileOptions.cs | 10 +++- .../Protocol/ResourceOperationKind.cs | 3 +- .../Protocol/Protocol/TextDocumentEdit.cs | 15 +++--- .../Protocol/WorkspaceClientCapabilities.cs | 2 +- .../Protocol/Protocol/WorkspaceEdit.cs | 43 +++++++++++------ .../Protocol/Protocol/WorkspaceEditSetting.cs | 34 ++++++++++++-- 16 files changed, 298 insertions(+), 35 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/AnnotatedTextEdit.cs create mode 100644 src/LanguageServer/Protocol/Protocol/ChangeAnnotation.cs create mode 100644 src/LanguageServer/Protocol/Protocol/ChangeAnnotationIdentifier.cs create mode 100644 src/LanguageServer/Protocol/Protocol/ChangeAnnotationSupport.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FailureHandlingKind.cs create mode 100644 src/LanguageServer/Protocol/Protocol/IAnnotatedChange.cs diff --git a/src/LanguageServer/Protocol/Protocol/AnnotatedTextEdit.cs b/src/LanguageServer/Protocol/Protocol/AnnotatedTextEdit.cs new file mode 100644 index 0000000000000..d24e1a5554dfd --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/AnnotatedTextEdit.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Class which represents a text edit with a change annotation +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class AnnotatedTextEdit : TextEdit +{ + /// + /// The annotation identifier. + /// + [JsonPropertyName("annotationId")] + [JsonRequired] + public ChangeAnnotationIdentifier AnnotationId { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/ChangeAnnotation.cs b/src/LanguageServer/Protocol/Protocol/ChangeAnnotation.cs new file mode 100644 index 0000000000000..1004a68e0193e --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ChangeAnnotation.cs @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Additional information that describes document changes +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// +/// Since LSP 3.16 +/// +internal class ChangeAnnotation +{ + /// + /// Human-readable string describing the change, rendered in the UI. + /// + [JsonPropertyName("label")] + [JsonRequired] + public string Label { get; init; } + + /// + /// Indicates whether user confirmation is needed before applying the change. + /// + [JsonPropertyName("needsConfirmation")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public bool? NeedsConfirmation { get; init; } + + /// + /// Human-readable string describing the change, rendered in the UI less prominently than the . + /// + [JsonPropertyName("description")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Description { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/ChangeAnnotationIdentifier.cs b/src/LanguageServer/Protocol/Protocol/ChangeAnnotationIdentifier.cs new file mode 100644 index 0000000000000..f522f0bb6405b --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ChangeAnnotationIdentifier.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// An identifier referring to a change annotation managed by a workspace edit +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// +/// Since LSP 3.16 +/// +[JsonConverter(typeof(StringEnumConverter))] +[TypeConverter(typeof(StringEnumConverter.TypeConverter))] +internal readonly record struct ChangeAnnotationIdentifier(string Value) : IStringEnum +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/ChangeAnnotationSupport.cs b/src/LanguageServer/Protocol/Protocol/ChangeAnnotationSupport.cs new file mode 100644 index 0000000000000..8fa9d84712d5c --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ChangeAnnotationSupport.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Describes how the client handles change annotations on workspace edits. +/// +/// Since LSP 3.16 +internal class ChangeAnnotationSupport +{ + /// + /// Whether the client groups edits with equal labels into tree nodes, + /// for instance all edits labelled with "Changes in Strings" would + /// be a tree node.. + /// + [JsonPropertyName("groupsOnLabel")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public bool? GroupsOnLabel { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/CreateFile.cs b/src/LanguageServer/Protocol/Protocol/CreateFile.cs index 723850708e18b..2ca8e1a7e3a8c 100644 --- a/src/LanguageServer/Protocol/Protocol/CreateFile.cs +++ b/src/LanguageServer/Protocol/Protocol/CreateFile.cs @@ -9,11 +9,13 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing a create file operation. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.13 [Kind("create")] - internal class CreateFile + internal class CreateFile : IAnnotatedChange { /// /// Gets the kind value. @@ -44,5 +46,10 @@ public CreateFileOptions? Options get; set; } + + /// + [JsonPropertyName("annotationId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ChangeAnnotationIdentifier? AnnotationId { get; init; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/CreateFileOptions.cs b/src/LanguageServer/Protocol/Protocol/CreateFileOptions.cs index c8215d3a14223..3e47c186b70e7 100644 --- a/src/LanguageServer/Protocol/Protocol/CreateFileOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/CreateFileOptions.cs @@ -8,14 +8,19 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the options for a create file operation. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.13 internal class CreateFileOptions { /// - /// Gets or sets a value indicating whether the creation should overwrite the file if it already exists. (Overwrite wins over ignoreIfExists). + /// Gets or sets a value indicating whether the creation should overwrite the file if it already exists. /// + /// + /// wins over . + /// [JsonPropertyName("overwrite")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool Overwrite @@ -27,6 +32,9 @@ public bool Overwrite /// /// Gets or sets a value indicating whether the action should be ignored if the file already exists. /// + /// + /// wins over . + /// [JsonPropertyName("ignoreIfExists")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool IgnoreIfExists diff --git a/src/LanguageServer/Protocol/Protocol/DeleteFile.cs b/src/LanguageServer/Protocol/Protocol/DeleteFile.cs index 919093f482981..72cae2338387d 100644 --- a/src/LanguageServer/Protocol/Protocol/DeleteFile.cs +++ b/src/LanguageServer/Protocol/Protocol/DeleteFile.cs @@ -9,11 +9,13 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing a delete file operation. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.13 [Kind("delete")] - internal class DeleteFile + internal class DeleteFile : IAnnotatedChange { /// /// Gets the kind value. @@ -44,5 +46,10 @@ public DeleteFileOptions? Options get; set; } + + /// + [JsonPropertyName("annotationId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ChangeAnnotationIdentifier? AnnotationId { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/FailureHandlingKind.cs b/src/LanguageServer/Protocol/Protocol/FailureHandlingKind.cs new file mode 100644 index 0000000000000..6bd54bc7181ee --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FailureHandlingKind.cs @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Describes the client's failure handling strategy for workspace changes. +/// +/// +/// See the Language Server Protocol specification for additional information. +/// +/// Since 3.13 +[JsonConverter(typeof(StringEnumConverter))] +[TypeConverter(typeof(StringEnumConverter.TypeConverter))] +internal readonly record struct FailureHandlingKind(string Value) : IStringEnum +{ + /// + /// Applying the workspace change is simply aborted if one of the changes + /// provided fails. All operations executed before the failing operation + /// stay executed. + /// + public static readonly FailureHandlingKind Abort = new("abort"); + + /// + /// All operations are executed transactionally. That means they either all + /// succeed or no changes at all are applied to the workspace. + /// + public static readonly FailureHandlingKind Transactional = new("transactional"); + + /// + /// If the workspace edit contains only textual file changes they are + /// executed transactional. If resource changes (create, rename or delete + /// file) are part of the change the failure handling strategy is . + /// + public static readonly FailureHandlingKind TextOnlyTransactional = new("textOnlyTransactional"); + + /// + /// The client tries to undo the operations already executed, but there is no + /// guarantee that will succeed. + /// + public static readonly FailureHandlingKind Undo = new("undo"); +} diff --git a/src/LanguageServer/Protocol/Protocol/IAnnotatedChange.cs b/src/LanguageServer/Protocol/Protocol/IAnnotatedChange.cs new file mode 100644 index 0000000000000..ac61f94458d0f --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/IAnnotatedChange.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A change operation with a change annotation identifier +/// +interface IAnnotatedChange +{ + /// + /// Optional annotation identifier describing the operation + /// + /// Since 3.16 + [JsonPropertyName("annotationId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ChangeAnnotationIdentifier? AnnotationId { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/RenameFile.cs b/src/LanguageServer/Protocol/Protocol/RenameFile.cs index 969e8a039d867..4b50223b1495c 100644 --- a/src/LanguageServer/Protocol/Protocol/RenameFile.cs +++ b/src/LanguageServer/Protocol/Protocol/RenameFile.cs @@ -9,11 +9,13 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing a rename file operation. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.13 [Kind("rename")] - internal class RenameFile + internal class RenameFile : IAnnotatedChange { /// /// Gets the kind value. @@ -56,5 +58,10 @@ public RenameFileOptions? Options get; set; } + + /// + [JsonPropertyName("annotationId")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ChangeAnnotationIdentifier? AnnotationId { get; init; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/RenameFileOptions.cs b/src/LanguageServer/Protocol/Protocol/RenameFileOptions.cs index 59d45c42a225b..1db7dab2344aa 100644 --- a/src/LanguageServer/Protocol/Protocol/RenameFileOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/RenameFileOptions.cs @@ -8,14 +8,19 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the options for a create file operation. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.13 internal class RenameFileOptions { /// /// Gets or sets a value indicating whether the rename should overwrite the target if it already exists. (Overwrite wins over ignoreIfExists). /// + /// + /// wins over . + /// [JsonPropertyName("overwrite")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool Overwrite @@ -27,6 +32,9 @@ public bool Overwrite /// /// Gets or sets a value indicating whether the action should be ignored if the file already exists. /// + /// + /// wins over . + /// [JsonPropertyName("ignoreIfExists")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool IgnoreIfExists diff --git a/src/LanguageServer/Protocol/Protocol/ResourceOperationKind.cs b/src/LanguageServer/Protocol/Protocol/ResourceOperationKind.cs index 228b44234bf60..0f217bd338e94 100644 --- a/src/LanguageServer/Protocol/Protocol/ResourceOperationKind.cs +++ b/src/LanguageServer/Protocol/Protocol/ResourceOperationKind.cs @@ -9,8 +9,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Value representing the kind of resource operations supported by the client. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// [JsonConverter(typeof(StringEnumConverter))] [TypeConverter(typeof(StringEnumConverter.TypeConverter))] diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentEdit.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentEdit.cs index 26af2f8e87483..d2f1e706699da 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentEdit.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentEdit.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing a set of changes to a single text document. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class TextDocumentEdit { @@ -27,12 +28,14 @@ public OptionalVersionedTextDocumentIdentifier TextDocument /// /// Gets or sets the array of edits to be applied to the document. /// + /// + /// Use of is guarded by the capability . + /// + /// + /// Since LSP 3.16 + /// [JsonPropertyName("edits")] [JsonRequired] - public TextEdit[] Edits - { - get; - set; - } + public SumType[] Edits { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs index b697665723efd..97b86d2787d81 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs @@ -24,7 +24,7 @@ internal class WorkspaceClientCapabilities public bool ApplyEdit { get; set; } /// - /// Gets or sets the workspace edit setting. + /// Capabilities specific to /// [JsonPropertyName("workspaceEdit")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceEdit.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceEdit.cs index d3739a5a90425..038937f3b8302 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceEdit.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceEdit.cs @@ -9,31 +9,48 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing a request sent from a language server to modify resources in the workspace. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class WorkspaceEdit { /// - /// Gets or sets a dictionary holding changes to existing resources. + /// Holds changes to existing resources. /// [JsonPropertyName("changes")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public Dictionary? Changes - { - get; - set; - } + public Dictionary? Changes { get; set; } /// - /// Gets or sets an array representing versioned document changes. + /// Depending on the client capability , + /// document changes are either an array of to express changes + /// to n different text documents where each text document edit addresses a specific version of a text document, + /// or it can contain above `TextDocumentEdit`s mixed with create, rename and delete file / folder operations. + /// + /// Whether a client supports versioned document edits is expressed via the + /// client capability. + /// + /// + /// If a client neither supports nor + /// then only plain s + /// using the property are supported. + /// /// [JsonPropertyName("documentChanges")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public SumType[]>? DocumentChanges - { - get; - set; - } + public SumType[]>? DocumentChanges { get; set; } + + /// + /// A map of change annotations that can be referenced in s or create, rename + /// and delete file / folder operations. + /// + /// + /// Whether clients honor this property depends on the client capability . + /// + /// Since 3.16 + [JsonPropertyName("changeAnnotations")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public Dictionary? ChangeAnnotations { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceEditSetting.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceEditSetting.cs index c3aee573bdf8f..b913f87fc0d68 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceEditSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceEditSetting.cs @@ -8,13 +8,14 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents initialization settings for workspace edit. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class WorkspaceEditSetting { /// - /// Gets or sets a value indicating whether document changes event is supported. + /// Whether the client supports versioned document changes in /// [JsonPropertyName("documentChanges")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -25,8 +26,9 @@ public bool DocumentChanges } /// - /// GEts or sets the resource operations the client supports. + /// The resource operations the client supports. /// + /// Since LSP 3.13 [JsonPropertyName("resourceOperations")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ResourceOperationKind[]? ResourceOperations @@ -34,5 +36,31 @@ public ResourceOperationKind[]? ResourceOperations get; set; } + + /// + /// The client's failure handling strategy when applying workspace changes. + /// + /// Since LSP 3.13 + [JsonPropertyName("failureHandling")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public FailureHandlingKind[]? FailureHandling { get; init; } + + /// + /// Whether the client normalizes line endings to the client specific setting + /// when applying workspace changes. + /// + /// Since LSP 3.16 + [JsonPropertyName("normalizesLineEndings")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public bool? NormalizesLineEndings { get; init; } + + /// + /// Whether the client supports change annotations on workspace edits, and + /// information about how it handles them. + /// + /// Since LSP 3.16 + [JsonPropertyName("changeAnnotationSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ChangeAnnotationSupport? ChangeAnnotationSupport { get; init; } } } From edd564806ea451200d29bd50a5a9038d71a0fd3a Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 9 Jun 2024 02:28:48 -0400 Subject: [PATCH 24/46] LSP Protocol: Update Linked Editing Range types --- .../LinkedEditingRangeClientCapabilities.cs | 16 ++++++++++ .../Protocol/LinkedEditingRangeOptions.cs | 8 ++--- .../Protocol/LinkedEditingRangeParams.cs | 10 +++++- .../LinkedEditingRangeRegistrationOptions.cs | 32 +++++++++++++++++++ .../Protocol/Protocol/LinkedEditingRanges.cs | 13 ++++++-- .../Protocol/Protocol/Methods.Document.cs | 19 +++++++++++ .../Protocol/Protocol/Methods.cs | 10 ------ .../Protocol/Protocol/ServerCapabilities.cs | 1 + .../TextDocumentClientCapabilities.cs | 5 +-- 9 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/LinkedEditingRangeClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/LinkedEditingRangeRegistrationOptions.cs diff --git a/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeClientCapabilities.cs new file mode 100644 index 0000000000000..f5d2d093b2509 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeClientCapabilities.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `textDocument/linkedEditingRange` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class LinkedEditingRangeClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeOptions.cs b/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeOptions.cs index 16d07390197b3..b337ac9739456 100644 --- a/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeOptions.cs @@ -8,14 +8,14 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents linked editing range capabilities. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class LinkedEditingRangeOptions : IWorkDoneProgressOptions { - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// + /// [JsonPropertyName("workDoneProgress")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } diff --git a/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeParams.cs b/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeParams.cs index 78cbad670a95f..03a900cf05bed 100644 --- a/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeParams.cs +++ b/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeParams.cs @@ -2,6 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Text.Json.Serialization; + namespace Roslyn.LanguageServer.Protocol { /// @@ -9,7 +12,12 @@ namespace Roslyn.LanguageServer.Protocol /// /// See the Language Server Protocol specification for additional information. /// - internal class LinkedEditingRangeParams : TextDocumentPositionParams + /// Since LSP 3.16 + internal class LinkedEditingRangeParams : TextDocumentPositionParams, IWorkDoneProgressParams { + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeRegistrationOptions.cs new file mode 100644 index 0000000000000..b3814a440c761 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/LinkedEditingRangeRegistrationOptions.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class LinkedEditingRangeRegistrationOptions : LinkedEditingRangeOptions, ITextDocumentRegistrationOptions, IStaticRegistrationOptions +{ + /// + /// 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. + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } + + /// + /// The id used to register the request. The id can be used to deregister the request again. + /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Id { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/LinkedEditingRanges.cs b/src/LanguageServer/Protocol/Protocol/LinkedEditingRanges.cs index a60978b1e0cb9..953e0f8533861 100644 --- a/src/LanguageServer/Protocol/Protocol/LinkedEditingRanges.cs +++ b/src/LanguageServer/Protocol/Protocol/LinkedEditingRanges.cs @@ -8,15 +8,20 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the response of an LinkedEditingRanges response. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// + /// Since LSP 3.16 internal class LinkedEditingRanges { /// - /// Gets or sets the ranges for the type rename. + /// A list of ranges that can be renamed together. The ranges must have + /// identical length and contain identical text content. The ranges cannot + /// overlap. /// [JsonPropertyName("ranges")] + [JsonRequired] public Range[] Ranges { get; @@ -24,7 +29,9 @@ public Range[] Ranges } /// - /// Gets or sets the word pattern for the type rename. + /// An optional word pattern (regular expression) that describes valid + /// contents for the given ranges. If no pattern is provided, the client + /// configuration's word pattern will be used. /// [JsonPropertyName("wordPattern")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index edf6d72595b12..7614db428cf47 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -596,4 +596,23 @@ partial class Methods /// /// Since LSP 3.12 public static readonly LspRequest?> TextDocumentPrepareRename = new(TextDocumentPrepareRenameName); + + /// + /// Method name for 'textDocument/linkedEditingRange'. + /// + /// The linked editing request is sent from the client to the server to return for a given + /// position in a document the range of the symbol at the position and all ranges that have the same content. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string TextDocumentLinkedEditingRangeName = "textDocument/linkedEditingRange"; + + /// + /// Strongly typed message object for 'textDocument/linkedEditingRange'. + /// + /// Since LSP 3.16 + public static readonly LspRequest TextDocumentLinkedEditingRange = new(TextDocumentLinkedEditingRangeName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index 358ccb558d9a9..dacc00e96fa06 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -31,11 +31,6 @@ internal static partial class Methods /// public const string ProgressNotificationTokenName = "token"; - /// - /// Method name for 'textDocument/linkedEditingRange'. - /// - public const string TextDocumentLinkedEditingRangeName = "textDocument/linkedEditingRange"; - /// /// Method name for 'window/logMessage'. /// @@ -87,11 +82,6 @@ internal static partial class Methods /// public const string TelemetryEventName = "telemetry/event"; - /// - /// Strongly typed message object for 'textDocument/linkedEditingRange'. - /// - public static readonly LspRequest TextDocumentLinkedEditingRange = new LspRequest(TextDocumentLinkedEditingRangeName); - /// /// Strongly typed message object for 'window/logMessage'. /// diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index f508245ff9e30..b08251d2782a3 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -217,6 +217,7 @@ public TextDocumentSyncOptions? TextDocumentSync /// /// Gets or sets a value indicating whether the server supports linked editing range. /// + /// Since LSP 3.16 [JsonPropertyName("linkedEditingRangeProvider")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? LinkedEditingRangeProvider { get; set; } diff --git a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs index 4074bf21eb10f..efde53965ed6d 100644 --- a/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/TextDocumentClientCapabilities.cs @@ -177,11 +177,12 @@ internal class TextDocumentClientCapabilities public SelectionRangeClientCapabilities? SelectionRange { get; set; } /// - /// Gets or sets the setting which determines if linked editing range can be dynamically registered. + /// Capabilities specific to the `textDocument/linkedEditingRange` request. /// + /// Since LSP 3.16 [JsonPropertyName("linkedEditingRange")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting LinkedEditingRange { get; set; } + public LinkedEditingRangeClientCapabilities LinkedEditingRange { get; set; } /// /// Capabilities specific to the various call hierarchy requests. From b9b589b7ba6d6bd823ea3d381dca30e0592beb58 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 9 Jun 2024 02:44:01 -0400 Subject: [PATCH 25/46] LSP Protocol: Update workspace symbol types --- .../Protocol/Protocol/Methods.Workspace.cs | 43 ++++++++++++ .../Protocol/Protocol/Methods.cs | 10 --- .../Protocol/Protocol/SymbolSetting.cs | 29 ++++++-- .../Protocol/WorkspaceClientCapabilities.cs | 2 +- .../Protocol/Protocol/WorkspaceSymbol.cs | 66 +++++++++++++++++++ .../Protocol/WorkspaceSymbolLocation.cs | 20 ++++++ .../Protocol/WorkspaceSymbolOptions.cs | 12 +++- .../Protocol/WorkspaceSymbolParams.cs | 27 ++++---- .../WorkspaceSymbolRegistrationOptions.cs | 15 +++++ .../Protocol/WorkspaceSymbolResolveSupport.cs | 21 ++++++ 10 files changed, 213 insertions(+), 32 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WorkspaceSymbol.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WorkspaceSymbolLocation.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WorkspaceSymbolRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WorkspaceSymbolResolveSupport.cs diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs b/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs new file mode 100644 index 0000000000000..d88daf3a9c5d2 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspaceFeatures +partial class Methods +{ + // NOTE: these are sorted/grouped in the order used by the spec + + /// + /// Method name for 'workspace/symbol'. + /// + /// The workspace symbol request is sent from the client to the server to list project-wide symbols matching the query string. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string WorkspaceSymbolName = "workspace/symbol"; + + /// + /// Strongly typed message object for 'workspace/symbol'. + /// + public static readonly LspRequest?> WorkspaceSymbol = new(WorkspaceSymbolName); + + /// + /// Method name for 'workspaceSymbol/resolve'. + /// + /// The request is sent from the client to the server to resolve additional information for a given workspace symbol. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string WorkspaceSymbolResolveName = "workspaceSymbol/resolve"; + + /// + /// Strongly typed message object for 'workspaceSymbol/resolve'. + /// + public static readonly LspRequest WorkspaceSymbolResolve = new(WorkspaceSymbolResolveName); +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index dacc00e96fa06..3f98880d1017e 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -67,11 +67,6 @@ internal static partial class Methods /// public const string WorkspaceExecuteCommandName = "workspace/executeCommand"; - /// - /// Method name for 'workspace/symbol'. - /// - public const string WorkspaceSymbolName = "workspace/symbol"; - /// /// Method name for 'workspace/didChangeWatchedFiles'. /// @@ -117,11 +112,6 @@ internal static partial class Methods /// public static readonly LspRequest WorkspaceExecuteCommand = new LspRequest(WorkspaceExecuteCommandName); - /// - /// Strongly typed message object for 'workspace/symbol'. - /// - public static readonly LspRequest WorkspaceSymbol = new LspRequest(WorkspaceSymbolName); - /// /// Strongly typed message object for 'workspace/didChangeWatchedFiles'. /// diff --git a/src/LanguageServer/Protocol/Protocol/SymbolSetting.cs b/src/LanguageServer/Protocol/Protocol/SymbolSetting.cs index bad49978458a1..cdb73488d4e61 100644 --- a/src/LanguageServer/Protocol/Protocol/SymbolSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/SymbolSetting.cs @@ -7,14 +7,15 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing the symbol setting for initialization. - /// + /// Capabilities specific to the workspace/symbol request. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class SymbolSetting : DynamicRegistrationSetting { /// - /// Gets or sets the information. + /// Specific capabilities for in workspace/symbol requests /// [JsonPropertyName("symbolKind")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -23,5 +24,25 @@ public SymbolKindSetting? SymbolKind get; set; } + /// + /// The client supports tags on and . + /// + /// Clients supporting tags have to handle unknown tags gracefully. + /// + /// + /// Since LSP 3.16 + [JsonPropertyName("tagSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SymbolTagSupport? TagSupport { get; init; } + + /// + /// The client support partial workspace symbols. The client will send the + /// request `workspaceSymbol/resolve` to the server to resolve additional + /// properties. + /// + /// Since LSP 3.17 + [JsonPropertyName("resolveSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public WorkspaceSymbolResolveSupport? ResolveSupport { get; init; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs index 97b86d2787d81..fa12de92062de 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs @@ -45,7 +45,7 @@ internal class WorkspaceClientCapabilities public DynamicRegistrationSetting? DidChangeWatchedFiles { get; set; } /// - /// Gets or sets the setting which determines if symbols can be dynamically registered. + /// Capabilities specific to the `workspace/symbol` request. /// [JsonPropertyName("symbol")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceSymbol.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbol.cs new file mode 100644 index 0000000000000..6cd2de0a10e39 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbol.cs @@ -0,0 +1,66 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A special workspace symbol that supports locations without a range +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.17 +internal class WorkspaceSymbol +{ + /// + /// The name of this symbol. + /// + [JsonPropertyName("name")] + [JsonRequired] + public string Name { get; init; } + + /// + /// The kind of the symbol + /// + [JsonPropertyName("kind")] + [JsonRequired] + public SymbolKind Kind { get; init; } + + /// + /// Tags for this symbol. + /// + [JsonPropertyName("tags")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SymbolTag? Tags { get; init; } + + /// + /// The name of the symbol containing this symbol. This information is for + /// user interface purposes (e.g. to render a qualifier in the user interface + /// if necessary). It can't be used to re-infer a hierarchy for the document + /// symbols. + /// + [JsonPropertyName("containerName")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? ContainerName { get; init; } + + /// + /// The location of this symbol. Whether a server is allowed to + /// return a location without a range depends on the client + /// workspace capability + /// + /// + [JsonPropertyName("location")] + [JsonRequired] + public SumType Location { get; init; } + + /// + /// Data field that is preserved on a workspace symbol between a + /// workspace symbol request and a workspace symbol resolve request. + /// + [JsonPropertyName("data")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public object? Data { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolLocation.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolLocation.cs new file mode 100644 index 0000000000000..6719e157caac2 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolLocation.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A workspace symbol location without a range +/// +internal class WorkspaceSymbolLocation +{ + [JsonPropertyName("uri")] + [JsonRequired] + [JsonConverter(typeof(DocumentUriConverter))] + public Uri Uri { get; init; } +} + diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolOptions.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolOptions.cs index 01ac93b66f538..8b3b362d3add8 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolOptions.cs @@ -8,14 +8,22 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents workspace symbols capabilities. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class WorkspaceSymbolOptions : IWorkDoneProgressOptions { /// - /// Gets or sets a value indicating whether work done progress is supported. + /// The server provides support to resolve additional + /// information for a workspace symbol. /// + /// Since LSP 3.17 + [JsonPropertyName("resolveProvider")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool ResolveProvider { get; init; } + + /// [JsonPropertyName("workDoneProgress")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolParams.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolParams.cs index bc70cf64c559a..954760df677dc 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolParams.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolParams.cs @@ -9,30 +9,27 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents the parameter that's sent with the 'workspace/symbol' request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class WorkspaceSymbolParams : IPartialResultParams + internal class WorkspaceSymbolParams : IPartialResultParams>, IWorkDoneProgressParams { /// /// Gets or sets the query (a non-empty string). /// [JsonPropertyName("query")] - public string Query - { - get; - set; - } + [JsonRequired] + public string Query { get; set; } - /// - /// Gets or sets the value of the Progress instance. - /// + /// [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public IProgress? PartialResultToken - { - get; - set; - } + public IProgress>? PartialResultToken { get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolRegistrationOptions.cs new file mode 100644 index 0000000000000..a3798075060a4 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolRegistrationOptions.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Registration options for +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class WorkspaceSymbolRegistrationOptions : WorkspaceSymbolOptions +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolResolveSupport.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolResolveSupport.cs new file mode 100644 index 0000000000000..696e780cbf395 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolResolveSupport.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +using System.Text.Json.Serialization; + +/// +/// Describes the client's support for partial workspace symbols +/// +/// Since LSP 3.17 +internal class WorkspaceSymbolResolveSupport +{ + /// + /// The properties that a client can resolve lazily. Usually `location.range` + /// + [JsonPropertyName("properties")] + [JsonRequired] + public string[] Properties { get; init; } +} From f92eea215bc8c36d09a92714ea1d4b7e5e1ce470 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 9 Jun 2024 02:52:22 -0400 Subject: [PATCH 26/46] LSP Protocol: Update Configuration types --- .../Protocol/Protocol/ConfigurationItem.cs | 5 +-- .../Protocol/Protocol/ConfigurationParams.cs | 6 ++-- ...idChangeConfigurationClientCapabilities.cs | 15 ++++++++ .../Protocol/DidChangeConfigurationParams.cs | 3 +- .../Protocol/Protocol/Methods.Workspace.cs | 35 +++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 21 ----------- .../Protocol/WorkspaceClientCapabilities.cs | 7 ++-- 7 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/DidChangeConfigurationClientCapabilities.cs diff --git a/src/LanguageServer/Protocol/Protocol/ConfigurationItem.cs b/src/LanguageServer/Protocol/Protocol/ConfigurationItem.cs index 51c7596a161c8..f97fcd9a3652c 100644 --- a/src/LanguageServer/Protocol/Protocol/ConfigurationItem.cs +++ b/src/LanguageServer/Protocol/Protocol/ConfigurationItem.cs @@ -9,8 +9,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents an configuration item. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class ConfigurationItem { @@ -37,4 +38,4 @@ public string? Section set; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/ConfigurationParams.cs b/src/LanguageServer/Protocol/Protocol/ConfigurationParams.cs index 3cfc4fd4a19cf..0420f8b2f1ecd 100644 --- a/src/LanguageServer/Protocol/Protocol/ConfigurationParams.cs +++ b/src/LanguageServer/Protocol/Protocol/ConfigurationParams.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the parameters for the workspace/configuration request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class ConfigurationParams { @@ -17,10 +18,11 @@ internal class ConfigurationParams /// Gets or sets the ConfigurationItems being requested. /// [JsonPropertyName("items")] + [JsonRequired] public ConfigurationItem[] Items { get; set; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/DidChangeConfigurationClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/DidChangeConfigurationClientCapabilities.cs new file mode 100644 index 0000000000000..36a00a7cbc617 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/DidChangeConfigurationClientCapabilities.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `workspace/didChangeConfiguration` notification. +/// +/// +/// See the Language Server Protocol specification for additional information. +/// +internal class DidChangeConfigurationClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/DidChangeConfigurationParams.cs b/src/LanguageServer/Protocol/Protocol/DidChangeConfigurationParams.cs index 102c94551b080..dd846d1a242a7 100644 --- a/src/LanguageServer/Protocol/Protocol/DidChangeConfigurationParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DidChangeConfigurationParams.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents the parameter sent with workspace/didChangeConfiguration requests. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DidChangeConfigurationParams { diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs b/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs index d88daf3a9c5d2..7c9a67853847a 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs @@ -40,4 +40,39 @@ partial class Methods /// Strongly typed message object for 'workspaceSymbol/resolve'. /// public static readonly LspRequest WorkspaceSymbolResolve = new(WorkspaceSymbolResolveName); + + /// + /// Method name for 'workspace/configuration'. + /// + /// The workspace/configuration request is sent from the server to the client to fetch configuration + /// settings from the client. The request can fetch several configuration settings in one roundtrip. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.6 + public const string WorkspaceConfigurationName = "workspace/configuration"; + + /// + /// Strongly typed message object for 'workspace/configuration'. + /// + /// Since LSP 3.6 + public static readonly LspRequest WorkspaceConfiguration = new(WorkspaceConfigurationName); + + /// + /// Method name for 'workspace/didChangeConfiguration'. + /// + /// A notification sent from the client to the server to signal the change of configuration settings. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string WorkspaceDidChangeConfigurationName = "workspace/didChangeConfiguration"; + + /// + /// Strongly typed message object for 'workspace/didChangeConfiguration'. + /// + public static readonly LspNotification WorkspaceDidChangeConfiguration = new(WorkspaceDidChangeConfigurationName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index 3f98880d1017e..107b4546fbfe9 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -51,17 +51,6 @@ internal static partial class Methods /// public const string WorkspaceApplyEditName = "workspace/applyEdit"; - /// - /// Method name for 'workspace/configuration'. - /// - public const string WorkspaceConfigurationName = "workspace/configuration"; - - - /// - /// Method name for 'workspace/didChangeConfiguration'. - /// - public const string WorkspaceDidChangeConfigurationName = "workspace/didChangeConfiguration"; - /// /// Method name for 'workspace/executeCommand'. /// @@ -97,16 +86,6 @@ internal static partial class Methods /// public static readonly LspRequest WorkspaceApplyEdit = new LspRequest(WorkspaceApplyEditName); - /// - /// Strongly typed message object for 'workspace/configuration'. - /// - public static readonly LspRequest WorkspaceConfiguration = new LspRequest(WorkspaceConfigurationName); - - /// - /// Strongly typed message object for 'workspace/didChangeConfiguration'. - /// - public static readonly LspNotification WorkspaceDidChangeConfiguration = new LspNotification(WorkspaceDidChangeConfigurationName); - /// /// Strongly typed message object for 'workspace/executeCommand'. /// diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs index fa12de92062de..b22e0cd0d5d76 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs @@ -31,11 +31,11 @@ internal class WorkspaceClientCapabilities public WorkspaceEditSetting? WorkspaceEdit { get; set; } /// - /// Gets or sets the setting which determines if did change configuration can be dynamically registered. + /// Capabilities specific to the `workspace/didChangeConfiguration` notification. /// [JsonPropertyName("didChangeConfiguration")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? DidChangeConfiguration { get; set; } + public DidChangeConfigurationClientCapabilities? DidChangeConfiguration { get; set; } /// /// Gets or sets the setting which determines if did change watched files can be dynamically registered. @@ -59,8 +59,9 @@ internal class WorkspaceClientCapabilities public DynamicRegistrationSetting? ExecuteCommand { get; set; } /// - /// Gets or sets the capabilities if client support 'workspace/configuration' requests. + /// The client supports `workspace/configuration` requests. /// + /// Since LSP 3.6 [JsonPropertyName("configuration")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool Configuration { get; set; } From 415a2c9c75249bd6e5da33be9d7db13e6669fb92 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 9 Jun 2024 04:10:45 -0400 Subject: [PATCH 27/46] LSP Protocol: Add/update file operations types --- .../FileOperations/CreateFilesParams.cs | 24 +++ .../FileOperations/DeleteFilesParams.cs | 24 +++ ...DidChangeWatchedFilesClientCapabilities.cs | 24 +++ .../DidChangeWatchedFilesParams.cs | 4 +- ...idChangeWatchedFilesRegistrationOptions.cs | 24 +++ .../DidChangeWorkspaceFoldersParams.cs | 24 +++ .../{ => FileOperations}/FileChangeType.cs | 3 +- .../Protocol/FileOperations/FileCreate.cs | 26 +++ .../Protocol/FileOperations/FileDelete.cs | 26 +++ .../{ => FileOperations}/FileEvent.cs | 9 +- .../FileOperations/FileOperationFilter.cs | 32 +++ .../FileOperations/FileOperationPattern.cs | 51 +++++ .../FileOperationPatternKind.cs | 30 +++ .../FileOperationPatternOptions.cs | 23 +++ .../FileOperationRegistrationOptions.cs | 24 +++ ...leOperationsWorkspaceClientCapabilities.cs | 55 ++++++ .../Protocol/FileOperations/FileRename.cs | 34 ++++ .../FileOperations/FileSystemWatcher.cs | 37 ++++ .../FileOperations/RelativePattern.cs | 32 +++ .../FileOperations/RenameFilesParams.cs | 25 +++ .../Protocol/FileOperations/WatchKind.cs | 32 +++ ...rkspaceFileOperationsServerCapabilities.cs | 59 ++++++ .../WorkspaceFoldersChangeEvent.cs | 31 +++ .../WorkspaceFoldersServerCapabilities.cs | 38 ++++ .../Protocol/Protocol/Methods.Workspace.cs | 183 ++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 10 - .../Protocol/Protocol/ServerCapabilities.cs | 7 + .../Protocol/WorkspaceClientCapabilities.cs | 20 +- .../Protocol/WorkspaceServerCapabilities.cs | 29 +++ 29 files changed, 920 insertions(+), 20 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/CreateFilesParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/DeleteFilesParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesClientCapabilities.cs rename src/LanguageServer/Protocol/Protocol/{ => FileOperations}/DidChangeWatchedFilesParams.cs (94%) create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWorkspaceFoldersParams.cs rename src/LanguageServer/Protocol/Protocol/{ => FileOperations}/FileChangeType.cs (96%) create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/FileCreate.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/FileDelete.cs rename src/LanguageServer/Protocol/Protocol/{ => FileOperations}/FileEvent.cs (92%) create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationFilter.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationPattern.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationPatternKind.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationPatternOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationRegistrationOptions.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationsWorkspaceClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/FileRename.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/FileSystemWatcher.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/RelativePattern.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/RenameFilesParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/WatchKind.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/WorkspaceFileOperationsServerCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/WorkspaceFoldersChangeEvent.cs create mode 100644 src/LanguageServer/Protocol/Protocol/FileOperations/WorkspaceFoldersServerCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WorkspaceServerCapabilities.cs diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/CreateFilesParams.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/CreateFilesParams.cs new file mode 100644 index 0000000000000..8ce2c42e4a190 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/CreateFilesParams.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The parameters sent in notifications/requests for user-initiated creation of files. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class CreateFilesParams +{ + /// + /// An array of all files/folders created in this operation. + /// + [JsonPropertyName("files")] + [JsonRequired] + public FileCreate[] Files { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/DeleteFilesParams.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/DeleteFilesParams.cs new file mode 100644 index 0000000000000..d952fc88593c0 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/DeleteFilesParams.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The parameters sent in notifications/requests for user-initiated deletes of files. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class DeleteFilesParams +{ + /// + /// An array of all files/folders deleted in this operation. + /// + [JsonPropertyName("files")] + [JsonRequired] + public FileCreate[] Files { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesClientCapabilities.cs new file mode 100644 index 0000000000000..967953eb6e963 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesClientCapabilities.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `workspace/didChangeWatchedFiles` notification. +/// +/// +/// See the Language Server Protocol specification for additional information. +/// +internal class DidChangeWatchedFilesClientCapabilities : DynamicRegistrationSetting +{ + /// + /// Whether the client has support for relative patterns. + /// + /// Since LSP 3.17 + [JsonPropertyName("relativePatternSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool RelativePatternSupport { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/DidChangeWatchedFilesParams.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesParams.cs similarity index 94% rename from src/LanguageServer/Protocol/Protocol/DidChangeWatchedFilesParams.cs rename to src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesParams.cs index e090da167da4e..e677fc58cb3e1 100644 --- a/src/LanguageServer/Protocol/Protocol/DidChangeWatchedFilesParams.cs +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesParams.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents the parameter that is sent with workspace/didChangeWatchedFiles message. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class DidChangeWatchedFilesParams { @@ -17,6 +18,7 @@ internal class DidChangeWatchedFilesParams /// Gets or sets of the collection of file change events. /// [JsonPropertyName("changes")] + [JsonRequired] public FileEvent[] Changes { get; diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesRegistrationOptions.cs new file mode 100644 index 0000000000000..381638544a752 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesRegistrationOptions.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Describe options to be used when registering for file system change events. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class DidChangeWatchedFilesRegistrationOptions : DynamicRegistrationSetting +{ + /// + /// The watchers to register. + /// + /// Since LSP 3.17 + [JsonPropertyName("relativePatternSupport")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public FileSystemWatcher[] Watchers { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWorkspaceFoldersParams.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWorkspaceFoldersParams.cs new file mode 100644 index 0000000000000..1fd3cfc39b118 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWorkspaceFoldersParams.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Class which represents the parameter sent with workspace/didChangeWorkspaceFolders requests. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.6 +internal class DidChangeWorkspaceFoldersParams +{ + /// + /// The actual workspace folder change event. + /// + [JsonPropertyName("event")] + [JsonRequired] + public WorkspaceFoldersChangeEvent Event { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileChangeType.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileChangeType.cs similarity index 96% rename from src/LanguageServer/Protocol/Protocol/FileChangeType.cs rename to src/LanguageServer/Protocol/Protocol/FileOperations/FileChangeType.cs index e09e40a3478b2..72e22a71d06f1 100644 --- a/src/LanguageServer/Protocol/Protocol/FileChangeType.cs +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileChangeType.cs @@ -6,8 +6,9 @@ namespace Roslyn.LanguageServer.Protocol { /// /// File event type enum. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal enum FileChangeType { diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/FileCreate.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileCreate.cs new file mode 100644 index 0000000000000..ddd7192f4af3e --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileCreate.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Represents information on a file/folder create. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class FileCreate +{ + /// + /// A file:// URI for the location of the file/folder being created. + /// + [JsonPropertyName("uri")] + [JsonRequired] + [JsonConverter(typeof(DocumentUriConverter))] + public Uri Uri { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/FileDelete.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileDelete.cs new file mode 100644 index 0000000000000..f5ff575a3cc27 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileDelete.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Represents information on a file/folder delete. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class FileDelete +{ + /// + /// A file:// URI for the location of the file/folder being deleted. + /// + [JsonPropertyName("uri")] + [JsonRequired] + [JsonConverter(typeof(DocumentUriConverter))] + public Uri Uri { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileEvent.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileEvent.cs similarity index 92% rename from src/LanguageServer/Protocol/Protocol/FileEvent.cs rename to src/LanguageServer/Protocol/Protocol/FileOperations/FileEvent.cs index 6133abc68ec98..6a45333d8a5ee 100644 --- a/src/LanguageServer/Protocol/Protocol/FileEvent.cs +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileEvent.cs @@ -9,8 +9,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents a file change event. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class FileEvent { @@ -19,11 +20,7 @@ internal class FileEvent /// [JsonPropertyName("uri")] [JsonConverter(typeof(DocumentUriConverter))] - public Uri Uri - { - get; - set; - } + public Uri Uri { get; set; } /// /// Gets or sets the file change type. diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationFilter.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationFilter.cs new file mode 100644 index 0000000000000..4a70d2ee13a83 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationFilter.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A filter to describe in which file operation requests or notifications +/// the server is interested in. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class FileOperationFilter +{ + /// + /// A Uri like `file` or `untitled`. + /// + [JsonPropertyName("scheme")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Scheme { get; init; } + + /// + /// The actual file operation pattern. + /// + [JsonPropertyName("pattern")] + [JsonRequired] + public FileOperationPattern Pattern { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationPattern.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationPattern.cs new file mode 100644 index 0000000000000..88ac96f5f57ef --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationPattern.cs @@ -0,0 +1,51 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A filter to describe in which file operation requests or notifications +/// the server is interested in. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class FileOperationPattern +{ + /// + /// The glob pattern to match. Glob patterns can have the following syntax: + /// + /// * to match one or more characters in a path segment + /// ? to match on one character in a path segment + /// ** to match any number of path segments, including none + /// {} to group sub patterns into an OR expression. + /// (e.g. **​/*.{ts,js}matches all TypeScript and JavaScript files) + /// []to declare a range of characters to match in a path segment + /// (e.g., example.[0-9] to match on example.0, example.1, …) + /// [!...] to negate a range of characters to match in a path segment + /// (e.g., example.[!0-9] to match on example.a, example.b, but not example.0) + /// + /// + [JsonPropertyName("glob")] + [JsonRequired] + public string Glob { get; init; } + + /// + /// Whether to match files or folders with this pattern. + /// Matches both if undefined. + /// + [JsonPropertyName("matches")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public FileOperationPatternKind? Matches { get; init; } + + /// + /// Additional options used during matching. + /// + [JsonPropertyName("options")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public FileOperationPatternOptions? Options { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationPatternKind.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationPatternKind.cs new file mode 100644 index 0000000000000..ca3ce3486e43d --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationPatternKind.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A pattern kind describing if a glob pattern matches a file a folder or both. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +[JsonConverter(typeof(StringEnumConverter))] +[TypeConverter(typeof(StringEnumConverter.TypeConverter))] +internal readonly record struct FileOperationPatternKind(string Value) : IStringEnum +{ + /// + /// The pattern matches a file only. + /// + public static readonly FileOperationPatternKind File = new("file"); + + /// + /// The pattern matches a folder only. + /// + public static readonly FileOperationPatternKind Folder = new("folder"); +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationPatternOptions.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationPatternOptions.cs new file mode 100644 index 0000000000000..a5f20e8b99e9c --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationPatternOptions.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Matching options for the file operation pattern. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// Since LSP 3.16 +internal class FileOperationPatternOptions +{ + /// + /// The pattern should be matched ignoring casing. + /// + [JsonPropertyName("ignoreCase")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool IgnoreCase { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationRegistrationOptions.cs new file mode 100644 index 0000000000000..b0fb7a3ff8895 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationRegistrationOptions.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The options to register for file operations +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class FileOperationRegistrationOptions +{ + /// + /// The actual filters. + /// + [JsonPropertyName("filters")] + [JsonRequired] + public FileOperationFilter[] Filters { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationsWorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationsWorkspaceClientCapabilities.cs new file mode 100644 index 0000000000000..ca9af203384ad --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileOperationsWorkspaceClientCapabilities.cs @@ -0,0 +1,55 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The client's capabilities for file requests/notifications. +/// +internal class FileOperationsWorkspaceClientCapabilities +{ + /// + /// The client has support for sending didCreateFiles notifications. + /// + [JsonPropertyName("didCreate")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool DidCreate { get; init; } + + /// + /// The client has support for sending willCreateFiles requests. + /// + [JsonPropertyName("willCreate")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WillCreate { get; init; } + + /// + /// The client has support for sending didRenameFiles notifications. + /// + [JsonPropertyName("didRename")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool DidRename { get; init; } + + /// + /// The client has support for sending willRenameFiles requests. + /// + [JsonPropertyName("willRename")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WillRename { get; init; } + + /// + /// The client has support for sending didDeleteFiles notifications. + /// + [JsonPropertyName("didDelete")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool DidDelete { get; init; } + + /// + /// The client has support for sending willDeleteFiles requests. + /// /// + [JsonPropertyName("willDelete")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WillDelete { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/FileRename.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileRename.cs new file mode 100644 index 0000000000000..fada354f69415 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileRename.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Represents information on a file/folder rename. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class FileRename +{ + /// + /// A file:// URI for the original location of the file/folder being renamed + /// + [JsonPropertyName("oldUri")] + [JsonRequired] + [JsonConverter(typeof(DocumentUriConverter))] + public Uri OldUri { get; set; } + + /// + /// A file:// URI for the new location of the file/folder being renamed. + /// + [JsonPropertyName("newUri")] + [JsonRequired] + [JsonConverter(typeof(DocumentUriConverter))] + public Uri NewUri { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/FileSystemWatcher.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileSystemWatcher.cs new file mode 100644 index 0000000000000..7557bcc57097a --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileSystemWatcher.cs @@ -0,0 +1,37 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Specifies patterns and kinds of file events to watch. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class FileSystemWatcher +{ + /// + /// The glob pattern to watch. See Glob Pattern + /// and for more detail. + /// + [JsonPropertyName("globPattern")] + [JsonRequired] + public SumType GlobPattern { get; init; } + + /// The kind of events of interest. + /// + /// + /// If omitted it defaults to + /// WatchKind.Create | WatchKind.Change | WatchKind.Delete + /// which is 7. + /// + [JsonPropertyName("kind")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [DefaultValue(WatchKind.Create | WatchKind.Change | WatchKind.Delete)] + public WatchKind Kind { get; init; } = WatchKind.Create | WatchKind.Change | WatchKind.Delete; +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/RelativePattern.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/RelativePattern.cs new file mode 100644 index 0000000000000..f4d9994a825e9 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/RelativePattern.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// A relative pattern is a helper to construct glob patterns that are matched +/// relatively to a base URI. The common value for a is a workspace +/// folder root, but it can be another absolute URI as well. +/// +/// Since LSP 3.17 +internal class RelativePattern +{ + /// + /// A workspace folder or a base URI to which this pattern will be matched + /// against relatively. + /// + [JsonPropertyName("baseUri")] + [JsonRequired] + public SumType BaseUri { get; init; } + + /// + /// The actual glob pattern. See Glob Pattern for more detail. + /// + [JsonPropertyName("pattern")] + [JsonRequired] + public string Pattern { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/RenameFilesParams.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/RenameFilesParams.cs new file mode 100644 index 0000000000000..bf016ae48f83f --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/RenameFilesParams.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The parameters sent in notifications/requests for user-initiated renames of files. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class RenameFilesParams +{ + /// + /// An array of all files/folders renamed in this operation. When a folder + /// is renamed, only the folder will be included, and not its children. + /// + [JsonPropertyName("files")] + [JsonRequired] + public FileRename[] Files { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/WatchKind.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/WatchKind.cs new file mode 100644 index 0000000000000..7d5ef0306bef4 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/WatchKind.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// File watch events of interest to a +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +[Flags] +internal enum WatchKind +{ + /// + /// Interested in create events. + /// + Create = 1, + + /// + /// Interested in change events + /// + Change = 2, + + /// + /// Interested in delete events + /// + Delete = 4, +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/WorkspaceFileOperationsServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/WorkspaceFileOperationsServerCapabilities.cs new file mode 100644 index 0000000000000..5b5c161ab8e62 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/WorkspaceFileOperationsServerCapabilities.cs @@ -0,0 +1,59 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The server capabilities specific to workspace file operations. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class WorkspaceFileOperationsServerCapabilities +{ + /// + /// The server is interested in receiving didCreateFiles notifications. + /// + [JsonPropertyName("didCreate")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public FileOperationRegistrationOptions? DidCreate { get; init; } + + /// + /// The server is interested in receiving willCreateFiles requests. + /// + [JsonPropertyName("willCreate")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public FileOperationRegistrationOptions? WillCreate { get; init; } + + /// + /// The server is interested in receiving didRenameFiles notifications. + /// + [JsonPropertyName("didRename")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public FileOperationRegistrationOptions? DidRename { get; init; } + + /// + /// The server is interested in receiving willRenameFiles requests. + /// + [JsonPropertyName("willRename")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public FileOperationRegistrationOptions? WillRename { get; init; } + + /// + /// The server is interested in receiving didDeleteFiles file notifications. + /// + [JsonPropertyName("didDelete")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public FileOperationRegistrationOptions? DidDelete { get; init; } + + /// + /// The server is interested in receiving willDeleteFiles file requests. + /// + [JsonPropertyName("willDelete")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public FileOperationRegistrationOptions? WillDelete { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/WorkspaceFoldersChangeEvent.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/WorkspaceFoldersChangeEvent.cs new file mode 100644 index 0000000000000..8e7abed2dc04e --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/WorkspaceFoldersChangeEvent.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The workspace folder change event provided by the +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.6 +internal class WorkspaceFoldersChangeEvent +{ + /// + /// The array of added workspace folders + /// + [JsonPropertyName("added")] + [JsonRequired] + public WorkspaceFolder[] Added { get; init; } + + /// + /// The array of the removed workspace folders + /// + [JsonPropertyName("removed")] + [JsonRequired] + public WorkspaceFolder[] Removed { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/WorkspaceFoldersServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/WorkspaceFoldersServerCapabilities.cs new file mode 100644 index 0000000000000..789f2da3d90e4 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/WorkspaceFoldersServerCapabilities.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The server capabilities specific to workspace folders +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.6 +internal class WorkspaceFoldersServerCapabilities +{ + /// + /// The server has support for workspace folders + /// + [JsonPropertyName("supported")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool? Supported { get; init; } + + /// + /// Whether the server wants to receive workspace folder + /// change notifications. + /// + /// If a string is provided, the string is treated as an ID + /// under which the notification is registered on the client + /// side. The ID can be used to unregister for these events + /// using the request. + /// + /// + [JsonPropertyName("changeNotifications")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public SumType? ChangeNotifications { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs b/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs index 7c9a67853847a..0d56eb146332f 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs @@ -75,4 +75,187 @@ partial class Methods /// Strongly typed message object for 'workspace/didChangeConfiguration'. /// public static readonly LspNotification WorkspaceDidChangeConfiguration = new(WorkspaceDidChangeConfigurationName); + + /// + /// Method name for 'workspace/workspaceFolders'. + /// + /// The workspace/workspaceFolders request is sent from the server to the client to fetch the current open + /// list of workspace folders. Returns in the response if only a single file is open in the tool. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.6 + public const string WorkspaceFoldersName = "workspace/workspaceFolders"; + + /// + /// Strongly typed message object for 'workspace/workspaceFolders'. + /// + /// Since LSP 3.6 + public static readonly LspRequest WorkspaceFolders = new(WorkspaceFoldersName); + + /// + /// Method name for 'workspace/didChangeWorkspaceFolders'. + /// + /// The workspace/didChangeWorkspaceFolders notification is sent from the client to the server + /// to inform the server about workspace folder configuration changes. + /// + /// + /// A server can register for this notification by using either the server capability + /// or by using the dynamic capability registration mechanism. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.6 + public const string WorkspaceDidChangeWorkspaceFoldersName = "workspace/didChangeWorkspaceFolders"; + + /// + /// Strongly typed message object for 'workspace/didChangeWorkspaceFolders'. + /// + /// Since LSP 3.6 + public static readonly LspNotification WorkspaceDidChangeWorkspaceFolders = new(WorkspaceDidChangeWorkspaceFoldersName); + + /// + /// Method name for 'workspace/willCreateFiles'. + /// + /// The will create files request is sent from the client to the server before files are actually created as long + /// as the creation is triggered from within the client either by a user action or by applying a workspace edit. + /// + /// + /// The request can return a which will be applied to the workspace before the files are created + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string WorkspaceWillCreateFilesName = "workspace/willCreateFiles"; + + /// + /// Strongly typed message object for 'workspace/willCreateFiles'. + /// + /// Since LSP 3.16 + public static readonly LspRequest WorkspaceWillCreateFiles = new(WorkspaceWillCreateFilesName); + + /// + /// Method name for 'workspace/didCreateFiles'. + /// + /// The did create files notification is sent from the client to the server when files were created from within the client. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string WorkspaceDidCreateFilesName = "workspace/didCreateFiles"; + + /// + /// Strongly typed message object for 'workspace/didCreateFiles'. + /// + /// Since LSP 3.16 + public static readonly LspNotification WorkspaceDidCreateFiles = new(WorkspaceDidCreateFilesName); + + /// + /// Method name for 'workspace/willRenameFiles'. + /// + /// The will rename files request is sent from the client to the server before files are actually renamed as long as the + /// rename is triggered from within the client either by a user action or by applying a workspace edit. + /// + /// + /// The request can return a which will be applied to the workspace before the files are renamed. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string WorkspaceWillRenameFilesName = "workspace/willRenameFiles"; + + /// + /// Strongly typed message object for 'workspace/willRenameFiles'. + /// + /// Since LSP 3.16 + public static readonly LspRequest WorkspaceWillRenameFiles = new(WorkspaceWillRenameFilesName); + + /// + /// Method name for 'workspace/didRenameFiles'. + /// + /// The did rename files notification is sent from the client to the server when files were renamed from within the client. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string WorkspaceDidRenameFilesName = "workspace/didRenameFiles"; + + /// + /// Strongly typed message object for 'workspace/didRenameFiles'. + /// + /// Since LSP 3.16 + public static readonly LspNotification WorkspaceDidRenameFiles = new(WorkspaceDidRenameFilesName); + + /// + /// Method name for 'workspace/willDeleteFiles'. + /// + /// The will delete files request is sent from the client to the server before files are actually deleted as + /// long as the deletion is triggered from within the client either by a user action or by applying a workspace edit. + /// + /// + /// The request can return a which will be applied to workspace before the files are deleted. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string WorkspaceWillDeleteFilesName = "workspace/willDeleteFiles"; + + /// + /// Strongly typed message object for 'workspace/willDeleteFiles'. + /// + /// Since LSP 3.16 + public static readonly LspRequest WorkspaceWillDeleteFiles = new(WorkspaceWillDeleteFilesName); + + /// + /// Method name for 'workspace/didDeleteFiles'. + /// + /// The did delete files notification is sent from the client to the server when files were deleted from within the client. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string WorkspaceDidDeleteFilesName = "workspace/didDeleteFiles"; + + /// + /// Strongly typed message object for 'workspace/didDeleteFiles'. + /// + /// Since LSP 3.16 + public static readonly LspNotification WorkspaceDidDeleteFiles = new(WorkspaceDidDeleteFilesName); + + /// + /// Method name for 'workspace/didChangeWatchedFiles'. + /// + /// The watched files notification is sent from the client to the server when the client detects changes to files + /// and folders watched by the language client. + /// + /// + /// Note that although the name suggest that only file events are sent, it is about file system events, which includes folders as well. + /// It is recommended that servers register for these file system events using the registration mechanism. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string WorkspaceDidChangeWatchedFilesName = "workspace/didChangeWatchedFiles"; + + /// + /// Strongly typed message object for 'workspace/didChangeWatchedFiles'. + /// + public static readonly LspNotification WorkspaceDidChangeWatchedFiles = new(WorkspaceDidChangeWatchedFilesName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index 107b4546fbfe9..702425d8bb4da 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -56,11 +56,6 @@ internal static partial class Methods /// public const string WorkspaceExecuteCommandName = "workspace/executeCommand"; - /// - /// Method name for 'workspace/didChangeWatchedFiles'. - /// - public const string WorkspaceDidChangeWatchedFilesName = "workspace/didChangeWatchedFiles"; - /// /// Method name for 'telemetry/event'. /// @@ -91,11 +86,6 @@ internal static partial class Methods /// public static readonly LspRequest WorkspaceExecuteCommand = new LspRequest(WorkspaceExecuteCommandName); - /// - /// Strongly typed message object for 'workspace/didChangeWatchedFiles'. - /// - public static readonly LspNotification WorkspaceDidChangeWatchedFiles = new LspNotification(WorkspaceDidChangeWatchedFilesName); - /// /// Strongly typed message object for 'telemetry/event'. /// diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index b08251d2782a3..747a27d78d9b5 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -285,6 +285,13 @@ public TextDocumentSyncOptions? TextDocumentSync [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? WorkspaceSymbolProvider { get; set; } + /// + /// Workspace specific server capabilities. + /// + [JsonPropertyName("workspace")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public WorkspaceServerCapabilities? Workspace { get; init; } + /// /// Gets or sets experimental server capabilities. /// diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs index b22e0cd0d5d76..99b42e6807238 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs @@ -38,11 +38,11 @@ internal class WorkspaceClientCapabilities public DidChangeConfigurationClientCapabilities? DidChangeConfiguration { get; set; } /// - /// Gets or sets the setting which determines if did change watched files can be dynamically registered. + /// Capabilities specific to the `workspace/didChangeWatchedFiles` notification. /// [JsonPropertyName("didChangeWatchedFiles")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? DidChangeWatchedFiles { get; set; } + public DidChangeWatchedFilesClientCapabilities? DidChangeWatchedFiles { get; set; } /// /// Capabilities specific to the `workspace/symbol` request. @@ -58,6 +58,14 @@ internal class WorkspaceClientCapabilities [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DynamicRegistrationSetting? ExecuteCommand { get; set; } + /// + /// The client has support for workspace folders. + /// + /// Since LSP 3.6 + [JsonPropertyName("workspaceFolders")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkspaceFolders { get; init; } + /// /// The client supports `workspace/configuration` requests. /// @@ -82,6 +90,14 @@ internal class WorkspaceClientCapabilities [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public CodeLensWorkspaceSetting? CodeLens { get; set; } + /// + /// The client's capabilities for file requests/notifications. + /// + /// Since LSP 3.16 + [JsonPropertyName("fileOperations")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public FileOperationsWorkspaceClientCapabilities? FileOperations { get; init; } + /// /// Client workspace capabilities specific to inline values. /// diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceServerCapabilities.cs new file mode 100644 index 0000000000000..94389e05a265e --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceServerCapabilities.cs @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Workspace specific server capabilities. +/// +internal class WorkspaceServerCapabilities +{ + /// + /// The server supports workspace folder. + /// + /// Since LSP 3.6 + [JsonPropertyName("workspaceFolders")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public WorkspaceFoldersServerCapabilities? WorkspaceFolders { get; init; } + + /// + /// The server is interested in file notifications/requests. + /// + /// Since LSP 3.16 + [JsonPropertyName("fileOperations")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public WorkspaceFileOperationsServerCapabilities? FileOperations { get; init; } +} From 79fcd944a15b27e4d360179253bc5f3a1b66e3fd Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 9 Jun 2024 04:24:29 -0400 Subject: [PATCH 28/46] LSP Protocol: Update Workspace Execute/Apply methods --- .../Protocol/ApplyWorkspaceEditParams.cs | 7 +++- .../Protocol/ApplyWorkspaceEditResponse.cs | 38 +++++++++++-------- .../ExecuteCommandClientCapabilities.cs | 15 ++++++++ .../Protocol/ExecuteCommandOptions.cs | 7 ++-- .../Protocol/Protocol/ExecuteCommandParams.cs | 11 +++++- .../ExecuteCommandRegistrationOptions.cs | 21 ++++++++++ .../Protocol/Protocol/Methods.Workspace.cs | 36 ++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 20 ---------- .../Protocol/WorkspaceClientCapabilities.cs | 6 +-- 9 files changed, 115 insertions(+), 46 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/ExecuteCommandClientCapabilities.cs create mode 100644 src/LanguageServer/Protocol/Protocol/ExecuteCommandRegistrationOptions.cs diff --git a/src/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditParams.cs b/src/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditParams.cs index 2ede34011caaf..92f63f409781b 100644 --- a/src/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditParams.cs +++ b/src/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditParams.cs @@ -14,7 +14,9 @@ namespace Roslyn.LanguageServer.Protocol internal class ApplyWorkspaceEditParams { /// - /// Gets or sets the label associated with this edit. + /// An optional label of the workspace edit. This label is + /// presented in the user interface for example on an undo + /// stack to undo the workspace edit. /// [JsonPropertyName("label")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] @@ -25,9 +27,10 @@ public string? Label } /// - /// Gets or sets the edit to be applied to the workspace. + /// The edits to apply. /// [JsonPropertyName("edit")] + [JsonRequired] public WorkspaceEdit Edit { get; diff --git a/src/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditResponse.cs b/src/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditResponse.cs index 0fb22929337ba..98a99cba03de6 100644 --- a/src/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditResponse.cs +++ b/src/LanguageServer/Protocol/Protocol/ApplyWorkspaceEditResponse.cs @@ -7,32 +7,40 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class representing the response sent for a workspace/applyEdit request. - /// + /// Class representing the response sent for a workspace/applyEdit request. + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class ApplyWorkspaceEditResponse { /// - /// Gets or sets a value indicating whether edits were applied or not. + /// Indicates whether the edit was applied or not. /// [JsonPropertyName("applied")] - public bool Applied - { - get; - set; - } + [JsonRequired] + public bool Applied { get; set; } /// - /// Gets or sets a string with textual description for why the edit was not applied. + /// An optional textual description for why the edit was not applied. + /// + /// This may be used by the server for diagnostic logging or to provide + /// a suitable error for a request that triggered the edit. + /// /// [JsonPropertyName("failureReason")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string? FailureReason - { - get; - set; - } + public string? FailureReason { get; set; } + + /// + /// Depending on the client's failure handling strategy this + /// might contain the index of the change that failed. + /// + /// This property is only available if the client signals a strategy in its client capabilities. + /// + /// + [JsonPropertyName("failedChange")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public int? FailedChange { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/ExecuteCommandClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ExecuteCommandClientCapabilities.cs new file mode 100644 index 0000000000000..d1f8593dc575f --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ExecuteCommandClientCapabilities.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Capabilities specific to the `workspace/executeCommand` request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class ExecuteCommandClientCapabilities : DynamicRegistrationSetting +{ +} diff --git a/src/LanguageServer/Protocol/Protocol/ExecuteCommandOptions.cs b/src/LanguageServer/Protocol/Protocol/ExecuteCommandOptions.cs index d79e56516f134..63b3ce8174c5e 100644 --- a/src/LanguageServer/Protocol/Protocol/ExecuteCommandOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/ExecuteCommandOptions.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class representing the options for execute command support. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class ExecuteCommandOptions : IWorkDoneProgressOptions { @@ -23,9 +24,7 @@ public string[] Commands set; } - /// - /// Gets or sets a value indicating whether work done progress is supported. - /// + /// [JsonPropertyName("workDoneProgress")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } diff --git a/src/LanguageServer/Protocol/Protocol/ExecuteCommandParams.cs b/src/LanguageServer/Protocol/Protocol/ExecuteCommandParams.cs index 6269066a2ad07..7f7fea2bcafa5 100644 --- a/src/LanguageServer/Protocol/Protocol/ExecuteCommandParams.cs +++ b/src/LanguageServer/Protocol/Protocol/ExecuteCommandParams.cs @@ -4,14 +4,16 @@ namespace Roslyn.LanguageServer.Protocol { + using System; using System.Text.Json.Serialization; /// /// Class representing the parameters sent from client to server for the workspace/executeCommand request. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// - internal class ExecuteCommandParams + internal class ExecuteCommandParams : IWorkDoneProgressParams { /// /// Gets or sets the command identifier associated with the command handler. @@ -33,5 +35,10 @@ public object[]? Arguments get; set; } + + /// + [JsonPropertyName(Methods.WorkDoneTokenName)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public IProgress? WorkDoneToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/ExecuteCommandRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/ExecuteCommandRegistrationOptions.cs new file mode 100644 index 0000000000000..cd96e68405708 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ExecuteCommandRegistrationOptions.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Subclass of that allows scoping the registration. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +internal class ExecuteCommandRegistrationOptions : ExecuteCommandOptions, ITextDocumentRegistrationOptions +{ + /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public DocumentFilter[]? DocumentSelector { get; set; } +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs b/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs index 0d56eb146332f..b8e80b72864d7 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs @@ -258,4 +258,40 @@ partial class Methods /// Strongly typed message object for 'workspace/didChangeWatchedFiles'. /// public static readonly LspNotification WorkspaceDidChangeWatchedFiles = new(WorkspaceDidChangeWatchedFilesName); + + /// + /// Method name for 'workspace/executeCommand'. + /// + /// The workspace/executeCommand request is sent from the client to the server to trigger command execution on the server. + /// + /// + /// In most cases the server creates a WorkspaceEdit structure and applies the changes to the workspace using the + /// request workspace/applyEdit which is sent from the server to the client. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string WorkspaceExecuteCommandName = "workspace/executeCommand"; + + /// + /// Strongly typed message object for 'workspace/executeCommand'. + /// + public static readonly LspRequest WorkspaceExecuteCommand = new(WorkspaceExecuteCommandName); + + /// + /// Method name for 'workspace/applyEdit'. + /// + public const string WorkspaceApplyEditName = "workspace/applyEdit"; + + /// + /// Strongly typed message object for 'workspace/applyEdit'. + /// + /// The workspace/applyEdit request is sent from the server to the client to modify resource on the client side. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public static readonly LspRequest WorkspaceApplyEdit = new(WorkspaceApplyEditName); } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index 702425d8bb4da..bc2b4b2b15028 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -46,16 +46,6 @@ internal static partial class Methods /// public const string WindowShowMessageRequestName = "window/showMessageRequest"; - /// - /// Method name for 'workspace/applyEdit'. - /// - public const string WorkspaceApplyEditName = "workspace/applyEdit"; - - /// - /// Method name for 'workspace/executeCommand'. - /// - public const string WorkspaceExecuteCommandName = "workspace/executeCommand"; - /// /// Method name for 'telemetry/event'. /// @@ -76,16 +66,6 @@ internal static partial class Methods /// public static readonly LspRequest WindowShowMessageRequest = new LspRequest(WindowShowMessageRequestName); - /// - /// Strongly typed message object for 'workspace/applyEdit'. - /// - public static readonly LspRequest WorkspaceApplyEdit = new LspRequest(WorkspaceApplyEditName); - - /// - /// Strongly typed message object for 'workspace/executeCommand'. - /// - public static readonly LspRequest WorkspaceExecuteCommand = new LspRequest(WorkspaceExecuteCommandName); - /// /// Strongly typed message object for 'telemetry/event'. /// diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs index 99b42e6807238..1a10d7aea454b 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceClientCapabilities.cs @@ -17,7 +17,7 @@ internal class WorkspaceClientCapabilities // NOTE: these are kept in the same order as the spec to make them easier to update /// - /// Gets or sets a value indicating whether apply edit is supported. + /// Whether the client supports applying batch edits to the workspace by supporting the request 'workspace/applyEdit' /// [JsonPropertyName("applyEdit")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] @@ -52,11 +52,11 @@ internal class WorkspaceClientCapabilities public SymbolSetting? Symbol { get; set; } /// - /// Gets or sets the setting which determines if execute command can be dynamically registered. + /// Capabilities specific to the `workspace/executeCommand` request. /// [JsonPropertyName("executeCommand")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public DynamicRegistrationSetting? ExecuteCommand { get; set; } + public ExecuteCommandClientCapabilities? ExecuteCommand { get; set; } /// /// The client has support for workspace folders. From fbd8053aaf0a00e5b8f6ed94f203ed5eb4842f46 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 9 Jun 2024 12:56:56 -0400 Subject: [PATCH 29/46] LSP Protocol: Update window messages/types --- .../Protocol/Protocol/LogMessageParams.cs | 5 +- .../Protocol/Protocol/MessageActionItem.cs | 17 ++- .../Protocol/Protocol/MessageType.cs | 9 +- .../Protocol/Protocol/Methods.Window.cs | 140 ++++++++++++++++++ .../Protocol/Protocol/Methods.cs | 40 ----- .../Protocol/Protocol/ShowDocumentParams.cs | 56 +++++++ .../Protocol/Protocol/ShowDocumentResult.cs | 24 +++ .../Protocol/Protocol/ShowMessageParams.cs | 7 +- .../Protocol/ShowMessageRequestParams.cs | 3 +- .../Protocol/WorkDoneProgressCancelParams.cs | 24 +++ .../Protocol/WorkDoneProgressCreateParams.cs | 24 +++ 11 files changed, 301 insertions(+), 48 deletions(-) create mode 100644 src/LanguageServer/Protocol/Protocol/Methods.Window.cs create mode 100644 src/LanguageServer/Protocol/Protocol/ShowDocumentParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/ShowDocumentResult.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WorkDoneProgressCancelParams.cs create mode 100644 src/LanguageServer/Protocol/Protocol/WorkDoneProgressCreateParams.cs diff --git a/src/LanguageServer/Protocol/Protocol/LogMessageParams.cs b/src/LanguageServer/Protocol/Protocol/LogMessageParams.cs index 6918677cc3014..c0bfa9aef0f71 100644 --- a/src/LanguageServer/Protocol/Protocol/LogMessageParams.cs +++ b/src/LanguageServer/Protocol/Protocol/LogMessageParams.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents parameter sent with window/logMessage requests. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class LogMessageParams { @@ -17,6 +18,7 @@ internal class LogMessageParams /// Gets or sets the type of message. /// [JsonPropertyName("type")] + [JsonRequired] public MessageType MessageType { get; @@ -26,6 +28,7 @@ public MessageType MessageType /// /// Gets or sets the message. /// + [JsonRequired] [JsonPropertyName("message")] public string Message { diff --git a/src/LanguageServer/Protocol/Protocol/MessageActionItem.cs b/src/LanguageServer/Protocol/Protocol/MessageActionItem.cs index 8f4739241c9e2..d6b9d342a9409 100644 --- a/src/LanguageServer/Protocol/Protocol/MessageActionItem.cs +++ b/src/LanguageServer/Protocol/Protocol/MessageActionItem.cs @@ -4,17 +4,19 @@ namespace Roslyn.LanguageServer.Protocol { + using System.Collections.Generic; using System.Text.Json.Serialization; /// /// Class which represent an action the user performs after a window/showMessageRequest request is sent. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class MessageActionItem { /// - /// Gets or sets the title. + /// A short title like 'Retry', 'Open Log' etc. /// [JsonPropertyName("title")] public string Title @@ -22,5 +24,14 @@ public string Title get; set; } + + /// + /// Additional properties which will be returned to the server in the request's response. + /// + /// Support for this depends on the client capability . + /// + /// + [JsonExtensionData] + public Dictionary AdditionalProperties { get; set; } } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Protocol/Protocol/MessageType.cs b/src/LanguageServer/Protocol/Protocol/MessageType.cs index b36f16e24c9d4..f52d7428c280b 100644 --- a/src/LanguageServer/Protocol/Protocol/MessageType.cs +++ b/src/LanguageServer/Protocol/Protocol/MessageType.cs @@ -6,8 +6,9 @@ namespace Roslyn.LanguageServer.Protocol { /// /// Message type enum. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal enum MessageType { @@ -30,5 +31,11 @@ internal enum MessageType /// Log message. /// Log = 4, + + /// + /// Debug message + /// + /// Since LSP 3.18 + Debug = 5, } } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Window.cs b/src/LanguageServer/Protocol/Protocol/Methods.Window.cs new file mode 100644 index 0000000000000..2750c9f4b6776 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Methods.Window.cs @@ -0,0 +1,140 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Roslyn.LanguageServer.Protocol; + +// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#windowFeatures +partial class Methods +{ + /// + /// Method name for 'window/showMessage'. + /// + /// The show message notification is sent from a server to a client to ask the client to display a particular message in the user interface. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string WindowShowMessageName = "window/showMessage"; + + /// + /// Strongly typed message object for 'window/showMessage'. + /// + public static readonly LspNotification WindowShowMessage = new(WindowShowMessageName); + + /// + /// Method name for 'window/showMessageRequest'. + /// + /// The show message request is sent from a server to a client to ask the client to display a particular message in the user interface. + /// + /// + /// In addition to the show message notification the request allows to pass actions and to wait for an answer from the client. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string WindowShowMessageRequestName = "window/showMessageRequest"; + + /// + /// Strongly typed message object for 'window/showMessageRequest'. + /// + public static readonly LspRequest WindowShowMessageRequest = new(WindowShowMessageRequestName); + + /// + /// Method name for 'window/showDocument'. + /// + /// The show document request is sent from a server to a client to ask the client to display a particular resource referenced by a URI in the user interface. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.16 + public const string WindowShowDocumentName = "window/showDocument"; + + /// + /// Strongly typed message object for 'window/showDocument'. + /// + /// Since LSP 3.16 + public static readonly LspRequest WindowShowDocument = new(WindowShowDocumentName); + + /// + /// Method name for 'window/logMessage'. + /// + /// The log message notification is sent from the server to the client to ask the client to log a particular message. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string WindowLogMessageName = "window/logMessage"; + + /// + /// Strongly typed message object for 'window/logMessage'. + /// + public static readonly LspNotification WindowLogMessage = new(WindowLogMessageName); + + /// + /// Method name for 'window/workDoneProgress/create' + /// + /// Sent from the server to the client to ask the client to create a work done progress. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.15 + public const string WindowWorkDoneProgressCreateName = "window/workDoneProgress/create"; + + /// + /// Strongly typed message object for 'window/workDoneProgress/create'. + /// + /// Since LSP 3.15 + public static readonly LspRequest WindowWorkDoneProgressCreate = new(WindowWorkDoneProgressCreateName); + + /// + /// Method name for 'window/workDoneProgress/cancel' + /// + /// The window/workDoneProgress/cancel notification is sent from the client to the server to cancel a progress + /// initiated on the server side using the window/workDoneProgress/create. + /// + /// + /// The progress need not be marked as cancellable to be cancelled and a client may cancel a + /// progress for any number of reasons: in case of error, reloading a workspace etc. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + /// Since LSP 3.15 + public const string WindowWorkDoneProgressCancelName = "window/workDoneProgress/cancel"; + + /// + /// Strongly typed message object for 'window/workDoneProgress/cancel'. + /// + /// Since LSP 3.15 + public static readonly LspNotification WindowWorkDoneProgressCancel = new(WindowWorkDoneProgressCancelName); + + /// + /// Method name for 'telemetry/event'. + /// + /// The telemetry notification is sent from the server to the client to ask the client to log a telemetry event. + /// + /// + /// The protocol doesn't specify the payload since no interpretation of the data happens in the protocol. + /// Most clients even don’t handle the event directly but forward them to the extensions owing the + /// corresponding server issuing the event. + /// + /// + /// See the Language Server Protocol specification for additional information. + /// + /// + public const string TelemetryEventName = "telemetry/event"; + + /// + /// Strongly typed message object for 'telemetry/event'. + /// + public static readonly LspNotification TelemetryEvent = new(TelemetryEventName); +} diff --git a/src/LanguageServer/Protocol/Protocol/Methods.cs b/src/LanguageServer/Protocol/Protocol/Methods.cs index bc2b4b2b15028..7a2a7cc5efb51 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.cs @@ -30,45 +30,5 @@ internal static partial class Methods /// Name of the progress token in the $/progress notification. /// public const string ProgressNotificationTokenName = "token"; - - /// - /// Method name for 'window/logMessage'. - /// - public const string WindowLogMessageName = "window/logMessage"; - - /// - /// Method name for 'window/showMessage'. - /// - public const string WindowShowMessageName = "window/showMessage"; - - /// - /// Method name for 'window/showMessageRequest'. - /// - public const string WindowShowMessageRequestName = "window/showMessageRequest"; - - /// - /// Method name for 'telemetry/event'. - /// - public const string TelemetryEventName = "telemetry/event"; - - /// - /// Strongly typed message object for 'window/logMessage'. - /// - public static readonly LspNotification WindowLogMessage = new LspNotification(WindowLogMessageName); - - /// - /// Strongly typed message object for 'window/showMessage'. - /// - public static readonly LspNotification WindowShowMessage = new LspNotification(WindowShowMessageName); - - /// - /// Strongly typed message object for 'window/showMessageRequest'. - /// - public static readonly LspRequest WindowShowMessageRequest = new LspRequest(WindowShowMessageRequestName); - - /// - /// Strongly typed message object for 'telemetry/event'. - /// - public static readonly LspNotification TelemetryEvent = new LspNotification(TelemetryEventName); } } diff --git a/src/LanguageServer/Protocol/Protocol/ShowDocumentParams.cs b/src/LanguageServer/Protocol/Protocol/ShowDocumentParams.cs new file mode 100644 index 0000000000000..4226d8fa8e1ce --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ShowDocumentParams.cs @@ -0,0 +1,56 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// Params for the 'windows/showDocument' request +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class ShowDocumentParams +{ + /// + /// The uri to show. + /// + [JsonPropertyName("uri")] + [JsonRequired] + public Uri Uri { get; init; } + + /// + /// Indicates whether to show the resource in an external program. + /// + /// To show, for example, https://code.visualstudio.com/ in the default + /// web browser, set to . + /// + /// + [JsonPropertyName("external")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool External { get; init; } + + /// + /// Optionally indicates whether the editor showing the document should take focus or not. + /// + /// Clients might ignore this property if an external program is started. + /// + /// + [JsonPropertyName("takeFocus")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool TakeFocus { get; init; } + + /// + /// An optional selection range if the document is a text document. + /// + /// Clients might ignore the property if an external program is started or the file is not a text file. + /// + /// + [JsonPropertyName("selection")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public Range? Selection { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/ShowDocumentResult.cs b/src/LanguageServer/Protocol/Protocol/ShowDocumentResult.cs new file mode 100644 index 0000000000000..e124b3b254847 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/ShowDocumentResult.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The result of a 'windows/showDocument' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.16 +internal class ShowDocumentResult +{ + /// + /// Indicates whether the show was successful. + /// + [JsonPropertyName("success")] + [JsonRequired] + public bool Success { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/ShowMessageParams.cs b/src/LanguageServer/Protocol/Protocol/ShowMessageParams.cs index b7da5703aedba..7eb8186802a75 100644 --- a/src/LanguageServer/Protocol/Protocol/ShowMessageParams.cs +++ b/src/LanguageServer/Protocol/Protocol/ShowMessageParams.cs @@ -7,9 +7,10 @@ namespace Roslyn.LanguageServer.Protocol using System.Text.Json.Serialization; /// - /// Class which represents parameter sent with window/showMessage requests. - /// + /// The parameters sent with window/showMessage requests. + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class ShowMessageParams { @@ -17,6 +18,7 @@ internal class ShowMessageParams /// Gets or sets the type of message. /// [JsonPropertyName("type")] + [JsonRequired] public MessageType MessageType { get; @@ -27,6 +29,7 @@ public MessageType MessageType /// Gets or sets the message. /// [JsonPropertyName("message")] + [JsonRequired] public string Message { get; diff --git a/src/LanguageServer/Protocol/Protocol/ShowMessageRequestParams.cs b/src/LanguageServer/Protocol/Protocol/ShowMessageRequestParams.cs index b8df89cb3f998..3d169d5e36eb4 100644 --- a/src/LanguageServer/Protocol/Protocol/ShowMessageRequestParams.cs +++ b/src/LanguageServer/Protocol/Protocol/ShowMessageRequestParams.cs @@ -8,8 +8,9 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents parameter sent with window/showMessageRequest requests. - /// + /// /// See the Language Server Protocol specification for additional information. + /// /// internal class ShowMessageRequestParams : ShowMessageParams { diff --git a/src/LanguageServer/Protocol/Protocol/WorkDoneProgressCancelParams.cs b/src/LanguageServer/Protocol/Protocol/WorkDoneProgressCancelParams.cs new file mode 100644 index 0000000000000..2a88fabd1ad35 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WorkDoneProgressCancelParams.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The parameters sent with the 'window/workDoneProgress/cancel' notification. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.15 +internal class WorkDoneProgressCancelParams +{ + /// + /// The token used to report progress. + /// + [JsonPropertyName("token")] + [JsonRequired] + public SumType Token { get; init; } +} diff --git a/src/LanguageServer/Protocol/Protocol/WorkDoneProgressCreateParams.cs b/src/LanguageServer/Protocol/Protocol/WorkDoneProgressCreateParams.cs new file mode 100644 index 0000000000000..fc07545043836 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/WorkDoneProgressCreateParams.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Roslyn.LanguageServer.Protocol; + +/// +/// The parameters sent with the 'window/workDoneProgress/create' request. +/// +/// See the Language Server Protocol specification for additional information. +/// +/// +/// Since LSP 3.15 +internal class WorkDoneProgressCreateParams +{ + /// + /// The token to be used to report progress. + /// + [JsonPropertyName("token")] + [JsonRequired] + public SumType Token { get; init; } +} From c3792dd557b37e533d955594f0105506bbcfdfe3 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 9 Jun 2024 13:03:36 -0400 Subject: [PATCH 30/46] LSP Protocol: Update several interface types --- .../Protocol/IStaticRegistrationOptions.cs | 11 ++++++-- .../Protocol/Protocol/ITextDocumentParams.cs | 13 +++++---- .../Protocol/ITextDocumentPositionParams.cs | 28 +++++++------------ .../ITextDocumentRegistrationOptions.cs | 14 +++++++--- 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/LanguageServer/Protocol/Protocol/IStaticRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/IStaticRegistrationOptions.cs index 52fab2aad3cbd..8a6efa81edca5 100644 --- a/src/LanguageServer/Protocol/Protocol/IStaticRegistrationOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/IStaticRegistrationOptions.cs @@ -2,17 +2,22 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Text.Json.Serialization; + namespace Roslyn.LanguageServer.Protocol; /// /// Interface representing the static registration options for options returned in the initialize request. -/// -/// See the Language Server Protocol specification for additional information. +/// +/// See the Language Server Protocol specification for additional information. +/// /// internal interface IStaticRegistrationOptions { /// - /// Gets or sets the id used to register the request. The id can be used to deregister the request again. + /// Gets or sets the id used to register the request. The id can be used to deregister the request again. /// + [JsonPropertyName("id")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Id { get; set; } } diff --git a/src/LanguageServer/Protocol/Protocol/ITextDocumentParams.cs b/src/LanguageServer/Protocol/Protocol/ITextDocumentParams.cs index 4fa13027b0903..072b1297de8b2 100644 --- a/src/LanguageServer/Protocol/Protocol/ITextDocumentParams.cs +++ b/src/LanguageServer/Protocol/Protocol/ITextDocumentParams.cs @@ -2,19 +2,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Text.Json.Serialization; + namespace Roslyn.LanguageServer.Protocol { /// - /// Interface to identify a text document. + /// Interface for request/notification params that apply to a document /// internal interface ITextDocumentParams { /// - /// Gets or sets the value which identifies the document. + /// The identifier of the document. /// - public TextDocumentIdentifier TextDocument - { - get; - } + [JsonPropertyName("textDocument")] + [JsonRequired] + public TextDocumentIdentifier TextDocument { get; } } } diff --git a/src/LanguageServer/Protocol/Protocol/ITextDocumentPositionParams.cs b/src/LanguageServer/Protocol/Protocol/ITextDocumentPositionParams.cs index 22901df807aa9..5d4cb0509cd47 100644 --- a/src/LanguageServer/Protocol/Protocol/ITextDocumentPositionParams.cs +++ b/src/LanguageServer/Protocol/Protocol/ITextDocumentPositionParams.cs @@ -2,31 +2,23 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Text.Json.Serialization; + namespace Roslyn.LanguageServer.Protocol { /// - /// Interface to identify a text document and a position inside that document. - /// - /// See the Language Server Protocol specification for additional information. + /// Interface for request/notification params that apply to a a position inside a document + /// + /// See the Language Server Protocol specification for additional information. + /// /// internal interface ITextDocumentPositionParams : ITextDocumentParams { /// - /// Gets or sets the value which identifies the document. - /// - public new TextDocumentIdentifier TextDocument - { - get; - set; - } - - /// - /// Gets or sets the value which indicates the position within the document. + /// The position within the document. /// - public Position Position - { - get; - set; - } + [JsonPropertyName("position")] + [JsonRequired] + public Position Position { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/ITextDocumentRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/ITextDocumentRegistrationOptions.cs index b919469dfb16f..d3a6424880b63 100644 --- a/src/LanguageServer/Protocol/Protocol/ITextDocumentRegistrationOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/ITextDocumentRegistrationOptions.cs @@ -2,17 +2,23 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Text.Json.Serialization; + namespace Roslyn.LanguageServer.Protocol; /// -/// Interface representing the text document registration options. -/// -/// See the Language Server Protocol specification for additional information. +/// Interface for registration options that can be scoped to particular text documents. +/// +/// See the Language Server Protocol specification for additional information. +/// /// internal interface ITextDocumentRegistrationOptions { /// - /// Gets or sets the document filters for this registration option. + /// A document selector to identify the scope of the registration. If set to + /// the document selector provided on the client side will be used. /// + [JsonPropertyName("documentSelector")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DocumentFilter[]? DocumentSelector { get; set; } } From 4514769ae2c607cf8e58599e63c72ded8abb25ff Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 16 Jun 2024 21:49:41 -0400 Subject: [PATCH 31/46] LSP Protocol: Add note re. JSON attributes --- src/LanguageServer/Protocol/Protocol/IPartialResultParams.cs | 1 + .../Protocol/Protocol/IStaticRegistrationOptions.cs | 1 + src/LanguageServer/Protocol/Protocol/ITextDocumentParams.cs | 1 + .../Protocol/Protocol/ITextDocumentPositionParams.cs | 1 + .../Protocol/Protocol/ITextDocumentRegistrationOptions.cs | 1 + src/LanguageServer/Protocol/Protocol/IWorkDoneProgressOptions.cs | 1 + src/LanguageServer/Protocol/Protocol/IWorkDoneProgressParams.cs | 1 + 7 files changed, 7 insertions(+) diff --git a/src/LanguageServer/Protocol/Protocol/IPartialResultParams.cs b/src/LanguageServer/Protocol/Protocol/IPartialResultParams.cs index e21b13450804b..61db86ddda7b6 100644 --- a/src/LanguageServer/Protocol/Protocol/IPartialResultParams.cs +++ b/src/LanguageServer/Protocol/Protocol/IPartialResultParams.cs @@ -20,6 +20,7 @@ internal interface IPartialResultParams /// An instance that can be used to report partial results /// via the $/progress notification. /// + // NOTE: these JSON attributes are not inherited, they are here as a reference for implementations [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? PartialResultToken { get; set; } diff --git a/src/LanguageServer/Protocol/Protocol/IStaticRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/IStaticRegistrationOptions.cs index 8a6efa81edca5..4411c446a28ee 100644 --- a/src/LanguageServer/Protocol/Protocol/IStaticRegistrationOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/IStaticRegistrationOptions.cs @@ -17,6 +17,7 @@ internal interface IStaticRegistrationOptions /// /// Gets or sets the id used to register the request. The id can be used to deregister the request again. /// + // NOTE: these JSON attributes are not inherited, they are here as a reference for implementations [JsonPropertyName("id")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Id { get; set; } diff --git a/src/LanguageServer/Protocol/Protocol/ITextDocumentParams.cs b/src/LanguageServer/Protocol/Protocol/ITextDocumentParams.cs index 072b1297de8b2..6f271165befec 100644 --- a/src/LanguageServer/Protocol/Protocol/ITextDocumentParams.cs +++ b/src/LanguageServer/Protocol/Protocol/ITextDocumentParams.cs @@ -14,6 +14,7 @@ internal interface ITextDocumentParams /// /// The identifier of the document. /// + // NOTE: these JSON attributes are not inherited, they are here as a reference for implementations [JsonPropertyName("textDocument")] [JsonRequired] public TextDocumentIdentifier TextDocument { get; } diff --git a/src/LanguageServer/Protocol/Protocol/ITextDocumentPositionParams.cs b/src/LanguageServer/Protocol/Protocol/ITextDocumentPositionParams.cs index 5d4cb0509cd47..a567a5b949ab4 100644 --- a/src/LanguageServer/Protocol/Protocol/ITextDocumentPositionParams.cs +++ b/src/LanguageServer/Protocol/Protocol/ITextDocumentPositionParams.cs @@ -17,6 +17,7 @@ internal interface ITextDocumentPositionParams : ITextDocumentParams /// /// The position within the document. /// + // NOTE: these JSON attributes are not inherited, they are here as a reference for implementations [JsonPropertyName("position")] [JsonRequired] public Position Position { get; set; } diff --git a/src/LanguageServer/Protocol/Protocol/ITextDocumentRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/ITextDocumentRegistrationOptions.cs index d3a6424880b63..22fa3f67e4daf 100644 --- a/src/LanguageServer/Protocol/Protocol/ITextDocumentRegistrationOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/ITextDocumentRegistrationOptions.cs @@ -18,6 +18,7 @@ internal interface ITextDocumentRegistrationOptions /// A document selector to identify the scope of the registration. If set to /// the document selector provided on the client side will be used. /// + // NOTE: these JSON attributes are not inherited, they are here as a reference for implementations [JsonPropertyName("documentSelector")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public DocumentFilter[]? DocumentSelector { get; set; } diff --git a/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressOptions.cs b/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressOptions.cs index d130861d2488d..4dfd193f32bf8 100644 --- a/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressOptions.cs @@ -19,6 +19,7 @@ internal interface IWorkDoneProgressOptions /// /// /// Since LSP 3.15 + // NOTE: these JSON attributes are not inherited, they are here as a reference for implementations [JsonPropertyName("workDoneProgress")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool WorkDoneProgress { get; init; } diff --git a/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressParams.cs b/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressParams.cs index da39f9756df8e..5c315d40f706f 100644 --- a/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressParams.cs +++ b/src/LanguageServer/Protocol/Protocol/IWorkDoneProgressParams.cs @@ -24,6 +24,7 @@ internal interface IWorkDoneProgressParams /// /// /// Since LSP 3.15 + // NOTE: these JSON attributes are not inherited, they are here as a reference for implementations [JsonPropertyName(Methods.WorkDoneTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IProgress? WorkDoneToken { get; set; } From 7dd8c0fa6f8ddaf94f51346a6ea7e30ab7e88df3 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sun, 16 Jun 2024 21:35:16 -0400 Subject: [PATCH 32/46] LSP Protocol: Suppress obsoletion propagation --- .../Protocol/Protocol/DocumentSymbolParams.cs | 8 +++++++- .../Extensions/Converters/VSExtensionUtilities.cs | 2 ++ .../Protocol/Protocol/Extensions/VSSymbolInformation.cs | 5 ++++- src/LanguageServer/Protocol/Protocol/Hover.cs | 2 ++ .../Internal/Converters/VSInternalExtensionUtilities.cs | 2 ++ .../Protocol/Protocol/Internal/VSInternalHover.cs | 2 ++ src/LanguageServer/Protocol/Protocol/Methods.Document.cs | 2 ++ src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs | 2 ++ .../Protocol/Protocol/WorkspaceSymbolParams.cs | 7 ++++++- 9 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/LanguageServer/Protocol/Protocol/DocumentSymbolParams.cs b/src/LanguageServer/Protocol/Protocol/DocumentSymbolParams.cs index 4a4669cfd66c3..25ad0f315d286 100644 --- a/src/LanguageServer/Protocol/Protocol/DocumentSymbolParams.cs +++ b/src/LanguageServer/Protocol/Protocol/DocumentSymbolParams.cs @@ -13,7 +13,11 @@ namespace Roslyn.LanguageServer.Protocol; /// See the Language Server Protocol specification for additional information. /// /// -internal class DocumentSymbolParams : ITextDocumentParams, IWorkDoneProgressParams, IPartialResultParams> +internal class DocumentSymbolParams + : ITextDocumentParams, IWorkDoneProgressParams, +#pragma warning disable CS0618 // SymbolInformation is obsolete but this class is not + IPartialResultParams> +#pragma warning restore CS0618 { /// /// Gets or sets the text document. @@ -33,5 +37,7 @@ public TextDocumentIdentifier TextDocument /// [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] +#pragma warning disable CS0618 // SymbolInformation is obsolete but this property is not public IProgress>? PartialResultToken { get; set; } +#pragma warning restore CS0618 } diff --git a/src/LanguageServer/Protocol/Protocol/Extensions/Converters/VSExtensionUtilities.cs b/src/LanguageServer/Protocol/Protocol/Extensions/Converters/VSExtensionUtilities.cs index 0cd191528ca56..4db11ecf2f68b 100644 --- a/src/LanguageServer/Protocol/Protocol/Extensions/Converters/VSExtensionUtilities.cs +++ b/src/LanguageServer/Protocol/Protocol/Extensions/Converters/VSExtensionUtilities.cs @@ -34,7 +34,9 @@ private static void AddConverters(IList converters) TryAddConverter(); TryAddConverter(); TryAddConverter(); +#pragma warning disable CS0618 // SymbolInformation is obsolete but we need the converter regardless TryAddConverter(); +#pragma warning restore CS0618 TryAddConverter(); void TryAddConverter() diff --git a/src/LanguageServer/Protocol/Protocol/Extensions/VSSymbolInformation.cs b/src/LanguageServer/Protocol/Protocol/Extensions/VSSymbolInformation.cs index 84d77d40b6219..49d524328e2e1 100644 --- a/src/LanguageServer/Protocol/Protocol/Extensions/VSSymbolInformation.cs +++ b/src/LanguageServer/Protocol/Protocol/Extensions/VSSymbolInformation.cs @@ -9,7 +9,10 @@ namespace Roslyn.LanguageServer.Protocol /// /// extends providing additional properties used by Visual Studio. /// - internal class VSSymbolInformation : SymbolInformation + internal class VSSymbolInformation +#pragma warning disable CS0618 // SymbolInformation is obsolete but this class is not (yet) + : SymbolInformation +#pragma warning restore { /// /// Gets or sets the icon associated with the symbol. If specified, this icon is used instead of . diff --git a/src/LanguageServer/Protocol/Protocol/Hover.cs b/src/LanguageServer/Protocol/Protocol/Hover.cs index 82874f9c10149..0f73a4a751d67 100644 --- a/src/LanguageServer/Protocol/Protocol/Hover.cs +++ b/src/LanguageServer/Protocol/Protocol/Hover.cs @@ -19,7 +19,9 @@ internal class Hover /// [JsonPropertyName("contents")] [JsonRequired] +#pragma warning disable CS0618 // MarkedString is obsolete but this property is not public SumType[], MarkupContent> Contents { get; set; } +#pragma warning restore CS0618 /// /// An optional range inside a text document that is used to visualize the applicable diff --git a/src/LanguageServer/Protocol/Protocol/Internal/Converters/VSInternalExtensionUtilities.cs b/src/LanguageServer/Protocol/Protocol/Internal/Converters/VSInternalExtensionUtilities.cs index 15e162c6c13eb..d16f7f7ca20e0 100644 --- a/src/LanguageServer/Protocol/Protocol/Internal/Converters/VSInternalExtensionUtilities.cs +++ b/src/LanguageServer/Protocol/Protocol/Internal/Converters/VSInternalExtensionUtilities.cs @@ -41,7 +41,9 @@ private static void AddConverters(IList converters) AddOrReplaceConverter(); AddOrReplaceConverter(); AddOrReplaceConverter(); +#pragma warning disable CS0618 // SymbolInformation is obsolete but we need the converter regardless AddOrReplaceConverter(); +#pragma warning restore CS0618 AddOrReplaceConverter(); AddOrReplaceConverter(); AddOrReplaceConverter(); diff --git a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs index 44fa7428eb2d4..d7df82cad3c5b 100644 --- a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs +++ b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs @@ -29,6 +29,8 @@ internal class VSInternalHover : Hover /// [JsonPropertyName("contents")] [JsonRequired] +#pragma warning disable CS0618 // MarkedString is obsolete but this property is not public new SumType, SumType[], MarkupContent>? Contents { get; set; } +#pragma warning restore CS0618 } } diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs index 7614db428cf47..cf9ee709397e9 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Document.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Document.cs @@ -144,7 +144,9 @@ partial class Methods /// /// Strongly typed message object for 'textDocument/documentSymbol'. /// +#pragma warning disable CS0618 // SymbolInformation is obsolete but this property is not public static readonly LspRequest?> TextDocumentDocumentSymbol = new(TextDocumentDocumentSymbolName); +#pragma warning restore CS0618 /// /// Method name for 'textDocument/semanticTokens'. diff --git a/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs b/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs index b8e80b72864d7..811c75796666c 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.Workspace.cs @@ -23,7 +23,9 @@ partial class Methods /// /// Strongly typed message object for 'workspace/symbol'. /// +#pragma warning disable CS0618 // SymbolInformation is obsolete but this property is not public static readonly LspRequest?> WorkspaceSymbol = new(WorkspaceSymbolName); +#pragma warning restore CS0618 /// /// Method name for 'workspaceSymbol/resolve'. diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolParams.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolParams.cs index 954760df677dc..aa00f30785f83 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolParams.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceSymbolParams.cs @@ -13,7 +13,10 @@ namespace Roslyn.LanguageServer.Protocol /// See the Language Server Protocol specification for additional information. /// /// - internal class WorkspaceSymbolParams : IPartialResultParams>, IWorkDoneProgressParams + internal class WorkspaceSymbolParams +#pragma warning disable CS0618 // SymbolInformation is obsolete but this class is not + : IPartialResultParams>, IWorkDoneProgressParams +#pragma warning restore CS0618 { /// /// Gets or sets the query (a non-empty string). @@ -25,7 +28,9 @@ internal class WorkspaceSymbolParams : IPartialResultParams [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] +#pragma warning disable CS0618 // SymbolInformation is obsolete but this property is not public IProgress>? PartialResultToken { get; set; } +#pragma warning restore CS0618 /// [JsonPropertyName(Methods.WorkDoneTokenName)] From f349a25d5d8c31b1bac9075c1c4b9e497d62c58a Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Mon, 17 Jun 2024 00:13:34 -0400 Subject: [PATCH 33/46] LanguageServer: Suppress SymbolInformation obsoletion warnings SymbolInformation has been marked as deprecated in the protocol classes, per the current spec. The request handlers need to be updated to use DocumentSymbol/WorkspaceSymbol but this is nontrivial - they currently use a service to create instances of a special subclass of SymbolInformation with VS-specific extensions, and VS doesn't seem to have support for DocumentSymbol/WorkspaceSymbol. --- .../LanguageServer/EditorLspSymbolInformationCreationService.cs | 2 ++ .../Protocol/Handler/Symbols/DocumentSymbolsHandler.cs | 2 ++ .../Handler/Symbols/ILspSymbolInformationCreationService.cs | 2 ++ .../Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/EditorFeatures/Core/LanguageServer/EditorLspSymbolInformationCreationService.cs b/src/EditorFeatures/Core/LanguageServer/EditorLspSymbolInformationCreationService.cs index 63396a1ff96c5..97280faefd86b 100644 --- a/src/EditorFeatures/Core/LanguageServer/EditorLspSymbolInformationCreationService.cs +++ b/src/EditorFeatures/Core/LanguageServer/EditorLspSymbolInformationCreationService.cs @@ -10,6 +10,8 @@ using Roslyn.LanguageServer.Protocol; using LSP = Roslyn.LanguageServer.Protocol; +#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to DocumentSymbol/WorkspaceSymbol + namespace Microsoft.CodeAnalysis.LanguageServer; [ExportWorkspaceService(typeof(ILspSymbolInformationCreationService), ServiceLayer.Editor), Shared] diff --git a/src/LanguageServer/Protocol/Handler/Symbols/DocumentSymbolsHandler.cs b/src/LanguageServer/Protocol/Handler/Symbols/DocumentSymbolsHandler.cs index d9cd5fa1a5768..84d6468b6f24a 100644 --- a/src/LanguageServer/Protocol/Handler/Symbols/DocumentSymbolsHandler.cs +++ b/src/LanguageServer/Protocol/Handler/Symbols/DocumentSymbolsHandler.cs @@ -17,6 +17,8 @@ using Roslyn.Utilities; using LSP = Roslyn.LanguageServer.Protocol; +#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to DocumentSymbol + namespace Microsoft.CodeAnalysis.LanguageServer.Handler { /// diff --git a/src/LanguageServer/Protocol/Handler/Symbols/ILspSymbolInformationCreationService.cs b/src/LanguageServer/Protocol/Handler/Symbols/ILspSymbolInformationCreationService.cs index ebc72add98679..81041a17818d6 100644 --- a/src/LanguageServer/Protocol/Handler/Symbols/ILspSymbolInformationCreationService.cs +++ b/src/LanguageServer/Protocol/Handler/Symbols/ILspSymbolInformationCreationService.cs @@ -9,6 +9,8 @@ using Roslyn.LanguageServer.Protocol; using LSP = Roslyn.LanguageServer.Protocol; +#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to DocumentSymbol/WorkspaceSymbol + namespace Microsoft.CodeAnalysis.LanguageServer.Handler { internal interface ILspSymbolInformationCreationService : IWorkspaceService diff --git a/src/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs b/src/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs index f0ff5255f831b..18bbf2f09a39e 100644 --- a/src/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs +++ b/src/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs @@ -13,6 +13,8 @@ using Roslyn.LanguageServer.Protocol; using Roslyn.Utilities; +#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to WorkspaceSymbol + namespace Microsoft.CodeAnalysis.LanguageServer.Handler { /// From c74acb20e4b051e5bcce1d6e9b1ce1d38fd0b88a Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Tue, 30 Jul 2024 17:02:32 -0400 Subject: [PATCH 34/46] LSP Protocol: Fix issues discovered during usage --- .../Protocol/Protocol/CompletionParams.cs | 7 ++++++- .../Protocol/Protocol/Internal/VSInternalHover.cs | 14 +++++++++++++- .../Protocol/Protocol/ServerCapabilities.cs | 1 + .../Protocol/Protocol/WorkspaceEditSetting.cs | 2 +- .../Protocol/Protocol/WorkspaceFolder.cs | 2 +- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/LanguageServer/Protocol/Protocol/CompletionParams.cs b/src/LanguageServer/Protocol/Protocol/CompletionParams.cs index a0550ecd41e21..52aaf932c6f2f 100644 --- a/src/LanguageServer/Protocol/Protocol/CompletionParams.cs +++ b/src/LanguageServer/Protocol/Protocol/CompletionParams.cs @@ -13,7 +13,7 @@ namespace Roslyn.LanguageServer.Protocol /// See the Language Server Protocol specification for additional information. /// /// - internal class CompletionParams : TextDocumentPositionParams, IPartialResultParams?> + internal class CompletionParams : TextDocumentPositionParams, IPartialResultParams?>, IWorkDoneProgressOptions { /// /// The completion context. This is only available if the client specifies the @@ -35,5 +35,10 @@ public IProgress?>? PartialResultToken get; set; } + + /// + [JsonPropertyName("workDoneProgress")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public bool WorkDoneProgress { get; init; } } } diff --git a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs index d7df82cad3c5b..953115acd7b21 100644 --- a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs +++ b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs @@ -30,7 +30,19 @@ internal class VSInternalHover : Hover [JsonPropertyName("contents")] [JsonRequired] #pragma warning disable CS0618 // MarkedString is obsolete but this property is not - public new SumType, SumType[], MarkupContent>? Contents { get; set; } + public new SumType[], MarkupContent>? Contents { + get => contentsIsNull ? (SumType[], MarkupContent>?)null : base.Contents; + set + { + contentsIsNull = value is null; + if (value is not null) + { + base.Contents = value.Value; + } + } + } + + bool contentsIsNull = false; #pragma warning restore CS0618 } } diff --git a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs index 747a27d78d9b5..d6c950e164745 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerCapabilities.cs @@ -57,6 +57,7 @@ public TextDocumentSyncOptions? TextDocumentSync /// /// Since LSP 3.17 [JsonPropertyName("notebookDocumentSync")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public SumType? NotebookDocumentSync { get; init; } /// diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceEditSetting.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceEditSetting.cs index b913f87fc0d68..9926fbaf0642e 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceEditSetting.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceEditSetting.cs @@ -43,7 +43,7 @@ public ResourceOperationKind[]? ResourceOperations /// Since LSP 3.13 [JsonPropertyName("failureHandling")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public FailureHandlingKind[]? FailureHandling { get; init; } + public FailureHandlingKind? FailureHandling { get; init; } /// /// Whether the client normalizes line endings to the client specific setting diff --git a/src/LanguageServer/Protocol/Protocol/WorkspaceFolder.cs b/src/LanguageServer/Protocol/Protocol/WorkspaceFolder.cs index 8fb025fff24bc..baa62b41407f1 100644 --- a/src/LanguageServer/Protocol/Protocol/WorkspaceFolder.cs +++ b/src/LanguageServer/Protocol/Protocol/WorkspaceFolder.cs @@ -15,7 +15,7 @@ internal class WorkspaceFolder /// The URI for this workspace folder. /// [JsonPropertyName("uri")] - [JsonConverter(typeof(Uri))] + [JsonConverter(typeof(DocumentUriConverter))] [JsonRequired] public Uri Uri { get; init; } From 9f0416636083ab60da3adfd345a859cc5e8cc8d8 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Tue, 30 Jul 2024 20:32:31 -0400 Subject: [PATCH 35/46] LSP Protocol: Track protocol changes in language server --- .../Protocol/Extensions/ProtocolConversions.cs | 2 +- .../Protocol/Handler/BufferedProgress.cs | 12 ++++++++++++ .../Handler/CodeActions/CodeActionResolveHelper.cs | 2 +- .../Protocol/Handler/MapCode/MapCodeHandler.cs | 8 ++++---- .../Handler/References/FindAllReferencesHandler.cs | 10 +++++----- .../Handler/Symbols/WorkspaceSymbolsHandler.cs | 12 ++++++++---- src/LanguageServer/Protocol/Protocol/Diagnostic.cs | 13 ++++++++++++- .../Protocol/Internal/VSInternalReferenceParams.cs | 4 ++-- .../Protocol/Protocol/LocationLink.cs | 8 ++++++++ .../Protocol/Protocol/SymbolInformation.cs | 12 +++++++++++- 10 files changed, 64 insertions(+), 19 deletions(-) diff --git a/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs b/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs index 8a160dc30d3fc..62b0a7692e203 100644 --- a/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs +++ b/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs @@ -453,7 +453,7 @@ public static LSP.Range TextSpanToRange(TextSpan textSpan, SourceText text) } } - var documentEdits = uriToTextEdits.GroupBy(uriAndEdit => uriAndEdit.Uri, uriAndEdit => uriAndEdit.TextEdit, (uri, edits) => new LSP.TextDocumentEdit + var documentEdits = uriToTextEdits.GroupBy(uriAndEdit => uriAndEdit.Uri, uriAndEdit => new LSP.SumType(uriAndEdit.TextEdit), (uri, edits) => new LSP.TextDocumentEdit { TextDocument = new LSP.OptionalVersionedTextDocumentIdentifier { Uri = uri }, Edits = edits.ToArray(), diff --git a/src/LanguageServer/Protocol/Handler/BufferedProgress.cs b/src/LanguageServer/Protocol/Handler/BufferedProgress.cs index efd622a17c73c..2b13dfbae3c75 100644 --- a/src/LanguageServer/Protocol/Handler/BufferedProgress.cs +++ b/src/LanguageServer/Protocol/Handler/BufferedProgress.cs @@ -5,6 +5,7 @@ using System; using System.Linq; using Microsoft.CodeAnalysis.PooledObjects; +using Roslyn.LanguageServer.Protocol; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.LanguageServer.Handler @@ -69,6 +70,12 @@ internal static class BufferedProgress public static BufferedProgress Create(IProgress? progress) => new BufferedProgress(progress); + public static BufferedProgress Create(IProgress? progress, Func transform) + => Create(progress?.Transform(transform)); + + static IProgress Transform(this IProgress progress, Func transform) + => new ProgressTransformer(progress, transform); + public static void Report(this BufferedProgress progress, T item) { progress.Report([item]); @@ -78,5 +85,10 @@ public static void Report(this BufferedProgress progress, T item) { return progress.GetValues()?.Flatten().ToArray(); } + + class ProgressTransformer(IProgress inner, Func transform) : IProgress + { + public void Report(TIn value) => inner.Report(transform(value)); + } } } diff --git a/src/LanguageServer/Protocol/Handler/CodeActions/CodeActionResolveHelper.cs b/src/LanguageServer/Protocol/Handler/CodeActions/CodeActionResolveHelper.cs index 937ceb3901ab8..cec1f54f679ab 100644 --- a/src/LanguageServer/Protocol/Handler/CodeActions/CodeActionResolveHelper.cs +++ b/src/LanguageServer/Protocol/Handler/CodeActions/CodeActionResolveHelper.cs @@ -278,7 +278,7 @@ async Task AddTextDocumentEditsAsync( textChanges = newText.GetTextChanges(oldText); } - var edits = textChanges.Select(tc => ProtocolConversions.TextChangeToTextEdit(tc, oldText)).ToArray(); + var edits = textChanges.Select(tc => new LSP.SumType(ProtocolConversions.TextChangeToTextEdit(tc, oldText))).ToArray(); if (edits.Length > 0) { diff --git a/src/LanguageServer/Protocol/Handler/MapCode/MapCodeHandler.cs b/src/LanguageServer/Protocol/Handler/MapCode/MapCodeHandler.cs index 3967261f2131d..d2ea413a2eec3 100644 --- a/src/LanguageServer/Protocol/Handler/MapCode/MapCodeHandler.cs +++ b/src/LanguageServer/Protocol/Handler/MapCode/MapCodeHandler.cs @@ -42,12 +42,12 @@ public MapCodeHandler() throw new NotImplementedException("mapCode Request failed: additional workspace 'Update' is currently not supported"); } - using var _ = PooledDictionary.GetInstance(out var uriToEditsMap); + using var _ = PooledDictionary.GetInstance(out var uriToEditsMap); foreach (var codeMapping in request.Mappings) { var mappingResult = await MapCodeAsync(codeMapping).ConfigureAwait(false); - if (mappingResult is not (Uri uri, TextEdit[] textEdits)) + if (mappingResult is not (Uri uri, LSP.TextEdit[] textEdits)) { // Failed the entire request if any of the sub-requests failed return null; @@ -65,7 +65,7 @@ public MapCodeHandler() DocumentChanges = uriToEditsMap.Select(kvp => new TextDocumentEdit { TextDocument = new OptionalVersionedTextDocumentIdentifier { Uri = kvp.Key }, - Edits = kvp.Value, + Edits = kvp.Value.Select(v => new SumType(v)).ToArray(), }).ToArray() }; } @@ -77,7 +77,7 @@ public MapCodeHandler() }; } - async Task<(Uri, TextEdit[])?> MapCodeAsync(LSP.VSInternalMapCodeMapping codeMapping) + async Task<(Uri, LSP.TextEdit[])?> MapCodeAsync(LSP.VSInternalMapCodeMapping codeMapping) { var textDocument = codeMapping.TextDocument ?? throw new ArgumentException($"mapCode sub-request failed: MapCodeMapping.TextDocument not expected to be null."); diff --git a/src/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs b/src/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs index bdfdaf086746d..1b23de6749170 100644 --- a/src/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs +++ b/src/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs @@ -22,7 +22,7 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler { [ExportCSharpVisualBasicStatelessLspService(typeof(FindAllReferencesHandler)), Shared] [Method(LSP.Methods.TextDocumentReferencesName)] - internal sealed class FindAllReferencesHandler : ILspServiceDocumentRequestHandler[]?> + internal sealed class FindAllReferencesHandler : ILspServiceDocumentRequestHandler[]?> { private readonly IMetadataAsSourceFileService _metadataAsSourceFileService; private readonly IAsynchronousOperationListener _asyncListener; @@ -43,10 +43,10 @@ public FindAllReferencesHandler( public bool MutatesSolutionState => false; public bool RequiresLSPSolution => true; - public TextDocumentIdentifier GetTextDocumentIdentifier(ReferenceParams request) => request.TextDocument; + public TextDocumentIdentifier GetTextDocumentIdentifier(VSInternalReferenceParams request) => request.TextDocument; - public async Task[]?> HandleRequestAsync( - ReferenceParams referenceParams, + public async Task[]?> HandleRequestAsync( + VSInternalReferenceParams referenceParams, RequestContext context, CancellationToken cancellationToken) { @@ -55,7 +55,7 @@ public FindAllReferencesHandler( Contract.ThrowIfNull(document); Contract.ThrowIfNull(workspace); - using var progress = BufferedProgress.Create[]>(referenceParams.PartialResultToken); + using var progress = BufferedProgress.Create(referenceParams.PartialResultToken); var findUsagesService = document.GetRequiredLanguageService(); var position = await document.GetPositionFromLinePositionAsync( diff --git a/src/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs b/src/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs index 18bbf2f09a39e..4cf33eb4420e8 100644 --- a/src/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs +++ b/src/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Immutable; using System.Composition; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host.Mef; @@ -26,7 +27,7 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler [method: ImportingConstructor] [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] internal sealed class WorkspaceSymbolsHandler(IAsynchronousOperationListenerProvider listenerProvider) - : ILspServiceRequestHandler + : ILspServiceRequestHandler?> { private static readonly IImmutableSet s_supportedKinds = [ NavigateToItemKind.Class, @@ -48,13 +49,16 @@ internal sealed class WorkspaceSymbolsHandler(IAsynchronousOperationListenerProv public bool MutatesSolutionState => false; public bool RequiresLSPSolution => true; - public async Task HandleRequestAsync(WorkspaceSymbolParams request, RequestContext context, CancellationToken cancellationToken) + public async Task?> HandleRequestAsync(WorkspaceSymbolParams request, RequestContext context, CancellationToken cancellationToken) { Contract.ThrowIfNull(context.Solution); var solution = context.Solution; - using var progress = BufferedProgress.Create(request.PartialResultToken); + using var progress = BufferedProgress.Create( + request.PartialResultToken, + (SymbolInformation[] t) => new SumType(t)); + var searcher = NavigateToSearcher.Create( solution, _asyncListener, @@ -64,7 +68,7 @@ internal sealed class WorkspaceSymbolsHandler(IAsynchronousOperationListenerProv cancellationToken); await searcher.SearchAsync(NavigateToSearchScope.Solution, cancellationToken).ConfigureAwait(false); - return progress.GetFlattenedValues(); + return progress.GetValues()?.Flatten().ToArray(); } private sealed class LSPNavigateToCallback( diff --git a/src/LanguageServer/Protocol/Protocol/Diagnostic.cs b/src/LanguageServer/Protocol/Protocol/Diagnostic.cs index bd899f1dcb804..62bde07629785 100644 --- a/src/LanguageServer/Protocol/Protocol/Diagnostic.cs +++ b/src/LanguageServer/Protocol/Protocol/Diagnostic.cs @@ -7,6 +7,7 @@ namespace Roslyn.LanguageServer.Protocol using System; using System.Linq; using System.Text.Json.Serialization; + using Roslyn.Utilities; /// /// Class which represents a source code diagnostic message. @@ -169,6 +170,16 @@ public override bool Equals(object obj) /// public override int GetHashCode() => - HashCode.Combine(Range, Severity, Code, Source, Message, Utilities.Hash.CombineValues(Tags), CodeDescription, Data); +#if NETCOREAPP + HashCode.Combine(Range, Severity, Code, Source, Message, Hash.CombineValues(Tags), CodeDescription, Data); +#else + Hash.Combine(Range, + Hash.Combine((int)(Severity ?? 0), + Hash.Combine(Code?.GetHashCode() ?? 0, + Hash.Combine(Source, + Hash.Combine(Message, + Hash.Combine(Hash.CombineValues(Tags), + Hash.Combine(CodeDescription?.GetHashCode() ?? 0, Data?.GetHashCode() ?? 0))))))); +#endif } } diff --git a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceParams.cs b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceParams.cs index 3c16e2c21afb9..7b5748228994d 100644 --- a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceParams.cs +++ b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalReferenceParams.cs @@ -10,7 +10,7 @@ namespace Roslyn.LanguageServer.Protocol /// /// Class which represents extensions of passed as parameter of find reference requests. /// - internal class VSInternalReferenceParams : ReferenceParams, IPartialResultParams> + internal class VSInternalReferenceParams : ReferenceParams, IPartialResultParams[]> { /// /// Gets or sets a value indicating the scope of returned items. @@ -27,6 +27,6 @@ public VSInternalItemOrigin? Scope /// [JsonPropertyName(Methods.PartialResultTokenName)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public new IProgress>? PartialResultToken { get; set; } + public new IProgress[]>? PartialResultToken { get; set; } } } diff --git a/src/LanguageServer/Protocol/Protocol/LocationLink.cs b/src/LanguageServer/Protocol/Protocol/LocationLink.cs index e3f8738c33629..ebf3df4162440 100644 --- a/src/LanguageServer/Protocol/Protocol/LocationLink.cs +++ b/src/LanguageServer/Protocol/Protocol/LocationLink.cs @@ -6,6 +6,8 @@ using System.Collections.Generic; using System.Text.Json.Serialization; +using Roslyn.Utilities; + namespace Roslyn.LanguageServer.Protocol; /// @@ -67,5 +69,11 @@ public bool Equals(LocationLink? other) => /// public override int GetHashCode() => +#if NETCOREAPP HashCode.Combine(OriginSelectionRange, TargetUri, TargetRange, TargetSelectionRange); +#else + Hash.Combine(OriginSelectionRange, + Hash.Combine(TargetUri, + Hash.Combine(TargetRange, TargetSelectionRange.GetHashCode()))); +#endif } diff --git a/src/LanguageServer/Protocol/Protocol/SymbolInformation.cs b/src/LanguageServer/Protocol/Protocol/SymbolInformation.cs index 12f9676f5e7f7..a53962661039d 100644 --- a/src/LanguageServer/Protocol/Protocol/SymbolInformation.cs +++ b/src/LanguageServer/Protocol/Protocol/SymbolInformation.cs @@ -6,7 +6,9 @@ namespace Roslyn.LanguageServer.Protocol { using System; using System.Collections.Generic; + using System.Linq; using System.Text.Json.Serialization; + using Roslyn.Utilities; /// /// Class representing information about programming constructs like variables, classes, interfaces, etc. @@ -111,6 +113,14 @@ public bool Equals(SymbolInformation? other) /// public override int GetHashCode() => - HashCode.Combine(Name, Kind, Utilities.Hash.CombineValues(Tags), Deprecated, Location, ContainerName); +#if NETCOREAPP + HashCode.Combine(Name, Kind, Hash.CombineValues(Tags), Deprecated, Location, ContainerName); +#else + Hash.Combine(Name, + Hash.Combine((int)Kind, + Hash.Combine(Hash.CombineValues(Tags), + Hash.Combine(Deprecated, + Hash.Combine(ContainerName, Location?.GetHashCode() ?? 0))))); +#endif } } From 2c5e86dff92519da6e6bffd10764c977a78f8aed Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Tue, 13 Aug 2024 23:25:50 -0400 Subject: [PATCH 36/46] LSP Protocol: Track changes in Tests/LSIF/XAML --- .../IResultSetTrackerExtensions.cs | 1 + src/Features/Lsif/GeneratorTest/HoverTests.vb | 6 +-- .../LspFileChangeWatcherTests.cs | 12 ++--- .../FileWatching/LspContractTypes.cs | 48 ------------------- .../FileWatching/LspFileChangeWatcher.cs | 2 +- .../ExampleTests.cs | 2 +- .../Protocol/Protocol/SumType.cs | 15 ++++++ .../CodeActions/CodeActionResolveTests.cs | 16 +++---- ...ngeConfigurationNotificationHandlerTest.cs | 4 +- .../ProtocolUnitTests/Hover/HoverTests.cs | 10 ++-- .../ProtocolUnitTests/MapCode/MapCodeTests.cs | 2 +- .../LspMiscellaneousFilesWorkspaceTests.cs | 2 +- .../ProtocolUnitTests/Rename/RenameTests.cs | 4 +- .../Symbols/WorkspaceSymbolsTests.cs | 6 +-- .../AbstractFormatDocumentHandlerBase.cs | 6 ++- .../Formatting/FormatDocumentOnTypeHandler.cs | 2 +- 16 files changed, 55 insertions(+), 83 deletions(-) delete mode 100644 src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspContractTypes.cs diff --git a/src/Features/Lsif/Generator/ResultSetTracking/IResultSetTrackerExtensions.cs b/src/Features/Lsif/Generator/ResultSetTracking/IResultSetTrackerExtensions.cs index 2f39eae80379d..c2859c74cc92e 100644 --- a/src/Features/Lsif/Generator/ResultSetTracking/IResultSetTrackerExtensions.cs +++ b/src/Features/Lsif/Generator/ResultSetTracking/IResultSetTrackerExtensions.cs @@ -4,6 +4,7 @@ using Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.Graph; using Roslyn.LanguageServer.Protocol; +using Moniker = Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.Graph.Moniker; namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.ResultSetTracking { diff --git a/src/Features/Lsif/GeneratorTest/HoverTests.vb b/src/Features/Lsif/GeneratorTest/HoverTests.vb index 108e3ff2ce181..ea85e9660d473 100644 --- a/src/Features/Lsif/GeneratorTest/HoverTests.vb +++ b/src/Features/Lsif/GeneratorTest/HoverTests.vb @@ -36,7 +36,7 @@ class C Dim rangeVertex = Await lsif.GetSelectedRangeAsync() Dim resultSetVertex = lsif.GetLinkedVertices(Of Graph.ResultSet)(rangeVertex, "next").Single() Dim hoverVertex = lsif.GetLinkedVertices(Of Graph.HoverResult)(resultSetVertex, Methods.TextDocumentHoverName).SingleOrDefault() - Dim hoverMarkupContent = DirectCast(hoverVertex.Result.Contents.Value.Fourth, MarkupContent) + Dim hoverMarkupContent = DirectCast(hoverVertex.Result.Contents.Fourth, MarkupContent) Dim expectedHoverContents As String Select Case code @@ -110,7 +110,7 @@ class C Dim rangeVertex = Await lsif.GetSelectedRangeAsync() Dim resultSetVertex = lsif.GetLinkedVertices(Of Graph.ResultSet)(rangeVertex, "next").Single() Dim hoverVertex = lsif.GetLinkedVertices(Of Graph.HoverResult)(resultSetVertex, Methods.TextDocumentHoverName).SingleOrDefault() - Dim hoverMarkupContent = DirectCast(hoverVertex.Result.Contents.Value.Fourth, MarkupContent) + Dim hoverMarkupContent = DirectCast(hoverVertex.Result.Contents.Fourth, MarkupContent) Dim expectedHoverContents As String Select Case code @@ -196,7 +196,7 @@ void C.M() End If Next - Dim hoverMarkupContent = DirectCast(hoverVertex.Result.Contents.Value.Fourth, MarkupContent) + Dim hoverMarkupContent = DirectCast(hoverVertex.Result.Contents.Fourth, MarkupContent) Assert.Equal(MarkupKind.Markdown, hoverMarkupContent.Kind) Assert.Equal("```csharp class System.String diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs index a87b6604e47f6..a37824219251c 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs @@ -20,7 +20,7 @@ public class LspFileChangeWatcherTests : AbstractLanguageServerHostTests { Workspace = new WorkspaceClientCapabilities { - DidChangeWatchedFiles = new DynamicRegistrationSetting { DynamicRegistration = true } + DidChangeWatchedFiles = new DidChangeWatchedFilesClientCapabilities { DynamicRegistration = true } } }; @@ -66,8 +66,8 @@ public async Task CreatingDirectoryWatchRequestsDirectoryWatch() var watcher = GetSingleFileWatcher(dynamicCapabilitiesRpcTarget); - Assert.Equal(tempDirectory.Path, watcher.GlobPattern.BaseUri.LocalPath); - Assert.Equal("**/*", watcher.GlobPattern.Pattern); + Assert.Equal(tempDirectory.Path, watcher.GlobPattern.Second.BaseUri.First.LocalPath); + Assert.Equal("**/*", watcher.GlobPattern.Second.Pattern); // Get rid of the registration and it should be gone again context.Dispose(); @@ -98,8 +98,8 @@ public async Task CreatingFileWatchRequestsFileWatch() var watcher = GetSingleFileWatcher(dynamicCapabilitiesRpcTarget); - Assert.Equal("Z:\\", watcher.GlobPattern.BaseUri.LocalPath); - Assert.Equal("SingleFile.txt", watcher.GlobPattern.Pattern); + Assert.Equal("Z:\\", watcher.GlobPattern.Second.BaseUri.First.LocalPath); + Assert.Equal("SingleFile.txt", watcher.GlobPattern.Second.Pattern); // Get rid of the registration and it should be gone again watchedFile.Dispose(); @@ -134,7 +134,7 @@ public Task RegisterCapabilityAsync(RegistrationParams registrationParams, Cance } [JsonRpcMethod("client/unregisterCapability", UseSingleObjectParameterDeserialization = true)] - public Task UnregisterCapabilityAsync(UnregistrationParamsWithMisspelling unregistrationParams, CancellationToken _) + public Task UnregisterCapabilityAsync(UnregistrationParams unregistrationParams, CancellationToken _) { foreach (var unregistration in unregistrationParams.Unregistrations) Assert.True(Registrations.TryRemove(unregistration.Id, out var _)); diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspContractTypes.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspContractTypes.cs deleted file mode 100644 index ba53553cc6b9a..0000000000000 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspContractTypes.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Text.Json.Serialization; - -namespace Roslyn.LanguageServer.Protocol; - -internal class DidChangeWatchedFilesRegistrationOptions -{ - [JsonPropertyName("watchers")] - public required FileSystemWatcher[] Watchers { get; set; } -} - -internal class FileSystemWatcher -{ - [JsonPropertyName("globPattern")] - public required RelativePattern GlobPattern { get; set; } - - [JsonPropertyName("kind")] - public WatchKind? Kind { get; set; } -} - -internal class RelativePattern -{ - [JsonPropertyName("baseUri")] - [JsonConverter(typeof(DocumentUriConverter))] - public required Uri BaseUri { get; set; } - - [JsonPropertyName("pattern")] - public required string Pattern { get; set; } -} - -// The LSP specification has a spelling error in the protocol, but Microsoft.VisualStudio.LanguageServer.Protocol -// didn't carry that error along. This corrects that. -internal class UnregistrationParamsWithMisspelling -{ - [JsonPropertyName("unregisterations")] - public required Unregistration[] Unregistrations { get; set; } -} - -[Flags] -internal enum WatchKind -{ - Create = 1, - Change = 2, - Delete = 4 -} diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspFileChangeWatcher.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspFileChangeWatcher.cs index 254707da542a7..f03bd4d88fe76 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspFileChangeWatcher.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspFileChangeWatcher.cs @@ -234,7 +234,7 @@ public void Dispose() _registrationTask.ContinueWith(async _ => { - var unregistrationParams = new UnregistrationParamsWithMisspelling() + var unregistrationParams = new UnregistrationParams() { Unregistrations = [ diff --git a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/ExampleTests.cs b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/ExampleTests.cs index 844c1de5cd591..162faa16bd573 100644 --- a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/ExampleTests.cs +++ b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/ExampleTests.cs @@ -53,7 +53,7 @@ public async Task InitializeServer_SerializesCorrectly() var server = TestExampleLanguageServer.CreateLanguageServer(logger); var result = await server.InitializeServerAsync(); - Assert.True(result.Capabilities.SemanticTokensOptions!.Range!.Value.First); + Assert.True(result.Capabilities.SemanticTokensOptions.Value.Unify().Range!.Value.First); } [Fact] diff --git a/src/LanguageServer/Protocol/Protocol/SumType.cs b/src/LanguageServer/Protocol/Protocol/SumType.cs index 6d656e070a348..ec6100881756d 100644 --- a/src/LanguageServer/Protocol/Protocol/SumType.cs +++ b/src/LanguageServer/Protocol/Protocol/SumType.cs @@ -7,6 +7,7 @@ namespace Roslyn.LanguageServer.Protocol using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; + using System.Linq; using System.Text.Json.Serialization; using Microsoft.CodeAnalysis.LanguageServer; @@ -883,5 +884,19 @@ public static void ValidateTypeParameter(Type type) throw new NotSupportedException(LanguageServerProtocolResources.NestedSumType); } } + + public static TCommon Unify(this SumType sumType) + where TCommon : notnull + where TDerived : notnull, TCommon + => sumType.Match(common => common, derived => derived); + + public static TCommon[] Unify(this SumType sumType) + where TDerived : TCommon + => sumType.Match(common => common, derived => Array.ConvertAll(derived, d => (TCommon)d)); + + public static Dictionary AsUntyped(this Dictionary dictionary) + where TKey : notnull + where TValue : notnull, ISumType + => dictionary.ToDictionary(kvp => kvp.Key, kvp => (object)kvp.Value); } } diff --git a/src/LanguageServer/ProtocolUnitTests/CodeActions/CodeActionResolveTests.cs b/src/LanguageServer/ProtocolUnitTests/CodeActions/CodeActionResolveTests.cs index dc176ebbe4cd8..09b362a39c737 100644 --- a/src/LanguageServer/ProtocolUnitTests/CodeActions/CodeActionResolveTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/CodeActions/CodeActionResolveTests.cs @@ -57,7 +57,7 @@ void M() // var i = 1; // } // } - var expectedTextEdits = new LSP.TextEdit[] + var expectedTextEdits = new SumType[] { GenerateTextEdit("var", new LSP.Range { Start = new Position(4, 8), End = new Position(4, 11) }) }; @@ -112,7 +112,7 @@ void M() // int i = V; // } // } - var expectedTextEdits = new LSP.TextEdit[] + var expectedTextEdits = new SumType[] { GenerateTextEdit(@"private const int V = 1; @@ -230,7 +230,7 @@ public async Task TestLinkedDocuments(bool mutatingLspWorkspace) diagnostics: null); var actualResolvedAction = await RunGetCodeActionResolveAsync(testLspServer, unresolvedCodeAction); - var edits = new TextEdit[] + var edits = new SumType[] { new TextEdit() { @@ -355,7 +355,7 @@ class BCD new TextDocumentEdit() { TextDocument = new OptionalVersionedTextDocumentIdentifier { Uri = newDocumentUri }, - Edits = new TextEdit[] + Edits = new SumType[] { new TextEdit() { @@ -383,7 +383,7 @@ class BCD new TextDocumentEdit() { TextDocument = new OptionalVersionedTextDocumentIdentifier() { Uri = existingDocumentUri }, - Edits = new TextEdit[] + Edits = new SumType[] { new TextEdit() { @@ -482,7 +482,7 @@ class {|caret:BCD|} new TextDocumentEdit() { TextDocument = new OptionalVersionedTextDocumentIdentifier { Uri = newDocumentUri }, - Edits = new TextEdit[] + Edits = new SumType[] { new TextEdit() { @@ -509,7 +509,7 @@ class {|caret:BCD|} new TextDocumentEdit() { TextDocument = new OptionalVersionedTextDocumentIdentifier() { Uri = existingDocumentUri }, - Edits = new TextEdit[] + Edits = new SumType[] { new TextEdit() { @@ -567,7 +567,7 @@ private static LSP.TextEdit GenerateTextEdit(string newText, LSP.Range range) private static WorkspaceEdit GenerateWorkspaceEdit( IList locations, - TextEdit[] edits) + SumType[] edits) => new LSP.WorkspaceEdit { DocumentChanges = new TextDocumentEdit[] diff --git a/src/LanguageServer/ProtocolUnitTests/Configuration/DidChangeConfigurationNotificationHandlerTest.cs b/src/LanguageServer/ProtocolUnitTests/Configuration/DidChangeConfigurationNotificationHandlerTest.cs index 21d93d5e6d634..c11296c58b268 100644 --- a/src/LanguageServer/ProtocolUnitTests/Configuration/DidChangeConfigurationNotificationHandlerTest.cs +++ b/src/LanguageServer/ProtocolUnitTests/Configuration/DidChangeConfigurationNotificationHandlerTest.cs @@ -40,7 +40,7 @@ public class B { }"; { Workspace = new WorkspaceClientCapabilities() { - DidChangeConfiguration = new DynamicRegistrationSetting() { DynamicRegistration = true }, + DidChangeConfiguration = new DidChangeConfigurationClientCapabilities() { DynamicRegistration = true }, Configuration = false } }; @@ -69,7 +69,7 @@ public class A { }"; { Workspace = new WorkspaceClientCapabilities() { - DidChangeConfiguration = new DynamicRegistrationSetting() { DynamicRegistration = true }, + DidChangeConfiguration = new DidChangeConfigurationClientCapabilities() { DynamicRegistration = true }, Configuration = true } }; diff --git a/src/LanguageServer/ProtocolUnitTests/Hover/HoverTests.cs b/src/LanguageServer/ProtocolUnitTests/Hover/HoverTests.cs index 402d309db5426..a9579caff7969 100644 --- a/src/LanguageServer/ProtocolUnitTests/Hover/HoverTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Hover/HoverTests.cs @@ -263,7 +263,7 @@ Remarks are cool too\. var results = await RunGetHoverAsync( testLspServer, expectedLocation).ConfigureAwait(false); - Assert.Equal(expectedMarkdown, results.Contents.Value.Fourth.Value); + Assert.Equal(expectedMarkdown, results.Contents.Fourth.Value); } [Theory, CombinatorialData] @@ -330,7 +330,7 @@ a string var results = await RunGetHoverAsync( testLspServer, expectedLocation).ConfigureAwait(false); - Assert.Equal(expectedText, results.Contents.Value.Fourth.Value); + Assert.Equal(expectedText, results.Contents.Fourth.Value); } [Theory, CombinatorialData] @@ -384,7 +384,7 @@ void A.AMethod(int i) var results = await RunGetHoverAsync( testLspServer, expectedLocation).ConfigureAwait(false); - Assert.Equal(expectedMarkdown, results.Contents.Value.Fourth.Value); + Assert.Equal(expectedMarkdown, results.Contents.Fourth.Value); } [Theory, CombinatorialData] @@ -421,7 +421,7 @@ void A.AMethod(int i) var results = await RunGetHoverAsync( testLspServer, expectedLocation).ConfigureAwait(false); - Assert.Equal(expectedMarkdown, results.Contents.Value.Fourth.Value); + Assert.Equal(expectedMarkdown, results.Contents.Fourth.Value); } [Theory, CombinatorialData, WorkItem("https://github.com/dotnet/vscode-csharp/issues/6577")] @@ -449,7 +449,7 @@ public async Task DoAsync() var results = await RunGetHoverAsync( testLspServer, expectedLocation).ConfigureAwait(false); - Assert.Equal(expectedMarkdown, results.Contents.Value.Fourth.Value); + Assert.Equal(expectedMarkdown, results.Contents.Fourth.Value); } private static async Task RunGetHoverAsync( diff --git a/src/LanguageServer/ProtocolUnitTests/MapCode/MapCodeTests.cs b/src/LanguageServer/ProtocolUnitTests/MapCode/MapCodeTests.cs index bc094576d5ddb..e48b9fdc934f0 100644 --- a/src/LanguageServer/ProtocolUnitTests/MapCode/MapCodeTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/MapCode/MapCodeTests.cs @@ -121,7 +121,7 @@ static void Main(string[] args) var textDocumentEdits = results.DocumentChanges!.Value.First.Single(); Assert.Equal(textDocumentEdits.TextDocument.Uri, mapCodeParams.Mappings.Single().TextDocument!.Uri); - edits = textDocumentEdits.Edits; + edits = textDocumentEdits.Edits.Select(e => e.Unify()).ToArray(); } else { diff --git a/src/LanguageServer/ProtocolUnitTests/Miscellaneous/LspMiscellaneousFilesWorkspaceTests.cs b/src/LanguageServer/ProtocolUnitTests/Miscellaneous/LspMiscellaneousFilesWorkspaceTests.cs index 8374320d9f140..be2a76a84c976 100644 --- a/src/LanguageServer/ProtocolUnitTests/Miscellaneous/LspMiscellaneousFilesWorkspaceTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Miscellaneous/LspMiscellaneousFilesWorkspaceTests.cs @@ -76,7 +76,7 @@ void M() await testLspServer.InsertTextAsync(looseFileUri, (0, 0, source)).ConfigureAwait(false); var caret = new LSP.Location { Range = new() { Start = new(0, 6), End = new(0, 7) }, Uri = looseFileUri }; var hover = await RunGetHoverAsync(testLspServer, caret).ConfigureAwait(false); - Assert.Contains("class A", hover.Contents!.Value.Fourth.Value); + Assert.Contains("class A", hover.Contents.Fourth.Value); await AssertFileInMiscWorkspaceAsync(testLspServer, looseFileUri).ConfigureAwait(false); // Assert that the misc workspace contains the updated document. diff --git a/src/LanguageServer/ProtocolUnitTests/Rename/RenameTests.cs b/src/LanguageServer/ProtocolUnitTests/Rename/RenameTests.cs index 6a7550ab424e0..68c71fadb2528 100644 --- a/src/LanguageServer/ProtocolUnitTests/Rename/RenameTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Rename/RenameTests.cs @@ -182,8 +182,8 @@ void M2() var documentEdit = results.DocumentChanges.Value.First.Single(); Assert.Equal(expectedMappedDocument, documentEdit.TextDocument.Uri); - Assert.Equal(expectedMappedRanges, documentEdit.Edits.Select(edit => edit.Range)); - Assert.True(documentEdit.Edits.All(edit => edit.NewText == renameText)); + Assert.Equal(expectedMappedRanges, documentEdit.Edits.Select(edit => edit.Unify().Range)); + Assert.True(documentEdit.Edits.All(edit => edit.Unify().NewText == renameText)); } private static LSP.RenameParams CreateRenameParams(LSP.Location location, string newName) diff --git a/src/LanguageServer/ProtocolUnitTests/Symbols/WorkspaceSymbolsTests.cs b/src/LanguageServer/ProtocolUnitTests/Symbols/WorkspaceSymbolsTests.cs index 11db567b17042..d5ab8a0cda616 100644 --- a/src/LanguageServer/ProtocolUnitTests/Symbols/WorkspaceSymbolsTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Symbols/WorkspaceSymbolsTests.cs @@ -72,13 +72,13 @@ void M() CreateSymbolInformation(LSP.SymbolKind.Class, "A", testLspServer.GetLocations("class").Single(), Glyph.ClassInternal, GetContainerName(testLspServer.GetCurrentSolution())) }; - using var progress = BufferedProgress.Create(null); + using var progress = BufferedProgress.Create>(null); var results = await RunGetWorkspaceSymbolsAsync(testLspServer, "A", progress).ConfigureAwait(false); Assert.Null(results); - results = progress.GetFlattenedValues(); + results = progress.GetValues()?.SelectMany(v => v.First).ToArray(); AssertSetEquals(expected, results); } @@ -231,7 +231,7 @@ End Class AssertSetEquals(expected, results); } - private static Task RunGetWorkspaceSymbolsAsync(TestLspServer testLspServer, string query, IProgress? progress = null) + private static Task RunGetWorkspaceSymbolsAsync(TestLspServer testLspServer, string query, IProgress>? progress = null) { var request = new LSP.WorkspaceSymbolParams { diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs index 3008dc4545771..0e9a2f63bf7ea 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs @@ -39,7 +39,11 @@ internal abstract class AbstractFormatDocumentHandlerBase ProtocolConversions.TextChangeToTextEdit(change, text))); } diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Formatting/FormatDocumentOnTypeHandler.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Formatting/FormatDocumentOnTypeHandler.cs index b5952b67e4583..a4efbfb0c808a 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Formatting/FormatDocumentOnTypeHandler.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Formatting/FormatDocumentOnTypeHandler.cs @@ -44,7 +44,7 @@ public async Task HandleRequestAsync(DocumentOnTypeFormattingParams if (document != null && formattingService != null) { var position = await document.GetPositionFromLinePositionAsync(ProtocolConversions.PositionToLinePosition(request.Position), cancellationToken).ConfigureAwait(false); - var options = new XamlFormattingOptions { InsertSpaces = request.Options.InsertSpaces, TabSize = request.Options.TabSize, OtherOptions = request.Options.OtherOptions }; + var options = new XamlFormattingOptions { InsertSpaces = request.Options.InsertSpaces, TabSize = request.Options.TabSize, OtherOptions = request.Options.OtherOptions?.AsUntyped() }; var textChanges = await formattingService.GetFormattingChangesAsync(document, options, request.Character[0], position, cancellationToken).ConfigureAwait(false); if (textChanges != null) { From b0eb55d83978347a13762260998f73ddf7e1d322 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Tue, 13 Aug 2024 23:26:57 -0400 Subject: [PATCH 37/46] LSP Protocol: Better obsoletion handling --- ...itorLspSymbolInformationCreationService.cs | 4 ++-- .../AbstractLanguageServerProtocolTests.cs | 2 ++ .../Handler/Symbols/DocumentSymbolsHandler.cs | 4 ++-- .../ILspSymbolInformationCreationService.cs | 4 ++-- .../Symbols/WorkspaceSymbolsHandler.cs | 2 -- .../Protocol/Protocol/MarkedString.cs | 9 ++++++++- .../Notebook/NotebookDocumentFilter.cs | 2 +- .../Protocol/Protocol/SymbolInformation.cs | 19 +++++++++++++++++-- .../Symbols/DocumentSymbolsTests.cs | 7 +++++++ 9 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/EditorFeatures/Core/LanguageServer/EditorLspSymbolInformationCreationService.cs b/src/EditorFeatures/Core/LanguageServer/EditorLspSymbolInformationCreationService.cs index 97280faefd86b..a167a45407070 100644 --- a/src/EditorFeatures/Core/LanguageServer/EditorLspSymbolInformationCreationService.cs +++ b/src/EditorFeatures/Core/LanguageServer/EditorLspSymbolInformationCreationService.cs @@ -10,8 +10,6 @@ using Roslyn.LanguageServer.Protocol; using LSP = Roslyn.LanguageServer.Protocol; -#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to DocumentSymbol/WorkspaceSymbol - namespace Microsoft.CodeAnalysis.LanguageServer; [ExportWorkspaceService(typeof(ILspSymbolInformationCreationService), ServiceLayer.Editor), Shared] @@ -26,6 +24,7 @@ public EditorLspSymbolInformationCreationService() public SymbolInformation Create(string name, string? containerName, LSP.SymbolKind kind, LSP.Location location, Glyph glyph) { var imageId = glyph.GetImageId(); +#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to DocumentSymbol/WorkspaceSymbol return new VSSymbolInformation { Name = name, @@ -34,5 +33,6 @@ public SymbolInformation Create(string name, string? containerName, LSP.SymbolKi Location = location, Icon = new VSImageId { Guid = imageId.Guid, Id = imageId.Id }, }; +#pragma warning restore CS0618 } } diff --git a/src/EditorFeatures/TestUtilities/LanguageServer/AbstractLanguageServerProtocolTests.cs b/src/EditorFeatures/TestUtilities/LanguageServer/AbstractLanguageServerProtocolTests.cs index f27c0a623b30a..764938a38ec41 100644 --- a/src/EditorFeatures/TestUtilities/LanguageServer/AbstractLanguageServerProtocolTests.cs +++ b/src/EditorFeatures/TestUtilities/LanguageServer/AbstractLanguageServerProtocolTests.cs @@ -181,6 +181,7 @@ internal static LSP.SymbolInformation CreateSymbolInformation(LSP.SymbolKind kin { var imageId = glyph.GetImageId(); +#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to DocumentSymbol/WorkspaceSymbol var info = new LSP.VSSymbolInformation() { Kind = kind, @@ -191,6 +192,7 @@ internal static LSP.SymbolInformation CreateSymbolInformation(LSP.SymbolKind kin if (containerName != null) info.ContainerName = containerName; +#pragma warning restore CS0618 return info; } diff --git a/src/LanguageServer/Protocol/Handler/Symbols/DocumentSymbolsHandler.cs b/src/LanguageServer/Protocol/Handler/Symbols/DocumentSymbolsHandler.cs index 84d6468b6f24a..5ebaee74d395b 100644 --- a/src/LanguageServer/Protocol/Handler/Symbols/DocumentSymbolsHandler.cs +++ b/src/LanguageServer/Protocol/Handler/Symbols/DocumentSymbolsHandler.cs @@ -17,8 +17,6 @@ using Roslyn.Utilities; using LSP = Roslyn.LanguageServer.Protocol; -#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to DocumentSymbol - namespace Microsoft.CodeAnalysis.LanguageServer.Handler { /// @@ -120,7 +118,9 @@ public async Task HandleRequestAsync(RoslynDocumentSymbolParams reques Detail = item.Text, Kind = ProtocolConversions.GlyphToSymbolKind(item.Glyph), Glyph = (int)item.Glyph, +#pragma warning disable CS0618 // SymbolInformation.Deprecated is obsolete, use Tags Deprecated = symbolItem.IsObsolete, +#pragma warning restore CS0618 Range = ProtocolConversions.TextSpanToRange(spans.First(), text), SelectionRange = ProtocolConversions.TextSpanToRange(navigationSpan, text), Children = GetChildren(item.ChildItems, text, cancellationToken), diff --git a/src/LanguageServer/Protocol/Handler/Symbols/ILspSymbolInformationCreationService.cs b/src/LanguageServer/Protocol/Handler/Symbols/ILspSymbolInformationCreationService.cs index 81041a17818d6..9eaddbba460a9 100644 --- a/src/LanguageServer/Protocol/Handler/Symbols/ILspSymbolInformationCreationService.cs +++ b/src/LanguageServer/Protocol/Handler/Symbols/ILspSymbolInformationCreationService.cs @@ -9,8 +9,6 @@ using Roslyn.LanguageServer.Protocol; using LSP = Roslyn.LanguageServer.Protocol; -#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to DocumentSymbol/WorkspaceSymbol - namespace Microsoft.CodeAnalysis.LanguageServer.Handler { internal interface ILspSymbolInformationCreationService : IWorkspaceService @@ -30,11 +28,13 @@ public DefaultLspSymbolInformationCreationService() public SymbolInformation Create(string name, string? containerName, LSP.SymbolKind kind, LSP.Location location, Glyph glyph) => new() +#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to DocumentSymbol/WorkspaceSymbol { Name = name, ContainerName = containerName, Kind = kind, Location = location, }; +#pragma warning restore CS0618 } } diff --git a/src/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs b/src/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs index 4cf33eb4420e8..bc07b109bd023 100644 --- a/src/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs +++ b/src/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs @@ -14,8 +14,6 @@ using Roslyn.LanguageServer.Protocol; using Roslyn.Utilities; -#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to WorkspaceSymbol - namespace Microsoft.CodeAnalysis.LanguageServer.Handler { /// diff --git a/src/LanguageServer/Protocol/Protocol/MarkedString.cs b/src/LanguageServer/Protocol/Protocol/MarkedString.cs index 3b878bcb1b941..2e2f8b072067a 100644 --- a/src/LanguageServer/Protocol/Protocol/MarkedString.cs +++ b/src/LanguageServer/Protocol/Protocol/MarkedString.cs @@ -27,14 +27,20 @@ namespace Roslyn.LanguageServer.Protocol /// See the Language Server Protocol specification for additional information. /// /// - [Obsolete("Use MarkupContent instead")] internal class MarkedString { + // Code has to reference MarkedString in a SumType even if it's not using the class itself. + // This means that if we deprecate the type itself, referencing code would have to suppress + // deprecation warnings even if they are only using non-deprecated types. We work around + // by deprecating the members instead of the type itself. + const string DeprecationMessage = "The MarkedString class is deprecated. Use MarkupContent instead."; + /// /// Gets or sets the language of the code stored in . /// [JsonPropertyName("language")] [JsonRequired] + [Obsolete(DeprecationMessage)] public string Language { get; @@ -46,6 +52,7 @@ public string Language /// [JsonPropertyName("value")] [JsonRequired] + [Obsolete(DeprecationMessage)] public string Value { get; diff --git a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentFilter.cs b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentFilter.cs index 23e68b0c90b43..23baade1b6e51 100644 --- a/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentFilter.cs +++ b/src/LanguageServer/Protocol/Protocol/Notebook/NotebookDocumentFilter.cs @@ -25,7 +25,7 @@ internal class NotebookDocumentFilter public string? NotebookType { get; init; } /// - /// A Uri scheme () like file or untitled. + /// A Uri scheme () like file or untitled. /// [JsonPropertyName("scheme")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/LanguageServer/Protocol/Protocol/SymbolInformation.cs b/src/LanguageServer/Protocol/Protocol/SymbolInformation.cs index a53962661039d..5c41e0d6a5135 100644 --- a/src/LanguageServer/Protocol/Protocol/SymbolInformation.cs +++ b/src/LanguageServer/Protocol/Protocol/SymbolInformation.cs @@ -16,13 +16,20 @@ namespace Roslyn.LanguageServer.Protocol /// See the Language Server Protocol specification for additional information. /// /// - [Obsolete("Use DocumentSymbol or WorkspaceSymbol instead")] internal class SymbolInformation : IEquatable { + + // Code has to reference SymbolInformation in a SumType even if it's not using the class itself. + // This means that if we deprecate the type itself, referencing code would have to suppress + // deprecation warnings even if they are only using non-deprecated types. We work around + // by deprecating the members instead of the type itself. + const string DeprecationMessage = "The SymbolInformation class is deprecated. Use DocumentSymbol or WorkspaceSymbol instead."; + /// /// Gets or sets the name of this symbol. /// [JsonPropertyName("name")] + [Obsolete(DeprecationMessage)] public string Name { get; @@ -33,6 +40,7 @@ public string Name /// Gets or sets the of this symbol. /// [JsonPropertyName("kind")] + [Obsolete(DeprecationMessage)] public SymbolKind Kind { get; @@ -45,6 +53,7 @@ public SymbolKind Kind /// Since 3.16 [JsonPropertyName("tags")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [Obsolete(DeprecationMessage)] public SymbolTag[]? Tags { get; init; } /// @@ -52,7 +61,7 @@ public SymbolKind Kind /// [JsonPropertyName("deprecated")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - [Obsolete("Use Tags instead")] + [Obsolete("Use the Tags property instead")] public bool Deprecated { get; init; } /// @@ -69,6 +78,7 @@ public SymbolKind Kind /// /// [JsonPropertyName("location")] + [Obsolete(DeprecationMessage)] public Location Location { get; @@ -85,6 +95,7 @@ public Location Location /// [JsonPropertyName("containerName")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [Obsolete(DeprecationMessage)] public string? ContainerName { get; @@ -100,6 +111,7 @@ public override bool Equals(object obj) /// public bool Equals(SymbolInformation? other) { +#pragma warning disable CS0618 // Type or member is obsolete return other != null && this.Name == other.Name && this.Kind == other.Kind @@ -109,10 +121,12 @@ public bool Equals(SymbolInformation? other) && this.Deprecated == other.Deprecated && EqualityComparer.Default.Equals(this.Location, other.Location) && this.ContainerName == other.ContainerName; +#pragma warning restore CS0618 } /// public override int GetHashCode() => +#pragma warning disable CS0618 // Type or member is obsolete #if NETCOREAPP HashCode.Combine(Name, Kind, Hash.CombineValues(Tags), Deprecated, Location, ContainerName); #else @@ -122,5 +136,6 @@ public override int GetHashCode() => Hash.Combine(Deprecated, Hash.Combine(ContainerName, Location?.GetHashCode() ?? 0))))); #endif +#pragma warning restore CS0618 } } diff --git a/src/LanguageServer/ProtocolUnitTests/Symbols/DocumentSymbolsTests.cs b/src/LanguageServer/ProtocolUnitTests/Symbols/DocumentSymbolsTests.cs index 738c127bcc2be..7792d2308a9cd 100644 --- a/src/LanguageServer/ProtocolUnitTests/Symbols/DocumentSymbolsTests.cs +++ b/src/LanguageServer/ProtocolUnitTests/Symbols/DocumentSymbolsTests.cs @@ -101,7 +101,9 @@ public class await using var testLspServer = await CreateTestLspServerAsync(markup, mutatingLspWorkspace); var results = await RunGetDocumentSymbolsAsync(testLspServer).ConfigureAwait(false); +#pragma warning disable CS0618 // Type or member is obsolete Assert.Equal(".", results.First().Name); +#pragma warning restore CS0618 } [Theory, CombinatorialData] @@ -126,7 +128,10 @@ public class await using var testLspServer = await CreateTestLspServerAsync(markup, mutatingLspWorkspace, clientCapabilities); var results = await RunGetDocumentSymbolsAsync(testLspServer).ConfigureAwait(false); +#pragma warning disable CS0618 // Type or member is obsolete + Assert.Equal(".", results.First().Name); +#pragma warning restore CS0618 } [Theory, CombinatorialData] @@ -172,7 +177,9 @@ private static LSP.DocumentSymbol CreateDocumentSymbol(LSP.SymbolKind kind, stri Range = location.Range, Children = new LSP.DocumentSymbol[0], Detail = detail, +#pragma warning disable 618 // obsolete member Deprecated = false, +#pragma warning restore 618 SelectionRange = selection.Range }; From ef123cc0259729e0cdbc3f5a8d0120b2363a69ad Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Tue, 13 Aug 2024 23:45:23 -0400 Subject: [PATCH 38/46] Update VS Code config --- .vscode/settings.json | 9 ++++++++- .vscode/tasks.json | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2b4dc7d689aeb..1562c2e3a5d1c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -35,5 +35,12 @@ "azure-pipelines.customSchemaFile": ".vscode/dnceng-schema.json", "dotnet.defaultSolution": "Roslyn.sln", "dotnet.completion.showCompletionItemsFromUnimportedNamespaces": true, - "dotnet.testWindow.disableAutoDiscovery": true + "dotnet.testWindow.disableAutoDiscovery": true, + "cSpell.words": [ + "Nerdbank", + "NETCOREAPP", + "Unregistration", + "Unregistrations", + "Xunit" + ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 73dd695a2e492..06cbd516f96d1 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -145,7 +145,7 @@ "build", "-c", "Debug", - "src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Microsoft.CodeAnalysis.LanguageServer.csproj" + "src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Microsoft.CodeAnalysis.LanguageServer.csproj" ], "problemMatcher": "$msCompile", "group": "build" From 813296685ffc42d42a54c71237efa3a6b2ce3dbf Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Wed, 14 Aug 2024 01:12:33 -0400 Subject: [PATCH 39/46] Fix formatting warnings that only appear on CI --- .../Protocol/Protocol/Internal/VSInternalHover.cs | 3 ++- src/LanguageServer/Protocol/Protocol/Moniker/Moniker.cs | 2 +- src/LanguageServer/Protocol/Protocol/ServerInfo.cs | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs index 953115acd7b21..99dba5a0617a4 100644 --- a/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs +++ b/src/LanguageServer/Protocol/Protocol/Internal/VSInternalHover.cs @@ -30,7 +30,8 @@ internal class VSInternalHover : Hover [JsonPropertyName("contents")] [JsonRequired] #pragma warning disable CS0618 // MarkedString is obsolete but this property is not - public new SumType[], MarkupContent>? Contents { + public new SumType[], MarkupContent>? Contents + { get => contentsIsNull ? (SumType[], MarkupContent>?)null : base.Contents; set { diff --git a/src/LanguageServer/Protocol/Protocol/Moniker/Moniker.cs b/src/LanguageServer/Protocol/Protocol/Moniker/Moniker.cs index 120bfdcbb759d..5d2fca4260aad 100644 --- a/src/LanguageServer/Protocol/Protocol/Moniker/Moniker.cs +++ b/src/LanguageServer/Protocol/Protocol/Moniker/Moniker.cs @@ -41,6 +41,6 @@ internal class Moniker /// The moniker kind if known. /// [JsonPropertyName("kind")] - [JsonIgnore(Condition =JsonIgnoreCondition.WhenWritingNull)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public MonikerKind? Kind { get; init; } } diff --git a/src/LanguageServer/Protocol/Protocol/ServerInfo.cs b/src/LanguageServer/Protocol/Protocol/ServerInfo.cs index 1f2deef039f3e..569070d82f696 100644 --- a/src/LanguageServer/Protocol/Protocol/ServerInfo.cs +++ b/src/LanguageServer/Protocol/Protocol/ServerInfo.cs @@ -20,8 +20,6 @@ internal class ServerInfo [JsonRequired] public string Name { get; init; } - - /// /// The server version /// From e68ff7577360545af010eb97a3cd3ee5e4ec4df9 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Wed, 14 Aug 2024 01:12:56 -0400 Subject: [PATCH 40/46] Fix a couple more issues from CI --- .../LanguageServer/AlwaysActivateInProcLanguageClient.cs | 4 ++-- .../ExampleTests.cs | 2 +- .../Protocol/Protocol/Methods.DocumentSynchronization.cs | 5 +++++ .../Handler/Formatting/AbstractFormatDocumentHandlerBase.cs | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/EditorFeatures/Core/LanguageServer/AlwaysActivateInProcLanguageClient.cs b/src/EditorFeatures/Core/LanguageServer/AlwaysActivateInProcLanguageClient.cs index 5337319678531..8bd7fe294313c 100644 --- a/src/EditorFeatures/Core/LanguageServer/AlwaysActivateInProcLanguageClient.cs +++ b/src/EditorFeatures/Core/LanguageServer/AlwaysActivateInProcLanguageClient.cs @@ -70,8 +70,8 @@ public override ServerCapabilities GetCapabilities(ClientCapabilities clientCapa serverCapabilities.SupportsDiagnosticRequests = true; - serverCapabilities.DiagnosticOptions ??= new(); - serverCapabilities.DiagnosticOptions.WorkspaceDiagnostics = true; + var diagnosticOptions = (serverCapabilities.DiagnosticOptions ??= new DiagnosticOptions()); + diagnosticOptions.Unify().WorkspaceDiagnostics = true; serverCapabilities.DiagnosticProvider ??= new(); diff --git a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/ExampleTests.cs b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/ExampleTests.cs index 162faa16bd573..17e859f3a7049 100644 --- a/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/ExampleTests.cs +++ b/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/ExampleTests.cs @@ -53,7 +53,7 @@ public async Task InitializeServer_SerializesCorrectly() var server = TestExampleLanguageServer.CreateLanguageServer(logger); var result = await server.InitializeServerAsync(); - Assert.True(result.Capabilities.SemanticTokensOptions.Value.Unify().Range!.Value.First); + Assert.True(result.Capabilities.SemanticTokensOptions!.Value.Unify().Range!.Value.First); } [Fact] diff --git a/src/LanguageServer/Protocol/Protocol/Methods.DocumentSynchronization.cs b/src/LanguageServer/Protocol/Protocol/Methods.DocumentSynchronization.cs index 37dbffb9a051f..cf3b68c31e35a 100644 --- a/src/LanguageServer/Protocol/Protocol/Methods.DocumentSynchronization.cs +++ b/src/LanguageServer/Protocol/Protocol/Methods.DocumentSynchronization.cs @@ -104,4 +104,9 @@ partial class Methods /// /// public const string TextDocumentDidCloseName = "textDocument/didClose"; + + /// + /// Strongly typed message object for 'textDocument/didSave'. + /// + public static readonly LspNotification TextDocumentDidClose = new(TextDocumentDidCloseName); } diff --git a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs index 0e9a2f63bf7ea..03a1d678ccda8 100644 --- a/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs +++ b/src/VisualStudio/Xaml/Impl/Implementation/LanguageServer/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs @@ -39,7 +39,8 @@ internal abstract class AbstractFormatDocumentHandlerBase Date: Wed, 14 Aug 2024 23:25:28 -0400 Subject: [PATCH 41/46] LSP Protocol: fix FormattingOptions.OtherOptions serialization --- ...anguageServerProtocolResources.Designer.cs | 33 ++++ .../LanguageServerProtocolResources.resx | 9 ++ .../Converters/FormattingOptionsConverter.cs | 147 ++++++++++++++++++ .../Protocol/Protocol/FormattingOptions.cs | 3 + .../LanguageServerProtocolResources.cs.xlf | 15 ++ .../LanguageServerProtocolResources.de.xlf | 15 ++ .../LanguageServerProtocolResources.es.xlf | 15 ++ .../LanguageServerProtocolResources.fr.xlf | 15 ++ .../LanguageServerProtocolResources.it.xlf | 15 ++ .../LanguageServerProtocolResources.ja.xlf | 15 ++ .../LanguageServerProtocolResources.ko.xlf | 15 ++ .../LanguageServerProtocolResources.pl.xlf | 15 ++ .../LanguageServerProtocolResources.pt-BR.xlf | 15 ++ .../LanguageServerProtocolResources.ru.xlf | 15 ++ .../LanguageServerProtocolResources.tr.xlf | 15 ++ ...anguageServerProtocolResources.zh-Hans.xlf | 15 ++ ...anguageServerProtocolResources.zh-Hant.xlf | 15 ++ 17 files changed, 387 insertions(+) create mode 100644 src/LanguageServer/Protocol/Protocol/Converters/FormattingOptionsConverter.cs diff --git a/src/LanguageServer/Protocol/LanguageServerProtocolResources.Designer.cs b/src/LanguageServer/Protocol/LanguageServerProtocolResources.Designer.cs index 3497173ee3129..43d11a5dc023f 100644 --- a/src/LanguageServer/Protocol/LanguageServerProtocolResources.Designer.cs +++ b/src/LanguageServer/Protocol/LanguageServerProtocolResources.Designer.cs @@ -122,5 +122,38 @@ internal static string TextDocumentSyncSerializationError { return ResourceManager.GetString("TextDocumentSyncSerializationError", resourceCulture); } } + + /// + /// Looks up a localized string similar to Unable to deserialize FormattingOptions. Invalid token: {0}. + /// + internal static string FormattingOptionsEncounteredInvalidToken + { + get + { + return ResourceManager.GetString("FormattingOptionsEncounteredInvalidToken", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unable to deserialize FormattingOptions as it ended unexpectedly. + /// + internal static string FormattingOptionsEndedUnexpectedly + { + get + { + return ResourceManager.GetString("FormattingOptionsEndedUnexpectedly", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unable to deserialize FormattingOptions. Missing required property: {0}. + /// + internal static string FormattingOptionsMissingRequiredProperty + { + get + { + return ResourceManager.GetString("FormattingOptionsMissingRequiredProperty", resourceCulture); + } + } } } diff --git a/src/LanguageServer/Protocol/LanguageServerProtocolResources.resx b/src/LanguageServer/Protocol/LanguageServerProtocolResources.resx index 7dc4d9c00c182..b644ddb0186f8 100644 --- a/src/LanguageServer/Protocol/LanguageServerProtocolResources.resx +++ b/src/LanguageServer/Protocol/LanguageServerProtocolResources.resx @@ -101,6 +101,15 @@ Unable to deserialize Uri. Unexpected value encountered: {0} + + Unable to deserialize FormattingOptions. Invalid token: {0} + + + Unable to deserialize FormattingOptions as it ended unexpectedly + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize MarkupContent. Unexpected value encountered: {0} diff --git a/src/LanguageServer/Protocol/Protocol/Converters/FormattingOptionsConverter.cs b/src/LanguageServer/Protocol/Protocol/Converters/FormattingOptionsConverter.cs new file mode 100644 index 0000000000000..63439d0ae5b64 --- /dev/null +++ b/src/LanguageServer/Protocol/Protocol/Converters/FormattingOptionsConverter.cs @@ -0,0 +1,147 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; +using Microsoft.CodeAnalysis.LanguageServer; + +namespace Roslyn.LanguageServer.Protocol; + +/// Enables the FormattingOptions.OtherOptions JsonExtensionData to be strongly typed +internal class FormattingOptionsConverter : JsonConverter +{ + public override FormattingOptions? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var result = new FormattingOptions(); + + Debug.Assert(reader.TokenType == JsonTokenType.StartObject); + + static void ReadSkippingComments(ref Utf8JsonReader reader) + { + do + { + if (!reader.Read()) + { + throw new JsonException(LanguageServerProtocolResources.FormattingOptionsEndedUnexpectedly); + } + } + while (reader.TokenType == JsonTokenType.Comment); + } + + [DoesNotReturn] + static T ThrowMissingRequiredProperty(string propertyName) + { + throw new JsonException(string.Format(CultureInfo.InvariantCulture, LanguageServerProtocolResources.FormattingOptionsMissingRequiredProperty, propertyName)); + } + + int? tabSize = null; + bool? insertSpaces = null; + bool trimTrailingWhitespace = false; + bool insertFinalNewline = false; + bool trimFinalNewlines = false; + Dictionary>? otherOptions = null; + + while (true) + { + ReadSkippingComments(ref reader); + + if (reader.TokenType == JsonTokenType.EndObject) + { + return new FormattingOptions + { + TabSize = tabSize ?? ThrowMissingRequiredProperty(nameof(tabSize)), + InsertSpaces = insertSpaces ?? ThrowMissingRequiredProperty(nameof(insertSpaces)), + TrimTrailingWhitespace = trimTrailingWhitespace, + InsertFinalNewline = insertFinalNewline, + TrimFinalNewlines = trimFinalNewlines, + OtherOptions = otherOptions + }; + } + + if (reader.TokenType == JsonTokenType.Comment) + { + continue; + } + + if (reader.TokenType != JsonTokenType.PropertyName) + { + throw new JsonException(string.Format(CultureInfo.InvariantCulture, LanguageServerProtocolResources.FormattingOptionsEncounteredInvalidToken, reader.TokenType)); + } + + var propertyName = reader.GetString(); + + ReadSkippingComments(ref reader); + + switch (propertyName) + { + case nameof(tabSize): + tabSize = reader.GetInt32(); + continue; + case nameof(insertSpaces): + insertSpaces = reader.GetBoolean(); + continue; + case nameof(trimTrailingWhitespace): + trimTrailingWhitespace = reader.GetBoolean(); + continue; + case nameof(insertFinalNewline): + insertFinalNewline = reader.GetBoolean(); + continue; + case nameof(trimFinalNewlines): + trimFinalNewlines = reader.GetBoolean(); + continue; + default: + break; + } + + SumType value = reader.TokenType switch + { + JsonTokenType.Number => reader.GetInt32(), + JsonTokenType.String => reader.GetString(), + JsonTokenType.True => reader.GetBoolean(), + JsonTokenType.False => reader.GetBoolean(), + _ => throw new JsonException(string.Format(CultureInfo.InvariantCulture, LanguageServerProtocolResources.FormattingOptionsEncounteredInvalidToken, reader.TokenType)) + }; + + (otherOptions ??= []).Add(propertyName, value); + } + } + + public override void Write(Utf8JsonWriter writer, FormattingOptions value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + writer.WriteNumber("tabSize", value.TabSize); + writer.WriteBoolean("insertSpaces", value.InsertSpaces); + + if (value.TrimTrailingWhitespace != default) + { + writer.WriteBoolean("trimTrailingWhitespace", value.TrimTrailingWhitespace); + } + + if (value.InsertFinalNewline != default) + { + writer.WriteBoolean("insertFinalNewline", value.InsertFinalNewline); + } + + if (value.TrimFinalNewlines != default) + { + writer.WriteBoolean("trimFinalNewlines", value.TrimFinalNewlines); + } + + if (value.OtherOptions is not null) + { + foreach (var item in value.OtherOptions) + { + writer.WritePropertyName(item.Key); + JsonSerializer.Serialize(writer, item.Value, options); + } + } + + writer.WriteEndObject(); + } +} diff --git a/src/LanguageServer/Protocol/Protocol/FormattingOptions.cs b/src/LanguageServer/Protocol/Protocol/FormattingOptions.cs index c8f5b5e36f8d5..aec4268abece8 100644 --- a/src/LanguageServer/Protocol/Protocol/FormattingOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/FormattingOptions.cs @@ -13,6 +13,9 @@ namespace Roslyn.LanguageServer.Protocol /// See the Language Server Protocol specification for additional information. /// /// + // NOTE: The FormattingOptionsConverter enables the FormattingOptions.OtherOptions JsonExtensionData to be strongly typed. + // The Json* attributes on the members are for reference only - the converter is fully custom and ignores them. + [JsonConverter(typeof(FormattingOptionsConverter))] internal class FormattingOptions { /// diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.cs.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.cs.xlf index c1e6b6b4e7cac..c47c1b32c70f3 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.cs.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.cs.xlf @@ -7,6 +7,21 @@ Nejde deserializovat identifikátor Uri. Zjistila se neočekávaná hodnota: {0}. + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} Nejde deserializovat MarkupContent. Zjistila se neočekávaná hodnota: {0}. diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.de.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.de.xlf index 45a9a5ba4eb17..a53ede252ea69 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.de.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.de.xlf @@ -7,6 +7,21 @@ URI kann nicht deserialisiert werden kann. Unerwarteter Wert erkannt: {0} + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} MarkupContent kann nicht deserialisiert werden. Unerwarteter Wert erkannt: {0} diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.es.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.es.xlf index 7d5de84cbca99..c15618b613a02 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.es.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.es.xlf @@ -7,6 +7,21 @@ No se puede deserializar el URI. Se encontró un valor inesperado: {0} + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} No se puede deserializar MarkupContent. Se encontró un valor inesperado: {0} diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.fr.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.fr.xlf index b7736960fab22..857632098575f 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.fr.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.fr.xlf @@ -7,6 +7,21 @@ Impossible de désérialiser l'URI. Valeur inattendue rencontrée : {0} + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} Impossible de désérialiser MarkupContent. Valeur inattendue rencontrée : {0} diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.it.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.it.xlf index 535ef4ddfaf44..01330db80711b 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.it.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.it.xlf @@ -7,6 +7,21 @@ Non è possibile deserializzare Uri. È stato rilevato il valore imprevisto {0} + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} Non è possibile deserializzare MarkupContent. È stato rilevato il valore imprevisto {0} diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.ja.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.ja.xlf index 41a6348a60e4b..89efb2f358b63 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.ja.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.ja.xlf @@ -7,6 +7,21 @@ URI を逆シリアル化できません。予期しない値が発生しました: {0} + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} MarkupContent を逆シリアル化できません。予期しない値が発生しました: {0} diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.ko.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.ko.xlf index 73b4b9378652b..551dccb164487 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.ko.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.ko.xlf @@ -7,6 +7,21 @@ URI를 역직렬화할 수 없습니다. 예기치 않은 값 {0}이(가) 있습니다. + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} MarkupContent를 역직렬화할 수 없습니다. 예기치 않은 값 {0}이(가) 있습니다. diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.pl.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.pl.xlf index 5b943fd3b2952..2008e1e8e73ee 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.pl.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.pl.xlf @@ -7,6 +7,21 @@ Nie można zdeserializować identyfikatora Uri. Napotkano nieoczekiwaną wartość: {0} + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} Nie można zdeserializować elementu MarkupContent. Napotkano nieoczekiwaną wartość: {0} diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.pt-BR.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.pt-BR.xlf index 6ce3cec3aa0e9..dd8c02b8a9ba4 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.pt-BR.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.pt-BR.xlf @@ -7,6 +7,21 @@ Não é possível desserializar o Uri. Valor inesperado encontrado: {0} + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} Não é possível desserializar MarkupContent. Valor inesperado encontrado: {0} diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.ru.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.ru.xlf index 023bfe80b89d5..044be3dc3212b 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.ru.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.ru.xlf @@ -7,6 +7,21 @@ Не удалось десериализовать URI. Возникло непредвиденное значение: {0} + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} Не удалось десериализовать MarkupContent. Возникло непредвиденное значение: {0} diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.tr.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.tr.xlf index c2ec945623cea..9d41e59818118 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.tr.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.tr.xlf @@ -7,6 +7,21 @@ URI seri durumdan çıkarılamıyor. Beklenmeyen değerle karşılaşıldı: {0} + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} MarkupContent seri durumdan çıkarılamıyor. Beklenmeyen değerle karşılaşıldı: {0} diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.zh-Hans.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.zh-Hans.xlf index 12cd37c21ed35..9b7cfafe1a251 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.zh-Hans.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.zh-Hans.xlf @@ -7,6 +7,21 @@ 无法反序列化 URI。出现意外值: {0} + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} 无法反序列化 MarkupContent。出现意外值: {0} diff --git a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.zh-Hant.xlf b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.zh-Hant.xlf index f050d702caef7..86709c83cd70c 100644 --- a/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.zh-Hant.xlf +++ b/src/LanguageServer/Protocol/xlf/LanguageServerProtocolResources.zh-Hant.xlf @@ -7,6 +7,21 @@ 無法將 URI 還原序列化。發現非預期的值: {0} + + Unable to deserialize FormattingOptions. Invalid token: {0} + Unable to deserialize FormattingOptions. Invalid token: {0} + + + + Unable to deserialize FormattingOptions as it ended unexpectedly + Unable to deserialize FormattingOptions as it ended unexpectedly + + + + Unable to deserialize FormattingOptions. Missing required property: {0} + Unable to deserialize FormattingOptions. Missing required property: {0} + + Unable to deserialize MarkupContent. Unexpected value encountered: {0} 無法將 MarkupContent 還原序列化。發現非預期的值: {0} From 3adb76d641c85cc6480d50fc8075d050db70f58d Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Thu, 15 Aug 2024 00:37:36 -0400 Subject: [PATCH 42/46] LSP Protocol: Fix some serialization errors --- .../OptimizedVSCompletionListJsonConverter.cs | 15 +++------------ .../Protocol/UnchangedDocumentDiagnosticReport.cs | 1 - 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/LanguageServer/Protocol/Protocol/Internal/Efficiency/OptimizedVSCompletionListJsonConverter.cs b/src/LanguageServer/Protocol/Protocol/Internal/Efficiency/OptimizedVSCompletionListJsonConverter.cs index 5288dde922493..7f46d8dd8ed51 100644 --- a/src/LanguageServer/Protocol/Protocol/Internal/Efficiency/OptimizedVSCompletionListJsonConverter.cs +++ b/src/LanguageServer/Protocol/Protocol/Internal/Efficiency/OptimizedVSCompletionListJsonConverter.cs @@ -57,14 +57,8 @@ public override void Write(Utf8JsonWriter writer, OptimizedVSCompletionList valu JsonSerializer.Serialize(writer, completionList.CommitCharacters, options); } - if (completionList.IsIncomplete) - { - writer.WriteBoolean("isIncomplete", completionList.IsIncomplete); - } - else - { - // Default is "false" so no need to serialize - } + // this is a required property per the LSP spec + writer.WriteBoolean("isIncomplete", completionList.IsIncomplete); writer.WritePropertyName("items"); if (completionList.Items == null || completionList.Items.Length == 0) @@ -154,10 +148,7 @@ private static void WriteCompletionItem(Utf8JsonWriter writer, CompletionItem co } var label = completionItem.Label; - if (label != null) - { - writer.WriteString("label", label); - } + writer.WriteString("label", label); if (completionItem.LabelDetails != null) { diff --git a/src/LanguageServer/Protocol/Protocol/UnchangedDocumentDiagnosticReport.cs b/src/LanguageServer/Protocol/Protocol/UnchangedDocumentDiagnosticReport.cs index f99d560b1b687..3457581ccbc33 100644 --- a/src/LanguageServer/Protocol/Protocol/UnchangedDocumentDiagnosticReport.cs +++ b/src/LanguageServer/Protocol/Protocol/UnchangedDocumentDiagnosticReport.cs @@ -21,7 +21,6 @@ internal class UnchangedDocumentDiagnosticReport /// Gets the kind of this report. /// [JsonPropertyName("kind")] - [JsonRequired] #pragma warning disable CA1822 // Mark members as static public string Kind => DocumentDiagnosticReportKind.Unchanged; #pragma warning restore CA1822 // Mark members as static From 1b59c823f96e43db1396b620d463842806df40b2 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Thu, 15 Aug 2024 22:52:08 -0400 Subject: [PATCH 43/46] LSP Protocol: fix more CI failures --- src/Features/Lsif/GeneratorTest/OutputFormatTests.vb | 3 ++- src/Features/Lsif/GeneratorTest/SemanticTokensTests.vb | 6 +++--- .../ExternalAccess/Razor/Cohost/Handlers/DocumentSymbols.cs | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Features/Lsif/GeneratorTest/OutputFormatTests.vb b/src/Features/Lsif/GeneratorTest/OutputFormatTests.vb index 5b01bbd5725c8..bf8c20bd1e9ba 100644 --- a/src/Features/Lsif/GeneratorTest/OutputFormatTests.vb +++ b/src/Features/Lsif/GeneratorTest/OutputFormatTests.vb @@ -27,7 +27,7 @@ Namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.UnitTests , openDocuments:=False, composition:=TestLsifOutput.TestComposition), jsonWriter) AssertEx.EqualOrDiff( -"{""hoverProvider"":true,""declarationProvider"":false,""definitionProvider"":true,""referencesProvider"":true,""typeDefinitionProvider"":false,""documentSymbolProvider"":true,""foldingRangeProvider"":true,""diagnosticProvider"":false,""semanticTokensProvider"":{""tokenTypes"":[""namespace"",""type"",""class"",""enum"",""interface"",""struct"",""typeParameter"",""parameter"",""variable"",""property"",""enumMember"",""event"",""function"",""method"",""macro"",""keyword"",""modifier"",""comment"",""string"",""number"",""regexp"",""operator"",""class name"",""constant name"",""delegate name"",""enum member name"",""enum name"",""event name"",""excluded code"",""extension method name"",""field name"",""interface name"",""json - array"",""json - comment"",""json - constructor name"",""json - keyword"",""json - number"",""json - object"",""json - operator"",""json - property name"",""json - punctuation"",""json - string"",""json - text"",""keyword - control"",""label name"",""local name"",""method name"",""module name"",""namespace name"",""operator - overloaded"",""parameter name"",""preprocessor keyword"",""preprocessor text"",""property name"",""punctuation"",""record class name"",""record struct name"",""regex - alternation"",""regex - anchor"",""regex - character class"",""regex - comment"",""regex - grouping"",""regex - other escape"",""regex - quantifier"",""regex - self escaped character"",""regex - text"",""roslyn test code markdown"",""string - escape character"",""string - verbatim"",""struct name"",""text"",""type parameter name"",""whitespace"",""xml doc comment - attribute name"",""xml doc comment - attribute quotes"",""xml doc comment - attribute value"",""xml doc comment - cdata section"",""xml doc comment - comment"",""xml doc comment - delimiter"",""xml doc comment - entity reference"",""xml doc comment - name"",""xml doc comment - processing instruction"",""xml doc comment - text"",""xml literal - attribute name"",""xml literal - attribute quotes"",""xml literal - attribute value"",""xml literal - cdata section"",""xml literal - comment"",""xml literal - delimiter"",""xml literal - embedded expression"",""xml literal - entity reference"",""xml literal - name"",""xml literal - processing instruction"",""xml literal - text""],""tokenModifiers"":[""static"",""deprecated""]},""id"":1,""type"":""vertex"",""label"":""capabilities""} +"{""hoverProvider"":true,""declarationProvider"":false,""definitionProvider"":true,""referencesProvider"":true,""typeDefinitionProvider"":false,""documentSymbolProvider"":true,""foldingRangeProvider"":true,""diagnosticProvider"":false,""semanticTokensProvider"":{""tokenTypes"":[""namespace"",""type"",""class"",""enum"",""interface"",""struct"",""typeParameter"",""parameter"",""variable"",""property"",""enumMember"",""event"",""function"",""method"",""macro"",""keyword"",""modifier"",""comment"",""string"",""number"",""regexp"",""operator"",""decorator"",""class name"",""constant name"",""delegate name"",""enum member name"",""enum name"",""event name"",""excluded code"",""extension method name"",""field name"",""interface name"",""json - array"",""json - comment"",""json - constructor name"",""json - keyword"",""json - number"",""json - object"",""json - operator"",""json - property name"",""json - punctuation"",""json - string"",""json - text"",""keyword - control"",""label name"",""local name"",""method name"",""module name"",""namespace name"",""operator - overloaded"",""parameter name"",""preprocessor keyword"",""preprocessor text"",""property name"",""punctuation"",""record class name"",""record struct name"",""regex - alternation"",""regex - anchor"",""regex - character class"",""regex - comment"",""regex - grouping"",""regex - other escape"",""regex - quantifier"",""regex - self escaped character"",""regex - text"",""roslyn test code markdown"",""string - escape character"",""string - verbatim"",""struct name"",""text"",""type parameter name"",""whitespace"",""xml doc comment - attribute name"",""xml doc comment - attribute quotes"",""xml doc comment - attribute value"",""xml doc comment - cdata section"",""xml doc comment - comment"",""xml doc comment - delimiter"",""xml doc comment - entity reference"",""xml doc comment - name"",""xml doc comment - processing instruction"",""xml doc comment - text"",""xml literal - attribute name"",""xml literal - attribute quotes"",""xml literal - attribute value"",""xml literal - cdata section"",""xml literal - comment"",""xml literal - delimiter"",""xml literal - embedded expression"",""xml literal - entity reference"",""xml literal - name"",""xml literal - processing instruction"",""xml literal - text""],""tokenModifiers"":[""static"",""deprecated""]},""id"":1,""type"":""vertex"",""label"":""capabilities""} {""kind"":""csharp"",""resource"":""file:///Z:/%EE%89%9B/TestProject.csproj"",""name"":""TestProject"",""id"":2,""type"":""vertex"",""label"":""project""} {""kind"":""begin"",""scope"":""project"",""data"":2,""id"":3,""type"":""vertex"",""label"":""$event""} {""uri"":""file:///Z:/%EE%89%9B/a.cs"",""languageId"":""csharp"",""id"":4,""type"":""vertex"",""label"":""document""} @@ -94,6 +94,7 @@ Namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.UnitTests ""number"", ""regexp"", ""operator"", + ""decorator"", ""class name"", ""constant name"", ""delegate name"", diff --git a/src/Features/Lsif/GeneratorTest/SemanticTokensTests.vb b/src/Features/Lsif/GeneratorTest/SemanticTokensTests.vb index ce1bdcd6704e8..145ebc6daa135 100644 --- a/src/Features/Lsif/GeneratorTest/SemanticTokensTests.vb +++ b/src/Features/Lsif/GeneratorTest/SemanticTokensTests.vb @@ -16,9 +16,9 @@ Namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.UnitTests - - - + + + Public Async Function TestSemanticTokensData(code As String, expectedTokens As String) As Task ' This test performs LSIF specific validation of the semantic tokens output. As of this writing ' this feature is based on the same code path used to generate semantic tokens information in LSP diff --git a/src/Tools/ExternalAccess/Razor/Cohost/Handlers/DocumentSymbols.cs b/src/Tools/ExternalAccess/Razor/Cohost/Handlers/DocumentSymbols.cs index 2eca8ba10d16d..7a36b5d47c0f2 100644 --- a/src/Tools/ExternalAccess/Razor/Cohost/Handlers/DocumentSymbols.cs +++ b/src/Tools/ExternalAccess/Razor/Cohost/Handlers/DocumentSymbols.cs @@ -26,6 +26,7 @@ private sealed class RazorLspSymbolInformationCreationService : ILspSymbolInform public static readonly RazorLspSymbolInformationCreationService Instance = new(); public SymbolInformation Create(string name, string? containerName, LSP.SymbolKind kind, LSP.Location location, Glyph glyph) +#pragma warning disable CS0618 // SymbolInformation is obsolete => new() { Name = name, @@ -33,5 +34,6 @@ public SymbolInformation Create(string name, string? containerName, LSP.SymbolKi Kind = kind, Location = location, }; +#pragma warning restore CS0618 } } From 1f801810fd56851a0454d6f709c7d9fcf2aeaf70 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Sat, 17 Aug 2024 13:19:34 -0400 Subject: [PATCH 44/46] LSP Protocol: Fix another couple serialization errors System.Text.Json doesn't respect DefaultValueAttribute --- .../DidChangeWatchedFilesRegistrationOptions.cs | 4 ++-- .../Protocol/Protocol/FileOperations/FileSystemWatcher.cs | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesRegistrationOptions.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesRegistrationOptions.cs index 381638544a752..6747cb4a7a0f4 100644 --- a/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesRegistrationOptions.cs +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/DidChangeWatchedFilesRegistrationOptions.cs @@ -18,7 +18,7 @@ internal class DidChangeWatchedFilesRegistrationOptions : DynamicRegistrationSet /// The watchers to register. /// /// Since LSP 3.17 - [JsonPropertyName("relativePatternSupport")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [JsonPropertyName("watchers")] + [JsonRequired] public FileSystemWatcher[] Watchers { get; init; } } diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/FileSystemWatcher.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/FileSystemWatcher.cs index 7557bcc57097a..0fba2560eadfe 100644 --- a/src/LanguageServer/Protocol/Protocol/FileOperations/FileSystemWatcher.cs +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/FileSystemWatcher.cs @@ -31,7 +31,6 @@ internal class FileSystemWatcher /// which is 7. /// [JsonPropertyName("kind")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - [DefaultValue(WatchKind.Create | WatchKind.Change | WatchKind.Delete)] - public WatchKind Kind { get; init; } = WatchKind.Create | WatchKind.Change | WatchKind.Delete; + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public WatchKind? Kind { get; init; } } From e89c40205b5c141830477553561302f4eadec99c Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Mon, 19 Aug 2024 14:02:19 -0400 Subject: [PATCH 45/46] LSP Protocol: Support Uri in SumType --- .../LspFileChangeWatcherTests.cs | 4 ++-- .../Protocol/Protocol/Converters/SumConverter.cs | 11 ++++++++++- .../Protocol/FileOperations/RelativePattern.cs | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs index 3aa3bea65e1a2..41fe21c197552 100644 --- a/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs +++ b/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs @@ -66,7 +66,7 @@ public async Task CreatingDirectoryWatchRequestsDirectoryWatch() var watcher = GetSingleFileWatcher(dynamicCapabilitiesRpcTarget); - Assert.Equal(tempDirectory.Path, watcher.GlobPattern.Second.BaseUri.First.LocalPath); + Assert.Equal(tempDirectory.Path, watcher.GlobPattern.Second.BaseUri.Second.LocalPath); Assert.Equal("**/*", watcher.GlobPattern.Second.Pattern); // Get rid of the registration and it should be gone again @@ -98,7 +98,7 @@ public async Task CreatingFileWatchRequestsFileWatch() var watcher = GetSingleFileWatcher(dynamicCapabilitiesRpcTarget); - Assert.Equal("Z:\\", watcher.GlobPattern.Second.BaseUri.First.LocalPath); + Assert.Equal("Z:\\", watcher.GlobPattern.Second.BaseUri.Second.LocalPath); Assert.Equal("SingleFile.txt", watcher.GlobPattern.Second.Pattern); // Get rid of the registration and it should be gone again diff --git a/src/LanguageServer/Protocol/Protocol/Converters/SumConverter.cs b/src/LanguageServer/Protocol/Protocol/Converters/SumConverter.cs index d8fb1d10670a9..440b6e46b88ae 100644 --- a/src/LanguageServer/Protocol/Protocol/Converters/SumConverter.cs +++ b/src/LanguageServer/Protocol/Protocol/Converters/SumConverter.cs @@ -65,6 +65,7 @@ public SumTypeInfoCache(Type sumTypeType) if (parameterTypeInfo.IsPrimitive || parameterTypeInfo == typeof(string) || + parameterTypeInfo == typeof(Uri) || typeof(IStringEnum).IsAssignableFrom(parameterTypeInfo)) { primitiveUnionTypeInfosSet ??= new List(); @@ -249,7 +250,7 @@ public override T Read(ref Utf8JsonReader reader, Type objectType, JsonSerialize } } - throw new JsonException(LanguageServerProtocolResources.NoSumTypeMatch); + throw new JsonException($"No sum type match for {objectType}"); } /// @@ -259,6 +260,13 @@ public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions var sumValue = value.Value; + // behavior from DocumentUriConverter + if (sumValue is Uri) + { + writer.WriteStringValue(sumValue.ToString()); + return; + } + if (sumValue != null) { JsonSerializer.Serialize(writer, sumValue, options); @@ -288,6 +296,7 @@ private static bool IsTokenCompatibleWithType(ref Utf8JsonReader reader, SumConv break; case JsonTokenType.String: isCompatible = unionTypeInfo.Type == typeof(string) || + unionTypeInfo.Type == typeof(Uri) || typeof(IStringEnum).IsAssignableFrom(unionTypeInfo.Type); break; } diff --git a/src/LanguageServer/Protocol/Protocol/FileOperations/RelativePattern.cs b/src/LanguageServer/Protocol/Protocol/FileOperations/RelativePattern.cs index f4d9994a825e9..6126ef4a7c3b7 100644 --- a/src/LanguageServer/Protocol/Protocol/FileOperations/RelativePattern.cs +++ b/src/LanguageServer/Protocol/Protocol/FileOperations/RelativePattern.cs @@ -21,7 +21,7 @@ internal class RelativePattern /// [JsonPropertyName("baseUri")] [JsonRequired] - public SumType BaseUri { get; init; } + public SumType BaseUri { get; init; } /// /// The actual glob pattern. See Glob Pattern for more detail. From 3320e83b3608079d082dac578049665da1e2f5f2 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Mon, 19 Aug 2024 22:02:48 -0400 Subject: [PATCH 46/46] LSP Protocol: Fix another CI failure --- src/Features/Lsif/GeneratorTest/SemanticTokensTests.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Features/Lsif/GeneratorTest/SemanticTokensTests.vb b/src/Features/Lsif/GeneratorTest/SemanticTokensTests.vb index 145ebc6daa135..445cdebfd6a2f 100644 --- a/src/Features/Lsif/GeneratorTest/SemanticTokensTests.vb +++ b/src/Features/Lsif/GeneratorTest/SemanticTokensTests.vb @@ -18,7 +18,7 @@ Namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.UnitTests - + Public Async Function TestSemanticTokensData(code As String, expectedTokens As String) As Task ' This test performs LSIF specific validation of the semantic tokens output. As of this writing ' this feature is based on the same code path used to generate semantic tokens information in LSP