mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
feat(query): indents that reflect the formatter (#6154)
* feat(query): indents that reflect the formatter Indentation queries that reflect the query formatter. Only applicable if `lispoptions=expr:1`
This commit is contained in:
parent
01cdcfb216
commit
455f6586ba
4 changed files with 83 additions and 5 deletions
|
|
@ -1,8 +1,20 @@
|
|||
(list) @indent.begin
|
||||
|
||||
[
|
||||
(list)
|
||||
(named_node)
|
||||
(grouping)
|
||||
(predicate) ; WIP to newline wrap any-of?
|
||||
"["
|
||||
"]"
|
||||
] @indent.begin
|
||||
|
||||
"]" @indent.branch
|
||||
; ERROR node indents
|
||||
(ERROR
|
||||
"(") @indent.begin
|
||||
|
||||
"]" @indent.branch @indent.end
|
||||
|
||||
")" @indent.end
|
||||
|
||||
; Captures always mark the end of a node
|
||||
; Because of that, mark it as indent.end
|
||||
(capture
|
||||
name: (identifier) @indent.end)
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ local function compare_indent(before, after, xfail)
|
|||
end
|
||||
|
||||
local function set_buf_indent_opts(opts)
|
||||
local optnames = { "tabstop", "shiftwidth", "softtabstop", "expandtab", "filetype" }
|
||||
local optnames = { "tabstop", "shiftwidth", "softtabstop", "expandtab", "filetype", "lispoptions" }
|
||||
for _, opt in ipairs(optnames) do
|
||||
if opts[opt] ~= nil then
|
||||
vim.bo[opt] = opts[opt]
|
||||
|
|
|
|||
41
tests/indent/query/test.scm
Normal file
41
tests/indent/query/test.scm
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
; vim:ft=query
|
||||
; format-ignore
|
||||
(fenced_code_block (fenced_code_block_delimiter) @label
|
||||
(info_string
|
||||
(language) @_lang)
|
||||
(#offset! @label 0 1 0 -1)
|
||||
(#ft-conceal! @_lang))
|
||||
|
||||
([
|
||||
(list_marker_minus)
|
||||
(list_marker_plus)
|
||||
(list_marker_star)
|
||||
] @markup.list
|
||||
(#offset-first-n! @markup.list 1)
|
||||
(#set! conceal "•"))
|
||||
|
||||
(list
|
||||
(list_item
|
||||
(list
|
||||
(list_item
|
||||
([
|
||||
(list_marker_minus)
|
||||
(list_marker_plus)
|
||||
(list_marker_star)
|
||||
] @markup.list
|
||||
(#offset-first-n! @markup.list 1)
|
||||
(#set! conceal "◦"))))))
|
||||
|
||||
; comment
|
||||
(while_statement
|
||||
[
|
||||
"while"
|
||||
"do"
|
||||
] @open.loop
|
||||
"end" @close.loop) @scope.loop
|
||||
|
||||
[
|
||||
"toplevel"
|
||||
"list"
|
||||
] @variable
|
||||
((
|
||||
25
tests/indent/query_spec.lua
Normal file
25
tests/indent/query_spec.lua
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
local Runner = require("tests.indent.common").Runner
|
||||
|
||||
local run = Runner:new(it, "tests/indent/query", {
|
||||
tabstop = 2,
|
||||
shiftwidth = 2,
|
||||
softtabstop = 2,
|
||||
expandtab = true,
|
||||
lispoptions = "expr:1",
|
||||
})
|
||||
|
||||
describe("indent Query:", function()
|
||||
describe("whole file:", function()
|
||||
run:whole_file(".", {})
|
||||
end)
|
||||
describe("new line:", function()
|
||||
run:new_line("test.scm", { on_line = 3, text = "(node)", indent = 2 })
|
||||
run:new_line("test.scm", { on_line = 5, text = "(node)", indent = 2 })
|
||||
run:new_line("test.scm", { on_line = 12, text = "(node)", indent = 2 })
|
||||
run:new_line("test.scm", { on_line = 25, text = "(#my-directive!)", indent = 10 })
|
||||
run:new_line("test.scm", { on_line = 34, text = '"more"', indent = 2 })
|
||||
run:new_line("test.scm", { on_line = 35, text = "(node)", indent = 0 })
|
||||
run:new_line("test.scm", { on_line = 40, text = "(node)", indent = 0 })
|
||||
run:new_line("test.scm", { on_line = 41, text = "node_name", indent = 2 })
|
||||
end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue