aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorFelix Maurer2022-04-01 10:13:27 +0200
committerw0rp2022-04-01 10:42:40 +0100
commitf0fa1377218fe3ee622d16c1f882bef841c6a5e2 (patch)
treebb7a938ff92146f6b7c711587cea4e1fae8769e1
parent7e2342ab524d42b09545a7a3231251bdfeeccab8 (diff)
downloadale-v3.2.x.tar.gz

Fix end line number when it exceeds the file (#4130)

v3.2.x

If the end of the error exceeds the file, set it to the last line, similarly as it is done with the beginning of the error.

-rw-r--r--autoload/ale/engine.vim6
-rw-r--r--test/test_loclist_corrections.vader15
2 files changed, 14 insertions, 7 deletions
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index 5b9b1fca6..00789a2d2 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -347,6 +347,12 @@ function! ale#engine#FixLocList(buffer, linter_name, from_other_source, loclist)
if has_key(l:old_item, 'end_lnum')
let l:item.end_lnum = str2nr(l:old_item.end_lnum)
+
+ " When the error ends after the end of the file, put it at the
+ " end. This is only done for the current buffer.
+ if l:item.bufnr == a:buffer && l:item.end_lnum > l:last_line_number
+ let l:item.end_lnum = l:last_line_number
+ endif
endif
if has_key(l:old_item, 'sub_type')
diff --git a/test/test_loclist_corrections.vader b/test/test_loclist_corrections.vader
index d53b1411d..60b1eba7b 100644
--- a/test/test_loclist_corrections.vader
+++ b/test/test_loclist_corrections.vader
@@ -124,6 +124,7 @@ Execute(FixLocList should set items with lines beyond the end to the last line):
\ 'text': 'a',
\ 'lnum': 10,
\ 'col': 0,
+ \ 'end_lnum': 10,
\ 'bufnr': bufnr('%'),
\ 'vcol': 0,
\ 'type': 'E',
@@ -135,7 +136,7 @@ Execute(FixLocList should set items with lines beyond the end to the last line):
\ bufnr('%'),
\ 'foobar',
\ 0,
- \ [{'text': 'a', 'lnum': 11}],
+ \ [{'text': 'a', 'lnum': 11, 'end_lnum': 12}],
\ )
Execute(FixLocList should move line 0 to line 1):
@@ -223,9 +224,9 @@ Execute(FixLocList should pass on end_lnum values):
\ [
\ {
\ 'text': 'a',
- \ 'lnum': 10,
+ \ 'lnum': 7,
\ 'col': 10,
- \ 'end_lnum': 13,
+ \ 'end_lnum': 10,
\ 'end_col': 12,
\ 'bufnr': bufnr('%'),
\ 'vcol': 0,
@@ -235,9 +236,9 @@ Execute(FixLocList should pass on end_lnum values):
\ },
\ {
\ 'text': 'a',
- \ 'lnum': 10,
+ \ 'lnum': 7,
\ 'col': 11,
- \ 'end_lnum': 13,
+ \ 'end_lnum': 10,
\ 'end_col': 12,
\ 'bufnr': bufnr('%'),
\ 'vcol': 0,
@@ -251,8 +252,8 @@ Execute(FixLocList should pass on end_lnum values):
\ 'foobar',
\ 0,
\ [
- \ {'text': 'a', 'lnum': '010', 'col': '010', 'end_col': '012', 'end_lnum': '013'},
- \ {'text': 'a', 'lnum': '010', 'col': '011', 'end_col': 12, 'end_lnum': 13},
+ \ {'text': 'a', 'lnum': '07', 'col': '010', 'end_col': '012', 'end_lnum': '010'},
+ \ {'text': 'a', 'lnum': '07', 'col': '011', 'end_col': 12, 'end_lnum': 10},
\ ],
\ )