summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2020-11-21 19:00:53 +0000
committerw0rp <devw0rp@gmail.com>2020-11-21 19:00:53 +0000
commit06e7f2195ef6375be32a63f98b5e46070708a315 (patch)
tree35dea61349a6c9387b62c0bc365f13f16d56835e
parentb8aaff2cf77883702374aee28f088b8a64c3b492 (diff)
downloadale-06e7f2195ef6375be32a63f98b5e46070708a315.zip
Fix #3332 - Modify everything for rename/actions
ALE now just modifies every open buffer for rename and actions, and sets up a one-time use BufEnter event to reload buffers that are changed so you don't have to think about what to do with changed buffers.
-rw-r--r--autoload/ale/code_action.vim42
-rw-r--r--autoload/ale/rename.vim5
-rw-r--r--doc/ale.txt6
-rw-r--r--plugin/ale.vim2
-rw-r--r--test/test_rename.vader6
5 files changed, 31 insertions, 30 deletions
diff --git a/autoload/ale/code_action.vim b/autoload/ale/code_action.vim
index 6b808b34..69d40933 100644
--- a/autoload/ale/code_action.vim
+++ b/autoload/ale/code_action.vim
@@ -1,28 +1,24 @@
" Author: Jerko Steiner <jerko.steiner@gmail.com>
" Description: Code action support for LSP / tsserver
+function! ale#code_action#ReloadBuffer() abort
+ let l:buffer = bufnr('')
+
+ execute 'augroup ALECodeActionReloadGroup' . l:buffer
+ autocmd!
+ augroup END
+
+ silent! execute 'augroup! ALECodeActionReloadGroup' . l:buffer
+
+ call ale#util#Execute(':e!')
+endfunction
+
function! ale#code_action#HandleCodeAction(code_action, options) abort
let l:current_buffer = bufnr('')
let l:changes = a:code_action.changes
let l:should_save = get(a:options, 'should_save')
- let l:force_save = get(a:options, 'force_save')
- let l:safe_changes = []
for l:file_code_edit in l:changes
- let l:buf = bufnr(l:file_code_edit.fileName)
-
- if l:buf != -1 && l:buf != l:current_buffer && getbufvar(l:buf, '&mod')
- if !l:force_save
- call ale#util#Execute('echom ''Aborting action, file is unsaved''')
-
- return
- endif
- else
- call add(l:safe_changes, l:file_code_edit)
- endif
- endfor
-
- for l:file_code_edit in l:safe_changes
call ale#code_action#ApplyChanges(
\ l:file_code_edit.fileName,
\ l:file_code_edit.textChanges,
@@ -161,6 +157,20 @@ function! ale#code_action#ApplyChanges(filename, changes, should_save) abort
call setpos('.', [0, l:pos[0], l:pos[1], 0])
endif
+
+ if a:should_save && l:buffer > 0 && !l:is_current_buffer
+ " Set up a one-time use event that will delete itself to reload the
+ " buffer next time it's entered to view the changes made to it.
+ execute 'augroup ALECodeActionReloadGroup' . l:buffer
+ autocmd!
+
+ execute printf(
+ \ 'autocmd BufEnter <buffer=%d>'
+ \ . ' call ale#code_action#ReloadBuffer()',
+ \ l:buffer
+ \)
+ augroup END
+ endif
endfunction
function! s:UpdateCursor(cursor, start, end, offset) abort
diff --git a/autoload/ale/rename.vim b/autoload/ale/rename.vim
index 0d074c24..9030618e 100644
--- a/autoload/ale/rename.vim
+++ b/autoload/ale/rename.vim
@@ -85,7 +85,6 @@ function! ale#rename#HandleTSServerResponse(conn_id, response) abort
\ },
\ {
\ 'should_save': 1,
- \ 'force_save': get(l:options, 'force_save'),
\ },
\)
endfunction
@@ -118,7 +117,6 @@ function! ale#rename#HandleLSPResponse(conn_id, response) abort
\ },
\ {
\ 'should_save': 1,
- \ 'force_save': get(l:options, 'force_save'),
\ },
\)
endif
@@ -177,7 +175,7 @@ function! s:ExecuteRename(linter, options) abort
call ale#lsp_linter#StartLSP(l:buffer, a:linter, l:Callback)
endfunction
-function! ale#rename#Execute(options) abort
+function! ale#rename#Execute() abort
let l:lsp_linters = []
for l:linter in ale#linter#Get(&filetype)
@@ -205,7 +203,6 @@ function! ale#rename#Execute(options) abort
call s:ExecuteRename(l:lsp_linter, {
\ 'old_name': l:old_name,
\ 'new_name': l:new_name,
- \ 'force_save': get(a:options, 'force_save') is 1,
\})
endfor
endfunction
diff --git a/doc/ale.txt b/doc/ale.txt
index 71caf0e5..a64f86f0 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -3145,12 +3145,6 @@ ALERename *ALERename*
The symbol where the cursor is resting will be the symbol renamed, and a
prompt will open to request a new name.
- ALE will refuse to complete a rename operation if there are files to modify
- which have not yet been saved in Vim. If the command is run with a bang
- (`:ALERename!`), all warnings will be suppressed, and files that are still
- open in Vim and not saved will be ignored and left in a state where symbols
- in those files will not be updated.
-
ALECodeAction *ALECodeAction*
diff --git a/plugin/ale.vim b/plugin/ale.vim
index 2398956e..1fde9df1 100644
--- a/plugin/ale.vim
+++ b/plugin/ale.vim
@@ -245,7 +245,7 @@ command! -bar ALEComplete :call ale#completion#GetCompletions('ale-manual')
command! -bar ALEImport :call ale#completion#Import()
" Rename symbols using tsserver and LSP
-command! -bar -bang ALERename :call ale#rename#Execute({'force_save': '<bang>' is# '!'})
+command! -bar -bang ALERename :call ale#rename#Execute()
" Apply code actions to a range.
command! -bar -range ALECodeAction :call ale#codefix#Execute(<range>)
diff --git a/test/test_rename.vader b/test/test_rename.vader
index 2e8b746e..5bc655f4 100644
--- a/test/test_rename.vader
+++ b/test/test_rename.vader
@@ -269,7 +269,7 @@ Execute(tsserver rename requests should be sent):
\ }]
\ ],
\ g:message_list
- AssertEqual {'42': {'old_name': 'somelongerline', 'new_name': 'a-new-name', 'force_save': 0}},
+ AssertEqual {'42': {'old_name': 'somelongerline', 'new_name': 'a-new-name'}},
\ ale#rename#GetMap()
Given python(Some Python file):
@@ -470,7 +470,7 @@ Execute(LSP rename requests should be sent):
let b:ale_linters = ['pyls']
call setpos('.', [bufnr(''), 1, 5, 0])
- ALERename!
+ ALERename
" We shouldn't register the callback yet.
AssertEqual '''''', string(g:Callback)
@@ -500,5 +500,5 @@ Execute(LSP rename requests should be sent):
\ ],
\ g:message_list
- AssertEqual {'42': {'old_name': 'foo', 'new_name': 'a-new-name', 'force_save': 1}},
+ AssertEqual {'42': {'old_name': 'foo', 'new_name': 'a-new-name'}},
\ ale#rename#GetMap()