Skip to content

Commit

Permalink
Use popup two show lint messages
Browse files Browse the repository at this point in the history
  • Loading branch information
maralla committed Oct 2, 2019
1 parent 4eed0f5 commit dd7c762
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions autoload/validator.vim
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ let s:width = 16
let s:python_imported = v:false
let s:events = {}
let s:cursor_move_timer = -1
let s:lint_popup = -1
let s:lint_line = -1

let s:manager = {'refcount': 0, 'jobs': []}

@@ -162,29 +164,55 @@ function! s:_show_lint_message()

let info = get(get(g:_validator_sign_map[nr], 'text', {}), line, {})
let msg = get(info, 'msg', '')
let hi_type = get(info, 'type', 'NONE')
let expected = &columns - s:width
if strwidth(msg) > expected
let msg = msg[:expected].'...'
endif
if g:validator_highlight_message
exe 'echohl ' . hi_type
endif
echo msg
if g:validator_highlight_message
echohl NONE
if !empty(msg)
let length = strlen(getline('.')[col('.'):])
let s:lint_popup = popup_create(msg, #{
\ line: 'cursor+1',
\ col: 'cursor+'.length,
\ })
let s:lint_line = line
endif
" let hi_type = get(info, 'type', 'NONE')
" let expected = &columns - s:width
" if strwidth(msg) > expected
" let msg = msg[:expected].'...'
" endif
" if g:validator_highlight_message
" exe 'echohl ' . hi_type
" endif
" echo msg
" if g:validator_highlight_message
" echohl NONE
" endif
endfunction


function! s:on_cursor_move()
if line('.') == s:lint_line
return
endif
if s:lint_popup != -1
call popup_close(s:lint_popup)
let s:lint_popup = -1
let s:lint_line = -1
endif

if s:cursor_move_timer != -1
call timer_stop(s:cursor_move_timer)
endif
let s:cursor_move_timer = timer_start(200, {t->s:_show_lint_message()})
endfunction


function! s:on_cursor_movei()
if s:lint_popup != -1
call popup_close(s:lint_popup)
let s:lint_popup = -1
let s:lint_line = -1
endif
endfunction


function! s:do_check()
let instant = has_key(s:events, 'text_changed') || has_key(s:events, 'text_changed_i')
try
@@ -209,6 +237,7 @@ function! validator#enable_events()
augroup validator
autocmd!
autocmd CursorMoved * call s:on_cursor_move()
autocmd CursorMovedI * call s:on_cursor_movei()
autocmd TextChangedI * call s:add_task('text_changed_i')
autocmd TextChanged * call s:add_task('text_changed')
autocmd BufReadPost * call s:add_task('read_post')

0 comments on commit dd7c762

Please sign in to comment.