aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKiyan <yazdani.kiyan@protonmail.com>2022-07-21 13:48:03 +0200
committerGitHub <noreply@github.com>2022-07-21 13:48:03 +0200
commitd7f06bfb1381a2741c1bcbadf1bc1e3ed77abea4 (patch)
treeeac4f46b175c67afbe488a874854913667c319d2
parentUpdate lockfile.json (diff)
downloadnvim-treesitter-d7f06bfb1381a2741c1bcbadf1bc1e3ed77abea4.tar
nvim-treesitter-d7f06bfb1381a2741c1bcbadf1bc1e3ed77abea4.tar.gz
nvim-treesitter-d7f06bfb1381a2741c1bcbadf1bc1e3ed77abea4.tar.bz2
nvim-treesitter-d7f06bfb1381a2741c1bcbadf1bc1e3ed77abea4.tar.lz
nvim-treesitter-d7f06bfb1381a2741c1bcbadf1bc1e3ed77abea4.tar.xz
nvim-treesitter-d7f06bfb1381a2741c1bcbadf1bc1e3ed77abea4.tar.zst
nvim-treesitter-d7f06bfb1381a2741c1bcbadf1bc1e3ed77abea4.zip
fix(indents): indents for error block (css, lua) (#3207)
-rw-r--r--lua/nvim-treesitter/indent.lua17
-rw-r--r--queries/lua/indents.scm2
-rw-r--r--tests/indent/css_spec.lua8
-rw-r--r--tests/indent/lua/cond.lua2
-rw-r--r--tests/indent/lua/method_index_expr.lua3
-rw-r--r--tests/indent/lua_spec.lua4
6 files changed, 24 insertions, 12 deletions
diff --git a/lua/nvim-treesitter/indent.lua b/lua/nvim-treesitter/indent.lua
index dd3b2b876..0eac0a911 100644
--- a/lua/nvim-treesitter/indent.lua
+++ b/lua/nvim-treesitter/indent.lua
@@ -149,12 +149,19 @@ function M.get_indent(lnum)
end
-- do not indent for nodes that starts-and-ends on same line and starts on target line (lnum)
+ local should_process = not is_processed_by_row[srow]
+ local is_in_err = false
+ if should_process then
+ local parent = node:parent()
+ is_in_err = parent and parent:has_error()
+ end
if
- not is_processed_by_row[srow]
- -- Dear stylua, please don't change the semantics of this statement!
- -- stylua: ignore start
- and (q.indent[node:id()] and srow ~= erow and ((srow ~= lnum - 1) or q.indent[node:id()].start_at_same_line))
- -- stylua: ignore end
+ should_process
+ and (
+ q.indent[node:id()]
+ and (srow ~= erow or is_in_err)
+ and (srow ~= lnum - 1 or q.indent[node:id()].start_at_same_line)
+ )
then
indent = indent + indent_size
is_processed = true
diff --git a/queries/lua/indents.scm b/queries/lua/indents.scm
index 283808843..f23e7cc99 100644
--- a/queries/lua/indents.scm
+++ b/queries/lua/indents.scm
@@ -3,9 +3,11 @@
(function_declaration)
(field)
(do_statement)
+ (method_index_expression)
(while_statement)
(repeat_statement)
(if_statement)
+ "then"
(for_statement)
(return_statement)
(table_constructor)
diff --git a/tests/indent/css_spec.lua b/tests/indent/css_spec.lua
index e8eadf836..46c7e1afb 100644
--- a/tests/indent/css_spec.lua
+++ b/tests/indent/css_spec.lua
@@ -1,5 +1,4 @@
local Runner = require("tests.indent.common").Runner
-local XFAIL = require("tests.indent.common").XFAIL
local run = Runner:new(it, "tests/indent/css", {
tabstop = 2,
@@ -17,12 +16,7 @@ describe("indent CSS:", function()
describe("new line:", function()
run:new_line("open_block.css", { on_line = 1, text = "}", indent = 0 })
- run:new_line(
- "open_block.css",
- { on_line = 1, text = "color: green;", indent = 2 },
- "might fail because tree is in a broken state",
- XFAIL
- )
+ run:new_line("open_block.css", { on_line = 1, text = "color: green;", indent = 2 })
run:new_line("next_rule.css", { on_line = 3, text = ".next {", indent = 0 })
end)
end)
diff --git a/tests/indent/lua/cond.lua b/tests/indent/lua/cond.lua
index dfae37f05..9d0266a5a 100644
--- a/tests/indent/lua/cond.lua
+++ b/tests/indent/lua/cond.lua
@@ -10,3 +10,5 @@ else
end
x = 0
end
+
+if x > 2 then
diff --git a/tests/indent/lua/method_index_expr.lua b/tests/indent/lua/method_index_expr.lua
new file mode 100644
index 000000000..3f0ad1fb9
--- /dev/null
+++ b/tests/indent/lua/method_index_expr.lua
@@ -0,0 +1,3 @@
+Node.new()
+ :call()
+ :build()
diff --git a/tests/indent/lua_spec.lua b/tests/indent/lua_spec.lua
index f584e5574..3fd4d58a1 100644
--- a/tests/indent/lua_spec.lua
+++ b/tests/indent/lua_spec.lua
@@ -36,8 +36,12 @@ describe("indent Lua:", function()
run:new_line("cond.lua", { on_line = 8, text = "x = x + 1", indent = 4 })
run:new_line("cond.lua", { on_line = 10, text = "x = x + 1", indent = 2 })
run:new_line("cond.lua", { on_line = 12, text = "x = x + 1", indent = 0 })
+ run:new_line("cond.lua", { on_line = 14, text = "x = x + 1", indent = 2 })
+ run:new_line("cond.lua", { on_line = 14, text = "end", indent = 0 })
run:new_line("no-indent-after-paren-pairs.lua", { on_line = 3, text = "x = x + 1", indent = 0 })
run:new_line("no-indent-after-paren-pairs.lua", { on_line = 6, text = "x = x + 1", indent = 0 })
run:new_line("nested-table.lua", { on_line = 5, text = "{}", indent = 4 })
+ run:new_line("method_index_expr.lua", { on_line = 1, text = ":test()", indent = 2 })
+ run:new_line("method_index_expr.lua", { on_line = 3, text = "local a = 1", indent = 0 })
end)
end)