fix: Attribute block expand/collapse, TIME literal diagnostics, and formatter bugs
- SCLFormat: Remove clear_buffer_state() call that was preventing
expand after formatting (attr_toggle state now preserved)
- Diagnostics: Fix false 'Undefined variable' for IEC literals
like T#2s, D#1d, S5T#1s (TIME, DATE, S5TIME types)
- Formatter: Fix block comments (* ... *) being misidentified as
FB calls in VAR_IN_OUT/VAR_INPUT/VAR_OUTPUT sections
- Formatter: Fix array-based FB calls like instTimers[idx].TON()
not being properly formatted with aligned parameters
This commit is contained in:
+19
-3
@@ -175,7 +175,23 @@ function M.format_document(content, options)
|
||||
if not (trimmed:match("^#?%w+") or trimmed:match('^"')) then
|
||||
return false
|
||||
end
|
||||
local paren_pos = trimmed:find("%(")
|
||||
|
||||
-- Find the first ( that is not inside a block comment (* ... *)
|
||||
local paren_pos = nil
|
||||
local comment_depth = 0
|
||||
for i = 1, #trimmed do
|
||||
local c = trimmed:sub(i, i)
|
||||
local next_c = trimmed:sub(i+1, i+1)
|
||||
if c == "(" and next_c == "*" then
|
||||
comment_depth = comment_depth + 1
|
||||
elseif c == "*" and next_c == ")" and comment_depth > 0 then
|
||||
comment_depth = comment_depth - 1
|
||||
elseif c == "(" and comment_depth == 0 then
|
||||
paren_pos = i
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not paren_pos then return false end
|
||||
local assign_pos = trimmed:find(":=")
|
||||
if assign_pos and assign_pos < paren_pos then return false end
|
||||
@@ -196,7 +212,7 @@ function M.format_document(content, options)
|
||||
local result = {}
|
||||
local all_text = table.concat(fb_lines, " ")
|
||||
|
||||
local fb_name = all_text:match("^(#?[%w_]+)%s*%(")
|
||||
local fb_name = all_text:match("^(#?.-)%s*%(")
|
||||
if not fb_name then
|
||||
for _, l in ipairs(fb_lines) do
|
||||
table.insert(result, base_indent .. l)
|
||||
@@ -412,7 +428,7 @@ function M.format_document(content, options)
|
||||
in_fb_call = true
|
||||
fb_call_lines = { trimmed }
|
||||
fb_base_indent = get_indent()
|
||||
local fb_name = trimmed:match("^(#?[%w_]+)")
|
||||
local fb_name = trimmed:match("^(#?.-)%s*%(") or trimmed:match("^(#?.-)$")
|
||||
if fb_name then
|
||||
fb_param_indent = fb_base_indent .. string.rep(" ", #fb_name + 1)
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user