mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
don't follow imports automatically, there will be an attribute/method later on, that does this. -> #45
This commit is contained in:
19
jedi/api.py
19
jedi/api.py
@@ -27,6 +27,7 @@ from __future__ import with_statement
|
|||||||
__all__ = ['Script', 'NotFoundError', 'set_debug_function']
|
__all__ = ['Script', 'NotFoundError', 'set_debug_function']
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import weakref
|
||||||
|
|
||||||
import parsing
|
import parsing
|
||||||
import dynamic
|
import dynamic
|
||||||
@@ -91,15 +92,18 @@ class Script(object):
|
|||||||
:rtype: list
|
:rtype: list
|
||||||
"""
|
"""
|
||||||
def follow_imports_if_possible(name):
|
def follow_imports_if_possible(name):
|
||||||
return [name] #TODO remove
|
# TODO remove this, or move to another place (not used)
|
||||||
par = name.parent()
|
par = name.parent()
|
||||||
if isinstance(par, parsing.Import) and not \
|
if isinstance(par, parsing.Import) and not \
|
||||||
isinstance(self.parser.user_stmt, parsing.Import):
|
isinstance(self.parser.user_stmt, parsing.Import):
|
||||||
new = imports.ImportPath(par).follow(is_goto=True)
|
new = imports.ImportPath(par).follow(is_goto=True)
|
||||||
# Only remove the old entry if a new one has been found.
|
# Only remove the old entry if a new one has been found.
|
||||||
|
#print par, new, par.parent()
|
||||||
if new:
|
if new:
|
||||||
print(new, name)
|
try:
|
||||||
return new
|
return new
|
||||||
|
except AttributeError: # .name undefined
|
||||||
|
pass
|
||||||
return [name]
|
return [name]
|
||||||
|
|
||||||
path = self.module.get_path_until_cursor()
|
path = self.module.get_path_until_cursor()
|
||||||
@@ -159,10 +163,9 @@ class Script(object):
|
|||||||
or n.startswith(like):
|
or n.startswith(like):
|
||||||
if not evaluate.filter_private_variable(s,
|
if not evaluate.filter_private_variable(s,
|
||||||
self.parser.user_stmt, n):
|
self.parser.user_stmt, n):
|
||||||
for f in follow_imports_if_possible(c):
|
new = api_classes.Completion(c, needs_dot,
|
||||||
new = api_classes.Completion(f, needs_dot,
|
len(like), s)
|
||||||
len(like), s)
|
comps.append(new)
|
||||||
comps.append(new)
|
|
||||||
|
|
||||||
|
|
||||||
return sorted(comps, key=lambda x: (x.word.startswith('__'),
|
return sorted(comps, key=lambda x: (x.word.startswith('__'),
|
||||||
@@ -195,7 +198,7 @@ class Script(object):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
raise NotFoundError()
|
raise NotFoundError()
|
||||||
stmt.start_pos = self.pos
|
stmt.start_pos = self.pos
|
||||||
stmt.parent = lambda: self.parser.user_scope
|
stmt.parent = weakref.ref(self.parser.user_scope)
|
||||||
return stmt
|
return stmt
|
||||||
|
|
||||||
def get_definition(self):
|
def get_definition(self):
|
||||||
|
|||||||
@@ -228,9 +228,11 @@ class TestRegression(Base):
|
|||||||
|
|
||||||
def test_follow_imports_if_possible(self):
|
def test_follow_imports_if_possible(self):
|
||||||
""" github issue #45 """
|
""" github issue #45 """
|
||||||
s = self.complete("import datetime.timedelta; datetime.timedelta")
|
s = self.complete("from datetime import timedelta; timedelta")
|
||||||
#print s, [r.name.parent() for r in s], [r.type for r in s]
|
# type can also point to import, but there will be additional
|
||||||
#assert 'Import' not in [r.type for r in s]
|
# attributes
|
||||||
|
types = [r.type for r in s]
|
||||||
|
#assert 'Import' not in types and 'Class' in types
|
||||||
|
|
||||||
|
|
||||||
class TestFeature(Base):
|
class TestFeature(Base):
|
||||||
@@ -285,6 +287,5 @@ class TestSpeed(Base):
|
|||||||
script.get_in_function_call()
|
script.get_in_function_call()
|
||||||
#print(api.imports.imports_processed)
|
#print(api.imports.imports_processed)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user