Skip to content
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

Add only_files argument for lsp_save_all command #2376

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
{"key": "auto_complete_visible"}
]
},
// Save all open files with lsp_save
// Save all open files that have a language server attached with lsp_save
// {
// "keys": ["UNBOUND"],
// "command": "lsp_save_all"
// "command": "lsp_save_all",
// "args": {"only_files": false}
// },
// Run Code Action
// {
Expand Down
1 change: 1 addition & 0 deletions docs/src/keyboard_shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Refer to the [Customization section](customization.md#keyboard-shortcuts-key-bin
| Run Code Lens | unbound | `lsp_code_lens`
| Run Refactor Action | unbound | `lsp_code_actions` (with args: `{"only_kinds": ["refactor"]}`)
| Run Source Action | unbound | `lsp_code_actions` (with args: `{"only_kinds": ["source"]}`)
| Save All | unbound | `lsp_save_all` (supports optional args `{"only_files": true}` - to ignore buffers which have no associated file on disk)
| Show Call Hierarchy | unbound | `lsp_call_hierarchy`
| Show Type Hierarchy | unbound | `lsp_type_hierarchy`
| Signature Help | <kbd>ctrl</kbd> <kbd>alt</kbd> <kbd>space</kbd> | `lsp_signature_help_show`
Expand Down
4 changes: 3 additions & 1 deletion plugin/save_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ def _trigger_native_save(self) -> None:


class LspSaveAllCommand(sublime_plugin.WindowCommand):
def run(self) -> None:
def run(self, only_files: bool = False) -> None:
done = set()
for view in self.window.views():
buffer_id = view.buffer_id()
if buffer_id in done:
continue
if not view.is_dirty():
continue
if only_files and view.file_name() is None:
continue
done.add(buffer_id)
view.run_command("lsp_save", None)