From 4ac49eeb951259938c1ddf8793c990736387bff4 Mon Sep 17 00:00:00 2001 From: Lazar Bulovan Date: Thu, 19 Feb 2026 11:10:04 +0100 Subject: [PATCH] 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. --- src/formatter.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/formatter.lua b/src/formatter.lua index 3e6aef7..77cde74 100644 --- a/src/formatter.lua +++ b/src/formatter.lua @@ -260,7 +260,8 @@ function M.format_document(content, options) -- Helper: extract keyword from line 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 -- Helper: find case block in stack @@ -498,7 +499,7 @@ function M.format_document(content, options) goto continue end - -- Regular line + -- Regular line (including variable declarations inside VAR sections) local formatted = get_indent() .. trimmed -- Add semicolon if it looks like it needs one if NEEDS_SEMICOLON[kw] and trimmed:sub(-1) ~= ";" then