Skip to content

Commit

Permalink
Merge pull request #405 from mhanberg/didsavetext
Browse files Browse the repository at this point in the history
fix: send buffer text on textDocument/didSave
  • Loading branch information
yegappan authored Oct 6, 2023
2 parents 2233028 + 0e5a10b commit 882f350
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions autoload/lsp/lspserver.vim
Original file line number Diff line number Diff line change
Expand Up @@ -906,9 +906,12 @@ def DidSaveFile(lspserver: dict<any>, bnr: number): void

# Notification: 'textDocument/didSave'
# Params: DidSaveTextDocumentParams
var params = {textDocument: {uri: util.LspBufnrToUri(bnr)}}
# FIXME: Need to set "params.text" when
# 'lspserver.caps.textDocumentSync.save.includeText' is set to true.
var params: dict<any> = {textDocument: {uri: util.LspBufnrToUri(bnr)}}

if lspserver.caps.textDocumentSync->get("save", {})->get("includeText", v:false)
params.text = bnr->getbufline(1, '$')->join("\n") .. "\n"
endif

lspserver.sendNotification('textDocument/didSave', params)
enddef

Expand Down

3 comments on commit 882f350

@DanielViberg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using LspFormat on save, this change results in:

Error detected while processing BufWritePost Autocommands for "<buffer=11>"..function 32_LspSavedFile[10]..53_DidSaveFile:
line 11:
E896: Argument of get() must be a List, Dictionary or Blob
Error detected while compiling function 53_Output_cb[5]..lsp#handlers#ProcessMessages[32]..lsp#handlers#ProcessNotif[39]..54_ProcessDiagNotif[2]..lsp#diag#DiagNoti
fication:
line 17:
E1028: Compiling :def function failed
Error detected while processing function 53_Output_cb[5]..lsp#handlers#ProcessMessages[32]..lsp#handlers#ProcessNotif[39]..54_ProcessDiagNotif:
line 2:
E1091: Function is not compiled: lsp#diag#DiagNotification
E1091: Function is not compiled: lsp#diag#DiagNotification

@yegappan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have committed a fix for this. Can you try out the latest version of the plugin?

@DanielViberg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as intended, thank you!

Please sign in to comment.