diff options
author | w0rp <devw0rp@gmail.com> | 2023-09-06 00:17:27 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2023-09-06 00:17:27 +0100 |
commit | 551fbcfb0905629dcc2afc0db53dcca21994cca3 (patch) | |
tree | 6e29d601783f19aba69a153c75e6c9d1f1a3236e | |
parent | 8ba7ae818c33c3b9ed9627ae9661f0420d256d7c (diff) | |
download | ale-551fbcfb0905629dcc2afc0db53dcca21994cca3.zip |
Add an option to save hidden buffers
When commands are run, it can be useful to just save the hidden buffers
so language servers immediately get updated with changes to files
without you having to manually save each file. You can now enable this
by setting `g:ale_save_hidden` to `1`.
-rw-r--r-- | autoload/ale/organize_imports.vim | 2 | ||||
-rw-r--r-- | autoload/ale/rename.vim | 4 | ||||
-rw-r--r-- | doc/ale.txt | 18 | ||||
-rw-r--r-- | plugin/ale.vim | 3 | ||||
-rw-r--r-- | test/test_organize_imports.vader | 2 | ||||
-rw-r--r-- | test/test_rename.vader | 2 |
6 files changed, 22 insertions, 9 deletions
diff --git a/autoload/ale/organize_imports.vim b/autoload/ale/organize_imports.vim index a6e77863..395e6fbd 100644 --- a/autoload/ale/organize_imports.vim +++ b/autoload/ale/organize_imports.vim @@ -19,7 +19,7 @@ function! ale#organize_imports#HandleTSServerResponse(conn_id, response) abort \ }, \ { \ 'conn_id': a:conn_id, - \ 'should_save': !&hidden, + \ 'should_save': g:ale_save_hidden || !&hidden, \ }, \) endfunction diff --git a/autoload/ale/rename.vim b/autoload/ale/rename.vim index a722cc94..53c9fb5c 100644 --- a/autoload/ale/rename.vim +++ b/autoload/ale/rename.vim @@ -85,7 +85,7 @@ function! ale#rename#HandleTSServerResponse(conn_id, response) abort \ }, \ { \ 'conn_id': a:conn_id, - \ 'should_save': !&hidden, + \ 'should_save': g:ale_save_hidden || !&hidden, \ }, \) endfunction @@ -118,7 +118,7 @@ function! ale#rename#HandleLSPResponse(conn_id, response) abort \ }, \ { \ 'conn_id': a:conn_id, - \ 'should_save': !&hidden, + \ 'should_save': g:ale_save_hidden || !&hidden, \ }, \) endif diff --git a/doc/ale.txt b/doc/ale.txt index 5b411b58..189839cf 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1260,7 +1260,6 @@ g:ale_floating_preview_popup_opts *g:ale_floating_preview_popup_opts* let g:ale_floating_preview_popup_opts = 'g:CustomOpts' < - g:ale_floating_window_border *g:ale_floating_window_border* Type: |List| @@ -1974,6 +1973,16 @@ g:ale_root *g:ale_root* LSP linter, it will not run. +g:ale_save_hidden *g:ale_save_hidden* + + Type: |Number| + Default: `0` + + When set to `1`, save buffers when 'hidden' is set when applying code + actions or rename operations, such as through |ALERename| or + |ALEOrganizeImports|. + + g:ale_set_balloons *g:ale_set_balloons* *b:ale_set_balloons* @@ -3646,14 +3655,15 @@ ALERename *ALERename* The symbol where the cursor is resting will be the symbol renamed, and a prompt will open to request a new name. - The rename operation will save all modified buffers when `set nohidden` is - set, because that disables leaving unsaved buffers in the background. See - `:help hidden` for more details. + The rename operation will not save modified buffers when 'hidden' is on + unless |g:ale_save_hidden| is `1`. + ALEFileRename *ALEFileRename* Rename a file and fix imports using `tsserver`. + ALECodeAction *ALECodeAction* Apply a code action via LSP servers or `tsserver`. diff --git a/plugin/ale.vim b/plugin/ale.vim index f9b6cab8..d926bcfe 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -191,6 +191,9 @@ let g:ale_deno_executable = get(g:, 'ale_deno_executable', 'deno') " If 1, enable a popup menu for commands. let g:ale_popup_menu_enabled = get(g:, 'ale_popup_menu_enabled', has('gui_running')) +" If 0, save hidden files when code actions are applied. +let g:ale_save_hidden = get(g:, 'ale_save_hidden', 0) + " If 1, disables ALE's built in error display. Instead, all errors are piped " to the diagnostics API. let g:ale_use_neovim_diagnostics_api = get(g:, 'ale_use_neovim_diagnostics_api', 0) diff --git a/test/test_organize_imports.vader b/test/test_organize_imports.vader index 87cd295a..720e8950 100644 --- a/test/test_organize_imports.vader +++ b/test/test_organize_imports.vader @@ -59,7 +59,7 @@ Before: function! ale#code_action#HandleCodeAction(code_action, options) abort let g:handle_code_action_called = 1 - AssertEqual !&hidden, get(a:options, 'should_save') + AssertEqual g:ale_save_hidden || !&hidden, get(a:options, 'should_save') call add(g:code_actions, a:code_action) endfunction diff --git a/test/test_rename.vader b/test/test_rename.vader index 83f0aa7e..d58d1827 100644 --- a/test/test_rename.vader +++ b/test/test_rename.vader @@ -59,7 +59,7 @@ Before: function! ale#code_action#HandleCodeAction(code_action, options) abort let g:handle_code_action_called = 1 - AssertEqual !&hidden, get(a:options, 'should_save', 0) + AssertEqual g:ale_save_hidden || !&hidden, get(a:options, 'should_save', 0) call add(g:code_actions, a:code_action) endfunction |