#2017 Add support for display results from other sources

This commit is contained in:
w0rp
2018-10-29 18:28:28 +00:00
parent 2846e86217
commit caac5c93d6
16 changed files with 393 additions and 38 deletions

View File

@@ -23,7 +23,7 @@ Before:
autocmd!
autocmd User ALEFixPre let g:pre_success = 1
autocmd User ALEFixPost let g:post_success = 1
augroup end
augroup END
if !has('win32')
let &shell = '/bin/bash'
@@ -180,7 +180,6 @@ After:
unlet! g:ale_emulate_job_failure
unlet! b:ale_fixers
unlet! b:ale_fix_on_save
augroup! VaderTest
delfunction AddCarets
delfunction AddDollars
delfunction DoNothing
@@ -204,6 +203,12 @@ After:
delfunction FixWithJSONPostProcessing
delfunction JSONPostProcessor
augroup VaderTest
autocmd!
augroup END
augroup! VaderTest
call ale#test#RestoreDirectory()
call ale#fix#registry#ResetToDefaults()

View File

@@ -23,10 +23,11 @@ After:
let g:ale_run_synchronously = 0
try
augroup! VaderTest
catch
endtry
augroup VaderTest
autocmd!
augroup END
augroup! VaderTest
unlet! g:job_started_success
@@ -38,7 +39,7 @@ Execute(Run a lint cycle with an actual job to check for ALEJobStarted):
augroup VaderTest
autocmd!
autocmd User ALEJobStarted let g:job_started_success = 1
augroup end
augroup END
ALELint

View File

@@ -9,10 +9,11 @@ After:
let g:ale_run_synchronously = 0
let g:ale_buffer_info = {}
try
augroup! VaderTest
catch
endtry
augroup VaderTest
autocmd!
augroup END
augroup! VaderTest
Given testft(An empty file):
Execute(Run a lint cycle, and check that a variable is set in the autocmd):
@@ -20,7 +21,7 @@ Execute(Run a lint cycle, and check that a variable is set in the autocmd):
autocmd!
autocmd User ALELintPre let g:pre_success = 1
autocmd User ALELintPost let g:post_success = 1
augroup end
augroup END
call ale#Queue(0)

View File

@@ -31,7 +31,7 @@ After:
augroup VaderTest
autocmd!
augroup end
augroup END
augroup! VaderTest
@@ -40,7 +40,7 @@ Execute(ALELintPre should not return success on ale#engine#IsCheckingBuffer):
augroup VaderTest
autocmd!
autocmd User ALELintPre let g:checking_buffer = ale#engine#IsCheckingBuffer(bufnr('')) ? 1 : 0
augroup end
augroup END
ALELint
@@ -50,7 +50,7 @@ Execute(ALEJobStarted should return success on ale#engine#IsCheckingBuffer):
augroup VaderTest
autocmd!
autocmd User ALEJobStarted let g:checking_buffer = ale#engine#IsCheckingBuffer(bufnr('')) ? 1 : 0
augroup end
augroup END
ALELint

View File

@@ -108,7 +108,7 @@ Before:
let g:run_linters_called = 1
endfunction
function! ale#engine#HandleLoclist(linter_name, buffer, loclist) abort
function! ale#engine#HandleLoclist(linter_name, buffer, loclist, from_other_source) abort
let g:loclist = a:loclist
endfunction

View File

@@ -16,7 +16,7 @@ Execute(It should be possible to remap errors to style errors):
\ {'type': 'W', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'},
\ {'type': 'I', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'},
\ ],
\ ale#engine#FixLocList(bufnr(''), 'foo', [
\ ale#engine#FixLocList(bufnr(''), 'foo', 0, [
\ {'type': 'E', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
\ {'type': 'E', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
\ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
@@ -35,7 +35,7 @@ Execute(It should be possible to remap errors to style errors with buffer-local
\ {'type': 'W', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'},
\ {'type': 'I', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'},
\ ],
\ ale#engine#FixLocList(bufnr(''), 'foo', [
\ ale#engine#FixLocList(bufnr(''), 'foo', 0, [
\ {'type': 'E', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
\ {'type': 'E', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
\ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
@@ -54,7 +54,7 @@ Execute(It should be possible to remap warnings to style warnings):
\ {'type': 'W', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'},
\ {'type': 'I', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'},
\ ],
\ ale#engine#FixLocList(bufnr(''), 'foo', [
\ ale#engine#FixLocList(bufnr(''), 'foo', 0, [
\ {'type': 'E', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
\ {'type': 'E', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
\ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
@@ -73,7 +73,7 @@ Execute(It should be possible to remap style errors to errors):
\ {'type': 'W', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'},
\ {'type': 'I', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'},
\ ],
\ ale#engine#FixLocList(bufnr(''), 'foo', [
\ ale#engine#FixLocList(bufnr(''), 'foo', 0, [
\ {'type': 'E', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
\ {'type': 'E', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
\ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
@@ -92,7 +92,7 @@ Execute(It should be possible to remap style warnings to warnings):
\ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'},
\ {'type': 'I', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'},
\ ],
\ ale#engine#FixLocList(bufnr(''), 'foo', [
\ ale#engine#FixLocList(bufnr(''), 'foo', 0, [
\ {'type': 'E', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
\ {'type': 'E', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
\ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
@@ -111,7 +111,7 @@ Execute(It should be possible to info problems to warnings):
\ {'type': 'W', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'},
\ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1, 'linter_name': 'foo'},
\ ],
\ ale#engine#FixLocList(bufnr(''), 'foo', [
\ ale#engine#FixLocList(bufnr(''), 'foo', 0, [
\ {'type': 'E', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
\ {'type': 'E', 'sub_type': 'style', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},
\ {'type': 'W', 'lnum': 1, 'text': 'x', 'bufnr': bufnr(''), 'col': 0, 'vcol': 0, 'nr': -1},

View File

@@ -41,6 +41,7 @@ Execute(FixLocList should set all the default values correctly):
\ ale#engine#FixLocList(
\ bufnr('%'),
\ 'foobar',
\ 0,
\ [{'text': 'a', 'lnum': 2}, {'text': 'b', 'lnum': 2}],
\ )
@@ -61,6 +62,7 @@ Execute(FixLocList should use the values we supply):
\ ale#engine#FixLocList(
\ bufnr('%'),
\ 'foobar',
\ 0,
\ [{
\ 'text': 'a',
\ 'lnum': 3,
@@ -89,6 +91,7 @@ Execute(FixLocList should set items with lines beyond the end to the last line):
\ ale#engine#FixLocList(
\ bufnr('%'),
\ 'foobar',
\ 0,
\ [{'text': 'a', 'lnum': 11}],
\ )
@@ -109,6 +112,7 @@ Execute(FixLocList should move line 0 to line 1):
\ ale#engine#FixLocList(
\ bufnr('%'),
\ 'foobar',
\ 0,
\ [{'text': 'a', 'lnum': 0}],
\ )
@@ -130,6 +134,7 @@ Execute(FixLocList should convert line and column numbers correctly):
\ ale#engine#FixLocList(
\ bufnr('%'),
\ 'foobar',
\ 0,
\ [{'text': 'a', 'lnum': '010', 'col': '010'}],
\ )
@@ -163,6 +168,7 @@ Execute(FixLocList should pass on end_col values):
\ ale#engine#FixLocList(
\ bufnr('%'),
\ 'foobar',
\ 0,
\ [
\ {'text': 'a', 'lnum': '010', 'col': '010', 'end_col': '012'},
\ {'text': 'a', 'lnum': '010', 'col': '011', 'end_col': 12},
@@ -200,6 +206,7 @@ Execute(FixLocList should pass on end_lnum values):
\ ale#engine#FixLocList(
\ bufnr('%'),
\ '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},
@@ -224,6 +231,7 @@ Execute(FixLocList should allow subtypes to be set):
\ ale#engine#FixLocList(
\ bufnr('%'),
\ 'foobar',
\ 0,
\ [{'text': 'a', 'lnum': 11, 'sub_type': 'style'}],
\ )
@@ -285,6 +293,7 @@ Execute(FixLocList should accept filenames):
\ ale#engine#FixLocList(
\ bufnr('%'),
\ 'foobar',
\ 0,
\ [
\ {'text': 'a', 'lnum': 2, 'filename': expand('%:p')},
\ {'text': 'a', 'lnum': 3, 'filename': expand('%:p')},
@@ -322,6 +331,7 @@ Execute(FixLocList should interpret temporary filenames as being the current buf
\ ale#engine#FixLocList(
\ bufnr(''),
\ 'foobar',
\ 0,
\ [
\ {'text': 'a', 'lnum': 2, 'filename': b:temp_name},
\ {'text': 'a', 'lnum': 3, 'filename': substitute(b:temp_name, '\\', '/', 'g')},
@@ -346,9 +356,43 @@ Execute(The error code should be passed on):
\ ale#engine#FixLocList(
\ bufnr('%'),
\ 'foobar',
\ 0,
\ [{'text': 'a', 'lnum': 11, 'code': 'some-code'}],
\ )
Execute(FixLocList should mark problems as coming from other sources if requested):
AssertEqual
\ [
\ {
\ 'text': 'a',
\ 'lnum': 2,
\ 'col': 0,
\ 'bufnr': bufnr('%'),
\ 'vcol': 0,
\ 'type': 'E',
\ 'nr': -1,
\ 'linter_name': 'foobar',
\ 'from_other_source': 1,
\ },
\ {
\ 'text': 'b',
\ 'lnum': 2,
\ 'col': 0,
\ 'bufnr': bufnr('%'),
\ 'vcol': 0,
\ 'type': 'E',
\ 'nr': -1,
\ 'linter_name': 'foobar',
\ 'from_other_source': 1,
\ },
\],
\ ale#engine#FixLocList(
\ bufnr('%'),
\ 'foobar',
\ 1,
\ [{'text': 'a', 'lnum': 2}, {'text': 'b', 'lnum': 2}],
\ )
Given(A file with Japanese multi-byte text):
はじめまして!
-私はワープです。
@@ -367,6 +411,7 @@ Execute(character positions should be converted to byte positions):
\ ale#engine#FixLocList(
\ bufnr('%'),
\ 'foobar',
\ 0,
\ [
\ {'text': 'a', 'lnum': 1, 'col': 0, 'vcol': 1},
\ {'text': 'a', 'lnum': 1, 'col': 1, 'vcol': 1},

View File

@@ -0,0 +1,153 @@
Before:
Save g:ale_buffer_info
Save g:ale_set_signs
Save g:ale_set_quickfix
Save g:ale_set_loclist
Save g:ale_set_highlights
Save g:ale_echo_cursor
let g:ale_buffer_info = {}
let g:ale_run_synchronously = 1
let g:ale_set_lists_synchronously = 1
let g:ale_set_signs = 0
let g:ale_set_quickfix = 0
let g:ale_set_loclist = 1
let g:ale_set_highlights = 0
let g:ale_echo_cursor = 0
function! TestCallback(buffer, output)
return []
endfunction
call ale#linter#Define('foobar', {
\ 'name': 'testlinter',
\ 'callback': 'TestCallback',
\ 'executable': has('win32') ? 'cmd' : 'echo',
\ 'command': has('win32') ? 'echo foo bar' : '/bin/sh -c ''echo foo bar''',
\})
After:
Restore
unlet! b:ale_linters
unlet! g:want_results_signaled
unlet! g:want_results_buffer_value
unlet! g:lint_pre_signaled
unlet! g:ale_run_synchronously
unlet! g:ale_set_lists_synchronously
delfunction TestCallback
augroup VaderTest
autocmd!
augroup END
augroup! VaderTest
call ale#linter#Reset()
call setloclist(0, [])
Given foobar (Some imaginary filetype):
Execute(StartChecking should mark a buffer as being actively checked):
Assert !ale#engine#IsCheckingBuffer(bufnr(''))
call ale#other_source#StartChecking(bufnr(''), 'other-source-linter')
Assert ale#engine#IsCheckingBuffer(bufnr(''))
Execute(ShowResults sould make a buffer inactive):
call ale#other_source#StartChecking(bufnr(''), 'other-source-linter')
call ale#other_source#StartChecking(bufnr(''), 'second-other-source-linter')
call ale#other_source#ShowResults(bufnr(''), 'other-source-linter', [])
Assert ale#engine#IsCheckingBuffer(bufnr(''))
call ale#other_source#ShowResults(bufnr(''), 'second-other-source-linter', [])
Assert !ale#engine#IsCheckingBuffer(bufnr(''))
Execute(ShowResults should show results at any time):
call ale#other_source#ShowResults(bufnr(''), 'other-source-linter', [
\ {'text': 'xyz', 'lnum': 1},
\])
AssertEqual
\ [
\ {
\ 'lnum': 1,
\ 'bufnr': bufnr(''),
\ 'col': 0,
\ 'valid': 1,
\ 'vcol': 0,
\ 'nr': -1,
\ 'type': 'E',
\ 'pattern': '',
\ 'text': 'xyz',
\ },
\ ],
\ ale#test#GetLoclistWithoutModule()
call ale#other_source#ShowResults(bufnr(''), 'other-source-linter', [])
AssertEqual [], ale#test#GetLoclistWithoutModule()
Execute(A regular lint cycle shouldn't clear results from other sources):
call ale#other_source#ShowResults(bufnr(''), 'other-source-linter', [
\ {'text': 'xyz', 'lnum': 1},
\])
ALELint
AssertEqual
\ [
\ {
\ 'lnum': 1,
\ 'bufnr': bufnr(''),
\ 'col': 0,
\ 'valid': 1,
\ 'vcol': 0,
\ 'nr': -1,
\ 'type': 'E',
\ 'pattern': '',
\ 'text': 'xyz',
\ },
\ ],
\ ale#test#GetLoclistWithoutModule()
Execute(ALEWantResults should be signaled when a buffer is checked):
augroup VaderTest
autocmd!
autocmd User ALEWantResults let g:want_results_signaled = 1
autocmd User ALELintPre let g:lint_pre_signaled = 1
augroup END
" Even when all linters are disabled, we should send the signal.
let b:ale_linters = []
ALELint
Assert get(g:, 'want_results_signaled')
Assert !get(g:, 'lint_pre_signaled')
Execute(ALEWantResults should set a variable indicating which buffer is being checked):
augroup VaderTest
autocmd!
autocmd User ALEWantResults let g:want_results_buffer_value = g:ale_want_results_buffer
augroup END
let b:ale_linters = []
ALELint
AssertEqual bufnr(''), g:want_results_buffer_value
Execute(ALEWantResults should lead to an ALELintPre signal if another source responds):
augroup VaderTest
autocmd!
autocmd User ALEWantResults call ale#other_source#StartChecking(bufnr(''), 'other-source-linter')
autocmd User ALELintPre let g:lint_pre_signaled = 1
augroup END
" Even when all linters are disabled, we should send the signal.
let b:ale_linters = []
ALELint
Assert get(g:, 'lint_pre_signaled')

View File

@@ -45,7 +45,7 @@ Before:
let g:ale_buffer_info = {bufnr(''): {'loclist': []}}
let g:ale_handle_loclist_called = 0
function! ale#engine#HandleLoclist(linter_name, buffer, loclist) abort
function! ale#engine#HandleLoclist(linter_name, buffer, loclist, from_other_source) abort
let g:ale_handle_loclist_called = 1
endfunction

View File

@@ -9,14 +9,14 @@ Before:
let g:ale_buffer_info = {}
call ale#engine#InitBufferInfo(bufnr('') + 1)
let g:ale_buffer_info[bufnr('') + 1].loclist =
\ ale#engine#FixLocList(bufnr('') + 1, 'linter_one', [
\ ale#engine#FixLocList(bufnr('') + 1, 'linter_one', 0, [
\ {'lnum': 1, 'filename': expand('%:p'), 'text': 'foo'},
\ {'lnum': 2, 'filename': expand('%:p'), 'text': 'bar'},
\ {'lnum': 2, 'text': 'ignore this one'},
\ ])
call ale#engine#InitBufferInfo(bufnr('') + 2)
let g:ale_buffer_info[bufnr('') + 2].loclist =
\ ale#engine#FixLocList(bufnr('') + 2, 'linter_one', [
\ ale#engine#FixLocList(bufnr('') + 2, 'linter_one', 0, [
\ {'lnum': 1, 'filename': expand('%:p'), 'text': 'foo'},
\ {'lnum': 3, 'filename': expand('%:p'), 'text': 'baz'},
\ {'lnum': 5, 'text': 'ignore this one'},