1
0
forked from VimPlug/jedi

renaming again, should be a little bit better. but some things are commented.

This commit is contained in:
David Halter
2012-09-20 17:27:00 +02:00
parent ea53d07238
commit 0e5a70a2db
4 changed files with 35 additions and 3 deletions

View File

@@ -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()

View File

@@ -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]:

View File

@@ -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

View File

@@ -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. """