1
0
forked from VimPlug/jedi

Reenable call signature caching and move a lot of parser specific caching to the parser itself.

This commit is contained in:
Dave Halter
2016-06-28 08:46:29 +02:00
parent 746a513ef9
commit 52c42c3392
10 changed files with 65 additions and 251 deletions

View File

@@ -17,6 +17,7 @@ from jedi._compatibility import unicode
from jedi.parser import load_grammar
from jedi.parser import tree
from jedi.parser.fast import FastParser
from jedi.parser.utils import save_parser
from jedi import debug
from jedi import settings
from jedi import common
@@ -131,7 +132,7 @@ class Script(object):
def _get_module(self):
cache.invalidate_star_import_cache(self._path)
parser = FastParser(self._grammar, self._source, self._path)
cache.save_parser(self._path, parser, pickling=False)
save_parser(self._path, parser, pickling=False)
module = self._evaluator.wrap(parser.module)
imports.add_module(self._evaluator, unicode(module.name), module)
@@ -282,14 +283,13 @@ class Script(object):
if call_signature_details is None:
return []
# TODO insert caching again here.
#with common.scale_speed_settings(settings.scale_call_signatures):
# definitions = cache.cache_call_signatures(self._evaluator, stmt,
# self._source, self._pos)
definitions = helpers.evaluate_goto_definition(
self._evaluator,
call_signature_details.bracket_leaf.get_previous_leaf()
)
with common.scale_speed_settings(settings.scale_call_signatures):
definitions = helpers.cache_call_signatures(
self._evaluator,
call_signature_details.bracket_leaf,
self._code_lines,
self._pos
)
debug.speed('func_call followed')
return [classes.CallSignature(self._evaluator, d.name,

View File

@@ -7,6 +7,7 @@ from collections import namedtuple
from jedi.evaluate.helpers import call_of_leaf
from jedi import parser
from jedi.parser import tokenize, token
from jedi.cache import time_cache
CompletionParts = namedtuple('CompletionParts', ['path', 'has_dot', 'name'])
@@ -240,3 +241,24 @@ def get_call_signature_details(module, position):
node = node.parent
return None
@time_cache("call_signatures_validity")
def cache_call_signatures(evaluator, bracket_leaf, code_lines, user_pos):
"""This function calculates the cache key."""
index = user_pos[0] - 1
before_cursor = code_lines[index][:user_pos[1]]
other_lines = code_lines[bracket_leaf.start_pos[0]:index]
whole = '\n'.join(other_lines + [before_cursor])
before_bracket = re.match(r'.*\(', whole, re.DOTALL)
module_path = bracket_leaf.get_parent_until().path
if module_path is None:
yield None # Don't cache!
else:
yield (module_path, before_bracket, bracket_leaf.start_pos)
yield evaluate_goto_definition(
evaluator,
bracket_leaf.get_previous_leaf()
)