forked from VimPlug/jedi
best patch in a long time, deleted all the part_parser stuff which was necessary for fast function_definitions, but with the new parser Jedi's fast enough -> fixes #136
This commit is contained in:
46
jedi/api.py
46
jedi/api.py
@@ -416,49 +416,13 @@ class Script(object):
|
|||||||
return api_classes.CallDef(executable, index, call)
|
return api_classes.CallDef(executable, index, call)
|
||||||
|
|
||||||
def _func_call_and_param_index(self):
|
def _func_call_and_param_index(self):
|
||||||
def check_user_stmt(user_stmt):
|
|
||||||
if user_stmt is None \
|
|
||||||
or not isinstance(user_stmt, pr.Statement):
|
|
||||||
return None, 0
|
|
||||||
|
|
||||||
call, index, stop = helpers.search_function_definition(user_stmt, self.pos)
|
|
||||||
return call, index
|
|
||||||
|
|
||||||
def check_cache():
|
|
||||||
""" Do the parsing with a part parser, therefore reduce ressource
|
|
||||||
costs.
|
|
||||||
TODO this is not working with multi-line docstrings, improve.
|
|
||||||
"""
|
|
||||||
if self.source_path is None:
|
|
||||||
return None, 0
|
|
||||||
|
|
||||||
try:
|
|
||||||
parser = cache.parser_cache[self.source_path].parser
|
|
||||||
except KeyError:
|
|
||||||
return None, 0
|
|
||||||
part_parser = self._module.get_part_parser()
|
|
||||||
user_stmt = part_parser.user_stmt
|
|
||||||
call, index = check_user_stmt(user_stmt)
|
|
||||||
if call:
|
|
||||||
old_stmt = parser.module.get_statement_for_position(self.pos)
|
|
||||||
if old_stmt is None:
|
|
||||||
return None, 0
|
|
||||||
old_call, old_index = check_user_stmt(old_stmt)
|
|
||||||
if old_call:
|
|
||||||
# compare repr because that should definitely be the same.
|
|
||||||
# Otherwise the whole thing is out of sync.
|
|
||||||
if repr(old_call) == repr(call):
|
|
||||||
# return the index of the part_parser
|
|
||||||
return old_call, index
|
|
||||||
return None, 0
|
|
||||||
|
|
||||||
debug.speed('func_call start')
|
debug.speed('func_call start')
|
||||||
call = None
|
call, index = None, 0
|
||||||
index = 0
|
|
||||||
if settings.use_function_definition_cache:
|
|
||||||
call, index = check_cache()
|
|
||||||
if call is None:
|
if call is None:
|
||||||
call, index = check_user_stmt(self._parser.user_stmt)
|
user_stmt = self._parser.user_stmt
|
||||||
|
if user_stmt is not None and isinstance(user_stmt, pr.Statement):
|
||||||
|
call, index, _ = helpers.search_function_definition(
|
||||||
|
user_stmt, self.pos)
|
||||||
debug.speed('func_call parsed')
|
debug.speed('func_call parsed')
|
||||||
return call, index
|
return call, index
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,9 @@ from ast import literal_eval
|
|||||||
|
|
||||||
from jedi._compatibility import exec_function, unicode
|
from jedi._compatibility import exec_function, unicode
|
||||||
from jedi import cache
|
from jedi import cache
|
||||||
from jedi import parsing
|
|
||||||
from jedi import parsing_representation as pr
|
from jedi import parsing_representation as pr
|
||||||
from jedi import fast_parser
|
from jedi import fast_parser
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import settings
|
|
||||||
from jedi import common
|
from jedi import common
|
||||||
|
|
||||||
|
|
||||||
@@ -103,7 +101,6 @@ class ModuleWithCursor(Module):
|
|||||||
self._relevant_temp = None
|
self._relevant_temp = None
|
||||||
|
|
||||||
self.source = source
|
self.source = source
|
||||||
self._part_parser = None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parser(self):
|
def parser(self):
|
||||||
@@ -251,21 +248,6 @@ class ModuleWithCursor(Module):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
raise StopIteration()
|
raise StopIteration()
|
||||||
|
|
||||||
def get_part_parser(self):
|
|
||||||
""" Returns a parser that contains only part of the source code. This
|
|
||||||
exists only because of performance reasons.
|
|
||||||
"""
|
|
||||||
if self._part_parser:
|
|
||||||
return self._part_parser
|
|
||||||
|
|
||||||
# TODO check for docstrings
|
|
||||||
length = settings.part_line_length
|
|
||||||
offset = max(self.position[0] - length, 0)
|
|
||||||
s = '\n'.join(self.source.splitlines()[offset:offset + length])
|
|
||||||
self._part_parser = parsing.Parser(s, self.path, self.position,
|
|
||||||
offset=(offset, 0))
|
|
||||||
return self._part_parser
|
|
||||||
|
|
||||||
|
|
||||||
def get_sys_path():
|
def get_sys_path():
|
||||||
def check_virtual_env(sys_path):
|
def check_virtual_env(sys_path):
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ Parser
|
|||||||
~~~~~~
|
~~~~~~
|
||||||
|
|
||||||
.. autodata:: fast_parser
|
.. autodata:: fast_parser
|
||||||
.. autodata:: use_function_definition_cache
|
|
||||||
|
|
||||||
|
|
||||||
Dynamic stuff
|
Dynamic stuff
|
||||||
@@ -149,13 +148,6 @@ something has been changed e.g. to a function. If this happens, only the
|
|||||||
function is being reparsed.
|
function is being reparsed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
use_function_definition_cache = True
|
|
||||||
"""
|
|
||||||
Use the cache (full cache) to generate function_definition's. This may fail
|
|
||||||
with multiline docstrings (likely) and other complicated changes (unlikely).
|
|
||||||
The goal is to move away from it by making the rest faster.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# ----------------
|
# ----------------
|
||||||
# dynamic stuff
|
# dynamic stuff
|
||||||
# ----------------
|
# ----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user