aboutsummaryrefslogtreecommitdiffstats
path: root/queries/python
diff options
context:
space:
mode:
authorGrace Petryk <gracepetryk99@gmail.com>2024-07-16 04:13:41 -0700
committerGitHub <noreply@github.com>2024-07-16 20:13:41 +0900
commitf16a77583047d6d3ea684092c679bbe88398cb01 (patch)
tree7c0fce69fd9468f46aca3bd192274a0fcb6603c8 /queries/python
parentfeat(templ): add folds (diff)
downloadnvim-treesitter-f16a77583047d6d3ea684092c679bbe88398cb01.tar
nvim-treesitter-f16a77583047d6d3ea684092c679bbe88398cb01.tar.gz
nvim-treesitter-f16a77583047d6d3ea684092c679bbe88398cb01.tar.bz2
nvim-treesitter-f16a77583047d6d3ea684092c679bbe88398cb01.tar.lz
nvim-treesitter-f16a77583047d6d3ea684092c679bbe88398cb01.tar.xz
nvim-treesitter-f16a77583047d6d3ea684092c679bbe88398cb01.tar.zst
nvim-treesitter-f16a77583047d6d3ea684092c679bbe88398cb01.zip
feat(python): Improved python indentation (#6859)
* feat: improve python indentation * use lua-match * revert concatenated_string changes, handle function def hanging indents * lint * add delimiters to param query * add test cases
Diffstat (limited to 'queries/python')
-rw-r--r--queries/python/indents.scm39
1 files changed, 35 insertions, 4 deletions
diff --git a/queries/python/indents.scm b/queries/python/indents.scm
index dbda25b5c..2414812a7 100644
--- a/queries/python/indents.scm
+++ b/queries/python/indents.scm
@@ -1,6 +1,5 @@
[
(import_from_statement)
- (parenthesized_expression)
(generator_expression)
(list_comprehension)
(set_comprehension)
@@ -24,6 +23,10 @@
(#set! indent.open_delimiter "{")
(#set! indent.close_delimiter "}"))
+((parenthesized_expression) @indent.align
+ (#set! indent.open_delimiter "(")
+ (#set! indent.close_delimiter ")"))
+
((for_statement) @indent.begin
(#set! indent.immediate 1))
@@ -67,14 +70,40 @@
((case_clause) @indent.begin
(#set! indent.immediate 1))
+; if (cond1
+; or cond2
+; or cond3):
+; pass
+;
(if_statement
condition: (parenthesized_expression) @indent.align
+ (#lua-match? @indent.align "^%([^\n]")
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")")
(#set! indent.avoid_last_matching_next 1))
+; while (
+; cond1
+; or cond2
+; or cond3):
+; pass
+;
(while_statement
condition: (parenthesized_expression) @indent.align
+ (#lua-match? @indent.align "[^\n ]%)$")
+ (#set! indent.open_delimiter "(")
+ (#set! indent.close_delimiter ")")
+ (#set! indent.avoid_last_matching_next 1))
+
+; if (
+; cond1
+; or cond2
+; or cond3):
+; pass
+;
+(if_statement
+ condition: (parenthesized_expression) @indent.align
+ (#lua-match? @indent.align "[^\n ]%)$")
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")")
(#set! indent.avoid_last_matching_next 1))
@@ -92,6 +121,11 @@
((parameters) @indent.align
(#set! indent.open_delimiter "(")
+ (#set! indent.close_delimiter ")"))
+
+((parameters) @indent.align
+ (#lua-match? @indent.align "[^\n ]%)$")
+ (#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")")
(#set! indent.avoid_last_matching_next 1))
@@ -130,9 +164,6 @@
.
(#lua-match? @indent.branch "^elif"))
-(parenthesized_expression
- ")" @indent.end)
-
(generator_expression
")" @indent.end)