From 70711022db8c8a5602550601ef275c20b2105bcc Mon Sep 17 00:00:00 2001 From: Jasper Woudenberg Date: Wed, 1 Mar 2017 23:14:30 -0800 Subject: [PATCH 1/4] Add support for error details Some review needed. --- ale_linters/elm/make.vim | 1 + autoload/ale/cursor.vim | 25 +++++++++++++++++++++++++ autoload/ale/engine.vim | 4 ++++ plugin/ale.vim | 4 ++++ test/test_cursor_warnings.vader | 14 +++++++++++++- 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/ale_linters/elm/make.vim b/ale_linters/elm/make.vim index 23297838..3a4febc9 100644 --- a/ale_linters/elm/make.vim +++ b/ale_linters/elm/make.vim @@ -25,6 +25,7 @@ function! ale_linters#elm#make#Handle(buffer, lines) abort \ 'col': l:error.region.start.column, \ 'type': (l:error.type ==? 'error') ? 'E' : 'W', \ 'text': l:error.overview, + \ 'detail': l:error.overview . "\n\n" . l:error.details \}) endif endfor diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim index 9aaa8e91..d6594db5 100644 --- a/autoload/ale/cursor.vim +++ b/autoload/ale/cursor.vim @@ -93,3 +93,28 @@ function! ale#cursor#EchoCursorWarningWithDelay() abort let s:cursor_timer = timer_start(10, function('ale#cursor#EchoCursorWarning')) endif endfunction + + +function! ale#cursor#ShowCursorDetail(...) abort + " Only show the details in normal mode, otherwise we will get problems. + if mode() !=# 'n' + return + endif + + let l:buffer = bufnr('%') + + if !has_key(g:ale_buffer_info, l:buffer) + return + endif + + let l:pos = getcurpos() + let l:loclist = g:ale_buffer_info[l:buffer].loclist + let l:index = ale#util#BinarySearch(l:loclist, l:pos[1], l:pos[2]) + + if l:index >= 0 + let l:loc = l:loclist[l:index] + if has_key(l:loc, 'detail') + echo l:loc.detail + endif + endif +endfunction diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index bc834083..fdf19db2 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -332,6 +332,10 @@ function! ale#engine#FixLocList(buffer, linter, loclist) abort \ 'linter_name': a:linter.name, \} + if has_key(l:old_item, 'detail') + let l:item.detail = l:old_item.detail + endif + if l:item.lnum == 0 " When errors appear at line 0, put them at line 1 instead. let l:item.lnum = 1 diff --git a/plugin/ale.vim b/plugin/ale.vim index 1d7f77a5..a3a407c4 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -208,6 +208,9 @@ command! ALEPreviousWrap :call ale#loclist_jumping#Jump('before', 1) command! ALENext :call ale#loclist_jumping#Jump('after', 0) command! ALENextWrap :call ale#loclist_jumping#Jump('after', 1) +" A command for showing error details. +command! ALEDetail :call ale#cursor#ShowCursorDetail() + " A command for turning ALE on or off. command! ALEToggle :call s:ALEToggle() " A command for linting manually. @@ -225,6 +228,7 @@ nnoremap (ale_next) :ALENext nnoremap (ale_next_wrap) :ALENextWrap nnoremap (ale_toggle) :ALEToggle nnoremap (ale_lint) :ALELint +nnoremap (ale_detail) :ALEDetail " Housekeeping diff --git a/test/test_cursor_warnings.vader b/test/test_cursor_warnings.vader index b12f2451..dbf5360f 100644 --- a/test/test_cursor_warnings.vader +++ b/test/test_cursor_warnings.vader @@ -10,7 +10,8 @@ Before: \ 'nr': -1, \ 'type': 'E', \ 'col': 10, - \ 'text': 'Missing semicolon. (semi)' + \ 'text': 'Missing semicolon. (semi)', + \ 'detail': 'Every statement should end with a semicolon' \ }, \ { \ 'lnum': 2, @@ -84,3 +85,14 @@ Then(Check the cursor output): let g:lines = split(g:output, "\n") AssertEqual 'Missing radix parameter (radix)', g:lines[-1] + +Execute(Evaluate the cursor detail function at line 1): + :1 + call ale#cursor#ShowCursorDetail() + +Then(Check the cursor output): + redir => g:output + :mess + redir END + + AssertEqual "Every statement should end with a semicolon", g:output[-1] From f5ddc51d8588844e7c21b0a8882114b0597ca502 Mon Sep 17 00:00:00 2001 From: Jasper Woudenberg Date: Thu, 2 Mar 2017 18:40:07 -0800 Subject: [PATCH 2/4] Address some feedback --- autoload/ale/cursor.vim | 50 +++++++++++++-------------------- test/test_cursor_warnings.vader | 17 ++++++++++- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim index d6594db5..7a9cfc80 100644 --- a/autoload/ale/cursor.vim +++ b/autoload/ale/cursor.vim @@ -38,34 +38,32 @@ function! ale#cursor#TruncatedEcho(message) abort endtry endfunction +function! s:FindItemAtCursor() abort + let l:info = get(g:ale_buffer_info, bufnr('%'), {'loclist': []}) + let l:pos = getcurpos() + let l:index = ale#util#BinarySearch(l:info.loclist, l:pos[1], l:pos[2]) + let l:loc = l:index >= 0 ? l:info.loclist[l:index] : {} + + return [l:info, l:loc] +endfunction + function! ale#cursor#EchoCursorWarning(...) abort " Only echo the warnings in normal mode, otherwise we will get problems. if mode() !=# 'n' return endif - let l:buffer = bufnr('%') + let [l:info, l:loc] = s:FindItemAtCursor() - if !has_key(g:ale_buffer_info, l:buffer) - return - endif - - let l:pos = getcurpos() - let l:loclist = g:ale_buffer_info[l:buffer].loclist - let l:index = ale#util#BinarySearch(l:loclist, l:pos[1], l:pos[2]) - - if l:index >= 0 - let l:loc = l:loclist[l:index] + if !empty(l:loc) let l:msg = s:GetMessage(l:loc.linter_name, l:loc.type, l:loc.text) call ale#cursor#TruncatedEcho(l:msg) - let g:ale_buffer_info[l:buffer].echoed = 1 - else + let l:info.echoed = 1 + elseif get(l:info, 'echoed') " We'll only clear the echoed message when moving off errors once, " so we don't continually clear the echo line. - if get(g:ale_buffer_info[l:buffer], 'echoed') - echo - let g:ale_buffer_info[l:buffer].echoed = 0 - endif + echo + let l:info.echoed = 1 endif endfunction @@ -94,27 +92,19 @@ function! ale#cursor#EchoCursorWarningWithDelay() abort endif endfunction - function! ale#cursor#ShowCursorDetail(...) abort - " Only show the details in normal mode, otherwise we will get problems. + " Only echo the warnings in normal mode, otherwise we will get problems. if mode() !=# 'n' return endif - let l:buffer = bufnr('%') + let [l:info, l:loc] = s:FindItemAtCursor() - if !has_key(g:ale_buffer_info, l:buffer) - return - endif - - let l:pos = getcurpos() - let l:loclist = g:ale_buffer_info[l:buffer].loclist - let l:index = ale#util#BinarySearch(l:loclist, l:pos[1], l:pos[2]) - - if l:index >= 0 - let l:loc = l:loclist[l:index] + if !empty(l:loc) if has_key(l:loc, 'detail') echo l:loc.detail + else + echo l:loc.text endif endif endfunction diff --git a/test/test_cursor_warnings.vader b/test/test_cursor_warnings.vader index dbf5360f..136e6abc 100644 --- a/test/test_cursor_warnings.vader +++ b/test/test_cursor_warnings.vader @@ -95,4 +95,19 @@ Then(Check the cursor output): :mess redir END - AssertEqual "Every statement should end with a semicolon", g:output[-1] + let g:lines = split(g:output, "\n") + + AssertEqual "Every statement should end with a semicolon", g:lines[-1] + +Execute(Evaluate the cursor detail function at line 2): + :2 + call ale#cursor#ShowCursorDetail() + +Then(Check the cursor output): + redir => g:output + :mess + redir END + + let g:lines = split(g:output, "\n") + + AssertEqual "Infix operators must be spaced. (space-infix-ops)", g:lines[-1] From ae88263f0ff5d50563c43745acf2f48ea9a8d057 Mon Sep 17 00:00:00 2001 From: Jasper Woudenberg Date: Thu, 2 Mar 2017 18:55:22 -0800 Subject: [PATCH 3/4] Add documentation for ALEDetail --- doc/ale.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/ale.txt b/doc/ale.txt index 72daa97f..b21409bb 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1141,6 +1141,7 @@ ALELint *ALELint* ALEPrevious *ALEPrevious* ALEPreviousWrap *ALEPreviousWrap* ALENext *ALENext* +ALENextWrap *ALENextWrap* ALENextWrap *ALENextWrap* *ale-navigation-commands* @@ -1173,6 +1174,14 @@ ALEToggle *ALEToggle* quickfix items, signs, current jobs, etc. Calling this option will change the |g:ale_enabled| variable. + +ALEDetail *ALEDetail* + + Show the full linter message for the current line. This will only have an + effect on lines that contain a linter message. + + A plug mapping `(ale_detail)` is defined for this command. + =============================================================================== 7. API *ale-api* From 7030758da623ad692d18ecaaffdac283b91d4d09 Mon Sep 17 00:00:00 2001 From: Jasper Woudenberg Date: Thu, 2 Mar 2017 23:20:00 -0800 Subject: [PATCH 4/4] Fix documentation error. --- doc/ale.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/ale.txt b/doc/ale.txt index b21409bb..af26b9c9 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1141,7 +1141,6 @@ ALELint *ALELint* ALEPrevious *ALEPrevious* ALEPreviousWrap *ALEPreviousWrap* ALENext *ALENext* -ALENextWrap *ALENextWrap* ALENextWrap *ALENextWrap* *ale-navigation-commands*