From 0d3426a2e88709175f545b4caf74eb2c54bee79a Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Sun, 3 Nov 2024 21:13:52 -0800 Subject: fix(wgsl): indent first parameter of function definition --- queries/wgsl/indents.scm | 15 ++++++++++++++- tests/indent/wgsl/basic.wgsl | 17 +++++++++++++++++ tests/indent/wgsl_spec.lua | 7 ++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/queries/wgsl/indents.scm b/queries/wgsl/indents.scm index b74e56e34..a866bd62f 100644 --- a/queries/wgsl/indents.scm +++ b/queries/wgsl/indents.scm @@ -1,10 +1,23 @@ [ - (parameter_list) (compound_statement) (loop_statement) (struct_declaration) ] @indent.begin +((parameter_list) @indent.begin + (#set! indent.immediate) + (#set! indent.start_at_same_line)) + +(function_declaration + "(" @indent.begin + (#set! indent.immediate)) + +(ERROR + "fn" + (identifier) + "(" @indent.begin + (#set! indent.immediate)) + (compound_statement "}" @indent.end) diff --git a/tests/indent/wgsl/basic.wgsl b/tests/indent/wgsl/basic.wgsl index 7dd50f87e..ccf29a360 100644 --- a/tests/indent/wgsl/basic.wgsl +++ b/tests/indent/wgsl/basic.wgsl @@ -41,3 +41,20 @@ fn vertex(vertex: Vertex, out.b = 2; return out; } + +fn foo( + a: u32, + b: u32, +) { + return a; +} + +fn bar( +) {} + +fn baz( + a: u32, +) {} + +fn qux( +) diff --git a/tests/indent/wgsl_spec.lua b/tests/indent/wgsl_spec.lua index 55d59acbd..e70215a7b 100644 --- a/tests/indent/wgsl_spec.lua +++ b/tests/indent/wgsl_spec.lua @@ -15,5 +15,10 @@ describe("indent WGSL:", function() }) end) - describe("new line:", function() end) + describe("new line:", function() + run:new_line("basic.wgsl", { on_line = 47, text = "c: u32,", indent = 2 }) + run:new_line("basic.wgsl", { on_line = 52, text = "c: u32,", indent = 2 }) + run:new_line("basic.wgsl", { on_line = 56, text = "c: u32,", indent = 2 }) + run:new_line("basic.wgsl", { on_line = 59, text = "c: u32,", indent = 2 }) + end) end) -- cgit v1.2.3-70-g09d2