runtime/termdebug.vim #10015

* bugfix
* use NormalFloat for floating window background
* use floating window by default
* correctly use nvim_open_win()
* use nvim_win_set_option to set window local option
* use nvim_buf_set_option for buffer options
* renamed augroup to nvim_termdebug_close_hover to be consistent with
nvim_terminal_... augroup
This commit is contained in:
Kwon-Young Choi
2019-05-16 21:58:07 +02:00
committed by Justin M. Keyes
parent 3a699a790c
commit 9420a2127f
2 changed files with 67 additions and 69 deletions

View File

@@ -328,9 +328,9 @@ To change the name of the gdb command, set the "termdebugger" variable before
invoking `:Termdebug`: > invoking `:Termdebug`: >
let termdebugger = "mygdb" let termdebugger = "mygdb"
To use neovim floating windows for previewing variable evaluation, set the To not use neovim floating windows for previewing variable evaluation, set the
`g:termdebug_useFloatingHover` variable like this: > `g:termdebug_useFloatingHover` variable like this: >
let g:termdebug_useFloatingHover = 1 let g:termdebug_useFloatingHover = 0
If you are a mouse person, you can also define a mapping using your right If you are a mouse person, you can also define a mapping using your right
click to one of the terminal command like evaluate the variable under the click to one of the terminal command like evaluate the variable under the

View File

@@ -579,7 +579,7 @@ func s:HandleEvaluate(msg)
endif endif
endfunc endfunc
function! s:ShouldUseFloatWindow() abort function! s:ShouldUseFloatWindow() abort
if exists('*nvim_open_win') && (get(g:, 'termdebug_useFloatingHover', 1) == 1) if exists('*nvim_open_win') && (get(g:, 'termdebug_useFloatingHover', 1) == 1)
return v:true return v:true
else else
@@ -593,19 +593,19 @@ function! s:CloseFloatingHoverOnCursorMove(win_id, opened) abort
" To avoid closing floating window immediately, check the cursor " To avoid closing floating window immediately, check the cursor
" was really moved " was really moved
return return
endif endif
autocmd! nvim_termdebug_close_hover autocmd! nvim_termdebug_close_hover
let winnr = win_id2win(a:win_id) let winnr = win_id2win(a:win_id)
if winnr == 0 if winnr == 0
return return
endif endif
call nvim_win_close(a:win_id, v:true) call nvim_win_close(a:win_id, v:true)
endfunction endfunction
function! s:CloseFloatingHoverOnBufEnter(win_id, bufnr) abort function! s:CloseFloatingHoverOnBufEnter(win_id, bufnr) abort
let winnr = win_id2win(a:win_id) let winnr = win_id2win(a:win_id)
if winnr == 0 if winnr == 0
" Float window was already closed " Float window was already closed
autocmd! nvim_termdebug_close_hover autocmd! nvim_termdebug_close_hover
return return
endif endif
@@ -616,8 +616,8 @@ function! s:CloseFloatingHoverOnBufEnter(win_id, bufnr) abort
if bufnr('%') == a:bufnr if bufnr('%') == a:bufnr
" When current buffer opened hover window, it's not another buffer. Skipped " When current buffer opened hover window, it's not another buffer. Skipped
return return
endif endif
autocmd! plugin-LC-neovim-close-hover autocmd! nvim_termdebug_close_hover
call nvim_win_close(a:win_id, v:true) call nvim_win_close(a:win_id, v:true)
endfunction endfunction
@@ -630,18 +630,12 @@ function! s:OpenHoverPreview(lines, filetype) abort
let bufnr = bufnr('%') let bufnr = bufnr('%')
let use_float_win = s:ShouldUseFloatWindow() let use_float_win = s:ShouldUseFloatWindow()
if use_float_win
let bufname = nvim_create_buf(v:false, v:true)
if use_float_win if use_float_win
let pos = getpos('.') let pos = getpos('.')
" Calculate width and height " Calculate width and height
let width = 0 let width = 0
for index in range(len(lines)) for index in range(len(lines))
let line = lines[index]
if line !=# ''
" Give a left margin
let line = ' ' . line
let line = lines[index] let line = lines[index]
let lw = strdisplaywidth(line) let lw = strdisplaywidth(line)
if lw > width if lw > width
@@ -649,9 +643,6 @@ function! s:OpenHoverPreview(lines, filetype) abort
endif endif
let lines[index] = line let lines[index] = line
endfor endfor
" Give margin
let width += 1
let height = len(lines) let height = len(lines)
@@ -674,7 +665,11 @@ function! s:OpenHoverPreview(lines, filetype) abort
let hor = 'E' let hor = 'E'
let col = 1 let col = 1
endif endif
let buf = nvim_create_buf(v:false, v:true)
call nvim_buf_set_lines(buf, 0, -1, v:true, lines)
" using v:true for second argument of nvim_open_win make the floating
" window disappear
let float_win_id = nvim_open_win(buf, v:false, { let float_win_id = nvim_open_win(buf, v:false, {
\ 'relative': 'cursor', \ 'relative': 'cursor',
\ 'anchor': vert . hor, \ 'anchor': vert . hor,
@@ -682,23 +677,26 @@ function! s:OpenHoverPreview(lines, filetype) abort
\ 'col': col, \ 'col': col,
\ 'width': width, \ 'width': width,
\ 'height': height, \ 'height': height,
\ }) \ })
call nvim_win_set_option(float_win_id, 'relativenumber', v:false)
execute 'noswapfile edit!' bufname call nvim_win_set_option(float_win_id, 'signcolumn', 'no')
call nvim_win_set_option(float_win_id, 'signcolumn', 'no')
setlocal winhl=Normal:CursorLine if a:filetype isnot v:null
else
call nvim_win_set_option(float_win_id, 'filetype', a:filetype) call nvim_win_set_option(float_win_id, 'filetype', a:filetype)
endif endif
call nvim_buf_set_option(buf, 'modified', v:false)
call nvim_buf_set_option(buf, 'modifiable', v:false)
" Unlike preview window, :pclose does not close window. Instead, close " Unlike preview window, :pclose does not close window. Instead, close
" hover window automatically when cursor is moved. " hover window automatically when cursor is moved.
let call_after_move = printf('<SID>CloseFloatingHoverOnCursorMove(%d, %s)', float_win_id, string(pos)) let call_after_move = printf('<SID>CloseFloatingHoverOnCursorMove(%d, %s)', float_win_id, string(pos))
let call_on_bufenter = printf('<SID>CloseFloatingHoverOnBufEnter(%d, %d)', float_win_id, bufnr) let call_on_bufenter = printf('<SID>CloseFloatingHoverOnBufEnter(%d, %d)', float_win_id, bufnr)
augroup nvim_termdebug_close_hover augroup nvim_termdebug_close_hover
execute 'autocmd CursorMoved,CursorMovedI,InsertEnter <buffer> call ' . call_after_move execute 'autocmd CursorMoved,CursorMovedI,InsertEnter <buffer> call ' . call_after_move
execute 'autocmd BufEnter * call ' . call_on_bufenter execute 'autocmd BufEnter * call ' . call_on_bufenter
augroup END
else
echomsg a:lines[0] echomsg a:lines[0]
endif endif
endfunction endfunction