Skip to content

Commit

Permalink
fix lsp types to allow workspace/applyEdit to work (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel authored Jul 20, 2021
1 parent b4a50f3 commit 0d3c341
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/FsAutoComplete/FsAutoComplete.Lsp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoreResponse<'a>>) =
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<Result<'a, string>>) =
ar |> AsyncResult.mapError JsonRpc.Error.InternalErrorMessage
Expand Down
21 changes: 21 additions & 0 deletions src/LanguageServerProtocol/LanguageServerProtocol.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
[<JsonProperty(NullValueHandling = NullValueHandling.Include)>]
Version: int option
}
interface ITextDocumentIdentifier with
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion test/FsAutoComplete.Tests.Lsp/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 0d3c341

Please sign in to comment.