feat(meson): add indents.scm

This commit is contained in:
Jędrzej Boczar 2024-01-19 16:08:23 +01:00 committed by Christian Clason
parent d198a75e2c
commit 6548bb64c1
10 changed files with 172 additions and 0 deletions

25
queries/meson/indents.scm Normal file
View file

@ -0,0 +1,25 @@
[
(list)
(dictionaries)
(normal_command)
(if_condition)
(foreach_command)
(ternaryoperator)
(ERROR
"?") ; support partial ternary
] @indent.begin
[
")"
"]"
"}"
(elseif_command)
(else_command)
"endif"
"endforeach"
] @indent.branch @indent.end
(experession_statement
object: (_)) @indent.begin
(comment) @indent.auto

View file

@ -0,0 +1,16 @@
# vim: ft=meson
if a == b
endif
if a == b
foo()
endif
if a == b
foo()
elif a != b
foo()
else
foo()
endif

View file

@ -0,0 +1,15 @@
# vim: ft=meson
foo = {
'a': 1,
'b': 2,
}
bar = {
'a': 1,
'b': 2}
baz = {'a': 1,
'b': 2
}

View file

@ -0,0 +1,13 @@
# vim: ft=meson
executable('progname',
)
executable('progname',
sources: 'prog.c',
c_args: '-DFOO=1'
)
executable('progname',
sources: 'prog.c',
c_args: '-DFOO=1')

View file

@ -0,0 +1,14 @@
# vim: ft=meson
foo = [
'a',
'b',
]
bar = [
'a',
'b']
baz = ['a',
'b'
]

View file

@ -0,0 +1,8 @@
# vim: ft=meson
foreach elem : list
endforeach
foreach elem : list
foo()
endforeach

View file

@ -0,0 +1,34 @@
project('simple', 'c')
src = [
'source1.c',
'source2.c',
]
if 1 == 2
if meson.is_cross_build()
src += [
'src1.c',
'src2.c']
endif
endif
inc = include_directories([
'dir1/',
])
dep = declare_dependency(
sources : src,
include_directories : inc,
)
executable('myexe', src,
include_directories : [
'd1',
[
'd2',
'd3',
]
],
dependencies: dep)

View file

@ -0,0 +1,8 @@
# vim: ft=meson
myobj
.do_something('now')
myobj.do_something('now')
.do_something('now')
.do_something('now')

View file

@ -0,0 +1,11 @@
# vim: ft=meson
x = cond ?
iftrue :
iffalse
x = cond
? iftrue
: iffalse
x = cond ?

View file

@ -0,0 +1,28 @@
local Runner = require("tests.indent.common").Runner
local run = Runner:new(it, "tests/indent/meson", {
tabstop = 2,
shiftwidth = 2,
softtabstop = 0,
expandtab = true,
})
describe("indent Meson:", function()
describe("whole file:", function()
run:whole_file(".", {
expected_failures = {},
})
end)
describe("new line:", function()
run:new_line("cond.meson", { on_line = 3, text = "foo()", indent = 2 })
run:new_line("cond.meson", { on_line = 6, text = "foo()", indent = 2 })
run:new_line("cond.meson", { on_line = 7, text = "foo()", indent = 2 })
run:new_line("cond.meson", { on_line = 12, text = "foo()", indent = 2 })
run:new_line("cond.meson", { on_line = 14, text = "foo()", indent = 2 })
run:new_line("dict.meson", { on_line = 13, text = ",'x':1,", indent = 2 })
run:new_line("loop.meson", { on_line = 3, text = "foo()", indent = 2 })
run:new_line("loop.meson", { on_line = 7, text = "foo()", indent = 2 })
run:new_line("ternary.meson", { on_line = 11, text = "x : y", indent = 2 })
end)
end)