From 7901affe0458c47677c9b2a6a20d9bbda251c6c7 Mon Sep 17 00:00:00 2001 From: baronfel Date: Tue, 20 Jul 2021 14:52:45 -0500 Subject: [PATCH] fix lsp types to allow workspace/applyEdit to work --- src/FsAutoComplete/FsAutoComplete.Lsp.fs | 9 +++++++- .../LanguageServerProtocol.fs | 21 +++++++++++++++++++ test/FsAutoComplete.Tests.Lsp/Helpers.fs | 6 +++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/FsAutoComplete/FsAutoComplete.Lsp.fs b/src/FsAutoComplete/FsAutoComplete.Lsp.fs index 0394e11de..ba787e136 100644 --- a/src/FsAutoComplete/FsAutoComplete.Lsp.fs +++ b/src/FsAutoComplete/FsAutoComplete.Lsp.fs @@ -26,9 +26,16 @@ type FcsRange = FSharp.Compiler.Text.Range module FcsPos = FSharp.Compiler.Text.Pos type FcsPos = FSharp.Compiler.Text.Pos +module Result = + let ofCoreResponse (r: CoreResponse<'a>) = + match r with + | CoreResponse.Res a -> Ok a + | CoreResponse.ErrorRes msg + | CoreResponse.InfoRes msg -> Error (JsonRpc.Error.InternalErrorMessage msg) + module AsyncResult = let ofCoreResponse (ar: Async>) = - ar |> Async.map (function | CoreResponse.Res a -> Ok a | CoreResponse.ErrorRes msg | CoreResponse.InfoRes msg -> Error (JsonRpc.Error.InternalErrorMessage msg)) + ar |> Async.map Result.ofCoreResponse let ofStringErr (ar: Async>) = ar |> AsyncResult.mapError JsonRpc.Error.InternalErrorMessage diff --git a/src/LanguageServerProtocol/LanguageServerProtocol.fs b/src/LanguageServerProtocol/LanguageServerProtocol.fs index 540d77afb..15cf8db88 100644 --- a/src/LanguageServerProtocol/LanguageServerProtocol.fs +++ b/src/LanguageServerProtocol/LanguageServerProtocol.fs @@ -226,6 +226,8 @@ module Types = /// (the server has not received an open notification before) the server can send /// `null` to indicate that the version is known and the content on disk is the /// truth (as speced with document content ownership) + /// Explicitly include the null value here. + [] Version: int option } interface ITextDocumentIdentifier with @@ -321,10 +323,29 @@ module Types = DynamicRegistration: bool option } + type ResourceOperationKind = Create | Rename | Delete + + type FailureHandlingKind = Abort | Transactional | Undo | TextOnlyTransactional + + type ChangeAnnotationSupport = { + GroupsOnLabel: bool option + } + /// Capabilities specific to `WorkspaceEdit`s type WorkspaceEditCapabilities = { /// The client supports versioned document changes in `WorkspaceEdit`s DocumentChanges: bool option + /// The resource operations the client supports. Clients should at least + /// support 'create', 'rename' and 'delete' files and folders. + ResourceOperations: ResourceOperationKind [] option + /// The failure handling strategy of a client if applying the workspace edit fails. + FailureHandling: FailureHandlingKind option + /// Whether the client normalizes line endings to the client specific setting. + /// If set to `true` the client will normalize line ending characters + /// in a workspace edit to the client specific new line character(s). + NormalizesLineEndings: bool option + /// Whether the client in general supports change annotations on text edits, create file, rename file and delete file changes. + ChangeAnnotationSupport: ChangeAnnotationSupport option } /// Specific capabilities for the `SymbolKind` in the `workspace/symbol` request. diff --git a/test/FsAutoComplete.Tests.Lsp/Helpers.fs b/test/FsAutoComplete.Tests.Lsp/Helpers.fs index de054a77d..dfb1b3d7a 100644 --- a/test/FsAutoComplete.Tests.Lsp/Helpers.fs +++ b/test/FsAutoComplete.Tests.Lsp/Helpers.fs @@ -160,7 +160,11 @@ let defaultConfigDto : FSharpConfigDto = let clientCaps : ClientCapabilities = let dynCaps : DynamicCapabilities = { DynamicRegistration = Some true} let workspaceCaps : WorkspaceClientCapabilities = - let weCaps : WorkspaceEditCapabilities = { DocumentChanges = Some true} + let weCaps : WorkspaceEditCapabilities = { DocumentChanges = Some true + ResourceOperations = None + FailureHandling = None + NormalizesLineEndings = None + ChangeAnnotationSupport = None } let symbolCaps: SymbolCapabilities = { DynamicRegistration = Some true SymbolKind = None} let semanticTokenCaps: SemanticTokensWorkspaceClientCapabilities = { RefreshSupport = Some true }