fix(formatter): correctly indent variables in VAR_IN_OUT sections

The get_keyword() function was using pattern ^(%w+_%w+) which only
matched up to the second underscore, causing VAR_IN_OUT to be
extracted as VAR_IN. Since VAR_IN is not in VAR_KEYWORDS, the
VAR_IN_OUT block was not being pushed onto the stack.

Fixed by changing the pattern to ^([%w_]+) to capture the entire
keyword including all underscores.

This ensures variables inside VAR_IN_OUT, VAR_CONSTANT, and other
multi-underscore VAR sections are properly indented.
This commit is contained in:
2026-02-19 11:10:04 +01:00
parent cba10851d2
commit 4ac49eeb95
+3 -2
View File
@@ -260,7 +260,8 @@ function M.format_document(content, options)
-- Helper: extract keyword from line -- Helper: extract keyword from line
local function get_keyword(trimmed) local function get_keyword(trimmed)
return trimmed:match("^(%w+_%w+)") or trimmed:match("^(%w+)") -- Match VAR_IN_OUT, VAR_CONSTANT, etc. (words with multiple underscores)
return trimmed:match("^([%w_]+)") or trimmed:match("^(%w+)")
end end
-- Helper: find case block in stack -- Helper: find case block in stack
@@ -498,7 +499,7 @@ function M.format_document(content, options)
goto continue goto continue
end end
-- Regular line -- Regular line (including variable declarations inside VAR sections)
local formatted = get_indent() .. trimmed local formatted = get_indent() .. trimmed
-- Add semicolon if it looks like it needs one -- Add semicolon if it looks like it needs one
if NEEDS_SEMICOLON[kw] and trimmed:sub(-1) ~= ";" then if NEEDS_SEMICOLON[kw] and trimmed:sub(-1) ~= ";" then