From 20f6bebdf22afca71b136a1ce8cff9f8b5ec7410 Mon Sep 17 00:00:00 2001 From: Christian Keil Date: Wed, 9 Sep 2020 17:30:41 +0200 Subject: Fix handling of ranges at file end. --- autoload/ale/code_action.vim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/autoload/ale/code_action.vim b/autoload/ale/code_action.vim index 8c7263f3..849942ca 100644 --- a/autoload/ale/code_action.vim +++ b/autoload/ale/code_action.vim @@ -127,10 +127,20 @@ function! ale#code_action#ApplyChanges(filename, changes, should_save) abort endif call extend(l:middle, l:insertions[1:]) - let l:middle[-1] .= l:lines[l:end_line - 1][l:end_column - 1 :] + if l:end_line <= len(l:lines) + " Only extend the last line if end_line is within the range of + " lines. + let l:middle[-1] .= l:lines[l:end_line - 1][l:end_column - 1 :] + endif let l:lines_before_change = len(l:lines) - let l:lines = l:start + l:middle + l:lines[l:end_line :] + + if l:end_line < len(l:lines) + let l:end = l:lines[l:end_line :] + else + let l:end = [] + endif + let l:lines = l:start + l:middle + l:end let l:current_line_offset = len(l:lines) - l:lines_before_change let l:line_offset += l:current_line_offset -- cgit v1.2.3 From d3932c02424eec0520faa2afa42371c27122f5a7 Mon Sep 17 00:00:00 2001 From: Christian Keil Date: Wed, 9 Sep 2020 17:44:09 +0200 Subject: Fix format linting error. --- autoload/ale/code_action.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/autoload/ale/code_action.vim b/autoload/ale/code_action.vim index 849942ca..1959d1b1 100644 --- a/autoload/ale/code_action.vim +++ b/autoload/ale/code_action.vim @@ -127,6 +127,7 @@ function! ale#code_action#ApplyChanges(filename, changes, should_save) abort endif call extend(l:middle, l:insertions[1:]) + if l:end_line <= len(l:lines) " Only extend the last line if end_line is within the range of " lines. @@ -140,6 +141,7 @@ function! ale#code_action#ApplyChanges(filename, changes, should_save) abort else let l:end = [] endif + let l:lines = l:start + l:middle + l:end let l:current_line_offset = len(l:lines) - l:lines_before_change -- cgit v1.2.3 From d1f48e5edef1d622817ffc054e6963e6ca956371 Mon Sep 17 00:00:00 2001 From: Christian Keil Date: Wed, 9 Sep 2020 17:49:21 +0200 Subject: Remove unnecessary length check. --- autoload/ale/code_action.vim | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/autoload/ale/code_action.vim b/autoload/ale/code_action.vim index 1959d1b1..359bc0d6 100644 --- a/autoload/ale/code_action.vim +++ b/autoload/ale/code_action.vim @@ -135,14 +135,7 @@ function! ale#code_action#ApplyChanges(filename, changes, should_save) abort endif let l:lines_before_change = len(l:lines) - - if l:end_line < len(l:lines) - let l:end = l:lines[l:end_line :] - else - let l:end = [] - endif - - let l:lines = l:start + l:middle + l:end + let l:lines = l:start + l:middle + l:lines[l:end_line :] let l:current_line_offset = len(l:lines) - l:lines_before_change let l:line_offset += l:current_line_offset -- cgit v1.2.3