From 5205819201ee245c9428959bca4028da508d09f5 Mon Sep 17 00:00:00 2001 From: Lazar Bulovan Date: Wed, 22 Jul 2026 17:43:18 +0200 Subject: [PATCH] feat: remove unassigned output params in formatter + SCL006 diagnostic - Formatter now strips unassigned output params (e.g. Q =>, ET =>) from FB/FC calls during formatting. - Diagnostics now produce SCL006 warning for unassigned output params. - Also converted src/ symlinks for diagnostics.lua and formatter.lua in mason package so all three files stay in sync. --- src/diagnostics.lua | 11 +++++++++++ src/formatter.lua | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/src/diagnostics.lua b/src/diagnostics.lua index d5cfd36..ed86057 100644 --- a/src/diagnostics.lua +++ b/src/diagnostics.lua @@ -254,6 +254,17 @@ function M.validate_diagnostics(content, workspace_types, root_dir) if trimmed:match("^%s*//") or trimmed:match("^%s*%(%*") then -- Skip comments else + -- Check for unassigned output parameters in FB/FC calls (e.g. "Q =>") + for unassigned in line:gmatch("([%w_]+)%s*=>%s*[,%)]") do + table.insert(diagnostics, { + range = range_to_lsp(line_num, line:find(unassigned, 1, true) - 1, line_num, line:find(unassigned, 1, true) + #unassigned), + severity = DiagnosticSeverity.Warning, + message = string.format("Unassigned output parameter: %s =>", unassigned), + code = "SCL006", + source = "tia_lsp", + }) + end + for assignment in line:gmatch("#[%w_]+%s*:=") do local var_name = assignment:match("#([%w_]+)") if var_name and in_var_section then diff --git a/src/formatter.lua b/src/formatter.lua index 0c31905..3843873 100644 --- a/src/formatter.lua +++ b/src/formatter.lua @@ -261,6 +261,15 @@ function M.format_document(content, options) table.insert(params, last_param) end + -- Remove unassigned output parameters (e.g. "Q =>", "ET =>") + local filtered = {} + for _, p in ipairs(params) do + if not p:match("^[%w_]+%s*=>%s*$") then + table.insert(filtered, p) + end + end + params = filtered + if #params == 0 then return { base_indent .. fb_name .. "();" } end