summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-08-10 23:08:32 +0100
committerw0rp <devw0rp@gmail.com>2017-08-10 23:08:40 +0100
commitb1462ac66c10ed323c5148ecd8821c3a433ff403 (patch)
treed840e608a7674296fddd7f5280d702e6c1acae7c
parent322910dc0b07c1b59bc968b1fb0d4c1d8bfb988e (diff)
downloadale-b1462ac66c10ed323c5148ecd8821c3a433ff403.zip
#653 - Pass on filenames for loclist items
-rw-r--r--autoload/ale/engine.vim26
-rw-r--r--test/test_loclist_corrections.vader70
2 files changed, 94 insertions, 2 deletions
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index 40cc7ad3..2cd691b7 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -333,6 +333,7 @@ function! s:RemapItemTypes(type_map, loclist) abort
endfunction
function! ale#engine#FixLocList(buffer, linter_name, loclist) abort
+ let l:bufnr_map = {}
let l:new_loclist = []
" Some errors have line numbers beyond the end of the file,
@@ -357,13 +358,36 @@ function! ale#engine#FixLocList(buffer, linter_name, loclist) abort
\ 'text': l:old_item.text,
\ 'lnum': str2nr(l:old_item.lnum),
\ 'col': str2nr(get(l:old_item, 'col', 0)),
- \ 'bufnr': get(l:old_item, 'bufnr', a:buffer),
\ 'vcol': get(l:old_item, 'vcol', 0),
\ 'type': get(l:old_item, 'type', 'E'),
\ 'nr': get(l:old_item, 'nr', -1),
\ 'linter_name': a:linter_name,
\}
+ if has_key(l:old_item, 'filename')
+ " Use the filename given.
+ let l:filename = l:old_item.filename
+ let l:item.filename = l:filename
+
+ if has_key(l:old_item, 'bufnr')
+ " If a buffer number is also given, include that too.
+ " If Vim detects that he buffer number is valid, it will
+ " be used instead of the filename.
+ let l:item.bufnr = l:old_item.bufnr
+ elseif has_key(l:bufnr_map, l:filename)
+ " Get the buffer number from the map, which can be faster.
+ let l:item.bufnr = l:bufnr_map[l:filename]
+ else
+ " Look up the buffer number.
+ let l:item.bufnr = bufnr(l:filename)
+ let l:bufnr_map[l:filename] = l:item.bufnr
+ endif
+ elseif has_key(l:old_item, 'bufnr')
+ let l:item.bufnr = l:old_item.bufnr
+ else
+ let l:item.bufnr = a:buffer
+ endif
+
if has_key(l:old_item, 'detail')
let l:item.detail = l:old_item.detail
endif
diff --git a/test/test_loclist_corrections.vader b/test/test_loclist_corrections.vader
index e23109ed..a00eb21a 100644
--- a/test/test_loclist_corrections.vader
+++ b/test/test_loclist_corrections.vader
@@ -1,3 +1,6 @@
+After:
+ unlet! b:other_bufnr
+
Given foo (Some file with lines to count):
foo12345678
bar12345678
@@ -202,7 +205,6 @@ Execute(FixLocList should pass on end_lnum values):
\ ],
\ )
-
Execute(FixLocList should allow subtypes to be set):
AssertEqual
\ [
@@ -223,3 +225,69 @@ Execute(FixLocList should allow subtypes to be set):
\ 'foobar',
\ [{'text': 'a', 'lnum': 11, 'sub_type': 'style'}],
\ )
+
+Execute(FixLocList should accept filenames):
+ let b:other_bufnr = bufnr('/foo/bar/baz', 1)
+
+ " Make sure we actually get another buffer number, or the test is invalid.
+ AssertNotEqual -1, b:other_bufnr
+
+ call ale#test#SetFilename('test.txt')
+
+ AssertEqual
+ \ [
+ \ {
+ \ 'text': 'a',
+ \ 'lnum': 2,
+ \ 'col': 0,
+ \ 'bufnr': bufnr('%'),
+ \ 'filename': expand('%:p'),
+ \ 'vcol': 0,
+ \ 'type': 'E',
+ \ 'nr': -1,
+ \ 'linter_name': 'foobar',
+ \ },
+ \ {
+ \ 'text': 'a',
+ \ 'lnum': 3,
+ \ 'col': 0,
+ \ 'bufnr': bufnr('%'),
+ \ 'filename': expand('%:p'),
+ \ 'vcol': 0,
+ \ 'type': 'E',
+ \ 'nr': -1,
+ \ 'linter_name': 'foobar',
+ \ },
+ \ {
+ \ 'text': 'a',
+ \ 'lnum': 4,
+ \ 'col': 0,
+ \ 'bufnr': b:other_bufnr,
+ \ 'filename': '/foo/bar/baz',
+ \ 'vcol': 0,
+ \ 'type': 'E',
+ \ 'nr': -1,
+ \ 'linter_name': 'foobar',
+ \ },
+ \ {
+ \ 'text': 'a',
+ \ 'lnum': 5,
+ \ 'col': 0,
+ \ 'bufnr': b:other_bufnr,
+ \ 'filename': '/foo/bar/baz',
+ \ 'vcol': 0,
+ \ 'type': 'E',
+ \ 'nr': -1,
+ \ 'linter_name': 'foobar',
+ \ },
+ \],
+ \ ale#engine#FixLocList(
+ \ bufnr('%'),
+ \ 'foobar',
+ \ [
+ \ {'text': 'a', 'lnum': 2, 'filename': expand('%:p')},
+ \ {'text': 'a', 'lnum': 3, 'filename': expand('%:p')},
+ \ {'text': 'a', 'lnum': 4, 'filename': '/foo/bar/baz'},
+ \ {'text': 'a', 'lnum': 5, 'filename': '/foo/bar/baz'},
+ \ ],
+ \ )