@@ -5,26 +5,29 @@ open Ionide.LanguageServerProtocol.Types
55open Ionide.LanguageServerProtocol .JsonRpc
66
77open CSharpLanguageServer.State
8+ open CSharpLanguageServer.Util
89open CSharpLanguageServer.Roslyn .Document
910
1011[<RequireQualifiedAccess>]
11- module DocumentFormatting =
12- let provider ( clientCapabilities : ClientCapabilities ) : U2 < bool , DocumentFormattingOptions > option =
13- Some( U2.C1 true )
1412
15- let handle ( context : ServerRequestContext ) ( p : DocumentFormattingParams ) : AsyncLspResult < TextEdit [] option > = async {
16- let lspFormattingOptions =
17- if context.State.Settings.ApplyFormattingOptions then
18- Some p.Options
19- else
20- None
13+ module DocumentFormatting =
14+ let provider ( _cc : ClientCapabilities ) : U2 < bool , DocumentFormattingOptions > option = Some( U2.C1 true )
2115
22- match context.GetUserDocument p.TextDocument.Uri with
23- | None -> return None |> LspResult.success
24- | Some doc ->
25- let! ct = Async.CancellationToken
26- let! options = getDocumentFormattingOptionSet doc lspFormattingOptions
27- let! newDoc = Formatter.FormatAsync( doc, options, cancellationToken = ct) |> Async.AwaitTask
28- let! textEdits = getDocumentDiffAsLspTextEdits newDoc doc
29- return textEdits |> Some |> LspResult.success
16+ let formatDocument lspFormattingOptions doc : Async < TextEdit array option > = async {
17+ let! ct = Async.CancellationToken
18+ let! options = getDocumentFormattingOptionSet doc lspFormattingOptions
19+ let! newDoc = Formatter.FormatAsync( doc, options, cancellationToken = ct) |> Async.AwaitTask
20+ let! textEdits = getDocumentDiffAsLspTextEdits newDoc doc
21+ return textEdits |> Some
3022 }
23+
24+ let handle ( context : ServerRequestContext ) ( p : DocumentFormattingParams ) : AsyncLspResult < TextEdit [] option > =
25+ let formatDocument =
26+ p.Options
27+ |> context.State.Settings.GetEffectiveFormattingOptions
28+ |> formatDocument
29+
30+ context.GetUserDocument p.TextDocument.Uri
31+ |> async.Return
32+ |> Async.bindOption formatDocument
33+ |> Async.map LspResult.success
0 commit comments