mirror of
https://github.com/chenasraf/nvim-treesitter.git
synced 2026-05-18 01:39:00 +00:00
feat(python): add "return" patterns to @indent_end
`return ...` is usually the last line of a function/statement, so mark some possible patterns of `return` with `@indent_end` to dedent the line after it
This commit is contained in:
committed by
Stephan Seitz
parent
273d5e9ac5
commit
01e8a51451
@@ -72,6 +72,15 @@
|
||||
(list_pattern "]" @indent_end)
|
||||
|
||||
|
||||
(return_statement
|
||||
[
|
||||
(_) @indent_end
|
||||
(_ (_) @indent_end .)
|
||||
(attribute
|
||||
attribute: (_) @indent_end)
|
||||
"return" @indent_end
|
||||
] .)
|
||||
|
||||
[
|
||||
")"
|
||||
"]"
|
||||
|
||||
16
tests/indent/python/return_dedent.py
Normal file
16
tests/indent/python/return_dedent.py
Normal file
@@ -0,0 +1,16 @@
|
||||
def a():
|
||||
return
|
||||
|
||||
def a():
|
||||
return True
|
||||
|
||||
def a():
|
||||
return (1, 2, 3)
|
||||
|
||||
def a():
|
||||
return x.y.z
|
||||
|
||||
def a():
|
||||
return (
|
||||
1, 2, 3
|
||||
)
|
||||
@@ -74,5 +74,9 @@ describe("indent Python:", function()
|
||||
run:new_line("line_after_indent.py", { on_line = 49, text = "x", indent = 0 })
|
||||
run:new_line("line_after_indent.py", { on_line = 55, text = "x", indent = 4 })
|
||||
run:new_line("line_after_indent.py", { on_line = 63, text = "x", indent = 4 })
|
||||
|
||||
for _, line in ipairs { 2, 5, 8, 11, 16 } do
|
||||
run:new_line("return_dedent.py", { on_line = line, text = "x", indent = 0 })
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user