diff options
| author | Riley Bruins <ribru17@hotmail.com> | 2024-02-14 09:39:59 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-15 00:39:59 +0700 |
| commit | d96bf9d522369eaf4ad57e607f134e51084ee1ad (patch) | |
| tree | dc3ef391ac26a9dbc2ca6bba60c8a391d65a6af2 | |
| parent | feat: add the hlsplaylist parser (diff) | |
| download | nvim-treesitter-d96bf9d522369eaf4ad57e607f134e51084ee1ad.tar nvim-treesitter-d96bf9d522369eaf4ad57e607f134e51084ee1ad.tar.gz nvim-treesitter-d96bf9d522369eaf4ad57e607f134e51084ee1ad.tar.bz2 nvim-treesitter-d96bf9d522369eaf4ad57e607f134e51084ee1ad.tar.lz nvim-treesitter-d96bf9d522369eaf4ad57e607f134e51084ee1ad.tar.xz nvim-treesitter-d96bf9d522369eaf4ad57e607f134e51084ee1ad.tar.zst nvim-treesitter-d96bf9d522369eaf4ad57e607f134e51084ee1ad.zip | |
fix(python): better try-except indentation (#6097)
| -rw-r--r-- | queries/python/indents.scm | 15 | ||||
| -rw-r--r-- | tests/indent/python/control_flow.py | 7 | ||||
| -rw-r--r-- | tests/indent/python_spec.lua | 1 |
3 files changed, 21 insertions, 2 deletions
diff --git a/queries/python/indents.scm b/queries/python/indents.scm index b89030425..94005ebab 100644 --- a/queries/python/indents.scm +++ b/queries/python/indents.scm @@ -38,8 +38,19 @@ (ERROR "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 (#set! indent.immediate 1)) diff --git a/tests/indent/python/control_flow.py b/tests/indent/python/control_flow.py index fca528a2d..387756f63 100644 --- a/tests/indent/python/control_flow.py +++ b/tests/indent/python/control_flow.py @@ -26,3 +26,10 @@ while (a > 4 and pass try: + +def foo(): + print('indentme') + + # comment + if True: + pass diff --git a/tests/indent/python_spec.lua b/tests/indent/python_spec.lua index ec44d551c..193b9901e 100644 --- a/tests/indent/python_spec.lua +++ b/tests/indent/python_spec.lua @@ -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 = 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 = 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 = 29, text = "and x > 9", indent = 4 }) run:new_line("hanging_indent.py", { on_line = 1, text = "arg0,", indent = 4 }) |
