mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
solved goto-import problems
This commit is contained in:
25
functions.py
25
functions.py
@@ -270,15 +270,32 @@ def goto(source, line, column, source_path):
|
|||||||
s = s.follow()[0]
|
s = s.follow()[0]
|
||||||
definitions.append(s)
|
definitions.append(s)
|
||||||
else:
|
else:
|
||||||
|
def remove_unreal_imports(names):
|
||||||
|
"""
|
||||||
|
These imports are only virtual, because of multi-line imports.
|
||||||
|
"""
|
||||||
|
new_names = []
|
||||||
|
for n in names:
|
||||||
|
par = n.parent
|
||||||
|
if isinstance(par, parsing.Import) and not par.start_pos[0]:
|
||||||
|
# this is a special case: If
|
||||||
|
for scope in imports.ImportPath(par).follow():
|
||||||
|
if isinstance(scope, parsing.Import):
|
||||||
|
temp = scope.get_defined_names()
|
||||||
|
new_names += remove_unreal_imports(temp)
|
||||||
|
elif isinstance(scope, parsing.Module):
|
||||||
|
new_names.append(scope.get_module_name(n.names))
|
||||||
|
else:
|
||||||
|
new_names.append(n)
|
||||||
|
return new_names
|
||||||
|
|
||||||
names = []
|
names = []
|
||||||
#print 's', scopes
|
|
||||||
for s in scopes:
|
for s in scopes:
|
||||||
names += s.get_defined_names()
|
names += s.get_defined_names()
|
||||||
|
names = remove_unreal_imports(names)
|
||||||
definitions = [n for n in names if n.names[-1] == search_name]
|
definitions = [n for n in names if n.names[-1] == search_name]
|
||||||
#print evaluate.statement_path
|
|
||||||
#print scopes, definitions
|
|
||||||
_clear_caches()
|
_clear_caches()
|
||||||
return [Definition(d) for d in definitions]
|
return [Definition(d) for d in set(definitions)]
|
||||||
|
|
||||||
|
|
||||||
def set_debug_function(func_cb):
|
def set_debug_function(func_cb):
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ class ImportPath(object):
|
|||||||
|
|
||||||
def get_nested_import(self, parent):
|
def get_nested_import(self, parent):
|
||||||
i = self.import_stmt
|
i = self.import_stmt
|
||||||
zero = (1,0)
|
# This is not an existing Import statement. Therefore, set position to
|
||||||
|
# None.
|
||||||
|
zero = (None, None)
|
||||||
n = parsing.Name(i.namespace.names[1:], zero, zero)
|
n = parsing.Name(i.namespace.names[1:], zero, zero)
|
||||||
new = parsing.Import(zero, zero, n)
|
new = parsing.Import(zero, zero, n)
|
||||||
new.parent = parent
|
new.parent = parent
|
||||||
|
|||||||
@@ -234,6 +234,7 @@ class Module(Scope):
|
|||||||
super(Module, self).__init__((1, 0), docstr)
|
super(Module, self).__init__((1, 0), docstr)
|
||||||
self.path = path
|
self.path = path
|
||||||
self.global_vars = []
|
self.global_vars = []
|
||||||
|
self._name = None
|
||||||
|
|
||||||
def add_global(self, name):
|
def add_global(self, name):
|
||||||
"""
|
"""
|
||||||
@@ -252,6 +253,12 @@ class Module(Scope):
|
|||||||
n += self.global_vars
|
n += self.global_vars
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
def get_module_name(self, names):
|
||||||
|
""" This is used for the goto function. """
|
||||||
|
if not self._name:
|
||||||
|
self._name = Name(names, self.start_pos, self.end_pos, self)
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
|
||||||
class Class(Scope):
|
class Class(Scope):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -49,9 +49,6 @@ def scope_nested():
|
|||||||
#? float()
|
#? float()
|
||||||
import_tree.pkg.mod1.a
|
import_tree.pkg.mod1.a
|
||||||
|
|
||||||
#? ['a', 'pkg']
|
|
||||||
import_tree.
|
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# std lib modules
|
# std lib modules
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
2
test/completion/thirdparty/pylab.py
vendored
2
test/completion/thirdparty/pylab.py
vendored
@@ -5,7 +5,7 @@ pylab.
|
|||||||
#! ['module numpy']
|
#! ['module numpy']
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
#! ['module random']
|
#! ['import random', 'module random']
|
||||||
import numpy.random
|
import numpy.random
|
||||||
|
|
||||||
#? ['array2string']
|
#? ['array2string']
|
||||||
|
|||||||
Reference in New Issue
Block a user