diff options
author | w0rp <devw0rp@gmail.com> | 2020-10-15 21:56:21 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2020-10-15 21:56:21 +0100 |
commit | 477eb89793f9be3be95cf89a22c8ff94a88ba9a8 (patch) | |
tree | 7b2b5d187b026bcb4a3860cfe85233dca76a62c4 /autoload | |
parent | f384d61c3d4d624fd391a6d877ec913096b2bb10 (diff) | |
download | ale-477eb89793f9be3be95cf89a22c8ff94a88ba9a8.zip |
#3332 Implement :ALERename! for ignoring errors
:ALERename! now ignores errors for files that cannot be modified, and
modifies all other files.
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/code_action.vim | 23 | ||||
-rw-r--r-- | autoload/ale/completion.vim | 2 | ||||
-rw-r--r-- | autoload/ale/organize_imports.vim | 11 | ||||
-rw-r--r-- | autoload/ale/rename.vim | 59 |
4 files changed, 59 insertions, 36 deletions
diff --git a/autoload/ale/code_action.vim b/autoload/ale/code_action.vim index 8c7263f3..42f4f265 100644 --- a/autoload/ale/code_action.vim +++ b/autoload/ale/code_action.vim @@ -1,26 +1,33 @@ " Author: Jerko Steiner <jerko.steiner@gmail.com> " Description: Code action support for LSP / tsserver -function! ale#code_action#HandleCodeAction(code_action, should_save) abort +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') - call ale#util#Execute('echom ''Aborting action, file is unsaved''') + if !l:force_save + call ale#util#Execute('echom ''Aborting action, file is unsaved''') - return + return + endif + else + call add(l:safe_changes, l:file_code_edit) endif endfor - for l:file_code_edit in l:changes + for l:file_code_edit in l:safe_changes call ale#code_action#ApplyChanges( - \ l:file_code_edit.fileName, - \ l:file_code_edit.textChanges, - \ a:should_save, - \ ) + \ l:file_code_edit.fileName, + \ l:file_code_edit.textChanges, + \ l:should_save, + \) endfor endfunction diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index ecd93600..efbf0fd5 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -1006,7 +1006,7 @@ function! ale#completion#HandleUserData(completed_item) abort \|| l:source is# 'ale-import' \|| l:source is# 'ale-omnifunc' for l:code_action in get(l:user_data, 'code_actions', []) - call ale#code_action#HandleCodeAction(l:code_action, v:false) + call ale#code_action#HandleCodeAction(l:code_action, {}) endfor endif diff --git a/autoload/ale/organize_imports.vim b/autoload/ale/organize_imports.vim index e89c832c..e2b1c0d2 100644 --- a/autoload/ale/organize_imports.vim +++ b/autoload/ale/organize_imports.vim @@ -12,10 +12,13 @@ function! ale#organize_imports#HandleTSServerResponse(conn_id, response) abort let l:file_code_edits = a:response.body - call ale#code_action#HandleCodeAction({ - \ 'description': 'Organize Imports', - \ 'changes': l:file_code_edits, - \}, v:false) + call ale#code_action#HandleCodeAction( + \ { + \ 'description': 'Organize Imports', + \ 'changes': l:file_code_edits, + \ }, + \ {} + \) endfunction function! s:OnReady(linter, lsp_details) abort diff --git a/autoload/ale/rename.vim b/autoload/ale/rename.vim index 64952e63..8190411d 100644 --- a/autoload/ale/rename.vim +++ b/autoload/ale/rename.vim @@ -33,9 +33,10 @@ function! ale#rename#HandleTSServerResponse(conn_id, response) abort return endif - let l:old_name = s:rename_map[a:response.request_seq].old_name - let l:new_name = s:rename_map[a:response.request_seq].new_name - call remove(s:rename_map, a:response.request_seq) + let l:options = remove(s:rename_map, a:response.request_seq) + + let l:old_name = l:options.old_name + let l:new_name = l:options.new_name if get(a:response, 'success', v:false) is v:false let l:message = get(a:response, 'message', 'unknown') @@ -77,10 +78,16 @@ function! ale#rename#HandleTSServerResponse(conn_id, response) abort return endif - call ale#code_action#HandleCodeAction({ - \ 'description': 'rename', - \ 'changes': l:changes, - \}, v:true) + call ale#code_action#HandleCodeAction( + \ { + \ 'description': 'rename', + \ 'changes': l:changes, + \ }, + \ { + \ 'should_save': 1, + \ 'force_save': get(l:options, 'force_save'), + \ }, + \) endfunction function! s:getChanges(workspace_edit) abort @@ -111,7 +118,7 @@ endfunction function! ale#rename#HandleLSPResponse(conn_id, response) abort if has_key(a:response, 'id') \&& has_key(s:rename_map, a:response.id) - call remove(s:rename_map, a:response.id) + let l:options = remove(s:rename_map, a:response.id) if !has_key(a:response, 'result') call s:message('No rename result received from server') @@ -156,14 +163,20 @@ function! ale#rename#HandleLSPResponse(conn_id, response) abort \}) endfor - call ale#code_action#HandleCodeAction({ - \ 'description': 'rename', - \ 'changes': l:changes, - \}, v:true) + call ale#code_action#HandleCodeAction( + \ { + \ 'description': 'rename', + \ 'changes': l:changes, + \ }, + \ { + \ 'should_save': 1, + \ 'force_save': get(l:options, 'force_save'), + \ }, + \) endif endfunction -function! s:OnReady(line, column, old_name, new_name, linter, lsp_details) abort +function! s:OnReady(line, column, options, linter, lsp_details) abort let l:id = a:lsp_details.connection_id if !ale#lsp#HasCapability(l:id, 'rename') @@ -195,19 +208,16 @@ function! s:OnReady(line, column, old_name, new_name, linter, lsp_details) abort \ l:buffer, \ a:line, \ a:column, - \ a:new_name + \ a:options.new_name \) endif let l:request_id = ale#lsp#Send(l:id, l:message) - let s:rename_map[l:request_id] = { - \ 'new_name': a:new_name, - \ 'old_name': a:old_name, - \} + let s:rename_map[l:request_id] = a:options endfunction -function! s:ExecuteRename(linter, old_name, new_name) abort +function! s:ExecuteRename(linter, options) abort let l:buffer = bufnr('') let [l:line, l:column] = getpos('.')[1:2] @@ -215,12 +225,11 @@ function! s:ExecuteRename(linter, old_name, new_name) abort let l:column = min([l:column, len(getline(l:line))]) endif - let l:Callback = function( - \ 's:OnReady', [l:line, l:column, a:old_name, a:new_name]) + let l:Callback = function('s:OnReady', [l:line, l:column, a:options]) call ale#lsp_linter#StartLSP(l:buffer, a:linter, l:Callback) endfunction -function! ale#rename#Execute() abort +function! ale#rename#Execute(options) abort let l:lsp_linters = [] for l:linter in ale#linter#Get(&filetype) @@ -245,6 +254,10 @@ function! ale#rename#Execute() abort endif for l:lsp_linter in l:lsp_linters - call s:ExecuteRename(l:lsp_linter, l:old_name, l:new_name) + 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 |