From 2d9ff56d7b6712afe201fefdb80480b031483bd5 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Sat, 16 Dec 2023 07:16:45 +0100 Subject: [PATCH] Add only_files argument for lsp_save_all command --- Default.sublime-keymap | 5 +++-- docs/src/keyboard_shortcuts.md | 1 + plugin/save_command.py | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Default.sublime-keymap b/Default.sublime-keymap index d95ffdb9e..bd59e5a76 100644 --- a/Default.sublime-keymap +++ b/Default.sublime-keymap @@ -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 // { diff --git a/docs/src/keyboard_shortcuts.md b/docs/src/keyboard_shortcuts.md index 81c39bfd7..41f0213ac 100644 --- a/docs/src/keyboard_shortcuts.md +++ b/docs/src/keyboard_shortcuts.md @@ -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 | ctrl alt space | `lsp_signature_help_show` diff --git a/plugin/save_command.py b/plugin/save_command.py index 9cc0c52ff..eb35f654b 100644 --- a/plugin/save_command.py +++ b/plugin/save_command.py @@ -117,7 +117,7 @@ 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() @@ -125,5 +125,7 @@ def run(self) -> None: 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)