diff --git a/jedi/cache.py b/jedi/cache.py index 45011871..6b2a4601 100644 --- a/jedi/cache.py +++ b/jedi/cache.py @@ -8,10 +8,16 @@ time_caches = [] star_import_cache = {} +# for fast_parser, should never be deleted +parser_cache = {} + def clear_caches(delete_all=False): """ Jedi caches many things, that should be completed after each completion finishes. + + :param delete_all: Deletes also the cache that is normally not deleted, + like parser cache, which is important for faster parsing. """ global memoize_caches @@ -31,6 +37,7 @@ def clear_caches(delete_all=False): global time_caches time_caches = [] star_import_cache.clear() + parser_cache.clear() def memoize_default(default=None, cache=memoize_caches): diff --git a/jedi/fast_parser.py b/jedi/fast_parser.py index 839090ee..e54c68b9 100644 --- a/jedi/fast_parser.py +++ b/jedi/fast_parser.py @@ -4,8 +4,7 @@ import operator from _compatibility import use_metaclass, reduce, property import settings import parsing - -parser_cache = {} +import cache class Module(parsing.Simple, parsing.Module): @@ -140,12 +139,12 @@ class CachedFastParser(type): def __call__(self, code, module_path=None, user_position=None): if not settings.fast_parser: return parsing.PyFuzzyParser(code, module_path, user_position) - if module_path is None or module_path not in parser_cache: + if module_path is None or module_path not in cache.parser_cache: p = super(CachedFastParser, self).__call__(code, module_path, user_position) - parser_cache[module_path] = p + cache.parser_cache[module_path] = p else: - p = parser_cache[module_path] + p = cache.parser_cache[module_path] p.update(code, user_position) return p