mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 07:14:48 +08:00
parentheses checks in the fast parser (tokenizer) have been improved to really cover all cases. real fix for davidhalter/jedi-vim#288
This commit is contained in:
@@ -392,6 +392,7 @@ class FastTokenizer(object):
|
|||||||
self.parser_indent = self.old_parser_indent = 0
|
self.parser_indent = self.old_parser_indent = 0
|
||||||
self.is_decorator = False
|
self.is_decorator = False
|
||||||
self.first_stmt = True
|
self.first_stmt = True
|
||||||
|
self.parentheses_level = 0
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
""" Python 2 Compatibility """
|
""" Python 2 Compatibility """
|
||||||
@@ -419,14 +420,15 @@ class FastTokenizer(object):
|
|||||||
self.closed = True
|
self.closed = True
|
||||||
raise common.MultiLevelStopIteration()
|
raise common.MultiLevelStopIteration()
|
||||||
|
|
||||||
# Ignore comments/newlines/closing parentheses, because they are all
|
# Ignore comments/newlines, irrelevant for indentation.
|
||||||
# irrelevant for the indentation.
|
|
||||||
if self.previous.type in (None, NEWLINE) \
|
if self.previous.type in (None, NEWLINE) \
|
||||||
and tok_type not in (COMMENT, NEWLINE) \
|
and tok_type not in (COMMENT, NEWLINE):
|
||||||
and tok_str not in ')]}':
|
|
||||||
# print c, tok_name[c[0]]
|
# print c, tok_name[c[0]]
|
||||||
indent = current.start_pos[1]
|
indent = current.start_pos[1]
|
||||||
if indent < self.parser_indent: # -> dedent
|
if self.parentheses_level:
|
||||||
|
# parentheses ignore the indentation rules.
|
||||||
|
pass
|
||||||
|
elif indent < self.parser_indent: # -> dedent
|
||||||
self.parser_indent = indent
|
self.parser_indent = indent
|
||||||
self.new_indent = False
|
self.new_indent = False
|
||||||
if not self.in_flow or indent < self.old_parser_indent:
|
if not self.in_flow or indent < self.old_parser_indent:
|
||||||
@@ -453,4 +455,12 @@ class FastTokenizer(object):
|
|||||||
if self.first_stmt and not self.new_indent:
|
if self.first_stmt and not self.new_indent:
|
||||||
self.parser_indent = indent
|
self.parser_indent = indent
|
||||||
self.first_stmt = False
|
self.first_stmt = False
|
||||||
|
|
||||||
|
# Ignore closing parentheses, because they are all
|
||||||
|
# irrelevant for the indentation.
|
||||||
|
|
||||||
|
if tok_str in '([{':
|
||||||
|
self.parentheses_level += 1
|
||||||
|
elif tok_str in ')]}':
|
||||||
|
self.parentheses_level = max(self.parentheses_level - 1, 0)
|
||||||
return current
|
return current
|
||||||
|
|||||||
@@ -2,17 +2,26 @@
|
|||||||
Issues with the parser not the completion engine should be here.
|
Issues with the parser not the completion engine should be here.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class C():
|
class IndentIssues():
|
||||||
"""
|
"""
|
||||||
issue jedi-vim#288
|
issue jedi-vim#288
|
||||||
Which is really a fast parser issue. It used to start a new block at the
|
Which is really a fast parser issue. It used to start a new block at the
|
||||||
parentheses, because it had problems with the indentation.
|
parentheses, because it had problems with the indentation.
|
||||||
"""
|
"""
|
||||||
def indent_issues(
|
def one_param(
|
||||||
self,
|
self,
|
||||||
):
|
):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
def with_param(
|
||||||
|
self,
|
||||||
|
y):
|
||||||
|
return y
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#? int()
|
#? int()
|
||||||
C().indent_issues()
|
IndentIssues().one_param()
|
||||||
|
|
||||||
|
#? str()
|
||||||
|
IndentIssues().with_param('')
|
||||||
|
|||||||
Reference in New Issue
Block a user