diff --git a/jedi/builtin.py b/jedi/builtin.py index 33fcec31..c0e76a8b 100644 --- a/jedi/builtin.py +++ b/jedi/builtin.py @@ -34,7 +34,7 @@ class CachedModule(object): if not self._parser: try: timestamp, parser = self.cache[self.path or self.name] - if not self.path or timestamp == os.path.getmtime(self.path): + if not self.path or os.path.getmtime(self.path) <= timestamp: self._parser = parser else: raise KeyError() diff --git a/jedi/dynamic.py b/jedi/dynamic.py index 8aaefa00..edb6a11f 100644 --- a/jedi/dynamic.py +++ b/jedi/dynamic.py @@ -353,7 +353,8 @@ def related_names(definitions, search_name, mods): else: search = None scopes = evaluate.follow_call_path(iter(f), scope, position) - follow_res = evaluate.goto(scopes, search, statement_path_offset=0) + follow_res = evaluate.goto(scopes, search, statement_path_offset=0, + follow_import=True) # compare to see if they match if True in [r in definitions for r in follow_res]: diff --git a/jedi/evaluate.py b/jedi/evaluate.py index 08fcdeae..f827ec29 100644 --- a/jedi/evaluate.py +++ b/jedi/evaluate.py @@ -1501,7 +1501,20 @@ def follow_path(path, scope, position=None): return follow_paths(path, set(result), position=position) -def goto(scopes, search_name=None, statement_path_offset=1): +def goto(scopes, search_name=None, statement_path_offset=1, + follow_import=False): + def follow_imports(names): + global statement_path + new = [] + for n in names: + if isinstance(n, parsing.Import): + statement_path = [] + scopes = imports.strip_imports([n]) + new += goto(scopes, follow_import=True) + else: + new.append(n) + return new + if search_name is None: try: definitions = [statement_path[statement_path_offset]] @@ -1527,4 +1540,13 @@ def goto(scopes, search_name=None, statement_path_offset=1): else: names += s.get_defined_names() definitions = [n for n in names if n.names[-1] == search_name] + + #if follow_import: + # definitions = follow_imports(definitions) + + definitions = set(definitions) + #for d in definitions.copy(): + #if d.isinstance(Function, Class): + # definitions.add(d.name) + # definitions.remove(d) return definitions diff --git a/jedi/modules.py b/jedi/modules.py index eeeb39a4..490baaa8 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -11,6 +11,7 @@ import parsing import builtin import debug import evaluate +import time class Module(builtin.CachedModule): @@ -26,6 +27,7 @@ class Module(builtin.CachedModule): self._line_cache = None def _get_source(self): + """ Just one time """ s = self.source del self.source # memory efficiency return s @@ -50,10 +52,17 @@ class ModuleWithCursor(Module): self._line_temp = None self._relevant_temp = None + self.source = source + + try: + del builtin.CachedModule.cache[self.path] + except KeyError: + pass # Call the parser already here, because it will be used anyways. # Also, the position is here important (which will not be used by # default), therefore fill the cache here. self._parser = parsing.PyFuzzyParser(source, path, position) + builtin.CachedModule.cache[self.path] = time.time(), self._parser def get_path_until_cursor(self): """ Get the path under the cursor. """