1
0
forked from VimPlug/jedi

make the invalidate_star_import stuff easier

This commit is contained in:
Dave Halter
2014-01-05 10:18:04 +01:00
parent 1b40414d90
commit 4fdfbcd7e4
2 changed files with 19 additions and 12 deletions

View File

@@ -109,7 +109,7 @@ def cache_star_import(func):
if mods[0] + settings.star_import_cache_validity > time.time(): if mods[0] + settings.star_import_cache_validity > time.time():
return mods[1] return mods[1]
# cache is too old and therefore invalid or not available # cache is too old and therefore invalid or not available
invalidate_star_import_cache(scope) _invalidate_star_import_cache_module(scope)
mods = func(evaluator, scope, *args, **kwargs) mods = func(evaluator, scope, *args, **kwargs)
_star_import_cache[scope] = time.time(), mods _star_import_cache[scope] = time.time(), mods
@@ -117,7 +117,7 @@ def cache_star_import(func):
return wrapper return wrapper
def invalidate_star_import_cache(module, only_main=False): def _invalidate_star_import_cache_module(module, only_main=False):
""" Important if some new modules are being reparsed """ """ Important if some new modules are being reparsed """
with common.ignored(KeyError): with common.ignored(KeyError):
t, mods = _star_import_cache[module] t, mods = _star_import_cache[module]
@@ -125,14 +125,25 @@ def invalidate_star_import_cache(module, only_main=False):
del _star_import_cache[module] del _star_import_cache[module]
for m in mods: for m in mods:
invalidate_star_import_cache(m, only_main=True) _invalidate_star_import_cache_module(m, only_main=True)
if not only_main: if not only_main:
# We need a list here because otherwise the list is being changed # We need a list here because otherwise the list is being changed
# during the iteration in py3k: iteritems -> items. # during the iteration in py3k: iteritems -> items.
for key, (t, mods) in list(_star_import_cache.items()): for key, (t, mods) in list(_star_import_cache.items()):
if module in mods: if module in mods:
invalidate_star_import_cache(key) _invalidate_star_import_cache_module(key)
def invalidate_star_import_cache(path):
"""On success returns True."""
try:
parser_cache_item = parser_cache[path]
except KeyError:
return False
else:
_invalidate_star_import_cache_module(parser_cache_item.parser.module)
return True
def load_parser(path, name): def load_parser(path, name):
@@ -152,7 +163,7 @@ def load_parser(path, name):
# In case there is already a module cached and this module # In case there is already a module cached and this module
# has to be reparsed, we also need to invalidate the import # has to be reparsed, we also need to invalidate the import
# caches. # caches.
invalidate_star_import_cache(parser_cache_item.parser.module) _invalidate_star_import_cache_module(parser_cache_item.parser.module)
except KeyError: except KeyError:
if settings.use_filesystem_cache: if settings.use_filesystem_cache:
return ParserPickling.load_parser(n, p_time) return ParserPickling.load_parser(n, p_time)

View File

@@ -77,14 +77,10 @@ class ModuleWithCursor(object):
def parser(self): def parser(self):
""" get the parser lazy """ """ get the parser lazy """
if not self._parser: if not self._parser:
with common.ignored(KeyError): cache.invalidate_star_import_cache(self.path)
parser = cache.parser_cache[self.path].parser
cache.invalidate_star_import_cache(parser.module)
# 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 = fast.FastParser(self.source, self.path, self.position) self._parser = fast.FastParser(self.source, self.path, self.position)
# don't pickle that module, because it's changing fast # don't pickle that module, because the main module is changing
# quickly usually.
cache.save_parser(self.path, self.name, self._parser, cache.save_parser(self.path, self.name, self._parser,
pickling=False) pickling=False)
return self._parser return self._parser