summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2020-09-04 09:37:33 +0100
committerw0rp <devw0rp@gmail.com>2020-09-04 09:37:33 +0100
commit844febb9fbfb66bb13dd652d958495e47f0bd408 (patch)
tree69781eefef1c9cc9cc410fee5e21a50bb56a35f8 /autoload
parentd4a14746cdcda99ec70915c5540962c85e33f661 (diff)
downloadale-844febb9fbfb66bb13dd652d958495e47f0bd408.zip
Fix #3322 - Apply rename changes correctly
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/code_action.vim39
1 files changed, 38 insertions, 1 deletions
diff --git a/autoload/ale/code_action.vim b/autoload/ale/code_action.vim
index 60c3bbef..8c7263f3 100644
--- a/autoload/ale/code_action.vim
+++ b/autoload/ale/code_action.vim
@@ -24,6 +24,42 @@ function! ale#code_action#HandleCodeAction(code_action, should_save) abort
endfor
endfunction
+function! s:ChangeCmp(left, right) abort
+ if a:left.start.line < a:right.start.line
+ return -1
+ endif
+
+ if a:left.start.line > a:right.start.line
+ return 1
+ endif
+
+ if a:left.start.offset < a:right.start.offset
+ return -1
+ endif
+
+ if a:left.start.offset > a:right.start.offset
+ return 1
+ endif
+
+ if a:left.end.line < a:right.end.line
+ return -1
+ endif
+
+ if a:left.end.line > a:right.end.line
+ return 1
+ endif
+
+ if a:left.end.offset < a:right.end.offset
+ return -1
+ endif
+
+ if a:left.end.offset > a:right.end.offset
+ return 1
+ endif
+
+ return 0
+endfunction
+
function! ale#code_action#ApplyChanges(filename, changes, should_save) abort
let l:current_buffer = bufnr('')
" The buffer is used to determine the fileformat, if available.
@@ -48,7 +84,8 @@ function! ale#code_action#ApplyChanges(filename, changes, should_save) abort
let l:column_offset = 0
let l:last_end_line = 0
- for l:code_edit in a:changes
+ " Changes have to be sorted so we apply them from top-to-bottom.
+ for l:code_edit in sort(copy(a:changes), function('s:ChangeCmp'))
if l:code_edit.start.line isnot l:last_end_line
let l:column_offset = 0
endif