diff --git a/LanguageServer.Framework/Protocol/Capabilities/Client/TextDocumentClientCapabilities/SemanticTokensClientCapabilities.cs b/LanguageServer.Framework/Protocol/Capabilities/Client/TextDocumentClientCapabilities/SemanticTokensClientCapabilities.cs index c4d4efe9..5eb3e118 100644 --- a/LanguageServer.Framework/Protocol/Capabilities/Client/TextDocumentClientCapabilities/SemanticTokensClientCapabilities.cs +++ b/LanguageServer.Framework/Protocol/Capabilities/Client/TextDocumentClientCapabilities/SemanticTokensClientCapabilities.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Common; using EmmyLua.LanguageServer.Framework.Protocol.Model.Kind; using EmmyLua.LanguageServer.Framework.Protocol.Model.Union; @@ -97,16 +98,8 @@ public class SemanticTokensClientCapabilitiesRequests * The client will send the `textDocument/semanticTokens/full` request if * the server provides a corresponding server capability. */ - [JsonPropertyName("full"), JsonConverter(typeof(BooleanOrConverter))] - public BooleanOr? Full { get; init; } + [JsonPropertyName("full"), JsonConverter(typeof(BooleanOrConverter))] + public BooleanOr? Full { get; init; } } -public class SemanticTokensClientCapabilitiesRequestsFull -{ - /** - * The client will send the `textDocument/semanticTokens/full/delta` request if - * the server provides a corresponding server capability. - */ - [JsonPropertyName("delta")] - public bool? Delta { get; init; } -} + diff --git a/LanguageServer.Framework/Protocol/Capabilities/Common/SemanticTokensCapabilitiesFull.cs b/LanguageServer.Framework/Protocol/Capabilities/Common/SemanticTokensCapabilitiesFull.cs new file mode 100644 index 00000000..c796c2ab --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Common/SemanticTokensCapabilitiesFull.cs @@ -0,0 +1,13 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Common; + +public class SemanticTokensCapabilitiesFull +{ + /** + * The client will send the `textDocument/semanticTokens/full/delta` request if + * the server provides a corresponding server capability. + */ + [JsonPropertyName("delta")] + public bool? Delta { get; init; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Common/SemanticTokensLegend.cs b/LanguageServer.Framework/Protocol/Capabilities/Common/SemanticTokensLegend.cs new file mode 100644 index 00000000..cfb89f41 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Common/SemanticTokensLegend.cs @@ -0,0 +1,18 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Common; + +public class SemanticTokensLegend +{ + /** + * The token types a server uses. + */ + [JsonPropertyName("tokenTypes")] + public List TokenTypes { get; init; } = []; + + /** + * The token modifiers a server uses. + */ + [JsonPropertyName("tokenModifiers")] + public List TokenModifiers { get; init; } = []; +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/CallHierarchyOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/CallHierarchyOptions.cs new file mode 100644 index 00000000..cbae3a61 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/CallHierarchyOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class CallHierarchyOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/CodeActionOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/CodeActionOptions.cs new file mode 100644 index 00000000..1a3605f1 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/CodeActionOptions.cs @@ -0,0 +1,80 @@ +using System.Text.Json.Serialization; +using EmmyLua.LanguageServer.Framework.Protocol.Model; +using EmmyLua.LanguageServer.Framework.Protocol.Model.Kind; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class CodeActionOptions : WorkDoneProgressOptions +{ + /** + * CodeActionKinds that this server may return. + * + * The list of kinds may be generic, such as `CodeActionKind.Refactor`, + * or the server may list out every specific kind they provide. + */ + [JsonPropertyName("codeActionKinds")] + public List CodeActionKinds { get; set; } + + /** + * Static documentation for a class of code actions. + * + * Documentation from the provider should be shown in the code actions + * menu if either: + * + * - Code actions of `kind` are requested by the editor. In this case, + * the editor will show the documentation that most closely matches the + * requested code action kind. For example, if a provider has + * documentation for both `Refactor` and `RefactorExtract`, when the + * user requests code actions for `RefactorExtract`, the editor will use + * the documentation for `RefactorExtract` instead of the documentation + * for `Refactor`. + * + * - Any code actions of `kind` are returned by the provider. + * + * At most one documentation entry should be shown per provider. + * + * @since 3.18.0 + * @proposed + */ + [JsonPropertyName("documentation")] + public List Documentation { get; set; } +} + +/** + * Documentation for a class of code actions. + * + * @since 3.18.0 + * @proposed + */ +public class CodeActionKindDocumentation +{ + /** + * The kind of the code action being documented. + * + * If the kind is generic, such as `CodeActionKind.Refactor`, the + * documentation will be shown whenever any refactorings are returned. If + * the kind is more specific, such as `CodeActionKind.RefactorExtract`, the + * documentation will only be shown when extract refactoring code actions + * are returned. + */ + [JsonPropertyName("kind")] + public CodeActionKind Kind { get; set; } + + /** + * Command that is used to display the documentation to the user. + * + * The title of this documentation code action is taken + * from {@linkcode Command.title} + */ + [JsonPropertyName("command")] + public Command Command { get; set; } = null!; + + /** + * The server provides support to resolve additional + * information for a code action. + * + * @since 3.16.0 + */ + [JsonPropertyName("resolveProvider")] + public bool? ResolveProvider { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/CodeLensOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/CodeLensOptions.cs new file mode 100644 index 00000000..42acc685 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/CodeLensOptions.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class CodeLensOptions : WorkDoneProgressOptions +{ + /** + * Code lens has a resolve provider as well. + */ + [JsonPropertyName("resolveProvider")] + public bool? ResolveProvider { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/CompletionOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/CompletionOptions.cs new file mode 100644 index 00000000..b0b36824 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/CompletionOptions.cs @@ -0,0 +1,64 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class CompletionOptions : WorkDoneProgressOptions +{ + /** + * Most tools trigger 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 and + * present `console` besides others as a completion item. Characters that + * make up identifiers don't need to be listed here. + * + * If code complete should automatically be triggered on characters not being + * valid inside an identifier (for example, `.` in JavaScript), list them in + * `triggerCharacters`. + */ + [JsonPropertyName("triggerCharacters")] + public List? TriggerCharacters { get; init; } + + /** + * 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 + * `completion.completionItem.commitCharactersSupport`. + * + * If a server provides both `allCommitCharacters` and commit characters on + * an individual completion item, the ones on the completion item win. + * + * @since 3.2.0 + */ + [JsonPropertyName("allCommitCharacters")] + public List? AllCommitCharacters { get; init; } + + /** + * The server provides support to resolve additional + * information for a completion item. + */ + [JsonPropertyName("resolveProvider")] + public bool ResolveProvider { get; init; } + + /** + * The server supports the following `CompletionItem` specific + * capabilities. + * + * @since 3.17.0 + */ + [JsonPropertyName("completionItem")] + public CompletionItemDetailOptions? CompletionItem { get; init; } +} + +public class CompletionItemDetailOptions +{ + /** + * The server has support for completion item label + * details (see also `CompletionItemLabelDetails`) when receiving + * a completion item in a resolve call. + * + * @since 3.17.0 + */ + [JsonPropertyName("labelDetailsSupport")] + public bool? LabelDetailsSupport { get; init; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DeclarationOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DeclarationOptions.cs new file mode 100644 index 00000000..c1c79e17 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DeclarationOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class DeclarationOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DefinitionOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DefinitionOptions.cs new file mode 100644 index 00000000..62da25cd --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DefinitionOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class DefinitionOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DiagnosticOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DiagnosticOptions.cs new file mode 100644 index 00000000..b35377bc --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DiagnosticOptions.cs @@ -0,0 +1,28 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class DiagnosticOptions : WorkDoneProgressOptions +{ + /** + * An optional identifier under which the diagnostics are + * managed by the client. + */ + [JsonPropertyName("identifier")] + public string? Identifier { get; set; } + + /** + * 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 { get; set; } + + /** + * The server provides support for workspace diagnostics as well. + */ + [JsonPropertyName("workspaceDiagnostics")] + public bool WorkspaceDiagnostics { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentColorOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentColorOptions.cs new file mode 100644 index 00000000..57094759 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentColorOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class DocumentColorOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentFormattingOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentFormattingOptions.cs new file mode 100644 index 00000000..d0bd5326 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentFormattingOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class DocumentFormattingOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentHighlightOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentHighlightOptions.cs new file mode 100644 index 00000000..936a9313 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentHighlightOptions.cs @@ -0,0 +1,5 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class DocumentHighlightOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentLinkOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentLinkOptions.cs new file mode 100644 index 00000000..81a5f530 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentLinkOptions.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class DocumentLinkOptions : WorkDoneProgressOptions +{ + /** + * Document links have a resolve provider as well. + */ + [JsonPropertyName("resolveProvider")] + public bool? ResolveProvider { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentOnTypeFormattingOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentOnTypeFormattingOptions.cs new file mode 100644 index 00000000..25d579bf --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentOnTypeFormattingOptions.cs @@ -0,0 +1,17 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class DocumentOnTypeFormattingOptions +{ + /** + * A character on which formatting should be triggered, like `{`. + */ + [JsonPropertyName("firstTriggerCharacter")] + public string FirstTriggerCharacter { get; set; } = null!; + + /** + * More trigger characters. + */ + public List? MoreTriggerCharacter { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentRangeFormattingOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentRangeFormattingOptions.cs new file mode 100644 index 00000000..1d38c735 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentRangeFormattingOptions.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class DocumentRangeFormattingOptions : WorkDoneProgressOptions +{ + /** + * Whether the server supports formatting multiple ranges at once. + * + * @since 3.18.0 + * @proposed + */ + [JsonPropertyName("rangesSupport")] + public bool? RangesSupport { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentSymbolOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentSymbolOptions.cs new file mode 100644 index 00000000..52e8f6cc --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/DocumentSymbolOptions.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class DocumentSymbolOptions : WorkDoneProgressOptions +{ + /** + * A human-readable string that is shown when multiple outlines trees + * are shown for the same document. + * + * @since 3.16.0 + */ + [JsonPropertyName("label")] + public string? Label { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/ExecuteCommandOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/ExecuteCommandOptions.cs new file mode 100644 index 00000000..d696ccb9 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/ExecuteCommandOptions.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class ExecuteCommandOptions : WorkDoneProgressOptions +{ + /** + * The commands to be executed on the server. + */ + [JsonPropertyName("commands")] + public List Commands { get; init; } = []; +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/FileOperationRegistrationOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/FileOperationRegistrationOptions.cs new file mode 100644 index 00000000..09500cfa --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/FileOperationRegistrationOptions.cs @@ -0,0 +1,18 @@ +using System.Text.Json.Serialization; +using EmmyLua.LanguageServer.Framework.Protocol.Model; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +/** + * The options to register for file operations. + * + * @since 3.16.0 + */ +public class FileOperationRegistrationOptions +{ + /** + * The actual filters. + */ + [JsonPropertyName("filters")] + public List Filters { get; set; } = []; +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/HoverOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/HoverOptions.cs new file mode 100644 index 00000000..687ce412 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/HoverOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class HoverOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/ImplementationOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/ImplementationOptions.cs new file mode 100644 index 00000000..e43bb338 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/ImplementationOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class ImplementationOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/InlayHintsOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/InlayHintsOptions.cs new file mode 100644 index 00000000..0112e887 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/InlayHintsOptions.cs @@ -0,0 +1,18 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +/** + * Inlay hint options used during static registration. + * + * @since 3.17.0 + */ +public class InlayHintsOptions : WorkDoneProgressOptions +{ + /** + * The server provides support to resolve additional + * information for an inlay hint item. + */ + [JsonPropertyName("resolveProvider")] + public bool? ResolveProvider { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/InlineCompletionsOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/InlineCompletionsOptions.cs new file mode 100644 index 00000000..28de64d5 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/InlineCompletionsOptions.cs @@ -0,0 +1,8 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +/** + * Inline completion options used during static registration. + * + * @since 3.18.0 + */ +public class InlineCompletionsOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/InlineValuesOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/InlineValuesOptions.cs new file mode 100644 index 00000000..6cb7f99b --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/InlineValuesOptions.cs @@ -0,0 +1,8 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +/** + * Inline value options used during static registration. + * + * @since 3.17.0 + */ +public class InlineValuesOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/LinkedEditingRangeOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/LinkedEditingRangeOptions.cs new file mode 100644 index 00000000..bcdb9d34 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/LinkedEditingRangeOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class LinkedEditingRangeOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/MonikerOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/MonikerOptions.cs new file mode 100644 index 00000000..6c0e80ea --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/MonikerOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class MonikerOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/NotebookDocumentSyncOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/NotebookDocumentSyncOptions.cs new file mode 100644 index 00000000..9d87fcee --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/NotebookDocumentSyncOptions.cs @@ -0,0 +1,90 @@ +using System.Text.Json.Serialization; +using EmmyLua.LanguageServer.Framework.Protocol.Model.Union; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +/** + * 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. + * + * @since 3.17.0 + */ +public class NotebookDocumentSyncOptions +{ + /** + * The notebooks to be synced + */ + [JsonPropertyName("notebookSelector")] + public List NotebookSelector { get; init; } = null!; + + /** + * Whether save notifications should be forwarded to + * the server. Will only be honored if mode === `notebook`. + */ + [JsonPropertyName("save")] + public bool? Save { get; init; } +} + +public class NotebookSelectorOptions +{ + /** + * The notebook to be synced. If a string + * value is provided, it matches against the + * notebook type. '*' matches every notebook. + */ + [JsonPropertyName("notebookType"), JsonConverter(typeof(StringOrJsonConverter))] + public StringOr? NotebookType { get; init; } + + /** + * The cells of the matching notebook to be synced. + */ + [JsonPropertyName("cells")] + public List? Cells { get; init; } +} + +/** + * A notebook document filter denotes a notebook document by + * different properties. + * + * @since 3.17.0 + */ +public class NotebookDocumentFilter +{ + /** + * The type of the enclosing notebook. + */ + [JsonPropertyName("notebookType")] + public string? NotebookType { get; init; } + + /** + * A Uri [scheme](#Uri.scheme), like `file` or `untitled`. + */ + [JsonPropertyName("scheme")] + public string? Scheme { get; init; } + + /** + * A glob pattern. + */ + [JsonPropertyName("pattern")] + public string? Pattern { get; init; } +} + +/** + * A cell selector denotes a cell in a notebook. + * + * @since 3.17.0 + */ +public class CellSelectorOptions +{ + [JsonPropertyName("language")] + public string Language { get; init; } = null!; +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/ReferencesOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/ReferencesOptions.cs new file mode 100644 index 00000000..e3a77c7a --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/ReferencesOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class ReferencesOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/SelectionRangeOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/SelectionRangeOptions.cs new file mode 100644 index 00000000..d4d54e45 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/SelectionRangeOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class SelectionRangeOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/SemanticTokensOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/SemanticTokensOptions.cs new file mode 100644 index 00000000..93049140 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/SemanticTokensOptions.cs @@ -0,0 +1,27 @@ +using System.Text.Json.Serialization; +using EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Common; +using EmmyLua.LanguageServer.Framework.Protocol.Model.Union; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class SemanticTokensOptions : WorkDoneProgressOptions +{ + /** + * The legend used by the server. + */ + [JsonPropertyName("legend")] + public SemanticTokensLegend Legend { get; init; } = new(); + + /** + * Server supports providing semantic tokens for a specific range + * of a document. + */ + [JsonPropertyName("range")] + public bool? Range { get; init; } + + /** + * Server supports providing semantic tokens for a full document. + */ + [JsonPropertyName("full"), JsonConverter(typeof(SemanticTokensCapabilitiesFull))] + public BooleanOr? Full { get; init; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/SignatureHelpOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/SignatureHelpOptions.cs new file mode 100644 index 00000000..3cb4126c --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/SignatureHelpOptions.cs @@ -0,0 +1,25 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class SignatureHelpOptions : WorkDoneProgressOptions +{ + /** + * The characters that trigger signature help + * automatically. + */ + [JsonPropertyName("triggerCharacters")] + public List? TriggerCharacters { get; init; } + + /** + * List of characters that re-trigger signature help. + * + * These trigger characters are only active when signature help is already + * showing. All trigger characters are also counted as re-trigger + * characters. + * + * @since 3.15.0 + */ + [JsonPropertyName("retriggerCharacters")] + public List? RetriggerCharacters { get; init; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/TextDocumentSyncOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/TextDocumentSyncOptions.cs index aa656a98..e8d5c394 100644 --- a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/TextDocumentSyncOptions.cs +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/TextDocumentSyncOptions.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; using EmmyLua.LanguageServer.Framework.Protocol.Model.Kind; -namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server; +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; public class TextDocumentSyncOptions { diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/TypeDefinitionOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/TypeDefinitionOptions.cs new file mode 100644 index 00000000..e8977e8e --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/TypeDefinitionOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class TypeDefinitionOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/TypeHierarchyOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/TypeHierarchyOptions.cs new file mode 100644 index 00000000..a804b1da --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/TypeHierarchyOptions.cs @@ -0,0 +1,3 @@ +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class TypeHierarchyOptions : WorkDoneProgressOptions; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/WorkDoneProgressOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/WorkDoneProgressOptions.cs new file mode 100644 index 00000000..2cfd76ad --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/WorkDoneProgressOptions.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class WorkDoneProgressOptions +{ + /** + * The server reports that it supports work done progress. + */ + [JsonPropertyName("workDoneProgress")] + public bool? WorkDoneProgress { get; init; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Options/WorkspaceSymbolOptions.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/WorkspaceSymbolOptions.cs new file mode 100644 index 00000000..b05ff1ae --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Options/WorkspaceSymbolOptions.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +public class WorkspaceSymbolOptions : WorkDoneProgressOptions +{ + /** + * The server provides support to resolve additional + * information for a workspace symbol. + * + * @since 3.17.0 + */ + [JsonPropertyName("resolveProvider")] + public bool? ResolveProvider { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/ServerCapabilities.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/ServerCapabilities.cs index 98e80d02..54513b5c 100644 --- a/LanguageServer.Framework/Protocol/Capabilities/Server/ServerCapabilities.cs +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/ServerCapabilities.cs @@ -1,6 +1,9 @@ -using System.Text.Json.Serialization; +using System.Text.Json; +using System.Text.Json.Serialization; +using EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; using EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Union; using EmmyLua.LanguageServer.Framework.Protocol.Model.Kind; +using EmmyLua.LanguageServer.Framework.Protocol.Model.Union; namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server; @@ -29,11 +32,236 @@ public class ServerCapabilities [JsonPropertyName("textDocumentSync")] public TextDocumentSyncOptionsOrKind? TextDocumentSync { get; init; } - // /** - // * Defines how notebook documents are synced. - // * - // * @since 3.17.0 - // */ - // [JsonPropertyName("notebookSync")] - // public NotebookSyncOptions? NotebookSync { get; init; } + /** + * Defines how notebook documents are synced. + * + * @since 3.17.0 + */ + [JsonPropertyName("notebookDocumentSync")] + public NotebookDocumentSyncOptions? NotebookDocumentSync { get; init; } + + /** + * The server provides completion support. + */ + [JsonPropertyName("completionProvider")] + public CompletionOptions? CompletionProvider { get; init; } + + /** + * The server provides hover support. + */ + [JsonPropertyName("hoverProvider")] + public BooleanOr? HoverProvider { get; init; } + + /** + * The server provides signature help support. + */ + [JsonPropertyName("signatureHelpProvider")] + public SignatureHelpOptions? SignatureHelpProvider { get; init; } + + /** + * The server provides go to declaration support. + * + * @since 3.14.0 + */ + [JsonPropertyName("declarationProvider")] + public BooleanOr? DeclarationProvider { get; init; } + + /** + * The server provides goto definition support. + */ + [JsonPropertyName("definitionProvider")] + public BooleanOr? DefinitionProvider { get; init; } + + /** + * The server provides goto type definition support. + * + * @since 3.6.0 + */ + [JsonPropertyName("typeDefinitionProvider")] + public BooleanOr? TypeDefinitionProvider { get; init; } + + /** + * The server provides goto implementation support. + * + * @since 3.6.0 + */ + [JsonPropertyName("implementationProvider")] + public BooleanOr? ImplementationProvider { get; init; } + + /** + * The server provides find references support. + */ + [JsonPropertyName("referencesProvider")] + public BooleanOr? ReferencesProvider { get; init; } + + /** + * The server provides document highlight support. + */ + [JsonPropertyName("documentHighlightProvider")] + public BooleanOr? DocumentHighlightProvider { get; init; } + + /** + * The server provides document symbol support. + */ + [JsonPropertyName("documentSymbolProvider")] + public BooleanOr? DocumentSymbolProvider { get; init; } + + /** + * The server provides code actions. The `CodeActionOptions` return type is + * only valid if the client signals code action literal support via the + * property `textDocument.codeAction.codeActionLiteralSupport`. + */ + [JsonPropertyName("codeActionProvider")] + public BooleanOr? CodeActionProvider { get; init; } + + /** + * The server provides code lens. + */ + [JsonPropertyName("codeLensProvider")] + public CodeLensOptions? CodeLensProvider { get; init; } + + /** + * The server provides document link support. + */ + [JsonPropertyName("documentLinkProvider")] + public DocumentLinkOptions? DocumentLinkProvider { get; init; } + + /** + * The server provides color provider support. + * + * @since 3.6.0 + */ + [JsonPropertyName("colorProvider")] + public BooleanOr? ColorProvider { get; init; } + + /** + * The server provides document formatting. + */ + [JsonPropertyName("documentFormattingProvider")] + public BooleanOr? DocumentFormattingProvider { get; init; } + + /** + * The server provides document range formatting. + */ + [JsonPropertyName("documentRangeFormattingProvider")] + public BooleanOr? DocumentRangeFormattingProvider { get; init; } + + /** + * The server provides document formatting on typing. + */ + [JsonPropertyName("documentOnTypeFormattingProvider")] + public DocumentOnTypeFormattingOptions? DocumentOnTypeFormattingProvider { get; init; } + + /** + * The server provides execute command support. + */ + [JsonPropertyName("executeCommandProvider")] + public ExecuteCommandOptions? ExecuteCommandProvider { get; init; } + + /** + * The server provides selection range support. + * + * @since 3.15.0 + */ + [JsonPropertyName("selectionRangeProvider")] + public BooleanOr? SelectionRangeProvider { get; init; } + + /** + * The server provides linked editing range support. + * + * @since 3.16.0 + */ + [JsonPropertyName("linkedEditingRangeProvider")] + public BooleanOr? LinkedEditingRangeProvider { get; init; } + + /** + * The server provides call hierarchy support. + * + * @since 3.16.0 + */ + [JsonPropertyName("callHierarchyProvider")] + public BooleanOr? CallHierarchyProvider { get; init; } + + /** + * The server provides semantic tokens support. + * + * @since 3.16.0 + */ + [JsonPropertyName("semanticTokensProvider")] + public SemanticTokensOptions? SemanticTokensProvider { get; init; } + + /** + * Whether server provides moniker support. + * + * @since 3.16.0 + */ + [JsonPropertyName("monikerProvider")] + public BooleanOr? MonikerProvider { get; init; } + + /** + * The server provides type hierarchy support. + * + * @since 3.17.0 + */ + [JsonPropertyName("typeHierarchyProvider")] + public BooleanOr? TypeHierarchyProvider { get; init; } + + /** + * The server provides inline values. + * + * @since 3.17.0 + */ + [JsonPropertyName("inlineValuesProvider")] + public BooleanOr? InlineValuesProvider { get; init; } + + /** + * The server provides inlay hints. + * + * @since 3.17.0 + */ + [JsonPropertyName("inlayHintsProvider")] + public BooleanOr? InlayHintsProvider { get; init; } + + /** + * The server has support for pull model diagnostics. + * + * @since 3.17.0 + */ + [JsonPropertyName("diagnosticProvider")] + public DiagnosticOptions? DiagnosticProvider { get; init; } + + /** + * The server provides workspace symbol support. + */ + [JsonPropertyName("workspaceSymbolProvider")] + public BooleanOr? WorkspaceSymbolProvider { get; init; } + + /** + * The server provides inline completions. + * + * @since 3.18.0 + */ + [JsonPropertyName("inlineCompletionsProvider")] + public BooleanOr? InlineCompletionsProvider { get; init; } + + /** + * Text document specific server capabilities. + * + * @since 3.18.0 + */ + [JsonPropertyName("textDocument")] + public TextDocumentServerCapabilities? TextDocument { get; init; } + + /** + * Workspace specific server capabilities + */ + [JsonPropertyName("workspace")] + public WorkspaceServerCapabilities.WorkspaceServerCapabilities? Workspace { get; init; } + + /** + * Experimental server capabilities. + */ + [JsonPropertyName("experimental")] + public JsonDocument? Experimental { get; init; } } + diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/TextDocumentServerCapabilities.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/TextDocumentServerCapabilities.cs new file mode 100644 index 00000000..eed16b08 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/TextDocumentServerCapabilities.cs @@ -0,0 +1,28 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server; + +public class TextDocumentServerCapabilities +{ + public class DiagnosticPullModel + { + /** + * Whether the server supports `MarkupContent` in diagnostic messages. + * + * @since 3.18.0 + * @proposed + */ + [JsonPropertyName("markupMessageSupport")] + public bool? MarkupMessageSupport { get; set; } + } + + /** + * Capabilities specific to the diagnostic pull model. + * + * @since 3.18.0 + */ + [JsonPropertyName("diagnostic")] + public DiagnosticPullModel? Diagnostic { get; set; } +} + + diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/Union/TextDocumentSyncOptionsOrKind.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/Union/TextDocumentSyncOptionsOrKind.cs index 5fa7b2be..d199c8f6 100644 --- a/LanguageServer.Framework/Protocol/Capabilities/Server/Union/TextDocumentSyncOptionsOrKind.cs +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/Union/TextDocumentSyncOptionsOrKind.cs @@ -1,5 +1,6 @@ using System.Text.Json; using System.Text.Json.Serialization; +using EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; using EmmyLua.LanguageServer.Framework.Protocol.Model.Kind; namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Union; diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/WorkspaceServerCapabilities/FileOperationsServerCapabilities.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/WorkspaceServerCapabilities/FileOperationsServerCapabilities.cs new file mode 100644 index 00000000..4723273c --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/WorkspaceServerCapabilities/FileOperationsServerCapabilities.cs @@ -0,0 +1,42 @@ +using System.Text.Json.Serialization; +using EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.Options; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.WorkspaceServerCapabilities; + +public class FileOperationsServerCapabilities +{ + /** + * The server is interested in receiving didCreateFiles + * notifications. + */ + [JsonPropertyName("didCreate")] + public FileOperationRegistrationOptions? DidCreate { get; set; } + + /** + * The server is interested in receiving willCreateFiles + * requests. + */ + [JsonPropertyName("willCreate")] + public FileOperationRegistrationOptions? WillCreate { get; set; } + + /** + * The server is interested in receiving didRenameFiles + * notifications. + */ + [JsonPropertyName("didRename")] + public FileOperationRegistrationOptions? DidRename { get; set; } + + /** + * The server is interested in receiving willRenameFiles + * requests. + */ + [JsonPropertyName("willRename")] + public FileOperationRegistrationOptions? WillRename { get; set; } + + /** + * The server is interested in receiving didDeleteFiles + * notifications. + */ + [JsonPropertyName("didDelete")] + public FileOperationRegistrationOptions? DidDelete { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/WorkspaceServerCapabilities/WorkspaceFoldersServerCapabilities.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/WorkspaceServerCapabilities/WorkspaceFoldersServerCapabilities.cs new file mode 100644 index 00000000..6f818076 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/WorkspaceServerCapabilities/WorkspaceFoldersServerCapabilities.cs @@ -0,0 +1,25 @@ +using System.Text.Json.Serialization; +using EmmyLua.LanguageServer.Framework.Protocol.Model.Union; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.WorkspaceServerCapabilities; + +public class WorkspaceFoldersServerCapabilities +{ + /** + * The server has support for workspace folders. + */ + [JsonPropertyName("supported")] + public bool? Supported { get; set; } + + /** + * 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 `client/unregisterCapability` request. + */ + [JsonPropertyName("changeNotifications")] + public BooleanOr? ChangeNotifications { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/Capabilities/Server/WorkspaceServerCapabilities/WorkspaceServerCapabilities.cs b/LanguageServer.Framework/Protocol/Capabilities/Server/WorkspaceServerCapabilities/WorkspaceServerCapabilities.cs new file mode 100644 index 00000000..3d4546fb --- /dev/null +++ b/LanguageServer.Framework/Protocol/Capabilities/Server/WorkspaceServerCapabilities/WorkspaceServerCapabilities.cs @@ -0,0 +1,22 @@ +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server.WorkspaceServerCapabilities; + +public class WorkspaceServerCapabilities +{ + /** + * The server supports workspace folder. + * + * @since 3.6.0 + */ + [JsonPropertyName("workspaceFolders")] + public WorkspaceFoldersServerCapabilities? WorkspaceFolders { get; set; } + + /** + * The server is interested in file notifications/requests. + * + * @since 3.16.0 + */ + [JsonPropertyName("fileOperations")] + public FileOperationsServerCapabilities? FileOperations { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/JsonProtocolContext.cs b/LanguageServer.Framework/Protocol/JsonProtocolContext.cs index c11a0e00..2e835552 100644 --- a/LanguageServer.Framework/Protocol/JsonProtocolContext.cs +++ b/LanguageServer.Framework/Protocol/JsonProtocolContext.cs @@ -1,6 +1,7 @@ using System.Text.Json.Serialization; using EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Client.TextDocumentClientCapabilities; using EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Client.WorkspaceEditClientCapabilities; +using EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server; using EmmyLua.LanguageServer.Framework.Protocol.JsonRpc; using EmmyLua.LanguageServer.Framework.Protocol.Model; using EmmyLua.LanguageServer.Framework.Protocol.Model.Diagnostic; @@ -25,6 +26,8 @@ namespace EmmyLua.LanguageServer.Framework.Protocol; [JsonSerializable(typeof(Message))] [JsonSerializable(typeof(MethodMessage))] [JsonSerializable(typeof(RequestMessage))] +[JsonSerializable(typeof(ResponseMessage))] +[JsonSerializable(typeof(NotificationMessage))] [JsonSerializable(typeof(ResponseError))] [JsonSerializable(typeof(InitializeParams))] [JsonSerializable(typeof(InitializeResult))] @@ -76,5 +79,6 @@ namespace EmmyLua.LanguageServer.Framework.Protocol; [JsonSerializable(typeof(StringOrInt))] [JsonSerializable(typeof(StringOrMarkupContent))] [JsonSerializable(typeof(WorkspaceEditDocumentChanges))] +[JsonSerializable(typeof(ServerCapabilities))] // ReSharper disable once ClassNeverInstantiated.Global internal partial class JsonProtocolContext: JsonSerializerContext; diff --git a/LanguageServer.Framework/Protocol/JsonRpc/Message.cs b/LanguageServer.Framework/Protocol/JsonRpc/Message.cs index 89ce7f36..78ce9158 100644 --- a/LanguageServer.Framework/Protocol/JsonRpc/Message.cs +++ b/LanguageServer.Framework/Protocol/JsonRpc/Message.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using System.Text.Json; +using System.Text.Json.Serialization; using EmmyLua.LanguageServer.Framework.Protocol.Model.Union; namespace EmmyLua.LanguageServer.Framework.Protocol.JsonRpc; @@ -63,14 +64,14 @@ public record ResponseError( public record ResponseMessage( StringOrInt Id, - object? Result, + JsonDocument? Result, ResponseError? Error ) : Message("2.0") { [JsonPropertyName("id")] public StringOrInt Id { get; } = Id; - [JsonPropertyName("result")] public object? Result { get; } = Result; + [JsonPropertyName("result")] public JsonDocument? Result { get; } = Result; [JsonPropertyName("error")] public ResponseError? Error { get; } = Error; } diff --git a/LanguageServer.Framework/Protocol/Model/Command.cs b/LanguageServer.Framework/Protocol/Model/Command.cs index fc197ab7..481b9ef0 100644 --- a/LanguageServer.Framework/Protocol/Model/Command.cs +++ b/LanguageServer.Framework/Protocol/Model/Command.cs @@ -3,7 +3,7 @@ namespace EmmyLua.LanguageServer.Framework.Protocol.Model; // ReSharper disable once InconsistentNaming -public record Command(string Title, string? ToolTip, string Name, List? Arguments) +public record Command(string Title, string? ToolTip, string Name, List? Arguments) { /** * Title of the command, like `save`. @@ -14,20 +14,20 @@ public record Command(string Title, string? ToolTip, string Name, List? /** * The command's identifier. */ - [JsonPropertyName("command")] + [JsonPropertyName("toolTip")] public string? ToolTip { get; } = ToolTip; - + /** * The identifier of the actual command handler. */ [JsonPropertyName("command")] // ReSharper disable once InconsistentNaming public string Name { get; } = Name; - + /** * Arguments that the command handler should be * invoked with. */ [JsonPropertyName("arguments")] public List? Arguments { get; } = Arguments; -} \ No newline at end of file +} diff --git a/LanguageServer.Framework/Protocol/Model/FileOperationFilter.cs b/LanguageServer.Framework/Protocol/Model/FileOperationFilter.cs new file mode 100644 index 00000000..53a54598 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Model/FileOperationFilter.cs @@ -0,0 +1,67 @@ +using System.Text.Json.Serialization; +using EmmyLua.LanguageServer.Framework.Protocol.Model.Kind; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Model; + +/** + * A filter to describe in which file operation requests or notifications + * the server is interested in. + * + * @since 3.16.0 + */ +public class FileOperationFilter +{ + /** + * A Uri like `file` or `untitled`. + */ + [JsonPropertyName("scheme")] + public string? Scheme { get; set; } + + /** + * The actual file operation filters. + */ + [JsonPropertyName("pattern")] + public FileOperationPattern[]? Pattern { get; set; } +} + +public 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")] + public string Glob { get; set; } = string.Empty; + + /** + * Whether to match files or folders with this pattern. + * + * Matches both if undefined. + */ + [JsonPropertyName("matches")] + public FileOperationPatternKind? Matches { get; set; } + + /** + * Additional options used during matching. + */ + [JsonPropertyName("options")] + public FileOperationPatternOptions? Options { get; set; } +} + +public class FileOperationPatternOptions +{ + /** + * The pattern should be matched ignoring casing. + */ + [JsonPropertyName("ignoreCase")] + public bool? IgnoreCase { get; set; } +} diff --git a/LanguageServer.Framework/Protocol/Model/Kind/FileOperationPatternKind.cs b/LanguageServer.Framework/Protocol/Model/Kind/FileOperationPatternKind.cs new file mode 100644 index 00000000..e50b28ae --- /dev/null +++ b/LanguageServer.Framework/Protocol/Model/Kind/FileOperationPatternKind.cs @@ -0,0 +1,27 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Model.Kind; + +[JsonConverter(typeof(FileOperationPatternKindConverter))] +public readonly record struct FileOperationPatternKind(string Value) +{ + public static readonly FileOperationPatternKind File = new("file"); + + public static readonly FileOperationPatternKind Folder = new("folder"); + + public string Value { get; init; } = Value; +} + +public class FileOperationPatternKindConverter : JsonConverter +{ + public override FileOperationPatternKind Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return new FileOperationPatternKind(reader.GetString()!); + } + + public override void Write(Utf8JsonWriter writer, FileOperationPatternKind value, JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } +} diff --git a/LanguageServer.Framework/Protocol/Model/Union/StringOr.cs b/LanguageServer.Framework/Protocol/Model/Union/StringOr.cs new file mode 100644 index 00000000..60858b70 --- /dev/null +++ b/LanguageServer.Framework/Protocol/Model/Union/StringOr.cs @@ -0,0 +1,50 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace EmmyLua.LanguageServer.Framework.Protocol.Model.Union; + +public class StringOr +{ + public string? String { get; } + + public T? Value { get; } + + public StringOr(string? value) + { + String = value; + } + + public StringOr(T value) + { + Value = value; + } + + public static implicit operator StringOr(string value) => new(value); + + public static implicit operator StringOr(T value) => new(value); +} + +public class StringOrJsonConverter : JsonConverter> +{ + public override StringOr Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.String) + { + return new StringOr(reader.GetString()); + } + + return new StringOr(JsonSerializer.Deserialize(ref reader, options)!); + } + + public override void Write(Utf8JsonWriter writer, StringOr value, JsonSerializerOptions options) + { + if (value.String != null) + { + writer.WriteStringValue(value.String); + } + else + { + JsonSerializer.Serialize(writer, value.Value, options); + } + } +} diff --git a/LanguageServer.Framework/Server/Handler/InitializeHandlerBase.cs b/LanguageServer.Framework/Server/Handler/InitializeHandlerBase.cs index 30752682..a0dfe8c5 100644 --- a/LanguageServer.Framework/Server/Handler/InitializeHandlerBase.cs +++ b/LanguageServer.Framework/Server/Handler/InitializeHandlerBase.cs @@ -1,4 +1,5 @@ -using EmmyLua.LanguageServer.Framework.Protocol.JsonRpc; +using EmmyLua.LanguageServer.Framework.Protocol.Capabilities.Server; +using EmmyLua.LanguageServer.Framework.Protocol.JsonRpc; using EmmyLua.LanguageServer.Framework.Protocol.Notification; using EmmyLua.LanguageServer.Framework.Protocol.Request.Initialize; using EmmyLua.LanguageServer.Framework.Server.Handler.Base; @@ -11,7 +12,15 @@ public class InitializeHandlerBase : IJsonRpcRequestHandler Handle(InitializeParams request, CancellationToken cancellationToken) { Console.Error.Write("hello world"); - return Task.FromResult(new InitializeResult()); + var result = new InitializeResult + { + ServerInfo = new ServerInfo() + { + Name = "EmmyLua", + }, + Capabilities = new ServerCapabilities() + }; + return Task.FromResult(result); } [JsonRpc("initialized")] diff --git a/LanguageServer.Framework/Server/JsonProtocol/JsonProtocolWriter.cs b/LanguageServer.Framework/Server/JsonProtocol/JsonProtocolWriter.cs index 899b9fbb..862b88c2 100644 --- a/LanguageServer.Framework/Server/JsonProtocol/JsonProtocolWriter.cs +++ b/LanguageServer.Framework/Server/JsonProtocol/JsonProtocolWriter.cs @@ -2,12 +2,24 @@ using System.Text.Json; using EmmyLua.LanguageServer.Framework.Protocol; using EmmyLua.LanguageServer.Framework.Protocol.JsonRpc; +using EmmyLua.LanguageServer.Framework.Protocol.Model.Union; namespace EmmyLua.LanguageServer.Framework.Server.JsonProtocol; public class JsonProtocolWriter(Stream output, JsonSerializerOptions jsonSerializerOptions) { - public void Write(object? message, Type messageType) + public void WriteResponse(StringOrInt id, object? message, Type messageType) + { + var result = JsonSerializer.SerializeToDocument(message, messageType, jsonSerializerOptions); + var response = new ResponseMessage(id, result, null); + var json = JsonSerializer.Serialize(response, jsonSerializerOptions); + var contentLength = Encoding.UTF8.GetByteCount(json); + var writeContent = $"Content-Length:{contentLength}\r\n\r\n{json}"; + var writeContentBytes = Encoding.UTF8.GetBytes(writeContent); + output.Write(writeContentBytes); + } + + public void WriteNotification(NotificationMessage message, Type messageType) { var json = JsonSerializer.Serialize(message, messageType, jsonSerializerOptions); var contentLength = Encoding.UTF8.GetByteCount(json); diff --git a/LanguageServer.Framework/Server/LanguageServer.cs b/LanguageServer.Framework/Server/LanguageServer.cs index 12606aea..06296d22 100644 --- a/LanguageServer.Framework/Server/LanguageServer.cs +++ b/LanguageServer.Framework/Server/LanguageServer.cs @@ -15,7 +15,8 @@ public class LanguageServer { private JsonSerializerOptions JsonSerializerOptions { get; } = new() { - TypeInfoResolver = JsonProtocolContext.Default + TypeInfoResolver = JsonProtocolContext.Default, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; private JsonProtocolReader Reader { get; } @@ -76,7 +77,7 @@ public LanguageServer WithServices(Action servicesAction) public Task SendNotification(NotificationMessage notification) { - Writer.Write(notification, typeof(NotificationMessage)); + Writer.WriteNotification(notification, typeof(NotificationMessage)); return Task.CompletedTask; } @@ -147,11 +148,11 @@ public async Task Run() if (task.GetType().IsGenericType) { result = task.GetType().GetProperty("Result")?.GetValue(task); - Writer.Write(result, handler.ReturnType); + Writer.WriteResponse(request.Id, result, handler.ReturnType); } else { - Writer.Write(result, handler.ReturnType); + Writer.WriteResponse(request.Id, result, handler.ReturnType); } } }