1
0
forked from VimPlug/jedi

Use the cache variables in more straight forward fashion.

This commit is contained in:
Dave Halter
2017-03-31 23:10:39 +02:00
parent b708b7f07d
commit a6829ca546
2 changed files with 11 additions and 7 deletions

View File

@@ -136,7 +136,7 @@ class Script(object):
code=self._source, code=self._source,
path=self.path, path=self.path,
grammar=self._grammar, grammar=self._grammar,
cache=True, cache=False, # No disk cache, because the current script often changes.
diff_cache=True, diff_cache=True,
) )

View File

@@ -76,8 +76,7 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
if path is not None: if path is not None:
path = os.path.expanduser(path) path = os.path.expanduser(path)
use_cache = cache and path is not None and not code if cache and not code and path is not None:
if use_cache:
# In this case we do actual caching. We just try to load it. # In this case we do actual caching. We just try to load it.
module_node = load_module(grammar, path) module_node = load_module(grammar, path)
if module_node is not None: if module_node is not None:
@@ -95,11 +94,16 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
else: else:
lines = splitlines(code, keepends=True) lines = splitlines(code, keepends=True)
module_node = module_cache_item.node module_node = module_cache_item.node
old_lines = module_cache_item.lines
if old_lines == lines:
save_module(grammar, path, module_node, lines, pickling=False)
return module_node
new_node = DiffParser(grammar, module_node).update( new_node = DiffParser(grammar, module_node).update(
old_lines=module_cache_item.lines, old_lines=old_lines,
new_lines=lines new_lines=lines
) )
save_module(grammar, path, module_node, lines, pickling=False) save_module(grammar, path, new_node, lines, pickling=cache)
return new_node return new_node
added_newline = not code.endswith('\n') added_newline = not code.endswith('\n')
@@ -117,6 +121,6 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
if added_newline: if added_newline:
_remove_last_newline(root_node) _remove_last_newline(root_node)
if use_cache or diff_cache: if cache or diff_cache:
save_module(grammar, path, root_node, lines) save_module(grammar, path, root_node, lines, pickling=cache)
return root_node return root_node