Skip to content

Commit

Permalink
Add an option to save hidden buffers
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
w0rp committed Sep 5, 2023
1 parent 8ba7ae8 commit 551fbcf
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion autoload/ale/organize_imports.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions autoload/ale/rename.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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*

Expand Down Expand Up @@ -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`.
Expand Down
3 changes: 3 additions & 0 deletions plugin/ale.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/test_organize_imports.vader
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/test_rename.vader
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 551fbcf

Please sign in to comment.