mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
again refactorings
This commit is contained in:
15
dynamic.py
15
dynamic.py
@@ -325,21 +325,6 @@ def related_names(definitions, search_name, modules):
|
||||
return result
|
||||
|
||||
names = []
|
||||
for d in definitions:
|
||||
if isinstance(d, parsing.Statement):
|
||||
def add_array(arr):
|
||||
calls = _scan_array(arr, search_name)
|
||||
for call in calls:
|
||||
for n in call.name.names:
|
||||
if n == search_name:
|
||||
names.append(RelatedName(n, d))
|
||||
for op, arr in d.assignment_details:
|
||||
add_array(arr)
|
||||
if not d.assignment_details:
|
||||
add_array(d.get_assignment_calls())
|
||||
else:
|
||||
names.append(RelatedName(d.name.names[0], d))
|
||||
|
||||
# TODO check modules in the same directoy
|
||||
for m in modules:
|
||||
try:
|
||||
|
||||
29
functions.py
29
functions.py
@@ -229,12 +229,12 @@ def get_definition(source, line, column, source_path):
|
||||
scopes = set([f.parser.user_scope])
|
||||
elif not goto_path:
|
||||
op = f.get_operator_under_cursor()
|
||||
scopes = set([keywords.get_operator(op)] if op else [])
|
||||
scopes = set([keywords.get_operator(op, pos)] if op else [])
|
||||
else:
|
||||
scopes = _prepare_goto(source, pos, source_path, f, goto_path)
|
||||
|
||||
# add keywords
|
||||
scopes |= keywords.get_keywords(string=goto_path)
|
||||
scopes |= keywords.get_keywords(string=goto_path, pos=pos)
|
||||
|
||||
d = set([Definition(s) for s in scopes])
|
||||
_clear_caches()
|
||||
@@ -288,7 +288,7 @@ def related_names(source, line, column, source_path):
|
||||
else:
|
||||
e = evaluate.Class(f.parser.user_scope)
|
||||
definitions = [e]
|
||||
elif isinstance(f.parser.user_stmt, parsing.Param):
|
||||
elif isinstance(f.parser.user_stmt, (parsing.Param, parsing.Import)):
|
||||
definitions = [f.parser.user_stmt]
|
||||
else:
|
||||
scopes = _prepare_goto(source, pos, source_path, f, goto_path)
|
||||
@@ -297,6 +297,29 @@ def related_names(source, line, column, source_path):
|
||||
module = set([d.get_parent_until() for d in definitions])
|
||||
module.add(f.parser.module)
|
||||
names = dynamic.related_names(definitions, search_name, module)
|
||||
|
||||
for d in definitions:
|
||||
if isinstance(d, parsing.Statement):
|
||||
def add_array(arr):
|
||||
calls = dynamic._scan_array(arr, search_name)
|
||||
for call in calls:
|
||||
for n in call.name.names:
|
||||
if n == search_name:
|
||||
names.append(dynamic.RelatedName(n, d))
|
||||
for op, arr in d.assignment_details:
|
||||
add_array(arr)
|
||||
if not d.assignment_details:
|
||||
add_array(d.get_assignment_calls())
|
||||
elif isinstance(d, parsing.Import):
|
||||
for name in [d.namespace, d.alias, d.from_ns]:
|
||||
if name:
|
||||
for n in name.names:
|
||||
print n.start_pos, pos, n.end_pos
|
||||
if n.start_pos <= pos <= n.end_pos:
|
||||
names.append(n, d)
|
||||
else:
|
||||
names.append(dynamic.RelatedName(d.name.names[0], d))
|
||||
|
||||
_clear_caches()
|
||||
return names
|
||||
|
||||
|
||||
17
keywords.py
17
keywords.py
@@ -20,22 +20,23 @@ else:
|
||||
keys = keyword.kwlist + ['None', 'False', 'True']
|
||||
|
||||
|
||||
def get_keywords(string='', all=False):
|
||||
def get_keywords(string='', pos=(0, 0), all=False):
|
||||
if all:
|
||||
return set([Keyword(k) for k in keys])
|
||||
return set([Keyword(k, pos) for k in keys])
|
||||
if string in keys:
|
||||
return set([Keyword(string)])
|
||||
return set([Keyword(string, pos)])
|
||||
return set()
|
||||
|
||||
|
||||
def get_operator(string):
|
||||
return Keyword(string)
|
||||
def get_operator(string, pos):
|
||||
return Keyword(string, pos)
|
||||
|
||||
|
||||
class Keyword(object):
|
||||
def __init__(self, name):
|
||||
def __init__(self, name, pos):
|
||||
self.name = name
|
||||
self.parent = lambda: None
|
||||
self.start_pos = pos
|
||||
|
||||
def get_parent_until(self):
|
||||
return builtin.builtin_scope
|
||||
@@ -49,6 +50,10 @@ class Keyword(object):
|
||||
|
||||
|
||||
def imitate_pydoc(string):
|
||||
"""
|
||||
It's not possible to get the pydoc's without starting the annoying pager
|
||||
stuff.
|
||||
"""
|
||||
h = pydoc.help
|
||||
try:
|
||||
# try to access symbols
|
||||
|
||||
@@ -75,7 +75,7 @@ endfunction
|
||||
" goto
|
||||
" ------------------------------------------------------------------------
|
||||
function! jedi#goto()
|
||||
python _goto(is_definition=False)
|
||||
python _goto()
|
||||
endfunction
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
@@ -89,7 +89,7 @@ endfunction
|
||||
" related_names
|
||||
" ------------------------------------------------------------------------
|
||||
function! jedi#related_names()
|
||||
python _goto(related_names=True)
|
||||
python _goto(is_related_name=True)
|
||||
endfunction
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
|
||||
@@ -58,3 +58,14 @@ def blub():
|
||||
#< (55,4) (59,1)
|
||||
@blub
|
||||
def a(): pass
|
||||
|
||||
|
||||
|
||||
#< (65,7) (68,0)
|
||||
import colorama
|
||||
|
||||
#< (65,7) (68,0)
|
||||
colorama
|
||||
|
||||
#< 3
|
||||
import abc
|
||||
|
||||
@@ -88,7 +88,7 @@ class TestRegression(unittest.TestCase):
|
||||
s = ("def abc(): pass\n"
|
||||
"abc.d.a.abc.d"
|
||||
)
|
||||
functions.get_related_names(s, 2, 2, '/')
|
||||
functions.related_names(s, 2, 2, '/')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user