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`.
This commit is contained in:
w0rp
2023-09-06 00:17:27 +01:00
parent 8ba7ae818c
commit 551fbcfb09
6 changed files with 22 additions and 9 deletions

View File

@@ -19,7 +19,7 @@ function! ale#organize_imports#HandleTSServerResponse(conn_id, response) abort
\ }, \ },
\ { \ {
\ 'conn_id': a:conn_id, \ 'conn_id': a:conn_id,
\ 'should_save': !&hidden, \ 'should_save': g:ale_save_hidden || !&hidden,
\ }, \ },
\) \)
endfunction endfunction

View File

@@ -85,7 +85,7 @@ function! ale#rename#HandleTSServerResponse(conn_id, response) abort
\ }, \ },
\ { \ {
\ 'conn_id': a:conn_id, \ 'conn_id': a:conn_id,
\ 'should_save': !&hidden, \ 'should_save': g:ale_save_hidden || !&hidden,
\ }, \ },
\) \)
endfunction endfunction
@@ -118,7 +118,7 @@ function! ale#rename#HandleLSPResponse(conn_id, response) abort
\ }, \ },
\ { \ {
\ 'conn_id': a:conn_id, \ 'conn_id': a:conn_id,
\ 'should_save': !&hidden, \ 'should_save': g:ale_save_hidden || !&hidden,
\ }, \ },
\) \)
endif endif

View File

@@ -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' let g:ale_floating_preview_popup_opts = 'g:CustomOpts'
< <
g:ale_floating_window_border *g:ale_floating_window_border* g:ale_floating_window_border *g:ale_floating_window_border*
Type: |List| Type: |List|
@@ -1974,6 +1973,16 @@ g:ale_root *g:ale_root*
LSP linter, it will not run. 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* g:ale_set_balloons *g:ale_set_balloons*
*b: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 The symbol where the cursor is resting will be the symbol renamed, and a
prompt will open to request a new name. prompt will open to request a new name.
The rename operation will save all modified buffers when `set nohidden` is The rename operation will not save modified buffers when 'hidden' is on
set, because that disables leaving unsaved buffers in the background. See unless |g:ale_save_hidden| is `1`.
`:help hidden` for more details.
ALEFileRename *ALEFileRename* ALEFileRename *ALEFileRename*
Rename a file and fix imports using `tsserver`. Rename a file and fix imports using `tsserver`.
ALECodeAction *ALECodeAction* ALECodeAction *ALECodeAction*
Apply a code action via LSP servers or `tsserver`. Apply a code action via LSP servers or `tsserver`.

View File

@@ -191,6 +191,9 @@ let g:ale_deno_executable = get(g:, 'ale_deno_executable', 'deno')
" If 1, enable a popup menu for commands. " If 1, enable a popup menu for commands.
let g:ale_popup_menu_enabled = get(g:, 'ale_popup_menu_enabled', has('gui_running')) 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 " If 1, disables ALE's built in error display. Instead, all errors are piped
" to the diagnostics API. " to the diagnostics API.
let g:ale_use_neovim_diagnostics_api = get(g:, 'ale_use_neovim_diagnostics_api', 0) let g:ale_use_neovim_diagnostics_api = get(g:, 'ale_use_neovim_diagnostics_api', 0)

View File

@@ -59,7 +59,7 @@ Before:
function! ale#code_action#HandleCodeAction(code_action, options) abort function! ale#code_action#HandleCodeAction(code_action, options) abort
let g:handle_code_action_called = 1 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) call add(g:code_actions, a:code_action)
endfunction endfunction

View File

@@ -59,7 +59,7 @@ Before:
function! ale#code_action#HandleCodeAction(code_action, options) abort function! ale#code_action#HandleCodeAction(code_action, options) abort
let g:handle_code_action_called = 1 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) call add(g:code_actions, a:code_action)
endfunction endfunction