forked from VimPlug/jedi
Fix some code_lines issues
This commit is contained in:
@@ -119,13 +119,19 @@ class Script(object):
|
|||||||
cache_path=settings.cache_directory
|
cache_path=settings.cache_directory
|
||||||
)
|
)
|
||||||
debug.speed('parsed')
|
debug.speed('parsed')
|
||||||
self._code_lines = parso.split_lines(source)
|
self._code_lines = parso.split_lines(source, keepends=True)
|
||||||
self._code = source
|
self._code = source
|
||||||
line = max(len(self._code_lines), 1) if line is None else line
|
line = max(len(self._code_lines), 1) if line is None else line
|
||||||
if not (0 < line <= len(self._code_lines)):
|
if not (0 < line <= len(self._code_lines)):
|
||||||
raise ValueError('`line` parameter is not in a valid range.')
|
raise ValueError('`line` parameter is not in a valid range.')
|
||||||
|
|
||||||
line_len = len(self._code_lines[line - 1])
|
line_string = self._code_lines[line - 1]
|
||||||
|
line_len = len(line_string)
|
||||||
|
if line_string.endswith('\r\n'):
|
||||||
|
line_len -= 1
|
||||||
|
if line_string.endswith('\n'):
|
||||||
|
line_len -= 1
|
||||||
|
|
||||||
column = line_len if column is None else column
|
column = line_len if column is None else column
|
||||||
if not (0 <= column <= line_len):
|
if not (0 <= column <= line_len):
|
||||||
raise ValueError('`column` parameter is not in a valid range.')
|
raise ValueError('`column` parameter is not in a valid range.')
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ the interesting information about completion and goto operations.
|
|||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from parso.cache import parser_cache
|
|
||||||
from parso.python.tree import search_ancestor
|
from parso.python.tree import search_ancestor
|
||||||
|
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
@@ -13,7 +12,6 @@ from jedi.evaluate.utils import ignored, unite
|
|||||||
from jedi.cache import memoize_method
|
from jedi.cache import memoize_method
|
||||||
from jedi.evaluate import imports
|
from jedi.evaluate import imports
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate.filters import ParamName
|
|
||||||
from jedi.evaluate.imports import ImportName
|
from jedi.evaluate.imports import ImportName
|
||||||
from jedi.evaluate.context import instance
|
from jedi.evaluate.context import instance
|
||||||
from jedi.evaluate.context import ClassContext, FunctionContext, FunctionExecutionContext
|
from jedi.evaluate.context import ClassContext, FunctionContext, FunctionExecutionContext
|
||||||
@@ -532,7 +530,6 @@ class Definition(BaseDefinition):
|
|||||||
)
|
)
|
||||||
return typ + ' ' + code
|
return typ + ' ' + code
|
||||||
|
|
||||||
|
|
||||||
definition = tree_name.get_definition() or tree_name
|
definition = tree_name.get_definition() or tree_name
|
||||||
# Remove the prefix, because that's not what we want for get_code
|
# Remove the prefix, because that's not what we want for get_code
|
||||||
# here.
|
# here.
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ from textwrap import dedent
|
|||||||
|
|
||||||
from parso.python.parser import Parser
|
from parso.python.parser import Parser
|
||||||
from parso.python import tree
|
from parso.python import tree
|
||||||
from parso import split_lines
|
|
||||||
|
|
||||||
from jedi._compatibility import u
|
from jedi._compatibility import u
|
||||||
from jedi.evaluate.syntax_tree import eval_atom
|
from jedi.evaluate.syntax_tree import eval_atom
|
||||||
@@ -44,7 +43,7 @@ def _get_code(code_lines, start_pos, end_pos):
|
|||||||
lines[-1] = lines[-1][:end_pos[1]]
|
lines[-1] = lines[-1][:end_pos[1]]
|
||||||
# Remove first line indentation.
|
# Remove first line indentation.
|
||||||
lines[0] = lines[0][start_pos[1]:]
|
lines[0] = lines[0][start_pos[1]:]
|
||||||
return '\n'.join(lines)
|
return ''.join(lines)
|
||||||
|
|
||||||
|
|
||||||
class OnErrorLeaf(Exception):
|
class OnErrorLeaf(Exception):
|
||||||
@@ -283,11 +282,11 @@ def get_call_signature_details(module, position):
|
|||||||
@time_cache("call_signatures_validity")
|
@time_cache("call_signatures_validity")
|
||||||
def cache_call_signatures(evaluator, context, bracket_leaf, code_lines, user_pos):
|
def cache_call_signatures(evaluator, context, bracket_leaf, code_lines, user_pos):
|
||||||
"""This function calculates the cache key."""
|
"""This function calculates the cache key."""
|
||||||
index = user_pos[0] - 1
|
line_index = user_pos[0] - 1
|
||||||
|
|
||||||
before_cursor = code_lines[index][:user_pos[1]]
|
before_cursor = code_lines[line_index][:user_pos[1]]
|
||||||
other_lines = code_lines[bracket_leaf.start_pos[0]:index]
|
other_lines = code_lines[bracket_leaf.start_pos[0]:line_index]
|
||||||
whole = '\n'.join(other_lines + [before_cursor])
|
whole = ''.join(other_lines + [before_cursor])
|
||||||
before_bracket = re.match(r'.*\(', whole, re.DOTALL)
|
before_bracket = re.match(r'.*\(', whole, re.DOTALL)
|
||||||
|
|
||||||
module_path = context.get_root_context().py__file__()
|
module_path = context.get_root_context().py__file__()
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ def _get_typing_replacement_module(grammar):
|
|||||||
with open(typing_path) as f:
|
with open(typing_path) as f:
|
||||||
code = unicode(f.read())
|
code = unicode(f.read())
|
||||||
_typing_module = grammar.parse(code)
|
_typing_module = grammar.parse(code)
|
||||||
_typing_module_code_lines = split_lines(code)
|
_typing_module_code_lines = split_lines(code, keepends=True)
|
||||||
return _typing_module, _typing_module_code_lines
|
return _typing_module, _typing_module_code_lines
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ def collections_namedtuple(evaluator, obj, arguments):
|
|||||||
generated_class = next(module.iter_classdefs())
|
generated_class = next(module.iter_classdefs())
|
||||||
parent_context = ModuleContext(
|
parent_context = ModuleContext(
|
||||||
evaluator, module, None,
|
evaluator, module, None,
|
||||||
code_lines=parso.split_lines(code),
|
code_lines=parso.split_lines(code, keepends=True),
|
||||||
)
|
)
|
||||||
return ContextSet(ClassContext(evaluator, parent_context, generated_class))
|
return ContextSet(ClassContext(evaluator, parent_context, generated_class))
|
||||||
|
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ def test_get_line_code(Script):
|
|||||||
# On custom code
|
# On custom code
|
||||||
first_line = 'def foo():\n'
|
first_line = 'def foo():\n'
|
||||||
line = ' foo'
|
line = ' foo'
|
||||||
code = '%s%s' % (first_line, line)
|
code = first_line + line
|
||||||
assert get_line_code(code) == first_line
|
assert get_line_code(code) == first_line
|
||||||
|
|
||||||
# With before/after
|
# With before/after
|
||||||
|
|||||||
@@ -84,5 +84,5 @@ def test_namedtuple_goto_definitions(Script):
|
|||||||
|
|
||||||
d1, = Script(source).goto_definitions()
|
d1, = Script(source).goto_definitions()
|
||||||
|
|
||||||
assert d1.get_line_code() == "class Foo(tuple):"
|
assert d1.get_line_code() == "class Foo(tuple):\n"
|
||||||
assert d1.module_path is None
|
assert d1.module_path is None
|
||||||
|
|||||||
Reference in New Issue
Block a user