diff options
| author | Pham Huy Hoang <hoangtun0810@gmail.com> | 2023-04-29 17:35:35 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-29 10:35:35 +0200 |
| commit | 1ca9b938c1c3d8b2c64a168f6a5419b8f3870410 (patch) | |
| tree | 708625a300dca93d3fcac5935c8e2be094c914bd | |
| parent | Update parsers: erlang, haskell (diff) | |
| download | nvim-treesitter-1ca9b938c1c3d8b2c64a168f6a5419b8f3870410.tar nvim-treesitter-1ca9b938c1c3d8b2c64a168f6a5419b8f3870410.tar.gz nvim-treesitter-1ca9b938c1c3d8b2c64a168f6a5419b8f3870410.tar.bz2 nvim-treesitter-1ca9b938c1c3d8b2c64a168f6a5419b8f3870410.tar.lz nvim-treesitter-1ca9b938c1c3d8b2c64a168f6a5419b8f3870410.tar.xz nvim-treesitter-1ca9b938c1c3d8b2c64a168f6a5419b8f3870410.tar.zst nvim-treesitter-1ca9b938c1c3d8b2c64a168f6a5419b8f3870410.zip | |
Add Python else elif dedent (#4618)
* feat(python): add interactive else/elif dedent
* fixup
* add test
| -rw-r--r-- | queries/python/indents.scm | 8 | ||||
| -rw-r--r-- | tests/indent/python/if_else.py | 3 | ||||
| -rw-r--r-- | tests/indent/python_spec.lua | 2 |
3 files changed, 13 insertions, 0 deletions
diff --git a/queries/python/indents.scm b/queries/python/indents.scm index efcdba6b2..338473f00 100644 --- a/queries/python/indents.scm +++ b/queries/python/indents.scm @@ -83,6 +83,14 @@ (continue_statement) ] @indent.dedent +(ERROR + (_) @indent.branch ":" . + (#lua-match? @indent.branch "^else")) + +(ERROR + (_) @indent.branch @indent.dedent ":" . + (#lua-match? @indent.branch "^elif")) + (parenthesized_expression ")" @indent.end) (generator_expression ")" @indent.end) (list_comprehension "]" @indent.end) diff --git a/tests/indent/python/if_else.py b/tests/indent/python/if_else.py new file mode 100644 index 000000000..d128597f0 --- /dev/null +++ b/tests/indent/python/if_else.py @@ -0,0 +1,3 @@ +def test_branch_else(): + if True: + x = 1 diff --git a/tests/indent/python_spec.lua b/tests/indent/python_spec.lua index aa9aa83e0..ec44d551c 100644 --- a/tests/indent/python_spec.lua +++ b/tests/indent/python_spec.lua @@ -50,6 +50,8 @@ describe("indent Python:", function() run:new_line("error_state_dict.py", { on_line = 6, text = "9:10,", indent = 6 }) run:new_line("error_state_set.py", { on_line = 5, text = "9,", indent = 6 }) run:new_line("error_state_funcall.py", { on_line = 5, text = "6,", indent = 2 }) + run:new_line("if_else.py", { on_line = 5, text = "else:", indent = 4 }) + run:new_line("if_else.py", { on_line = 5, text = "elif False:", indent = 4 }) run:new_line( "join_lines.py", { on_line = 1, text = "+ 1 \\", indent = 4 }, |
