mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-17 05:49:37 +08:00
Don't use NotFoundError anymore, since it's very ambiguous what that would imply.
This commit is contained in:
+15
-8
@@ -32,6 +32,7 @@ from jedi.evaluate import Evaluator
|
|||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate import imports
|
from jedi.evaluate import imports
|
||||||
|
from jedi.evaluate.cache import memoize_default
|
||||||
from jedi.evaluate.helpers import FakeName, get_module_name_parts
|
from jedi.evaluate.helpers import FakeName, get_module_name_parts
|
||||||
from jedi.evaluate.finder import get_names_of_scope, filter_private_variable
|
from jedi.evaluate.finder import get_names_of_scope, filter_private_variable
|
||||||
from jedi.evaluate.helpers import search_call_signatures
|
from jedi.evaluate.helpers import search_call_signatures
|
||||||
@@ -44,6 +45,7 @@ sys.setrecursionlimit(2000)
|
|||||||
|
|
||||||
class NotFoundError(Exception):
|
class NotFoundError(Exception):
|
||||||
"""A custom error to avoid catching the wrong exceptions."""
|
"""A custom error to avoid catching the wrong exceptions."""
|
||||||
|
# TODO deprecate this.
|
||||||
|
|
||||||
|
|
||||||
class Script(object):
|
class Script(object):
|
||||||
@@ -151,7 +153,7 @@ class Script(object):
|
|||||||
imp = imports.ImportWrapper(self._evaluator, name)
|
imp = imports.ImportWrapper(self._evaluator, name)
|
||||||
return [(n, module) for n in imp.get_defined_names()]
|
return [(n, module) for n in imp.get_defined_names()]
|
||||||
|
|
||||||
return self._simple_complete(path, like)
|
return self._simple_complete(path, dot, like)
|
||||||
|
|
||||||
def completion_possible(path):
|
def completion_possible(path):
|
||||||
"""
|
"""
|
||||||
@@ -226,11 +228,8 @@ class Script(object):
|
|||||||
x.name.startswith('_'),
|
x.name.startswith('_'),
|
||||||
x.name.lower()))
|
x.name.lower()))
|
||||||
|
|
||||||
def _simple_complete(self, path, like):
|
def _simple_complete(self, path, dot, like):
|
||||||
try:
|
if not path and not dot:
|
||||||
scopes = list(self._prepare_goto(path, True))
|
|
||||||
except NotFoundError:
|
|
||||||
scopes = []
|
|
||||||
scope_names_generator = get_names_of_scope(self._evaluator,
|
scope_names_generator = get_names_of_scope(self._evaluator,
|
||||||
self._parser.user_scope(),
|
self._parser.user_scope(),
|
||||||
self._pos)
|
self._pos)
|
||||||
@@ -238,7 +237,10 @@ class Script(object):
|
|||||||
for scope, name_list in scope_names_generator:
|
for scope, name_list in scope_names_generator:
|
||||||
for c in name_list:
|
for c in name_list:
|
||||||
completions.append((c, scope))
|
completions.append((c, scope))
|
||||||
|
elif self._get_under_cursor_stmt(path) is None:
|
||||||
|
return []
|
||||||
else:
|
else:
|
||||||
|
scopes = list(self._prepare_goto(path, True))
|
||||||
completions = []
|
completions = []
|
||||||
debug.dbg('possible completion scopes: %s', scopes)
|
debug.dbg('possible completion scopes: %s', scopes)
|
||||||
for s in scopes:
|
for s in scopes:
|
||||||
@@ -286,6 +288,8 @@ class Script(object):
|
|||||||
else:
|
else:
|
||||||
# just parse one statement, take it and evaluate it
|
# just parse one statement, take it and evaluate it
|
||||||
eval_stmt = self._get_under_cursor_stmt(goto_path)
|
eval_stmt = self._get_under_cursor_stmt(goto_path)
|
||||||
|
if eval_stmt is None:
|
||||||
|
return []
|
||||||
|
|
||||||
if not is_completion:
|
if not is_completion:
|
||||||
# goto_definition returns definitions of its statements if the
|
# goto_definition returns definitions of its statements if the
|
||||||
@@ -299,6 +303,7 @@ class Script(object):
|
|||||||
|
|
||||||
return scopes
|
return scopes
|
||||||
|
|
||||||
|
@memoize_default()
|
||||||
def _get_under_cursor_stmt(self, cursor_txt):
|
def _get_under_cursor_stmt(self, cursor_txt):
|
||||||
tokenizer = source_tokens(cursor_txt, line_offset=self._pos[0] - 1)
|
tokenizer = source_tokens(cursor_txt, line_offset=self._pos[0] - 1)
|
||||||
r = Parser(self._grammar, cursor_txt, tokenizer=tokenizer)
|
r = Parser(self._grammar, cursor_txt, tokenizer=tokenizer)
|
||||||
@@ -306,8 +311,10 @@ class Script(object):
|
|||||||
# Take the last statement available.
|
# Take the last statement available.
|
||||||
stmt = r.module.statements[-1]
|
stmt = r.module.statements[-1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
return None
|
||||||
raise NotFoundError()
|
raise NotFoundError()
|
||||||
if not isinstance(stmt, (pr.ExprStmt, pr.KeywordStatement)):
|
if not isinstance(stmt, (pr.ExprStmt, pr.KeywordStatement)):
|
||||||
|
raise NotImplementedError
|
||||||
raise NotFoundError()
|
raise NotFoundError()
|
||||||
|
|
||||||
# TODO remove?
|
# TODO remove?
|
||||||
@@ -647,11 +654,11 @@ class Interpreter(Script):
|
|||||||
# Here we add the namespaces to the current parser.
|
# Here we add the namespaces to the current parser.
|
||||||
interpreter.create(self._evaluator, namespaces[0], self._parser.module())
|
interpreter.create(self._evaluator, namespaces[0], self._parser.module())
|
||||||
|
|
||||||
def _simple_complete(self, path, like):
|
def _simple_complete(self, path, dot, like):
|
||||||
user_stmt = self._parser.user_stmt_with_whitespace()
|
user_stmt = self._parser.user_stmt_with_whitespace()
|
||||||
is_simple_path = not path or re.search('^[\w][\w\d.]*$', path)
|
is_simple_path = not path or re.search('^[\w][\w\d.]*$', path)
|
||||||
if isinstance(user_stmt, pr.Import) or not is_simple_path:
|
if isinstance(user_stmt, pr.Import) or not is_simple_path:
|
||||||
return super(Interpreter, self)._simple_complete(path, like)
|
return super(Interpreter, self)._simple_complete(path, dot, like)
|
||||||
else:
|
else:
|
||||||
class NamespaceModule(object):
|
class NamespaceModule(object):
|
||||||
def __getattr__(_, name):
|
def __getattr__(_, name):
|
||||||
|
|||||||
Reference in New Issue
Block a user