taplo icon indicating copy to clipboard operation
taplo copied to clipboard

Global replace cannot process with VSC turn on format on save.

Open SofiaXu opened this issue 2 years ago • 3 comments

I have turn on follow settings in vsc settings.json.

"editor.formatOnSave": true,

When I replace tokio = "1" with tokio.workspace = true. Changes cannot be saved.

SofiaXu avatar Sep 28 '22 03:09 SofiaXu

I haven't been able to reproduce this, can you provide logs from Even Better TOML LSP from the Output tab when this happens?

tamasfe avatar Oct 08 '22 12:10 tamasfe

I haven't been able to reproduce this, can you provide logs from Even Better TOML LSP from the Output tab when this happens?

Do you need to change some setting to get output in there? The output looks like this for me at startup and doesn't change when doing the find and replace:

 INFO registered request handler method="initialize"
 INFO registered request handler method="textDocument/foldingRange"
 INFO registered request handler method="textDocument/documentSymbol"
 INFO registered request handler method="textDocument/formatting"
 INFO registered request handler method="textDocument/completion"
 INFO registered request handler method="textDocument/hover"
 INFO registered request handler method="textDocument/documentLink"
 INFO registered request handler method="textDocument/semanticTokens/full"
 INFO registered request handler method="textDocument/prepareRename"
 INFO registered request handler method="textDocument/rename"
 INFO registered notification handler method="initialized"
 INFO registered notification handler method="textDocument/didOpen"
 INFO registered notification handler method="textDocument/didChange"
 INFO registered notification handler method="textDocument/didSave"
 INFO registered notification handler method="textDocument/didClose"
 INFO registered notification handler method="workspace/didChangeConfiguration"
 INFO registered notification handler method="workspace/didChangeWorkspaceFolders"
 INFO registered request handler method="taplo/convertToJson"
 INFO registered request handler method="taplo/convertToToml"
 INFO registered request handler method="taplo/listSchemas"
 INFO registered request handler method="taplo/associatedSchema"
 INFO registered notification handler method="taplo/associateSchema"
 WARN no notification handler registered method=$/setTrace

Here's my setup for replicating the issue:

# test1.toml
a = "b"
# test2.toml
a = "b"
  1. Find and replace a = "b" with a = "c"
  2. Check the file contents and see that one of them has changed and the other hasn't. Disabling format on save fixes the issue, and you can sometimes see the new contents flash before being replaced by the old contents, so it looks like it's formatting the old contents for some reason.

Heliozoa avatar Oct 08 '22 13:10 Heliozoa

Thanks, I managed to catch it as well using two files.

These are the relevant LSP messages sent to/from Taplo when doing a mass replace with formatOnSave enabled:

DEBUG taplo: request received id=Number(40) method=textDocument/formatting
DEBUG taplo: notification received method=textDocument/didChange
DEBUG message written method=None id=Some(Number(40))
DEBUG taplo: request received id=Number(41) method=textDocument/formatting
DEBUG message written method=None id=Some(Number(41))
DEBUG taplo: notification received method=textDocument/didChange
DEBUG taplo: notification received method=textDocument/didSave
DEBUG taplo: notification received method=textDocument/didChange
DEBUG taplo: notification received method=textDocument/didSave

After some tries it seems to me that didChange notifications either come out of order (after the formatting request) or do not come at all in some cases. To me it seems to be a vscode issue at a first glance.

The same thing happens if the documents are not opened, the order of requests for all but one of the documents is didOpen / format / didChange.

It is also possible that more complex LSP document synchronization is required in order to support this use-case, but I don't know where to even start with that in that case.

tamasfe avatar Oct 08 '22 14:10 tamasfe