-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format Document on save option #8
Comments
Thanks for the idea and implementation hints. Blocking in Perhaps two saves is okay?
|
How can you be sure step 4 is executed after step 3? Maybe the server sends back a response before the document is even saved? |
Good point, some experimentation is needed! |
That link is broken, the new documentation for LSP —and more specifically for this method— is here: https://microsoft.github.io/language-server-protocol/specification#textDocument_willSaveWaitUntil |
+1, voting for this. we need format_on_save |
I am currently working on a implementation of this. I decided to use a blocking format backed by a timeout. If the timeout expires, it will just save and ignore the formatting. Mostly working, just need to cleanup the code and add some settings so it is not always on with a hard-coded timeout. I also need to implement the willSaveWaitUntil for the language servers that support it, instead of a standard format document command. You can find what I have so far here: https://github.com/oralordos/LSP |
@oralordos looking forward to testing it :) |
@oralordos I'm testing your changes with my very barebones server that doesn't handle any text synchronization yet. The only capability it advertises is I don't know if this is a scenario that you actually want to support, but the format-on-save feature doesn't work properly in this case. Then again, neither does the regular To support this scenario, the client could detect it, then listen to |
Having much more experience with LSP now I think what I wanted to expres is that this text editor client should implement But I disagree with my past self now in that we should offer a "format on save" option; all we can do is enable willSaveWaitUntil and then let the language server decide. |
Some servers (Metals, RLS) rely on the editor (eg. VS Code's Gopls even leans on VS Code to run code actions (https://github.com/golang/go/wiki/gopls#vscode) instead of doing it in What do you think of implementing the "format_on_save" feature in LSP by blocking in |
Two suggestions from this issue are now implemented: Running "Format Document" on save is enabled by adding a The |
For anyone coming here in 2024, it seems that you must set |
I've tried to put this setting anywhere I could find and it has not yet worked. Manually running the lsp format command from the palette works at least. |
Just to clarify: it should not be in the LSP-specific settings, but in your sublime settings. Quoting @tomv564:
|
That is not the current behavior. The current behavior now is that
The same apples to other LSP global settings like lsp_format_on_paste and lsp_code_actions_on_save https://lsp.sublimetext.io/client_configuration/#per-project-overrides |
Hm, I cannot confirm this on my setup. I recorded a short video where I enable format_on_save.mp4Not sure what is going on. I'm not really disturbed by this, but wanted to mention it. I'm LSP 1.28.0 by the way. |
If you have lsp_format_on_save set to false in Preference.sublime-settings, Line 92 in 57c01e7
|
Ok, I got it now. I didn't have |
Similar to Clang Format, it'd be nice to have a setting in the settings (false by default maybe) called
"format_on_save"
that will apply the "Format Document" action when the view is saved (on_pre_save
)EDIT: Since it's probably an async option you'd have to bake in some way to "wait" for the server to give a response before actually returning from
EventListener.on_pre_save
. I'll stop thinking about details now.The text was updated successfully, but these errors were encountered: