-
Notifications
You must be signed in to change notification settings - Fork 186
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
lsp_save_all or a way to enable lsp_code_actions_on_save for save_all #1849
Comments
Supporting something like
It's not possible with the current ST API. |
There are the following methods of
I haven't followed the "code actions on save" PRs, so I don't know why Without knowing the background of |
So the custom command is needed so that we can perform our tasks asynchronously and then trigger the native save. |
Feel free to thumbs-up sublimehq/sublime_text#3273 and maybe the ST API for that will be added some day. |
Thanks, I understand. I guess the |
Yeah, the That said, I think having a blocking |
The problem with on_pre_save is that we'd end up using a condition variable to wait on some mutex while doing work in the async thread. But if you do that then calling any ST API function in the async thread results in a deadlock. |
An ideal approach would be for SublimeHQ to acknowledge that code actions and formatting are concepts that are missing in Sublime Text, and write appropriate provider API endpoints. Then ST can implement the formatting/code-actions-on-save functionality, while plugins only have to respond to the provider endpoint. |
I tried my hand at this. I ended up with a something like: class LspSaveAllCommand(sublime_plugin.WindowCommand):
def run(self) -> None:
for sheet in self.window.sheets():
sheet.view().run_command("lsp_save", None) which mostly works, except that the focus/active view is all over the place once this is called. Maybe some tasks of LSP assume that the current view is on focus or force it? I couldn't figure out which one yet. I also considered saving the |
I don't see the view switching issue. Though if you try to save a view that is not saved on disk then that will trigger a save dialog and switch the active view. Maybe something like this would be better so that it only saves files that are modified and only if they are on disk: class LspSaveAllCommand(sublime_plugin.WindowCommand):
def run(self) -> None:
for sheet in self.window.sheets():
view = sheet.view()
if view and view.is_dirty() and view.file_name():
view.run_command("lsp_save", None) |
If you edit file A, don't save, switch to file B then do lsp_save_all, file A comes back to the top. Also, if you have multiple columns, it always go back to the first one. |
I have 3 tasks running on save: If I disable the 3rd one, the focus doesn't switch. (I'm using the |
Bear with me while I learn the code and try to figure this out. :) What seems to be happening so far: Even when I disable |
Ok. I think I found the problem.
|
Aaaannnnnddd I found a fix. Sending the PR. |
Fixes #1849. * Adds a lsp_save_all function * We also fix open_file to avoid focusing the view if the file is already open. * fix order and variable names * Always focus view on center_selection * save-all every dirty buffer * check for window * default keymap * no context requirement for lsp_save_all
I usually have
{ "keys": ["super+s"], "command": "save_all" },
but I can't seem to find a way to makelsp_code_actions_on_save
to run onsave_all
.I can think of two solutions for this:
LSP could support a
lsp_save__all
command that would run LSP (when it makes sense) on all unsaved files.LSP could work on regular save commands (no special
lsp_save
) that would hook to ST4 save events.If there's another alternative that would also trigger it, please let me know.
The text was updated successfully, but these errors were encountered: