Don't use UserContextParser.user_stmt anymore, since we can access it directly.

This commit is contained in:
Dave Halter
2016-06-23 16:36:12 +02:00
parent 73e71b3c1a
commit bb4ab45131
3 changed files with 3 additions and 20 deletions

View File

@@ -172,7 +172,7 @@ class Completion:
if not names: if not names:
continue continue
completion_names += filter_definition_names( completion_names += filter_definition_names(
names, self._parser.user_stmt(), pos names, self._module.get_statement_for_position(self._position), pos
) )
return completion_names return completion_names
@@ -186,7 +186,7 @@ class Completion:
names += chain.from_iterable(names_dict.values()) names += chain.from_iterable(names_dict.values())
completion_names += filter_definition_names( completion_names += filter_definition_names(
names, self._parser.user_stmt() names, self._module.get_statement_for_position(self._position)
) )
return completion_names return completion_names

View File

@@ -12,16 +12,6 @@ from jedi.parser import tokenize, token
CompletionParts = namedtuple('CompletionParts', ['path', 'has_dot', 'name']) CompletionParts = namedtuple('CompletionParts', ['path', 'has_dot', 'name'])
def get_completion_parts(path_until_cursor):
"""
Returns the parts for the completion
:return: tuple - (path, dot, like)
"""
match = re.match(r'^(.*?)(\.|)(\w?[\w\d]*)$', path_until_cursor, flags=re.S)
path, dot, name = match.groups()
return CompletionParts(path, bool(dot), name)
def sorted_definitions(defs): def sorted_definitions(defs):
# Note: `or ''` below is required because `module_path` could be # Note: `or ''` below is required because `module_path` could be
return sorted(defs, key=lambda x: (x.module_path or '', x.line or 0, x.column or 0)) return sorted(defs, key=lambda x: (x.module_path or '', x.line or 0, x.column or 0))

View File

@@ -6,7 +6,6 @@ from jedi import cache
from jedi.parser import ParserWithRecovery from jedi.parser import ParserWithRecovery
from jedi.parser.fast import FastParser from jedi.parser.fast import FastParser
from jedi.parser import tree from jedi.parser import tree
from jedi import debug
# TODO this should be part of the tokenizer not just of this user_context. # TODO this should be part of the tokenizer not just of this user_context.
Token = namedtuple('Token', ['type', 'string', 'start_pos', 'prefix']) Token = namedtuple('Token', ['type', 'string', 'start_pos', 'prefix'])
@@ -39,18 +38,12 @@ class UserContextParser(object):
self._parser_done_callback(parser) self._parser_done_callback(parser)
return parser return parser
@cache.underscore_memoization
def user_stmt(self):
module = self.module()
debug.speed('parsed')
return module.get_statement_for_position(self._position)
@cache.underscore_memoization @cache.underscore_memoization
def user_scope(self): def user_scope(self):
""" """
Returns the scope in which the user resides. This includes flows. Returns the scope in which the user resides. This includes flows.
""" """
user_stmt = self.user_stmt() user_stmt = self.module().get_statement_for_position(self._position)
if user_stmt is None: if user_stmt is None:
def scan(scope): def scan(scope):
for s in scope.children: for s in scope.children: