Skip to content

Commit

Permalink
feat: introduce emptyClientCapabilities and us it to reduce ClientCap…
Browse files Browse the repository at this point in the history
…abilities option to ClientCapabilities throughout the codebase
  • Loading branch information
razzmatazz committed Jul 2, 2024
1 parent a3eacee commit 684dcc4
Show file tree
Hide file tree
Showing 36 changed files with 136 additions and 163 deletions.
9 changes: 4 additions & 5 deletions src/CSharpLanguageServer/Handlers/CallHierarchy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@ module CallHierarchy =
Microsoft.CodeAnalysis.SymbolKind.Event
Microsoft.CodeAnalysis.SymbolKind.Property ]

let private dynamicRegistration (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private dynamicRegistration (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.CallHierarchy)
|> Option.bind (fun x -> x.DynamicRegistration)
|> Option.defaultValue false

let provider (clientCapabilities: ClientCapabilities) : U3<bool, CallHierarchyOptions, CallHierarchyRegistrationOptions> option =
match dynamicRegistration (Some clientCapabilities) with
match dynamicRegistration clientCapabilities with
| true -> None
| false -> Some (U3.C1 true)

let registration (clientCapabilities: ClientCapabilities option) : Registration option =
let registration (clientCapabilities: ClientCapabilities) : Registration option =
match dynamicRegistration clientCapabilities with
| false -> None
| true ->
Expand Down
17 changes: 7 additions & 10 deletions src/CSharpLanguageServer/Handlers/CodeAction.fs
Original file line number Diff line number Diff line change
Expand Up @@ -284,21 +284,19 @@ module CodeAction =
}
}

let private dynamicRegistration (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private dynamicRegistration (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.CodeAction)
|> Option.bind (fun x -> x.DynamicRegistration)
|> Option.defaultValue false

let private literalSupport (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private literalSupport (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.CodeAction)
|> Option.bind (fun x -> x.CodeActionLiteralSupport)

let provider (clientCapabilities: ClientCapabilities) : U2<bool, CodeActionOptions> option =
match dynamicRegistration (Some clientCapabilities), literalSupport (Some clientCapabilities) with
match dynamicRegistration clientCapabilities, literalSupport clientCapabilities with
| true, _ -> None
| false, _ ->
// TODO: Server can only return CodeActionOptions if literalSupport is not None
Expand All @@ -308,7 +306,7 @@ module CodeAction =
|> U2.C2
|> Some

let registration (clientCapabilities: ClientCapabilities option) : Registration option =
let registration (clientCapabilities: ClientCapabilities) : Registration option =
match dynamicRegistration clientCapabilities with
| false -> None
| true ->
Expand All @@ -335,8 +333,7 @@ module CodeAction =
let! roslynCodeActions = getRoslynCodeActions doc textSpan ct

let clientSupportsCodeActionEditResolveWithEditAndData =
context.ClientCapabilities
|> Option.bind (fun x -> x.TextDocument)
context.ClientCapabilities.TextDocument
|> Option.bind (fun x -> x.CodeAction)
|> Option.bind (fun x -> x.ResolveSupport)
|> Option.map (fun resolveSupport -> resolveSupport.Properties |> Array.contains "edit")
Expand Down
9 changes: 4 additions & 5 deletions src/CSharpLanguageServer/Handlers/CodeLens.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,19 @@ module CodeLens =
{ DocumentUri = ""
Position = { Line = 0u; Character = 0u } }

let private dynamicRegistration (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private dynamicRegistration (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.CodeLens)
|> Option.bind (fun x -> x.DynamicRegistration)
|> Option.defaultValue false

let provider (clientCapabilities: ClientCapabilities) : CodeLensOptions option =
match dynamicRegistration (Some clientCapabilities) with
match dynamicRegistration clientCapabilities with
| true -> None
| false -> Some { ResolveProvider = Some true
WorkDoneProgress = None }

let registration (clientCapabilities: ClientCapabilities option) : Registration option =
let registration (clientCapabilities: ClientCapabilities) : Registration option =
match dynamicRegistration clientCapabilities with
| false -> None
| true ->
Expand Down
4 changes: 2 additions & 2 deletions src/CSharpLanguageServer/Handlers/Color.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ open CSharpLanguageServer.State

[<RequireQualifiedAccess>]
module Color =
let provider (clientCapabilities: ClientCapabilities option) = None
let provider (clientCapabilities: ClientCapabilities) = None

let registration (clientCapabilities: ClientCapabilities option) : Registration option = None
let registration (clientCapabilities: ClientCapabilities) : Registration option = None

let handle (context: ServerRequestContext) (p: DocumentColorParams) : AsyncLspResult<ColorInformation[]> =
LspResult.notImplemented<ColorInformation[]> |> async.Return
Expand Down
9 changes: 4 additions & 5 deletions src/CSharpLanguageServer/Handlers/Completion.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@ module Completion =
member __.ShouldTriggerCompletion(sourceText, position, completionTrigger) =
service.ShouldTriggerCompletion(sourceText, position, completionTrigger)

let private dynamicRegistration (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private dynamicRegistration (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.Completion)
|> Option.bind (fun x -> x.DynamicRegistration)
|> Option.defaultValue false

let provider (clientCapabilities: ClientCapabilities) : CompletionOptions option =
match dynamicRegistration (Some clientCapabilities) with
match dynamicRegistration clientCapabilities with
| true -> None
| false ->
Some { ResolveProvider = None
Expand All @@ -81,7 +80,7 @@ module Completion =
WorkDoneProgress = None
CompletionItem = None }

let registration (clientCapabilities: ClientCapabilities option) : Registration option =
let registration (clientCapabilities: ClientCapabilities) : Registration option =
match dynamicRegistration clientCapabilities with
| false -> None
| true ->
Expand Down
4 changes: 2 additions & 2 deletions src/CSharpLanguageServer/Handlers/Declaration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ open CSharpLanguageServer.State

[<RequireQualifiedAccess>]
module Declaration =
let provider (_cc: ClientCapabilities option) : bool option = None
let provider (_cc: ClientCapabilities) : bool option = None

let registration (_cc: ClientCapabilities option) : Registration option = None
let registration (_cc: ClientCapabilities) : Registration option = None

let handle (_context: ServerRequestContext) (_p: TextDocumentPositionParams) : AsyncLspResult<Declaration option> =
LspResult.notImplemented<Declaration option> |> async.Return
9 changes: 4 additions & 5 deletions src/CSharpLanguageServer/Handlers/Definition.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ open CSharpLanguageServer.Types

[<RequireQualifiedAccess>]
module Definition =
let private dynamicRegistration (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private dynamicRegistration (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.Definition)
|> Option.bind (fun x -> x.DynamicRegistration)
|> Option.defaultValue false

let provider (clientCapabilities: ClientCapabilities) : U2<bool, DefinitionOptions> option =
match dynamicRegistration (Some clientCapabilities) with
match dynamicRegistration clientCapabilities with
| true -> None
| false -> Some (U2.C1 true)

let registration (clientCapabilities: ClientCapabilities option) : Registration option =
let registration (clientCapabilities: ClientCapabilities) : Registration option =
match dynamicRegistration clientCapabilities with
| false -> None
| true ->
Expand Down
2 changes: 1 addition & 1 deletion src/CSharpLanguageServer/Handlers/Diagnostic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open CSharpLanguageServer.State
module Diagnostic =
let provider (clientCapabilities: ClientCapabilities) = None

let registration (clientCapabilities: ClientCapabilities option) : Registration option = None
let registration (clientCapabilities: ClientCapabilities) : Registration option = None

let handle (context: ServerRequestContext) (def: DocumentDiagnosticParams) : AsyncLspResult<DocumentDiagnosticReport> =
LspResult.notImplemented<DocumentDiagnosticReport> |> async.Return
9 changes: 4 additions & 5 deletions src/CSharpLanguageServer/Handlers/DocumentFormatting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ open CSharpLanguageServer.Types

[<RequireQualifiedAccess>]
module DocumentFormatting =
let private dynamicRegistration (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private dynamicRegistration (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.Formatting)
|> Option.bind (fun x -> x.DynamicRegistration)
|> Option.defaultValue false

let provider (clientCapabilities: ClientCapabilities) : U2<bool, DocumentFormattingOptions> option =
match dynamicRegistration (Some clientCapabilities) with
match dynamicRegistration clientCapabilities with
| true -> None
| false -> Some (U2.C1 true)

let registration (clientCapabilities: ClientCapabilities option) : Registration option =
let registration (clientCapabilities: ClientCapabilities) : Registration option =
match dynamicRegistration clientCapabilities with
| false -> None
| true ->
Expand Down
9 changes: 4 additions & 5 deletions src/CSharpLanguageServer/Handlers/DocumentHighlight.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@ open CSharpLanguageServer.Conversions

[<RequireQualifiedAccess>]
module DocumentHighlight =
let private dynamicRegistration (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private dynamicRegistration (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.DocumentHighlight)
|> Option.bind (fun x -> x.DynamicRegistration)
|> Option.defaultValue false

let provider (clientCapabilities: ClientCapabilities) : U2<bool, DocumentHighlightOptions> option =
match dynamicRegistration (Some clientCapabilities) with
match dynamicRegistration clientCapabilities with
| true -> None
| false -> Some (U2.C1 true)

let registration (clientCapabilities: ClientCapabilities option) : Registration option =
let registration (clientCapabilities: ClientCapabilities) : Registration option =
match dynamicRegistration clientCapabilities with
| false -> None
| true ->
Expand Down
4 changes: 2 additions & 2 deletions src/CSharpLanguageServer/Handlers/DocumentLink.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ open CSharpLanguageServer.State

[<RequireQualifiedAccess>]
module DocumentLink =
let provider (clientCapabilities: ClientCapabilities option) : DocumentLinkOptions option = None
let provider (clientCapabilities: ClientCapabilities) : DocumentLinkOptions option = None

let registration (clientCapabilities: ClientCapabilities option) : Registration option = None
let registration (clientCapabilities: ClientCapabilities) : Registration option = None

let handle (context: ServerRequestContext) (p: DocumentLinkParams) : AsyncLspResult<DocumentLink[] option> =
LspResult.notImplemented<DocumentLink[] option> |> async.Return
Expand Down
9 changes: 4 additions & 5 deletions src/CSharpLanguageServer/Handlers/DocumentOnTypeFormatting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ open CSharpLanguageServer.Conversions

[<RequireQualifiedAccess>]
module DocumentOnTypeFormatting =
let private dynamicRegistration (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private dynamicRegistration (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.OnTypeFormatting)
|> Option.bind (fun x -> x.DynamicRegistration)
|> Option.defaultValue false

let provider (clientCapabilities: ClientCapabilities) : DocumentOnTypeFormattingOptions option =
match dynamicRegistration (Some clientCapabilities) with
match dynamicRegistration clientCapabilities with
| true -> None
| false ->
Some
{ FirstTriggerCharacter = ";"
MoreTriggerCharacter = Some([| "}"; ")" |]) }

let registration (clientCapabilities: ClientCapabilities option) : Registration option =
let registration (clientCapabilities: ClientCapabilities) : Registration option =
match dynamicRegistration clientCapabilities with
| false -> None
| true ->
Expand Down
9 changes: 4 additions & 5 deletions src/CSharpLanguageServer/Handlers/DocumentRangeFormatting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@ open CSharpLanguageServer.Types

[<RequireQualifiedAccess>]
module DocumentRangeFormatting =
let private dynamicRegistration (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private dynamicRegistration (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.RangeFormatting)
|> Option.bind (fun x -> x.DynamicRegistration)
|> Option.defaultValue false

let provider (clientCapabilities: ClientCapabilities) : U2<bool, DocumentRangeFormattingOptions> option =
match dynamicRegistration (Some clientCapabilities) with
match dynamicRegistration clientCapabilities with
| true -> None
| false -> Some (U2.C1 true)

let registration (clientCapabilities: ClientCapabilities option) : Registration option =
let registration (clientCapabilities: ClientCapabilities) : Registration option =
match dynamicRegistration clientCapabilities with
| false -> None
| true ->
Expand Down
12 changes: 5 additions & 7 deletions src/CSharpLanguageServer/Handlers/DocumentSymbol.fs
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,18 @@ module DocumentSymbol =
base.VisitEventDeclaration(node)
pop node

let private dynamicRegistration (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private dynamicRegistration (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.DocumentSymbol)
|> Option.bind (fun x -> x.DynamicRegistration)
|> Option.defaultValue false

let provider (clientCapabilities: ClientCapabilities) : U2<bool, DocumentSymbolOptions> option =
match dynamicRegistration (Some clientCapabilities) with
match dynamicRegistration clientCapabilities with
| true -> None
| false -> true |> U2.C1 |> Some

let registration (clientCapabilities: ClientCapabilities option) : Registration option =
let registration (clientCapabilities: ClientCapabilities) : Registration option =
match dynamicRegistration clientCapabilities with
| false -> None
| true ->
Expand All @@ -312,8 +311,7 @@ module DocumentSymbol =
(p: DocumentSymbolParams)
: AsyncLspResult<U2<SymbolInformation[], DocumentSymbol[]> option> = async {
let canEmitDocSymbolHierarchy =
context.ClientCapabilities
|> Option.bind (fun cc -> cc.TextDocument)
context.ClientCapabilities.TextDocument
|> Option.bind (fun cc -> cc.DocumentSymbol)
|> Option.bind (fun cc -> cc.HierarchicalDocumentSymbolSupport)
|> Option.defaultValue false
Expand Down
4 changes: 2 additions & 2 deletions src/CSharpLanguageServer/Handlers/ExecuteCommand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ open CSharpLanguageServer.State

[<RequireQualifiedAccess>]
module ExecuteCommand =
let provider (_clientCapabilities: ClientCapabilities) : ExecuteCommandOptions option = None
let provider (_cc: ClientCapabilities) : ExecuteCommandOptions option = None

let registration (_clientCapabilities: ClientCapabilities option) : Registration option = None
let registration (_cc: ClientCapabilities) : Registration option = None

let handle (_context: ServerRequestContext) (_p: ExecuteCommandParams) : AsyncLspResult<LSPAny> =
notImplemented<LSPAny> |> async.Return
6 changes: 3 additions & 3 deletions src/CSharpLanguageServer/Handlers/FoldingRange.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ open CSharpLanguageServer.State

[<RequireQualifiedAccess>]
module FoldingRange =
let provider (clientCapabilities: ClientCapabilities option) : bool option = None
let provider (_c: ClientCapabilities) : bool option = None

let registration (clientCapabilities: ClientCapabilities option) : Registration option = None
let registration (_c: ClientCapabilities) : Registration option = None

let handle (context: ServerRequestContext) (p: FoldingRangeParams) : AsyncLspResult<FoldingRange list option> =
let handle (_c: ServerRequestContext) (_p: FoldingRangeParams) : AsyncLspResult<FoldingRange list option> =
notImplemented<FoldingRange list option> |> async.Return
9 changes: 4 additions & 5 deletions src/CSharpLanguageServer/Handlers/Hover.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ open CSharpLanguageServer.State

[<RequireQualifiedAccess>]
module Hover =
let private dynamicRegistration (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private dynamicRegistration (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.Hover)
|> Option.bind (fun x -> x.DynamicRegistration)
|> Option.defaultValue false

let provider (clientCapabilities: ClientCapabilities) : U2<bool, HoverOptions> option =
match dynamicRegistration (Some clientCapabilities) with
match dynamicRegistration clientCapabilities with
| true -> Some (U2.C1 false)
| false -> Some (U2.C1 true)

let registration (clientCapabilities: ClientCapabilities option) : Registration option =
let registration (clientCapabilities: ClientCapabilities) : Registration option =
match dynamicRegistration clientCapabilities with
| false -> None
| true ->
Expand Down
9 changes: 4 additions & 5 deletions src/CSharpLanguageServer/Handlers/Implementation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ open CSharpLanguageServer.State

[<RequireQualifiedAccess>]
module Implementation =
let private dynamicRegistration (clientCapabilities: ClientCapabilities option) =
clientCapabilities
|> Option.bind (fun x -> x.TextDocument)
let private dynamicRegistration (clientCapabilities: ClientCapabilities) =
clientCapabilities.TextDocument
|> Option.bind (fun x -> x.Implementation)
|> Option.bind (fun x -> x.DynamicRegistration)
|> Option.defaultValue false

let provider (clientCapabilities: ClientCapabilities) : U3<bool,ImplementationOptions,ImplementationRegistrationOptions> option =
match dynamicRegistration (Some clientCapabilities) with
match dynamicRegistration clientCapabilities with
| true -> None
| false -> Some (U3.C1 true)

let registration (clientCapabilities: ClientCapabilities option) : Registration option =
let registration (clientCapabilities: ClientCapabilities) : Registration option =
match dynamicRegistration clientCapabilities with
| false -> None
| true ->
Expand Down
Loading

0 comments on commit 684dcc4

Please sign in to comment.