mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-17 19:00:02 -04:00
fix(python): better try-except indentation (#6097)
This commit is contained in:
parent
5a5cabd712
commit
d96bf9d522
3 changed files with 21 additions and 2 deletions
|
|
@ -38,8 +38,19 @@
|
||||||
|
|
||||||
(ERROR
|
(ERROR
|
||||||
"try"
|
"try"
|
||||||
":" @indent.begin
|
.
|
||||||
(#set! indent.immediate 1))
|
":"
|
||||||
|
(#set! indent.immediate 1)) @indent.begin
|
||||||
|
|
||||||
|
(ERROR
|
||||||
|
"try"
|
||||||
|
.
|
||||||
|
":"
|
||||||
|
(ERROR
|
||||||
|
(block
|
||||||
|
(expression_statement
|
||||||
|
(identifier) @_except) @indent.branch))
|
||||||
|
(#eq? @_except "except"))
|
||||||
|
|
||||||
((function_definition) @indent.begin
|
((function_definition) @indent.begin
|
||||||
(#set! indent.immediate 1))
|
(#set! indent.immediate 1))
|
||||||
|
|
|
||||||
|
|
@ -26,3 +26,10 @@ while (a > 4 and
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
def foo():
|
||||||
|
print('indentme')
|
||||||
|
|
||||||
|
# comment
|
||||||
|
if True:
|
||||||
|
pass
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ describe("indent Python:", function()
|
||||||
run:new_line("control_flow.py", { on_line = 24, text = "c < 6 and", indent = 7 })
|
run:new_line("control_flow.py", { on_line = 24, text = "c < 6 and", indent = 7 })
|
||||||
run:new_line("control_flow.py", { on_line = 26, text = "x = 4", indent = 4 })
|
run:new_line("control_flow.py", { on_line = 26, text = "x = 4", indent = 4 })
|
||||||
run:new_line("control_flow.py", { on_line = 28, text = "x = 4", indent = 4 })
|
run:new_line("control_flow.py", { on_line = 28, text = "x = 4", indent = 4 })
|
||||||
|
run:new_line("control_flow.py", { on_line = 31, text = "try:", indent = 4 })
|
||||||
run:new_line("branches.py", { on_line = 25, text = "x > 9 and", indent = 4 })
|
run:new_line("branches.py", { on_line = 25, text = "x > 9 and", indent = 4 })
|
||||||
run:new_line("branches.py", { on_line = 29, text = "and x > 9", indent = 4 })
|
run:new_line("branches.py", { on_line = 29, text = "and x > 9", indent = 4 })
|
||||||
run:new_line("hanging_indent.py", { on_line = 1, text = "arg0,", indent = 4 })
|
run:new_line("hanging_indent.py", { on_line = 1, text = "arg0,", indent = 4 })
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue