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.
This commit is contained in:
@@ -254,6 +254,17 @@ function M.validate_diagnostics(content, workspace_types, root_dir)
|
|||||||
if trimmed:match("^%s*//") or trimmed:match("^%s*%(%*") then
|
if trimmed:match("^%s*//") or trimmed:match("^%s*%(%*") then
|
||||||
-- Skip comments
|
-- Skip comments
|
||||||
else
|
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
|
for assignment in line:gmatch("#[%w_]+%s*:=") do
|
||||||
local var_name = assignment:match("#([%w_]+)")
|
local var_name = assignment:match("#([%w_]+)")
|
||||||
if var_name and in_var_section then
|
if var_name and in_var_section then
|
||||||
|
|||||||
@@ -261,6 +261,15 @@ function M.format_document(content, options)
|
|||||||
table.insert(params, last_param)
|
table.insert(params, last_param)
|
||||||
end
|
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
|
if #params == 0 then
|
||||||
return { base_indent .. fb_name .. "();" }
|
return { base_indent .. fb_name .. "();" }
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user