mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-15 18:00:07 -04:00
fix(indents): indents for error block (css, lua) (#3207)
This commit is contained in:
parent
223a58bfca
commit
d7f06bfb13
6 changed files with 24 additions and 12 deletions
|
|
@ -149,12 +149,19 @@ function M.get_indent(lnum)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- do not indent for nodes that starts-and-ends on same line and starts on target line (lnum)
|
-- 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
|
if
|
||||||
not is_processed_by_row[srow]
|
should_process
|
||||||
-- Dear stylua, please don't change the semantics of this statement!
|
and (
|
||||||
-- stylua: ignore start
|
q.indent[node:id()]
|
||||||
and (q.indent[node:id()] and srow ~= erow and ((srow ~= lnum - 1) or q.indent[node:id()].start_at_same_line))
|
and (srow ~= erow or is_in_err)
|
||||||
-- stylua: ignore end
|
and (srow ~= lnum - 1 or q.indent[node:id()].start_at_same_line)
|
||||||
|
)
|
||||||
then
|
then
|
||||||
indent = indent + indent_size
|
indent = indent + indent_size
|
||||||
is_processed = true
|
is_processed = true
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,11 @@
|
||||||
(function_declaration)
|
(function_declaration)
|
||||||
(field)
|
(field)
|
||||||
(do_statement)
|
(do_statement)
|
||||||
|
(method_index_expression)
|
||||||
(while_statement)
|
(while_statement)
|
||||||
(repeat_statement)
|
(repeat_statement)
|
||||||
(if_statement)
|
(if_statement)
|
||||||
|
"then"
|
||||||
(for_statement)
|
(for_statement)
|
||||||
(return_statement)
|
(return_statement)
|
||||||
(table_constructor)
|
(table_constructor)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
local Runner = require("tests.indent.common").Runner
|
local Runner = require("tests.indent.common").Runner
|
||||||
local XFAIL = require("tests.indent.common").XFAIL
|
|
||||||
|
|
||||||
local run = Runner:new(it, "tests/indent/css", {
|
local run = Runner:new(it, "tests/indent/css", {
|
||||||
tabstop = 2,
|
tabstop = 2,
|
||||||
|
|
@ -17,12 +16,7 @@ describe("indent CSS:", function()
|
||||||
|
|
||||||
describe("new line:", 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 = "}", indent = 0 })
|
||||||
run:new_line(
|
run:new_line("open_block.css", { on_line = 1, text = "color: green;", indent = 2 })
|
||||||
"open_block.css",
|
|
||||||
{ on_line = 1, text = "color: green;", indent = 2 },
|
|
||||||
"might fail because tree is in a broken state",
|
|
||||||
XFAIL
|
|
||||||
)
|
|
||||||
run:new_line("next_rule.css", { on_line = 3, text = ".next {", indent = 0 })
|
run:new_line("next_rule.css", { on_line = 3, text = ".next {", indent = 0 })
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
|
|
@ -10,3 +10,5 @@ else
|
||||||
end
|
end
|
||||||
x = 0
|
x = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if x > 2 then
|
||||||
|
|
|
||||||
3
tests/indent/lua/method_index_expr.lua
Normal file
3
tests/indent/lua/method_index_expr.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
Node.new()
|
||||||
|
:call()
|
||||||
|
:build()
|
||||||
|
|
@ -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 = 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 = 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 = 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 = 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("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("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)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue