forked from VimPlug/jedi
first tests running again with the new structure
This commit is contained in:
21
jedi/api.py
21
jedi/api.py
@@ -25,7 +25,7 @@ from jedi import cache
|
|||||||
from jedi import modules
|
from jedi import modules
|
||||||
from jedi import interpret
|
from jedi import interpret
|
||||||
from jedi._compatibility import next, unicode, builtins
|
from jedi._compatibility import next, unicode, builtins
|
||||||
from jedi import evaluate
|
from jedi.evaluate import Evaluator
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
import keywords
|
import keywords
|
||||||
import api_classes
|
import api_classes
|
||||||
@@ -82,7 +82,7 @@ class Script(object):
|
|||||||
if not (0 <= self._column <= line_len):
|
if not (0 <= self._column <= line_len):
|
||||||
raise ValueError('`column` parameter is not in a valid range.')
|
raise ValueError('`column` parameter is not in a valid range.')
|
||||||
|
|
||||||
api_classes._clear_caches()
|
#api_classes._clear_caches() # TODO REMOVE
|
||||||
debug.reset_time()
|
debug.reset_time()
|
||||||
self.source = modules.source_to_unicode(source, encoding)
|
self.source = modules.source_to_unicode(source, encoding)
|
||||||
self._pos = self._line, self._column
|
self._pos = self._line, self._column
|
||||||
@@ -90,6 +90,7 @@ class Script(object):
|
|||||||
path, source=self.source, position=self._pos)
|
path, source=self.source, position=self._pos)
|
||||||
self._source_path = path
|
self._source_path = path
|
||||||
self.path = None if path is None else os.path.abspath(path)
|
self.path = None if path is None else os.path.abspath(path)
|
||||||
|
self._evaluator = Evaluator()
|
||||||
debug.speed('init')
|
debug.speed('init')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -110,7 +111,7 @@ class Script(object):
|
|||||||
""" lazy parser."""
|
""" lazy parser."""
|
||||||
return self._module.parser
|
return self._module.parser
|
||||||
|
|
||||||
@api_classes._clear_caches_after_call
|
#@api_classes._clear_caches_after_call
|
||||||
def completions(self):
|
def completions(self):
|
||||||
"""
|
"""
|
||||||
Return :class:`api_classes.Completion` objects. Those objects contain
|
Return :class:`api_classes.Completion` objects. Those objects contain
|
||||||
@@ -242,7 +243,7 @@ class Script(object):
|
|||||||
else:
|
else:
|
||||||
# just parse one statement, take it and evaluate it
|
# just parse one statement, take it and evaluate it
|
||||||
stmt = self._get_under_cursor_stmt(goto_path)
|
stmt = self._get_under_cursor_stmt(goto_path)
|
||||||
scopes = evaluate.follow_statement(stmt)
|
scopes = self._evaluator.follow_statement(stmt)
|
||||||
return scopes
|
return scopes
|
||||||
|
|
||||||
def _get_under_cursor_stmt(self, cursor_txt):
|
def _get_under_cursor_stmt(self, cursor_txt):
|
||||||
@@ -318,7 +319,7 @@ class Script(object):
|
|||||||
sig = self.call_signatures()
|
sig = self.call_signatures()
|
||||||
return sig[0] if sig else None
|
return sig[0] if sig else None
|
||||||
|
|
||||||
@api_classes._clear_caches_after_call
|
#@api_classes._clear_caches_after_call
|
||||||
def goto_definitions(self):
|
def goto_definitions(self):
|
||||||
"""
|
"""
|
||||||
Return the definitions of a the path under the cursor. goto function!
|
Return the definitions of a the path under the cursor. goto function!
|
||||||
@@ -382,7 +383,7 @@ class Script(object):
|
|||||||
if s is not imports.ImportPath.GlobalNamespace])
|
if s is not imports.ImportPath.GlobalNamespace])
|
||||||
return self._sorted_defs(d)
|
return self._sorted_defs(d)
|
||||||
|
|
||||||
@api_classes._clear_caches_after_call
|
#@api_classes._clear_caches_after_call
|
||||||
def goto_assignments(self):
|
def goto_assignments(self):
|
||||||
"""
|
"""
|
||||||
Return the first definition found. Imports and statements aren't
|
Return the first definition found. Imports and statements aren't
|
||||||
@@ -440,7 +441,7 @@ class Script(object):
|
|||||||
definitions.append(import_name[0])
|
definitions.append(import_name[0])
|
||||||
else:
|
else:
|
||||||
stmt = self._get_under_cursor_stmt(goto_path)
|
stmt = self._get_under_cursor_stmt(goto_path)
|
||||||
defs, search_name = evaluate.goto(stmt)
|
defs, search_name = self._evaluator.goto(stmt)
|
||||||
definitions = follow_inexistent_imports(defs)
|
definitions = follow_inexistent_imports(defs)
|
||||||
if isinstance(user_stmt, pr.Statement):
|
if isinstance(user_stmt, pr.Statement):
|
||||||
c = user_stmt.get_commands()
|
c = user_stmt.get_commands()
|
||||||
@@ -452,7 +453,7 @@ class Script(object):
|
|||||||
definitions = [user_stmt]
|
definitions = [user_stmt]
|
||||||
return definitions, search_name
|
return definitions, search_name
|
||||||
|
|
||||||
@api_classes._clear_caches_after_call
|
#@api_classes._clear_caches_after_call
|
||||||
def usages(self, additional_module_paths=()):
|
def usages(self, additional_module_paths=()):
|
||||||
"""
|
"""
|
||||||
Return :class:`api_classes.Usage` objects, which contain all
|
Return :class:`api_classes.Usage` objects, which contain all
|
||||||
@@ -496,7 +497,7 @@ class Script(object):
|
|||||||
settings.dynamic_flow_information = temp
|
settings.dynamic_flow_information = temp
|
||||||
return self._sorted_defs(set(names))
|
return self._sorted_defs(set(names))
|
||||||
|
|
||||||
@api_classes._clear_caches_after_call
|
#@api_classes._clear_caches_after_call
|
||||||
def call_signatures(self):
|
def call_signatures(self):
|
||||||
"""
|
"""
|
||||||
Return the function object of the call you're currently in.
|
Return the function object of the call you're currently in.
|
||||||
@@ -520,7 +521,7 @@ class Script(object):
|
|||||||
|
|
||||||
user_stmt = self._user_stmt()
|
user_stmt = self._user_stmt()
|
||||||
with common.scale_speed_settings(settings.scale_call_signatures):
|
with common.scale_speed_settings(settings.scale_call_signatures):
|
||||||
_callable = lambda: evaluate.follow_call(call)
|
_callable = lambda: self._evaluator.follow_call(call)
|
||||||
origins = cache.cache_call_signatures(_callable, user_stmt)
|
origins = cache.cache_call_signatures(_callable, user_stmt)
|
||||||
debug.speed('func_call followed')
|
debug.speed('func_call followed')
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ from jedi import settings
|
|||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
from jedi import cache
|
from jedi import cache
|
||||||
from jedi import evaluate
|
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
import keywords
|
import keywords
|
||||||
import recursion
|
import recursion
|
||||||
|
|||||||
@@ -287,9 +287,9 @@ class Evaluator(object):
|
|||||||
res_new += add
|
res_new += add
|
||||||
else:
|
else:
|
||||||
if isinstance(r, pr.Class):
|
if isinstance(r, pr.Class):
|
||||||
r = er.Class(r)
|
r = er.Class(self, r)
|
||||||
elif isinstance(r, pr.Function):
|
elif isinstance(r, pr.Function):
|
||||||
r = er.Function(r)
|
r = er.Function(self, r)
|
||||||
if r.isinstance(er.Function) and resolve_decorator:
|
if r.isinstance(er.Function) and resolve_decorator:
|
||||||
r = r.get_decorated_func()
|
r = r.get_decorated_func()
|
||||||
res_new.append(r)
|
res_new.append(r)
|
||||||
@@ -472,8 +472,8 @@ class Evaluator(object):
|
|||||||
return filter_name(scope_generator)
|
return filter_name(scope_generator)
|
||||||
return descriptor_check(remove_statements(filter_name(scope_generator)))
|
return descriptor_check(remove_statements(filter_name(scope_generator)))
|
||||||
|
|
||||||
@recursion.RecursionDecorator
|
|
||||||
@cache.memoize_default(default=())
|
@cache.memoize_default(default=())
|
||||||
|
@recursion.RecursionDecorator
|
||||||
def follow_statement(self, stmt, seek_name=None):
|
def follow_statement(self, stmt, seek_name=None):
|
||||||
"""
|
"""
|
||||||
The starting point of the completion. A statement always owns a call list,
|
The starting point of the completion. A statement always owns a call list,
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ class RecursionDecorator(object):
|
|||||||
self.func = func
|
self.func = func
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
def __call__(self, stmt, *args, **kwargs):
|
def __call__(self, evaluator, stmt, *args, **kwargs):
|
||||||
# print stmt, len(self.node_statements())
|
# print stmt, len(self.node_statements())
|
||||||
if self.push_stmt(stmt):
|
if self.push_stmt(stmt):
|
||||||
return []
|
return []
|
||||||
else:
|
else:
|
||||||
result = self.func(stmt, *args, **kwargs)
|
result = self.func(evaluator, stmt, *args, **kwargs)
|
||||||
self.pop_stmt()
|
self.pop_stmt()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user