mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 13:15:09 -07:00
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:
parent
3a699a790c
commit
9420a2127f
@ -328,9 +328,9 @@ To change the name of the gdb command, set the "termdebugger" variable before
|
||||
invoking `:Termdebug`: >
|
||||
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: >
|
||||
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
|
||||
click to one of the terminal command like evaluate the variable under the
|
||||
|
@ -579,7 +579,7 @@ func s:HandleEvaluate(msg)
|
||||
endfunc
|
||||
|
||||
function! s:ShouldUseFloatWindow() abort
|
||||
if has('nvim_open_win') && exists('g:termdebug_useFloatingHover') && (g:termdebug_useFloatingHover == 1)
|
||||
if exists('*nvim_open_win') && (get(g:, 'termdebug_useFloatingHover', 1) == 1)
|
||||
return v:true
|
||||
else
|
||||
return v:false
|
||||
@ -593,19 +593,19 @@ function! s:CloseFloatingHoverOnCursorMove(win_id, opened) abort
|
||||
" was really moved
|
||||
return
|
||||
endif
|
||||
autocmd! plugin-LC-neovim-close-hover
|
||||
autocmd! nvim_termdebug_close_hover
|
||||
let winnr = win_id2win(a:win_id)
|
||||
if winnr == 0
|
||||
return
|
||||
endif
|
||||
execute winnr . 'wincmd c'
|
||||
call nvim_win_close(a:win_id, v:true)
|
||||
endfunction
|
||||
|
||||
function! s:CloseFloatingHoverOnBufEnter(win_id, bufnr) abort
|
||||
let winnr = win_id2win(a:win_id)
|
||||
if winnr == 0
|
||||
" Float window was already closed
|
||||
autocmd! plugin-LC-neovim-close-hover
|
||||
autocmd! nvim_termdebug_close_hover
|
||||
return
|
||||
endif
|
||||
if winnr == winnr()
|
||||
@ -616,8 +616,8 @@ function! s:CloseFloatingHoverOnBufEnter(win_id, bufnr) abort
|
||||
" When current buffer opened hover window, it's not another buffer. Skipped
|
||||
return
|
||||
endif
|
||||
autocmd! plugin-LC-neovim-close-hover
|
||||
execute winnr . 'wincmd c'
|
||||
autocmd! nvim_termdebug_close_hover
|
||||
call nvim_win_close(a:win_id, v:true)
|
||||
endfunction
|
||||
|
||||
" Open preview window. Window is open in:
|
||||
@ -630,18 +630,12 @@ function! s:OpenHoverPreview(lines, filetype) abort
|
||||
|
||||
let use_float_win = s:ShouldUseFloatWindow()
|
||||
if use_float_win
|
||||
let bufname = nvim_create_buf(v:false, v:true)
|
||||
call nvim_buf_set_lines(buf, 0, -1, v:true, lines)
|
||||
let pos = getpos('.')
|
||||
|
||||
" Calculate width and height and give margin to lines
|
||||
" Calculate width and height
|
||||
let width = 0
|
||||
for index in range(len(lines))
|
||||
let line = lines[index]
|
||||
if line !=# ''
|
||||
" Give a left margin
|
||||
let line = ' ' . line
|
||||
endif
|
||||
let lw = strdisplaywidth(line)
|
||||
if lw > width
|
||||
let width = lw
|
||||
@ -649,9 +643,6 @@ function! s:OpenHoverPreview(lines, filetype) abort
|
||||
let lines[index] = line
|
||||
endfor
|
||||
|
||||
" Give margin
|
||||
let width += 1
|
||||
let lines = [''] + lines + ['']
|
||||
let height = len(lines)
|
||||
|
||||
" Calculate anchor
|
||||
@ -674,7 +665,11 @@ function! s:OpenHoverPreview(lines, filetype) abort
|
||||
let col = 1
|
||||
endif
|
||||
|
||||
let float_win_id = nvim_open_win(bufnr, v:true, {
|
||||
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, {
|
||||
\ 'relative': 'cursor',
|
||||
\ 'anchor': vert . hor,
|
||||
\ 'row': row,
|
||||
@ -682,23 +677,26 @@ function! s:OpenHoverPreview(lines, filetype) abort
|
||||
\ 'width': width,
|
||||
\ 'height': height,
|
||||
\ })
|
||||
|
||||
execute 'noswapfile edit!' bufname
|
||||
|
||||
setlocal winhl=Normal:CursorLine
|
||||
else
|
||||
echomsg a:lines[0]
|
||||
call nvim_win_set_option(float_win_id, 'relativenumber', v:false)
|
||||
call nvim_win_set_option(float_win_id, 'signcolumn', 'no')
|
||||
call nvim_win_set_option(float_win_id, 'signcolumn', 'no')
|
||||
if a:filetype isnot v:null
|
||||
call nvim_win_set_option(float_win_id, 'filetype', a:filetype)
|
||||
endif
|
||||
|
||||
if use_float_win
|
||||
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
|
||||
" hover window automatically when cursor is moved.
|
||||
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)
|
||||
augroup plugin-LC-neovim-close-hover
|
||||
augroup nvim_termdebug_close_hover
|
||||
execute 'autocmd CursorMoved,CursorMovedI,InsertEnter <buffer> call ' . call_after_move
|
||||
execute 'autocmd BufEnter * call ' . call_on_bufenter
|
||||
augroup END
|
||||
else
|
||||
echomsg a:lines[0]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user