@@ -71,7 +71,7 @@ proc initialize*(
71
71
openClose: some (true ),
72
72
change: some (TextDocumentSyncKind .Full .int ),
73
73
willSave: some (false ),
74
- willSaveWaitUntil: some (false ),
74
+ willSaveWaitUntil: some (true ),
75
75
save: some (SaveOptions (includeText: some (true ))),
76
76
)
77
77
),
@@ -924,33 +924,36 @@ proc didChange*(
924
924
925
925
ls.scheduleFileCheck (uri)
926
926
927
- proc autoFormat (ls: LanguageServer , config: NlsConfig , uri: string ) {.async .} =
928
- let nphPath = getNphPath ()
929
- let shouldAutoFormat =
930
- nphPath.isSome and ls.serverCapabilities.documentFormattingProvider.get (false ) and
931
- ls.clientCapabilities.workspace.get (ClientCapabilities_workspace ()).applyEdit.get (
932
- false
933
- ) and config.formatOnSave.get (false )
934
- if shouldAutoFormat:
927
+ proc willSaveWaitUntil * (
928
+ ls: LanguageServer ,
929
+ params: WillSaveTextDocumentParams
930
+ ): Future [seq [TextEdit ]] {.async .} =
931
+ debug " Received willSaveWaitUntil request"
932
+
933
+ let
934
+ uri = params.textDocument.uri
935
+ config = await ls.getWorkspaceConfiguration ()
936
+ nphPath = getNphPath ()
937
+
938
+ let shouldFormat =
939
+ nphPath.isSome and
940
+ ls.serverCapabilities.documentFormattingProvider.get (false ) and
941
+ config.formatOnSave.get (false )
942
+
943
+ if shouldFormat:
944
+ debug " Formatting document before save" , uri = uri
935
945
let formatTextEdit = await ls.format (nphPath.get (), uri)
936
946
if formatTextEdit.isSome:
937
- let workspaceEdit = WorkspaceEdit (
938
- documentChanges: some @ [
939
- TextDocumentEdit (
940
- textDocument: VersionedTextDocumentIdentifier (uri: uri),
941
- edits: some @ [formatTextEdit.get ()],
942
- )
943
- ]
944
- )
945
- discard await ls.applyEdit (ApplyWorkspaceEditParams (edit: workspaceEdit))
947
+ return @ [formatTextEdit.get]
948
+
949
+ return @ []
946
950
947
951
proc didSave * (
948
952
ls: LanguageServer , params: DidSaveTextDocumentParams
949
953
): Future [void ] {.async , gcsafe .} =
950
954
let
951
955
uri = params.textDocument.uri
952
956
config = await ls.getWorkspaceConfiguration ()
953
- asyncSpawn ls.autoFormat (config, uri)
954
957
let nimsuggest = await ls.tryGetNimsuggest (uri)
955
958
956
959
if nimsuggest.isNone:
0 commit comments