@@ -4,21 +4,30 @@ open Microsoft.CodeAnalysis.Formatting
44open Ionide.LanguageServerProtocol .Types
55open Ionide.LanguageServerProtocol .JsonRpc
66
7- open CSharpLanguageServer
87open CSharpLanguageServer.State
8+ open CSharpLanguageServer.Util
9+ open CSharpLanguageServer.Roslyn .Document
910
1011[<RequireQualifiedAccess>]
12+
1113module DocumentFormatting =
12- let provider ( clientCapabilities : ClientCapabilities ) : U2 < bool , DocumentFormattingOptions > option =
13- Some( U2.C1 true )
14+ let provider ( _cc : ClientCapabilities ) : U2 < bool , DocumentFormattingOptions > option = Some( U2.C1 true )
1415
15- let handle ( context : ServerRequestContext ) ( p : DocumentFormattingParams ) : AsyncLspResult < TextEdit [] option > = async {
16- match context.GetUserDocument p.TextDocument.Uri with
17- | None -> return None |> LspResult.success
18- | Some doc ->
19- let! ct = Async.CancellationToken
20- let! options = FormatUtil.getFormattingOptions context.State.Settings doc p.Options
21- let! newDoc = Formatter.FormatAsync( doc, options, cancellationToken = ct) |> Async.AwaitTask
22- let! textEdits = FormatUtil.getChanges newDoc doc
23- 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
2422 }
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