solved goto-import problems

This commit is contained in:
David Halter
2012-08-03 00:13:48 +02:00
parent 63c81a0bfe
commit b4d147738f
5 changed files with 32 additions and 9 deletions

View File

@@ -270,15 +270,32 @@ def goto(source, line, column, source_path):
s = s.follow()[0]
definitions.append(s)
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 = []
#print 's', scopes
for s in scopes:
names += s.get_defined_names()
names = remove_unreal_imports(names)
definitions = [n for n in names if n.names[-1] == search_name]
#print evaluate.statement_path
#print scopes, definitions
_clear_caches()
return [Definition(d) for d in definitions]
return [Definition(d) for d in set(definitions)]
def set_debug_function(func_cb):

View File

@@ -49,7 +49,9 @@ class ImportPath(object):
def get_nested_import(self, parent):
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)
new = parsing.Import(zero, zero, n)
new.parent = parent

View File

@@ -234,6 +234,7 @@ class Module(Scope):
super(Module, self).__init__((1, 0), docstr)
self.path = path
self.global_vars = []
self._name = None
def add_global(self, name):
"""
@@ -252,6 +253,12 @@ class Module(Scope):
n += self.global_vars
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):
"""

View File

@@ -49,9 +49,6 @@ def scope_nested():
#? float()
import_tree.pkg.mod1.a
#? ['a', 'pkg']
import_tree.
# -----------------
# std lib modules
# -----------------

View File

@@ -5,7 +5,7 @@ pylab.
#! ['module numpy']
import numpy
#! ['module random']
#! ['import random', 'module random']
import numpy.random
#? ['array2string']