Skip to content

Commit

Permalink
Add only_files argument for lsp_save_all command
Browse files Browse the repository at this point in the history
  • Loading branch information
jwortmann committed Dec 16, 2023
1 parent df4b5e4 commit 2d9ff56
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
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)

0 comments on commit 2d9ff56

Please sign in to comment.