Skip to content

Commit

Permalink
Compat with status line message
Browse files Browse the repository at this point in the history
  • Loading branch information
maralla committed Oct 25, 2019
1 parent dd7c762 commit 3a6bc83
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 26 deletions.
85 changes: 59 additions & 26 deletions autoload/validator.vim
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,44 @@ function! s:gen_handler(ft, nr, checker)
endfunction


function! s:show_in_popup(msg, line)
if empty(a:msg)
return
endif
let length = strdisplaywidth(getline('.')[:col('.')]) - 4
if length < 0
let length = 0
endif
let s:lint_popup = popup_create(a:msg, #{
\ line: 'cursor+1',
\ col: 'cursor-'.length,
\ highlight: 'ValidatorPopupColor',
\ border: [1, 2, 1, 2],
\ borderhighlight: ['ValidatorBorderColor'],
\ padding: [0, 1, 0, 1],
\ borderchars: ['', '', '', '', '', '', '', ''],
\ })
let s:lint_line = a:line
endfunction


function! s:show_in_status(info, msg)
let hi_type = get(a:info, 'type', 'NONE')
let expected = &columns - s:width
let msg = a:msg
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:_show_lint_message()
let nr = bufnr('')
let line = line('.')
Expand All @@ -164,37 +202,29 @@ function! s:_show_lint_message()

let info = get(get(g:_validator_sign_map[nr], 'text', {}), line, {})
let msg = get(info, 'msg', '')
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
if s:support_popup()
call s:show_in_popup(msg, line)
else
call s:show_in_status(info, msg)
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


func s:support_popup()
return g:validator_use_popup_window && exists('*popup_create')
endfunc


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
if s:support_popup()
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
endif

if s:cursor_move_timer != -1
Expand All @@ -205,6 +235,9 @@ endfunction


function! s:on_cursor_movei()
if !s:support_popup()
return
endif
if s:lint_popup != -1
call popup_close(s:lint_popup)
let s:lint_popup = -1
Expand Down
1 change: 1 addition & 0 deletions plugin/validator.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ let g:validator_filetype_map = get(g:, 'validator_filetype_map', {})
let g:validator_ignore = extend(get(g:, 'validator_ignore', []), s:ignores)
let g:validator_permament_sign = get(g:, 'validator_permament_sign', 0)
let g:validator_highlight_message = get(g:, 'validator_highlight_message', 0)
let g:validator_use_popup_window = get(g:, 'validator_use_popup_window', 0)


if get(g:, 'validator_autostart', 1)
Expand Down

0 comments on commit 3a6bc83

Please sign in to comment.