mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 18:17:07 +08:00
working related_names function
This commit is contained in:
@@ -327,6 +327,9 @@ def related_names(definitions, search_name, modules):
|
|||||||
names = []
|
names = []
|
||||||
# TODO check modules in the same directoy
|
# TODO check modules in the same directoy
|
||||||
for m in modules:
|
for m in modules:
|
||||||
|
if not m.path.endswith('.py'):
|
||||||
|
# don't search for names in builtin modules
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
stmts = m.used_names[search_name]
|
stmts = m.used_names[search_name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ def get_definition(source, line, column, source_path):
|
|||||||
op = f.get_operator_under_cursor()
|
op = f.get_operator_under_cursor()
|
||||||
scopes = set([keywords.get_operator(op, pos)] if op else [])
|
scopes = set([keywords.get_operator(op, pos)] if op else [])
|
||||||
else:
|
else:
|
||||||
scopes = _prepare_goto(source, pos, source_path, f, goto_path)
|
scopes = set(_prepare_goto(source, pos, source_path, f, goto_path))
|
||||||
|
|
||||||
# add keywords
|
# add keywords
|
||||||
scopes |= keywords.get_keywords(string=goto_path, pos=pos)
|
scopes |= keywords.get_keywords(string=goto_path, pos=pos)
|
||||||
@@ -325,11 +325,13 @@ def related_names(source, line, column, source_path):
|
|||||||
for n in name.names:
|
for n in name.names:
|
||||||
if n.start_pos <= pos <= n.end_pos or not is_user:
|
if n.start_pos <= pos <= n.end_pos or not is_user:
|
||||||
names.append(dynamic.RelatedName(n, d))
|
names.append(dynamic.RelatedName(n, d))
|
||||||
|
elif isinstance(d, parsing.Name):
|
||||||
|
names.append(dynamic.RelatedName(d.names[0], d))
|
||||||
else:
|
else:
|
||||||
names.append(dynamic.RelatedName(d.name.names[0], d))
|
names.append(dynamic.RelatedName(d.name.names[0], d))
|
||||||
|
|
||||||
_clear_caches()
|
_clear_caches()
|
||||||
return names
|
return sorted(names, key=lambda x: (x.module_path, x.start_pos))
|
||||||
|
|
||||||
|
|
||||||
def set_debug_function(func_cb):
|
def set_debug_function(func_cb):
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ PYTHONEOF
|
|||||||
syn include @rstPythonScript syntax/python.vim
|
syn include @rstPythonScript syntax/python.vim
|
||||||
" 4 spaces
|
" 4 spaces
|
||||||
syn region rstPythonRegion start=/^\v {4}/ end=/\v^( {4}|\n)@!/ contains=@rstPythonScript
|
syn region rstPythonRegion start=/^\v {4}/ end=/\v^( {4}|\n)@!/ contains=@rstPythonScript
|
||||||
" >>> python code
|
" >>> python code -> (doctests)
|
||||||
syn region rstPythonRegion matchgroup=pythonDoctest start=/^>>>\s*/ end=/\n/ contains=@rstPythonScript
|
syn region rstPythonRegion matchgroup=pythonDoctest start=/^>>>\s*/ end=/\n/ contains=@rstPythonScript
|
||||||
let b:current_syntax = "rst"
|
let b:current_syntax = "rst"
|
||||||
endfunction
|
endfunction
|
||||||
@@ -162,7 +162,7 @@ endfunction
|
|||||||
function! jedi#tabnew(path)
|
function! jedi#tabnew(path)
|
||||||
python << PYTHONEOF
|
python << PYTHONEOF
|
||||||
if 1:
|
if 1:
|
||||||
path = vim.eval('a:path')
|
path = os.path.abspath(vim.eval('a:path'))
|
||||||
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
|
||||||
@@ -172,6 +172,7 @@ if 1:
|
|||||||
# just do good old asking for forgiveness. don't know why this happens :-)
|
# just do good old asking for forgiveness. don't know why this happens :-)
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
print buf_path, path
|
||||||
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))
|
||||||
@@ -201,6 +202,8 @@ function! jedi#goto_window_on_enter()
|
|||||||
let l:list = getqflist()
|
let l:list = getqflist()
|
||||||
let l:data = l:list[line('.') - 1]
|
let l:data = l:list[line('.') - 1]
|
||||||
if l:data.bufnr
|
if l:data.bufnr
|
||||||
|
" close goto_window buffer
|
||||||
|
normal ZQ
|
||||||
call jedi#tabnew(bufname(l:data.bufnr))
|
call jedi#tabnew(bufname(l:data.bufnr))
|
||||||
call cursor(l:data.lnum, l:data.col)
|
call cursor(l:data.lnum, l:data.col)
|
||||||
else
|
else
|
||||||
@@ -287,6 +290,7 @@ import vim
|
|||||||
|
|
||||||
# update the system path, to include the python scripts
|
# update the system path, to include the python scripts
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
from os.path import dirname
|
from os.path import dirname
|
||||||
sys.path.insert(0, dirname(dirname(vim.eval('s:current_file'))))
|
sys.path.insert(0, dirname(dirname(vim.eval('s:current_file'))))
|
||||||
|
|
||||||
@@ -326,7 +330,7 @@ def _goto(is_definition=False, is_related_name=False):
|
|||||||
else:
|
else:
|
||||||
if not definitions:
|
if not definitions:
|
||||||
echo_highlight("Couldn't find any definitions for this.")
|
echo_highlight("Couldn't find any definitions for this.")
|
||||||
elif len(definitions) == 1:
|
elif len(definitions) == 1 and not is_related_name:
|
||||||
# just add some mark to add the current position to the jumplist.
|
# just add some mark to add the current position to the jumplist.
|
||||||
# this is ugly, because it overrides the mark for '`', so if anyone
|
# this is ugly, because it overrides the mark for '`', so if anyone
|
||||||
# has a better idea, let me know.
|
# has a better idea, let me know.
|
||||||
|
|||||||
Reference in New Issue
Block a user