forked from VimPlug/jedi
goto of vim-jedi is now able to handle multiple goto results, displays a new buffer
This commit is contained in:
18
functions.py
18
functions.py
@@ -109,6 +109,24 @@ class Definition(object):
|
|||||||
def column(self):
|
def column(self):
|
||||||
return self.definition.start_pos[1]
|
return self.definition.start_pos[1]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def description(self):
|
||||||
|
d = self.definition
|
||||||
|
if isinstance(d, evaluate.InstanceElement):
|
||||||
|
d = d.var
|
||||||
|
if isinstance(d, evaluate.parsing.Name):
|
||||||
|
d = d.parent
|
||||||
|
|
||||||
|
if isinstance(d, (evaluate.Class, evaluate.Instance)):
|
||||||
|
d = 'class ' + str(d.name)
|
||||||
|
elif isinstance(d, (evaluate.Function, evaluate.parsing.Function)):
|
||||||
|
d = 'def ' + str(d.name)
|
||||||
|
elif isinstance(d, evaluate.parsing.Module):
|
||||||
|
d = 'module ' + str(d.path)
|
||||||
|
else:
|
||||||
|
d = d.get_code().replace('\n', '')
|
||||||
|
return d
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.module_path[0] == '/':
|
if self.module_path[0] == '/':
|
||||||
position = '@%s' % (self.line_nr)
|
position = '@%s' % (self.line_nr)
|
||||||
|
|||||||
@@ -10,6 +10,12 @@ if !has('python')
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" load plugin only once
|
||||||
|
if exists("g:loaded_jedi") || &cp
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let g:loaded_jedi = 1
|
||||||
|
|
||||||
" ------------------------------------------------------------------------
|
" ------------------------------------------------------------------------
|
||||||
" completion
|
" completion
|
||||||
" ------------------------------------------------------------------------
|
" ------------------------------------------------------------------------
|
||||||
@@ -109,7 +115,14 @@ if 1:
|
|||||||
vim.current.window.cursor = d.line_nr, d.column
|
vim.current.window.cursor = d.line_nr, d.column
|
||||||
else:
|
else:
|
||||||
# multiple solutions
|
# multiple solutions
|
||||||
echo_highlight("Multiple solutions: Not implemented yet.")
|
lst = []
|
||||||
|
for d in definitions:
|
||||||
|
if d.in_builtin_module():
|
||||||
|
lst.append(dict(text='Builtin ' + d.description))
|
||||||
|
else:
|
||||||
|
lst.append(dict(filename=d.module_path, lnum=d.line_nr, col=d.column, text=d.description))
|
||||||
|
vim.command('call setqflist(%s)' % str(lst))
|
||||||
|
vim.command('call <sid>add_goto_window()')
|
||||||
|
|
||||||
#print 'end', strout
|
#print 'end', strout
|
||||||
PYTHONEOF
|
PYTHONEOF
|
||||||
@@ -122,7 +135,12 @@ if 1:
|
|||||||
for tab_nr in range(int(vim.eval("tabpagenr('$')"))):
|
for tab_nr in range(int(vim.eval("tabpagenr('$')"))):
|
||||||
for buf_nr in vim.eval("tabpagebuflist(%i + 1)" % tab_nr):
|
for buf_nr in vim.eval("tabpagebuflist(%i + 1)" % tab_nr):
|
||||||
buf_nr = int(buf_nr) - 1
|
buf_nr = int(buf_nr) - 1
|
||||||
|
try:
|
||||||
buf_path = vim.buffers[buf_nr].name
|
buf_path = vim.buffers[buf_nr].name
|
||||||
|
except IndexError:
|
||||||
|
# just do good old asking for forgiveness. don't know why this happens :-)
|
||||||
|
pass
|
||||||
|
else:
|
||||||
if buf_path == path:
|
if buf_path == path:
|
||||||
# tab exists, just switch to that tab
|
# tab exists, just switch to that tab
|
||||||
vim.command('tabfirst | tabnext %i' % (tab_nr + 1))
|
vim.command('tabfirst | tabnext %i' % (tab_nr + 1))
|
||||||
@@ -136,6 +154,28 @@ if 1:
|
|||||||
PYTHONEOF
|
PYTHONEOF
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:add_goto_window()
|
||||||
|
set lazyredraw
|
||||||
|
cclose
|
||||||
|
execute 'belowright copen 3'
|
||||||
|
set nolazyredraw
|
||||||
|
if g:jedi#use_tabs_not_buffers == 1
|
||||||
|
map <buffer> <CR> :call jedi#goto_window_on_enter()<CR>
|
||||||
|
endif
|
||||||
|
au WinLeave <buffer> q " automatically leave, if an option is chosen
|
||||||
|
redraw!
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! jedi#goto_window_on_enter()
|
||||||
|
let l:list = getqflist()
|
||||||
|
let l:data = l:list[line('.') - 1]
|
||||||
|
if l:data.bufnr
|
||||||
|
call jedi#tabnew(bufname(l:data.bufnr))
|
||||||
|
call cursor(l:data.lnum, l:data.col)
|
||||||
|
else
|
||||||
|
echohl WarningMsg | echo "Builtin module cannot be opened." | echohl None
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
" ------------------------------------------------------------------------
|
" ------------------------------------------------------------------------
|
||||||
" Initialization of jedi-vim
|
" Initialization of jedi-vim
|
||||||
" ------------------------------------------------------------------------
|
" ------------------------------------------------------------------------
|
||||||
|
|||||||
19
test/run.py
19
test/run.py
@@ -108,24 +108,7 @@ def run_goto_test(correct, source, line_nr, line, path):
|
|||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
lst = []
|
comp_str = str(sorted(r.description for r in result))
|
||||||
for r in result:
|
|
||||||
r = r.definition
|
|
||||||
if isinstance(r, evaluate.InstanceElement):
|
|
||||||
r = r.var
|
|
||||||
if isinstance(r, evaluate.parsing.Name):
|
|
||||||
r = r.parent
|
|
||||||
|
|
||||||
if isinstance(r, (evaluate.Class, evaluate.Instance)):
|
|
||||||
r = 'class ' + str(r.name)
|
|
||||||
elif isinstance(r, (evaluate.Function, evaluate.parsing.Function)):
|
|
||||||
r = 'def ' + str(r.name)
|
|
||||||
elif isinstance(r, evaluate.parsing.Module):
|
|
||||||
r = 'module ' + str(r.path)
|
|
||||||
else:
|
|
||||||
r = r.get_code().replace('\n', '')
|
|
||||||
lst.append(r)
|
|
||||||
comp_str = str(sorted(lst))
|
|
||||||
if comp_str != correct:
|
if comp_str != correct:
|
||||||
print('Solution @%s not right, received %s, wanted %s'\
|
print('Solution @%s not right, received %s, wanted %s'\
|
||||||
% (line_nr - 1, comp_str, correct))
|
% (line_nr - 1, comp_str, correct))
|
||||||
|
|||||||
Reference in New Issue
Block a user