mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-30 21:25:22 +08:00
Remove old indent/dedent usages. Now they are not needed anymore.
This commit is contained in:
@@ -51,19 +51,6 @@ class OnErrorLeaf(Exception):
|
||||
|
||||
|
||||
def _is_on_comment(leaf, position):
|
||||
# We might be on a comment.
|
||||
if leaf.type == 'endmarker':
|
||||
try:
|
||||
dedent = leaf.get_previous_leaf()
|
||||
if dedent.type == 'dedent' and dedent.prefix:
|
||||
# TODO This is needed because the fast parser uses multiple
|
||||
# endmarker tokens within a file which is obviously ugly.
|
||||
# This is so ugly that I'm not even commenting how it exactly
|
||||
# happens, but let me tell you that I want to get rid of it.
|
||||
leaf = dedent
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
comment_lines = common.splitlines(leaf.prefix)
|
||||
difference = leaf.start_pos[0] - position[0]
|
||||
prefix_start_pos = leaf.get_start_pos_of_prefix()
|
||||
@@ -98,9 +85,7 @@ def _get_code_for_stack(code_lines, module, position):
|
||||
except IndexError:
|
||||
return u('')
|
||||
|
||||
if leaf.type in ('indent', 'dedent'):
|
||||
return u('')
|
||||
elif leaf.type == 'error_leaf' or leaf.type == 'string':
|
||||
if leaf.type == 'error_leaf' or leaf.type == 'string':
|
||||
if leaf.start_pos[0] < position[0]:
|
||||
# On a different line, we just begin anew.
|
||||
return u('')
|
||||
@@ -146,7 +131,6 @@ def get_stack_at_position(grammar, code_lines, module, pos):
|
||||
# completion.
|
||||
# Use Z as a prefix because it's not part of a number suffix.
|
||||
safeword = 'ZZZ_USER_WANTS_TO_COMPLETE_HERE_WITH_JEDI'
|
||||
# Remove as many indents from **all** code lines as possible.
|
||||
code = code + safeword
|
||||
|
||||
p = parser.ParserWithRecovery(grammar, code, start_parsing=False)
|
||||
|
||||
@@ -134,7 +134,7 @@ def _evaluate_for_statement_string(evaluator, string, module):
|
||||
p = ParserWithRecovery(load_grammar(), code % indent_block(string))
|
||||
try:
|
||||
pseudo_cls = p.module.subscopes[0]
|
||||
# First pick suite, then simple_stmt (-2 for DEDENT) and then the node,
|
||||
# First pick suite, then simple_stmt and then the node,
|
||||
# which is also not the last item, because there's a newline.
|
||||
stmt = pseudo_cls.children[-1].children[-1].children[-2]
|
||||
except (AttributeError, IndexError):
|
||||
|
||||
@@ -27,7 +27,7 @@ def deep_ast_copy(obj, parent=None, new_elements=None):
|
||||
for child in obj.children:
|
||||
typ = child.type
|
||||
if typ in ('newline', 'operator', 'keyword', 'number', 'string',
|
||||
'indent', 'dedent', 'endmarker', 'error_leaf'):
|
||||
'endmarker', 'error_leaf'):
|
||||
# At the moment we're not actually copying those primitive
|
||||
# elements, because there's really no need to. The parents are
|
||||
# obviously wrong, but that's not an issue.
|
||||
|
||||
@@ -223,10 +223,6 @@ class Parser(object):
|
||||
return pt.Number(self.position_modifier, value, start_pos, prefix)
|
||||
elif type == NEWLINE:
|
||||
return pt.Newline(self.position_modifier, value, start_pos, prefix)
|
||||
elif type == INDENT:
|
||||
return pt.Indent(self.position_modifier, value, start_pos, prefix)
|
||||
elif type == DEDENT:
|
||||
return pt.Dedent(self.position_modifier, value, start_pos, prefix)
|
||||
elif type == ENDMARKER:
|
||||
return pt.EndMarker(self.position_modifier, value, start_pos, prefix)
|
||||
else:
|
||||
|
||||
@@ -147,7 +147,7 @@ class Base(object):
|
||||
return scope
|
||||
|
||||
def get_definition(self):
|
||||
if self.type in ('newline', 'dedent', 'indent', 'endmarker'):
|
||||
if self.type in ('newline', 'endmarker'):
|
||||
raise ValueError('Cannot get the indentation of whitespace or indentation.')
|
||||
scope = self
|
||||
while scope.parent is not None:
|
||||
@@ -294,11 +294,7 @@ class Leaf(Base):
|
||||
|
||||
def get_start_pos_of_prefix(self):
|
||||
try:
|
||||
previous_leaf = self
|
||||
while True:
|
||||
previous_leaf = previous_leaf.get_previous_leaf()
|
||||
if previous_leaf.type not in ('indent', 'dedent'):
|
||||
return previous_leaf.end_pos
|
||||
return self.get_previous_leaf().end_pos
|
||||
except IndexError:
|
||||
return 1, 0 # It's the first leaf.
|
||||
|
||||
@@ -426,16 +422,6 @@ class String(Literal):
|
||||
__slots__ = ()
|
||||
|
||||
|
||||
class Indent(Leaf):
|
||||
type = 'indent'
|
||||
__slots__ = ()
|
||||
|
||||
|
||||
class Dedent(Leaf):
|
||||
type = 'dedent'
|
||||
__slots__ = ()
|
||||
|
||||
|
||||
class Operator(Leaf):
|
||||
type = 'operator'
|
||||
__slots__ = ()
|
||||
@@ -550,10 +536,6 @@ class BaseNode(Base):
|
||||
try:
|
||||
return c.get_leaf_for_position(position, include_prefixes)
|
||||
except AttributeError:
|
||||
while c.type in ('indent', 'dedent'):
|
||||
# We'd rather not have indents and dedents as a leaf,
|
||||
# because they don't contain indentation information.
|
||||
c = c.get_next_leaf()
|
||||
return c
|
||||
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user