mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
@@ -393,9 +393,9 @@ class BaseDefinition(object):
|
|||||||
path = self._name.get_root_context().py__file__()
|
path = self._name.get_root_context().py__file__()
|
||||||
lines = parser_cache[self._evaluator.grammar._hashed][path].lines
|
lines = parser_cache[self._evaluator.grammar._hashed][path].lines
|
||||||
|
|
||||||
line_nr = self._name.start_pos[0]
|
index = self._name.start_pos[0] - 1
|
||||||
start_line_nr = max(line_nr - before, 0)
|
start_index = max(index - before, 0)
|
||||||
return ''.join(lines[start_line_nr:line_nr + after + 1])
|
return ''.join(lines[start_index:index + after + 1])
|
||||||
|
|
||||||
|
|
||||||
class Completion(BaseDefinition):
|
class Completion(BaseDefinition):
|
||||||
|
|||||||
@@ -162,18 +162,19 @@ def test_get_line_code():
|
|||||||
assert get_line_code('') == ''
|
assert get_line_code('') == ''
|
||||||
|
|
||||||
# On custom code
|
# On custom code
|
||||||
|
first_line = 'def foo():\n'
|
||||||
line = ' foo'
|
line = ' foo'
|
||||||
assert get_line_code('def foo():\n%s' % line) == line
|
code = '%s%s' % (first_line, line)
|
||||||
|
assert get_line_code(code) == first_line
|
||||||
|
|
||||||
# With before/after
|
# With before/after
|
||||||
line = ' foo'
|
code = code + '\nother_line'
|
||||||
source = 'def foo():\n%s\nother_line' % line
|
assert get_line_code(code, line=2) == first_line
|
||||||
assert get_line_code(source, line=2) == line + '\n'
|
assert get_line_code(code, line=2, after=1) == first_line + line + '\n'
|
||||||
assert get_line_code(source, line=2, after=1) == line + '\nother_line'
|
assert get_line_code(code, line=2, after=2, before=1) == code
|
||||||
assert get_line_code(source, line=2, after=1, before=1) == source
|
|
||||||
# Should just be the whole thing, since there are no more lines on both
|
# Should just be the whole thing, since there are no more lines on both
|
||||||
# sides.
|
# sides.
|
||||||
assert get_line_code(source, line=2, after=3, before=3) == source
|
assert get_line_code(code, line=2, after=3, before=3) == code
|
||||||
|
|
||||||
|
|
||||||
def test_goto_assignments_follow_imports():
|
def test_goto_assignments_follow_imports():
|
||||||
|
|||||||
Reference in New Issue
Block a user