1
0
forked from VimPlug/jedi

user_context is not needed anymore for completions. yay!

This commit is contained in:
Dave Halter
2016-06-23 09:19:09 +02:00
parent 8f39a6e89d
commit 9225db084a
3 changed files with 12 additions and 14 deletions

View File

@@ -106,12 +106,12 @@ class Script(object):
source = f.read()
self._source = common.source_to_unicode(source, encoding)
lines = common.splitlines(self._source)
line = max(len(lines), 1) if line is None else line
if not (0 < line <= len(lines)):
self._code_lines = common.splitlines(self._source)
line = max(len(self._code_lines), 1) if line is None else line
if not (0 < line <= len(self._code_lines)):
raise ValueError('`line` parameter is not in a valid range.')
line_len = len(lines[line - 1])
line_len = len(self._code_lines[line - 1])
column = line_len if column is None else column
if not (0 <= column <= line_len):
raise ValueError('`column` parameter is not in a valid range.')
@@ -162,7 +162,7 @@ class Script(object):
debug.speed('completions start')
path = self._user_context.get_path_until_cursor()
completion = Completion(
self._evaluator, self._parser, self._user_context,
self._evaluator, self._parser, self._code_lines,
self._pos, self.call_signatures
)
completions = completion.completions(path)

View File

@@ -53,11 +53,11 @@ def filter_names(evaluator, completion_names, like_name):
class Completion:
def __init__(self, evaluator, parser, user_context, position, call_signatures_method):
def __init__(self, evaluator, parser, code_lines, position, call_signatures_method):
self._evaluator = evaluator
self._parser = parser
self._module = evaluator.wrap(parser.module())
self._source = user_context.source
self._code_lines = code_lines
self._pos = position
self._call_signatures_method = call_signatures_method
@@ -97,7 +97,7 @@ class Completion:
pos = pos[0], pos[1] - len(completion_parts.name)
try:
stack = helpers.get_stack_at_position(grammar, self._source, self._module, pos)
stack = helpers.get_stack_at_position(grammar, self._code_lines, self._module, pos)
except helpers.OnErrorLeaf as e:
if e.error_leaf.value == '.':
# After ErrorLeaf's that are dots, we will not do any

View File

@@ -4,7 +4,6 @@ Helpers for the API
import re
from collections import namedtuple
from jedi import common
from jedi.evaluate.helpers import call_of_leaf
from jedi import parser
from jedi.parser import tokenize, token
@@ -28,13 +27,12 @@ def sorted_definitions(defs):
return sorted(defs, key=lambda x: (x.module_path or '', x.line or 0, x.column or 0))
def _get_code(code, start_pos, end_pos):
def _get_code(code_lines, start_pos, end_pos):
"""
:param code_start_pos: is where the code starts.
"""
lines = common.splitlines(code)
# Get relevant lines.
lines = lines[start_pos[0] - 1:end_pos[0]]
lines = code_lines[start_pos[0] - 1:end_pos[0]]
# Remove the parts at the end of the line.
lines[-1] = lines[-1][:end_pos[1]]
# Remove first line indentation.
@@ -48,7 +46,7 @@ class OnErrorLeaf(Exception):
return self.args[0]
def get_stack_at_position(grammar, source, module, pos):
def get_stack_at_position(grammar, code_lines, module, pos):
"""
Returns the possible node names (e.g. import_from, xor_test or yield_stmt).
"""
@@ -72,7 +70,7 @@ def get_stack_at_position(grammar, source, module, pos):
# impossible.
raise OnErrorLeaf(user_stmt)
code = _get_code(source, user_stmt.start_pos, pos)
code = _get_code(code_lines, user_stmt.start_pos, pos)
if code == ';':
# ; cannot be parsed.
code = ''