Fix cursor issues, and clean up the cursor tests
This commit is contained in:
parent
da8a0f25cc
commit
2750c605c1
@ -18,6 +18,26 @@ function! s:GetMessage(linter, type, text) abort
|
|||||||
return printf(l:msg, l:text)
|
return printf(l:msg, l:text)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:EchoWithShortMess(setting, message) abort
|
||||||
|
" We need to remember the setting for shormess and reset it again.
|
||||||
|
let l:shortmess_options = getbufvar('%', '&shortmess')
|
||||||
|
|
||||||
|
try
|
||||||
|
" Turn shormess on or off.
|
||||||
|
if a:setting ==# 'on'
|
||||||
|
setlocal shortmess+=T
|
||||||
|
elseif a:setting ==# 'off'
|
||||||
|
setlocal shortmess-=T
|
||||||
|
else
|
||||||
|
throw 'Invalid setting: ' . string(a:setting)
|
||||||
|
endif
|
||||||
|
|
||||||
|
exec "norm! :echomsg a:message\n"
|
||||||
|
finally
|
||||||
|
call setbufvar('%', '&shortmess', l:shortmess_options)
|
||||||
|
endtry
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale#cursor#TruncatedEcho(message) abort
|
function! ale#cursor#TruncatedEcho(message) abort
|
||||||
let l:message = a:message
|
let l:message = a:message
|
||||||
" Change tabs to spaces.
|
" Change tabs to spaces.
|
||||||
@ -25,17 +45,7 @@ function! ale#cursor#TruncatedEcho(message) abort
|
|||||||
" Remove any newlines in the message.
|
" Remove any newlines in the message.
|
||||||
let l:message = substitute(l:message, "\n", '', 'g')
|
let l:message = substitute(l:message, "\n", '', 'g')
|
||||||
|
|
||||||
" We need to turn T for truncated messages on for shortmess,
|
call s:EchoWithShortMess('on', l:message)
|
||||||
" and then then we need to reset the option back to what it was.
|
|
||||||
let l:shortmess_options = getbufvar('%', '&shortmess')
|
|
||||||
|
|
||||||
try
|
|
||||||
" Echo the message truncated to fit without creating a prompt.
|
|
||||||
setlocal shortmess+=T
|
|
||||||
exec "norm! :echomsg message\n"
|
|
||||||
finally
|
|
||||||
call setbufvar('%', '&shortmess', l:shortmess_options)
|
|
||||||
endtry
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:FindItemAtCursor() abort
|
function! s:FindItemAtCursor() abort
|
||||||
@ -47,6 +57,13 @@ function! s:FindItemAtCursor() abort
|
|||||||
return [l:info, l:loc]
|
return [l:info, l:loc]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:StopCursorTimer() abort
|
||||||
|
if s:cursor_timer != -1
|
||||||
|
call timer_stop(s:cursor_timer)
|
||||||
|
let s:cursor_timer = -1
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale#cursor#EchoCursorWarning(...) abort
|
function! ale#cursor#EchoCursorWarning(...) abort
|
||||||
" Only echo the warnings in normal mode, otherwise we will get problems.
|
" Only echo the warnings in normal mode, otherwise we will get problems.
|
||||||
if mode() !=# 'n'
|
if mode() !=# 'n'
|
||||||
@ -63,7 +80,7 @@ function! ale#cursor#EchoCursorWarning(...) abort
|
|||||||
" We'll only clear the echoed message when moving off errors once,
|
" We'll only clear the echoed message when moving off errors once,
|
||||||
" so we don't continually clear the echo line.
|
" so we don't continually clear the echo line.
|
||||||
echo
|
echo
|
||||||
let l:info.echoed = 1
|
let l:info.echoed = 0
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -75,10 +92,7 @@ function! ale#cursor#EchoCursorWarningWithDelay() abort
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if s:cursor_timer != -1
|
call s:StopCursorTimer()
|
||||||
call timer_stop(s:cursor_timer)
|
|
||||||
let s:cursor_timer = -1
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:pos = getcurpos()[0:2]
|
let l:pos = getcurpos()[0:2]
|
||||||
|
|
||||||
@ -92,19 +106,22 @@ function! ale#cursor#EchoCursorWarningWithDelay() abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#cursor#ShowCursorDetail(...) abort
|
function! ale#cursor#ShowCursorDetail() abort
|
||||||
" Only echo the warnings in normal mode, otherwise we will get problems.
|
" Only echo the warnings in normal mode, otherwise we will get problems.
|
||||||
if mode() !=# 'n'
|
if mode() !=# 'n'
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
call s:StopCursorTimer()
|
||||||
|
|
||||||
let [l:info, l:loc] = s:FindItemAtCursor()
|
let [l:info, l:loc] = s:FindItemAtCursor()
|
||||||
|
|
||||||
if !empty(l:loc)
|
if !empty(l:loc)
|
||||||
if has_key(l:loc, 'detail')
|
let l:message = get(l:loc, 'detail', l:loc.text)
|
||||||
echo l:loc.detail
|
|
||||||
else
|
call s:EchoWithShortMess('off', l:message)
|
||||||
echo l:loc.text
|
|
||||||
endif
|
" Set the echo marker, so we can clear it by moving the cursor.
|
||||||
|
let l:info.echoed = 1
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -4,33 +4,33 @@ Before:
|
|||||||
\ 'loclist': [
|
\ 'loclist': [
|
||||||
\ {
|
\ {
|
||||||
\ 'lnum': 1,
|
\ 'lnum': 1,
|
||||||
|
\ 'col': 10,
|
||||||
\ 'bufnr': bufnr('%'),
|
\ 'bufnr': bufnr('%'),
|
||||||
\ 'vcol': 0,
|
\ 'vcol': 0,
|
||||||
\ 'linter_name': 'eslint',
|
\ 'linter_name': 'eslint',
|
||||||
\ 'nr': -1,
|
\ 'nr': -1,
|
||||||
\ 'type': 'E',
|
\ 'type': 'E',
|
||||||
\ 'col': 10,
|
|
||||||
\ 'text': 'Missing semicolon. (semi)',
|
\ 'text': 'Missing semicolon. (semi)',
|
||||||
\ 'detail': 'Every statement should end with a semicolon'
|
\ 'detail': 'Every statement should end with a semicolon'
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
\ 'lnum': 2,
|
\ 'lnum': 2,
|
||||||
|
\ 'col': 10,
|
||||||
\ 'bufnr': bufnr('%'),
|
\ 'bufnr': bufnr('%'),
|
||||||
\ 'vcol': 0,
|
\ 'vcol': 0,
|
||||||
\ 'linter_name': 'eslint',
|
\ 'linter_name': 'eslint',
|
||||||
\ 'nr': -1,
|
\ 'nr': -1,
|
||||||
\ 'type': 'W',
|
\ 'type': 'W',
|
||||||
\ 'col': 10,
|
|
||||||
\ 'text': 'Infix operators must be spaced. (space-infix-ops)'
|
\ 'text': 'Infix operators must be spaced. (space-infix-ops)'
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
\ 'lnum': 2,
|
\ 'lnum': 2,
|
||||||
|
\ 'col': 15,
|
||||||
\ 'bufnr': bufnr('%'),
|
\ 'bufnr': bufnr('%'),
|
||||||
\ 'vcol': 0,
|
\ 'vcol': 0,
|
||||||
\ 'linter_name': 'eslint',
|
\ 'linter_name': 'eslint',
|
||||||
\ 'nr': -1,
|
\ 'nr': -1,
|
||||||
\ 'type': 'E',
|
\ 'type': 'E',
|
||||||
\ 'col': 15,
|
|
||||||
\ 'text': 'Missing radix parameter (radix)'
|
\ 'text': 'Missing radix parameter (radix)'
|
||||||
\ }
|
\ }
|
||||||
\ ],
|
\ ],
|
||||||
@ -42,107 +42,74 @@ Before:
|
|||||||
let g:ale_set_signs = 0
|
let g:ale_set_signs = 0
|
||||||
let g:ale_set_highlights = 0
|
let g:ale_set_highlights = 0
|
||||||
|
|
||||||
|
function GetLastMessage()
|
||||||
|
redir => l:output
|
||||||
|
silent mess
|
||||||
|
redir END
|
||||||
|
|
||||||
|
let l:lines = split(l:output, "\n")
|
||||||
|
|
||||||
|
return empty(l:lines) ? '' : l:lines[-1]
|
||||||
|
endfunction
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
call cursor(1, 1)
|
||||||
|
|
||||||
let g:ale_set_loclist = 1
|
let g:ale_set_loclist = 1
|
||||||
let g:ale_set_signs = 1
|
let g:ale_set_signs = 1
|
||||||
let g:ale_set_highlights = 1
|
let g:ale_set_highlights = 1
|
||||||
|
|
||||||
unlet! g:output
|
|
||||||
unlet! g:lines
|
|
||||||
let g:ale_buffer_info = {}
|
let g:ale_buffer_info = {}
|
||||||
|
|
||||||
|
delfunction GetLastMessage
|
||||||
|
|
||||||
|
mess clear
|
||||||
|
|
||||||
Given javascript(A Javscript file with warnings/errors):
|
Given javascript(A Javscript file with warnings/errors):
|
||||||
var x = 3
|
var x = 3
|
||||||
var x = 5*2 + parseInt("10");
|
var x = 5*2 + parseInt("10");
|
||||||
|
|
||||||
Execute(Evaluate the cursor function at line 1):
|
Execute(Messages should be shown for the correct lines):
|
||||||
:1
|
call cursor(1, 1)
|
||||||
call ale#cursor#EchoCursorWarning()
|
call ale#cursor#EchoCursorWarning()
|
||||||
|
|
||||||
Then(Check the cursor output):
|
AssertEqual 'Missing semicolon. (semi)', GetLastMessage()
|
||||||
redir => g:output
|
|
||||||
silent mess
|
|
||||||
redir END
|
|
||||||
|
|
||||||
let g:lines = split(g:output, "\n")
|
Execute(Messages should be shown for earlier columns):
|
||||||
|
call cursor(2, 1)
|
||||||
AssertEqual 'Missing semicolon. (semi)', g:lines[-1]
|
|
||||||
|
|
||||||
Execute(Evaluate the cursor function at line 2):
|
|
||||||
:2
|
|
||||||
call ale#cursor#EchoCursorWarning()
|
call ale#cursor#EchoCursorWarning()
|
||||||
|
|
||||||
Then(Check the cursor output):
|
AssertEqual 'Infix operators must be spaced. (space-infix-ops)', GetLastMessage()
|
||||||
redir => g:output
|
|
||||||
silent mess
|
|
||||||
redir END
|
|
||||||
|
|
||||||
let g:lines = split(g:output, "\n")
|
Execute(Messages should be shown for later columns):
|
||||||
|
call cursor(2, 16)
|
||||||
AssertEqual 'Infix operators must be spaced. (space-infix-ops)', g:lines[-1]
|
|
||||||
|
|
||||||
Execute(Evaluate the cursor function later in line 2):
|
|
||||||
:2
|
|
||||||
normal 16l
|
|
||||||
call ale#cursor#EchoCursorWarning()
|
call ale#cursor#EchoCursorWarning()
|
||||||
|
|
||||||
Then(Check the cursor output):
|
AssertEqual 'Missing radix parameter (radix)', GetLastMessage()
|
||||||
redir => g:output
|
|
||||||
silent mess
|
|
||||||
redir END
|
|
||||||
|
|
||||||
let g:lines = split(g:output, "\n")
|
Execute(The message at the cursor should be shown when linting ends):
|
||||||
|
call cursor(1, 1)
|
||||||
AssertEqual 'Missing radix parameter (radix)', g:lines[-1]
|
|
||||||
|
|
||||||
Execute(Set results for a lint cycle, with the cursor on line 1):
|
|
||||||
:1
|
|
||||||
call ale#engine#SetResults(
|
call ale#engine#SetResults(
|
||||||
\ bufnr('%'),
|
\ bufnr('%'),
|
||||||
\ g:ale_buffer_info[bufnr('%')].loclist,
|
\ g:ale_buffer_info[bufnr('%')].loclist,
|
||||||
\)
|
\)
|
||||||
|
|
||||||
Then(Check the cursor output):
|
AssertEqual 'Missing semicolon. (semi)', GetLastMessage()
|
||||||
redir => g:output
|
|
||||||
silent mess
|
|
||||||
redir END
|
|
||||||
|
|
||||||
let g:lines = split(g:output, "\n")
|
Execute(The message at the cursor should be shown on InsertLeave):
|
||||||
|
call cursor(2, 9)
|
||||||
AssertEqual 'Missing semicolon. (semi)', g:lines[-1]
|
|
||||||
|
|
||||||
Execute(Simulate leaving insert mode on line 2):
|
|
||||||
:2
|
|
||||||
normal 16h
|
|
||||||
doautocmd InsertLeave
|
doautocmd InsertLeave
|
||||||
|
|
||||||
Then(Check the cursor output):
|
AssertEqual 'Infix operators must be spaced. (space-infix-ops)', GetLastMessage()
|
||||||
redir => g:output
|
|
||||||
silent mess
|
|
||||||
redir END
|
|
||||||
|
|
||||||
let g:lines = split(g:output, "\n")
|
Execute(ALEDetail should print 'detail' attributes):
|
||||||
|
call cursor(1, 1)
|
||||||
|
ALEDetail
|
||||||
|
|
||||||
AssertEqual 'Infix operators must be spaced. (space-infix-ops)', g:lines[-1]
|
AssertEqual "Every statement should end with a semicolon", GetLastMessage()
|
||||||
|
|
||||||
Execute(Evaluate the cursor detail function at line 1):
|
Execute(ALEDetail should print regular 'text' attributes):
|
||||||
:1
|
call cursor(2, 10)
|
||||||
call ale#cursor#ShowCursorDetail()
|
ALEDetail
|
||||||
|
|
||||||
Then(Check the cursor output):
|
AssertEqual "Infix operators must be spaced. (space-infix-ops)", GetLastMessage()
|
||||||
redir => g:output
|
|
||||||
silent mess
|
|
||||||
redir END
|
|
||||||
|
|
||||||
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
|
|
||||||
silent mess
|
|
||||||
redir END
|
|
||||||
|
|
||||||
AssertEqual "Infix operators must be spaced. (space-infix-ops)", g:lines[-1]
|
|
||||||
|
Loading…
Reference in New Issue
Block a user