added popup support for vim, still need to figure out how to expand variables
This commit is contained in:
parent
7432be9532
commit
4e994968ff
2 changed files with 88 additions and 30 deletions
|
|
@ -47,24 +47,89 @@ function! vimspector#internal#state#GetAPIPrefix() abort
|
|||
return s:prefix
|
||||
endfunction
|
||||
|
||||
let s:float_win = 0
|
||||
|
||||
function! vimspector#internal#state#CreateTooltip() abort
|
||||
let buf = nvim_create_buf(v:false, v:true)
|
||||
call nvim_buf_set_lines(buf, 0, -1, v:true, [])
|
||||
if has('nvim')
|
||||
let buf = nvim_create_buf(v:false, v:true)
|
||||
call nvim_buf_set_lines(buf, 0, -1, v:true, [])
|
||||
|
||||
" default the dimensions for now. they can be easily overwritten later
|
||||
let opts = { 'relative': 'cursor', 'width': 50, 'height': 2, 'col': 0, 'row': 1, 'anchor': 'NW', 'style': 'minimal' }
|
||||
let g:float_win = nvim_open_win(buf, 0, opts)
|
||||
call setwinvar(g:float_win, '&wrap', 0)
|
||||
" default the dimensions for now. they can be easily overwritten later
|
||||
let opts = {
|
||||
\ 'relative': 'cursor',
|
||||
\ 'width': 50,
|
||||
\ 'height': 2,
|
||||
\ 'col': 0,
|
||||
\ 'row': 1,
|
||||
\ 'anchor': 'NW',
|
||||
\ 'style': 'minimal'
|
||||
\ }
|
||||
let s:float_win = nvim_open_win(buf, 0, opts)
|
||||
call setwinvar(s:float_win, '&wrap', 1)
|
||||
call setwinvar(s:float_win, '&cursorline', 1)
|
||||
|
||||
call win_gotoid(g:float_win)
|
||||
call win_gotoid(s:float_win)
|
||||
|
||||
" make sure we clean up the float after it loses focus
|
||||
augroup vimspector#internal#balloon#nvim_float
|
||||
autocmd!
|
||||
autocmd WinLeave * :call nvim_win_close(g:float_win, 1) | autocmd! vimspector#internal#balloon#nvim_float
|
||||
augroup END
|
||||
nnoremap <silent> <buffer> <CR> :<C-u>call vimspector#ExpandVariable()<CR>
|
||||
nnoremap <silent> <buffer> <esc>:quit<CR>
|
||||
nnoremap <silent> <buffer> <2-LeftMouse>:<C-u>call vimspector#ExpandVariable()<CR>
|
||||
|
||||
return g:float_win
|
||||
" make sure we clean up the float after it loses focus
|
||||
augroup vimspector#internal#balloon#nvim_float
|
||||
autocmd!
|
||||
autocmd WinLeave * :call nvim_win_close(s:float_win, 1) | autocmd! vimspector#internal#balloon#nvim_float
|
||||
augroup END
|
||||
|
||||
else
|
||||
" assume we are inside vim
|
||||
func! MyFilter(winid, key)
|
||||
if index(['j', 'k', 'h', 'l'], a:key) >= 0
|
||||
call win_execute(a:winid, ':normal '.a:key)
|
||||
" do something
|
||||
return 1
|
||||
elseif a:key == "\<leftmouse>"
|
||||
echo 'pressed left mouse'
|
||||
let mouse_coords = getmousepos()
|
||||
" close the popup if mouse is clicked outside the window
|
||||
if mouse_coords['winid'] != a:winid
|
||||
call popup_close(a:winid)
|
||||
endif
|
||||
|
||||
echo 'clicked line '.mouse_coords['line']
|
||||
call win_execute(a:winid, ":call cursor(".mouse_coords['line'].", ".mouse_coords['column'].")")
|
||||
return 1
|
||||
elseif a:key == "\<cr>"
|
||||
echo 'pressed enter at line '.line(".", a:winid)
|
||||
echo 'here'
|
||||
call vimspector#ExpandVariable()
|
||||
|
||||
return 1
|
||||
elseif a:key == "\<esc>"
|
||||
call popup_close(a:winid)
|
||||
let s:float_win = 0
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
endfunc
|
||||
|
||||
if s:float_win != 0
|
||||
popup_close(s:float_win)
|
||||
endif
|
||||
|
||||
let s:float_win = popup_create([], #{
|
||||
\ filter: "MyFilter",
|
||||
\ cursorline: 1,
|
||||
\ wrap: 1,
|
||||
\ filtermode: "n",
|
||||
\ maxwidth: 50,
|
||||
\ maxheight: 5,
|
||||
\ scrollbar: 1,
|
||||
\ moved: "any",
|
||||
\ })
|
||||
|
||||
endif
|
||||
|
||||
return s:float_win
|
||||
endfunction
|
||||
|
||||
function! vimspector#internal#state#ShowTooltip() abort
|
||||
|
|
@ -90,12 +155,12 @@ function! vimspector#internal#state#TooltipExec(body) abort
|
|||
|
||||
|
||||
let opts = { 'relative': 'cursor', 'width': width, 'height': len(a:body), 'col': 0, 'row': 1, 'anchor': 'NW', 'style': 'minimal' }
|
||||
let g:float_win = nvim_open_win(buf, 0, opts)
|
||||
call setwinvar(g:float_win, '&wrap', 0)
|
||||
let s:float_win = nvim_open_win(buf, 0, opts)
|
||||
call setwinvar(s:float_win, '&wrap', 0)
|
||||
|
||||
augroup vimspector#internal#balloon#nvim_float
|
||||
autocmd!
|
||||
autocmd CursorMoved * :call nvim_win_close(g:float_win, 1) | autocmd! vimspector#internal#balloon#nvim_float
|
||||
autocmd CursorMoved * :call nvim_win_close(s:float_win, 1) | autocmd! vimspector#internal#balloon#nvim_float
|
||||
augroup END
|
||||
endfunction
|
||||
" Boilerplate {{{
|
||||
|
|
|
|||
|
|
@ -140,7 +140,6 @@ class VariablesView( object ):
|
|||
|
||||
self._variable_eval = None
|
||||
self._variable_eval_view = None
|
||||
self._variable_eval_win = None
|
||||
|
||||
def AddExpandMappings():
|
||||
vim.command( 'nnoremap <silent> <buffer> <CR> '
|
||||
|
|
@ -272,7 +271,6 @@ class VariablesView( object ):
|
|||
} )
|
||||
|
||||
def _DrawEval(self):
|
||||
self._variable_eval_win.height = min(5, len(self._variable_eval.variables))
|
||||
with utils.RestoreCursorPosition():
|
||||
utils.ClearBuffer( self._variable_eval_view.buf )
|
||||
icon = '+' if self._variable_eval.IsExpandable() and not self._variable_eval.IsExpanded() else '-'
|
||||
|
|
@ -291,19 +289,14 @@ class VariablesView( object ):
|
|||
self._variable_eval = Scope(body)
|
||||
|
||||
float_win_id = vim.eval("vimspector#internal#state#CreateTooltip()")
|
||||
self._variable_eval_win = vim.current.window
|
||||
|
||||
with utils.LetCurrentWindow( self._variable_eval_win ):
|
||||
vim.command( 'nnoremap <silent> <buffer> <CR> '
|
||||
':<C-u>call vimspector#ExpandVariable()<CR>' )
|
||||
vim.command( 'nnoremap <silent> <buffer> <esc> '
|
||||
':quit<CR>' )
|
||||
vim.command( 'nnoremap <silent> <buffer> <2-LeftMouse> '
|
||||
':<C-u>call vimspector#ExpandVariable()<CR>' )
|
||||
float_buf_nr = int(vim.eval("winbufnr({})".format(float_win_id)))
|
||||
|
||||
# since vim's popup cant be focused there is no way
|
||||
# to get a reference to its window
|
||||
# we will emulate python's window object overselves
|
||||
self._variable_eval_view = View(type('__vim__window__', (object,), {'options': {}, 'buffer': vim.buffers[float_buf_nr]}), {}, self._DrawEval)
|
||||
|
||||
if(self._variable_eval.VariablesReference() > 0):
|
||||
self._variable_eval_view = View(self._variable_eval_win, {}, self._DrawEval)
|
||||
self._connection.DoRequest( partial( self._ConsumeVariables,
|
||||
self._DrawEval,
|
||||
self._variable_eval ), {
|
||||
|
|
@ -315,7 +308,6 @@ class VariablesView( object ):
|
|||
else:
|
||||
# in case that there is nothing to expand, we need to simulate a response from 'variables' request
|
||||
# it returns [Variable]
|
||||
self._variable_eval_view = View(self._variable_eval_win, {}, self._DrawEval)
|
||||
self._variable_eval.variables = [Variable({'name': expression, 'value': body['result']})]
|
||||
self._DrawEval()
|
||||
|
||||
|
|
@ -418,7 +410,8 @@ class VariablesView( object ):
|
|||
else:
|
||||
return
|
||||
|
||||
current_line = vim.current.window.cursor[ 0 ]
|
||||
current_line = int(vim.eval("getbufinfo({})['lnum']".format(view.buf.name)))
|
||||
print(current_line)
|
||||
if current_line not in view.lines:
|
||||
return
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue