diff options
| -rw-r--r-- | lua/nvim-treesitter/indent.lua | 3 | ||||
| -rw-r--r-- | queries/c/indents.scm | 6 | ||||
| -rw-r--r-- | queries/python/indents.scm | 2 | ||||
| -rw-r--r-- | tests/indent/c/aligned_indent.c | 10 | ||||
| -rw-r--r-- | tests/indent/c/func.c | 2 | ||||
| -rw-r--r-- | tests/indent/c/initializer_list.c | 3 | ||||
| -rw-r--r-- | tests/indent/python/aligned_indent.py | 3 |
7 files changed, 26 insertions, 3 deletions
diff --git a/lua/nvim-treesitter/indent.lua b/lua/nvim-treesitter/indent.lua index a86b5baf5..55b341f34 100644 --- a/lua/nvim-treesitter/indent.lua +++ b/lua/nvim-treesitter/indent.lua @@ -122,7 +122,8 @@ function M.get_indent(lnum) is_processed = true end - if q.aligned_indent[node:id()] and srow ~= erow then + -- do not indent for nodes that starts-and-ends on same line and starts on target line (lnum) + if q.aligned_indent[node:id()] and srow ~= erow and (srow ~= lnum - 1) then local metadata = q.aligned_indent[node:id()] local opening_delimiter = metadata.delimiter:sub(1, 1) local o_delim_node, pos = get_matching_prev_sibling(node, { srow, #vim.fn.getline(srow + 1) - 1 }, function(n) diff --git a/queries/c/indents.scm b/queries/c/indents.scm index 7803a477f..234e67056 100644 --- a/queries/c/indents.scm +++ b/queries/c/indents.scm @@ -7,7 +7,6 @@ (enumerator_list) (struct_specifier) (compound_literal_expression) - (parameter_list) (initializer_list) (concatenated_string) (while_statement) @@ -44,3 +43,8 @@ ] @ignore (binary_expression) @auto + +((ERROR (parameter_declaration)) @aligned_indent + (#set! "delimiter" "()")) +([(argument_list) (parameter_list)] @aligned_indent + (#set! "delimiter" "()")) diff --git a/queries/python/indents.scm b/queries/python/indents.scm index 25f622909..e83b3762f 100644 --- a/queries/python/indents.scm +++ b/queries/python/indents.scm @@ -32,6 +32,8 @@ condition: (parenthesized_expression) @aligned_indent (#set! "delimiter" "()") ) +((ERROR "(" . (_)) @aligned_indent + (#set! "delimiter" "()")) ((argument_list) @aligned_indent (#set! "delimiter" "()")) ((argument_list) @aligned_indent diff --git a/tests/indent/c/aligned_indent.c b/tests/indent/c/aligned_indent.c new file mode 100644 index 000000000..75555b971 --- /dev/null +++ b/tests/indent/c/aligned_indent.c @@ -0,0 +1,10 @@ +void foo(int a, + int b, + int c); + +void foo(int a, + int b + + + + diff --git a/tests/indent/c/func.c b/tests/indent/c/func.c index c188acc01..0c1ede8e0 100644 --- a/tests/indent/c/func.c +++ b/tests/indent/c/func.c @@ -21,7 +21,7 @@ int f4( } int f5(int x, - int y) + int y) { return 1; } diff --git a/tests/indent/c/initializer_list.c b/tests/indent/c/initializer_list.c new file mode 100644 index 000000000..9bf28d946 --- /dev/null +++ b/tests/indent/c/initializer_list.c @@ -0,0 +1,3 @@ +int a[] = { + 1, 2, 3, + 4}; diff --git a/tests/indent/python/aligned_indent.py b/tests/indent/python/aligned_indent.py index 2a4b827f4..b92356740 100644 --- a/tests/indent/python/aligned_indent.py +++ b/tests/indent/python/aligned_indent.py @@ -9,3 +9,6 @@ aligned_indent(1, aligned_indent(1, 2 ) + +foodsadsa(sdada, + 2 |
