fix: skip commented lines in undefined variable diagnostic

This commit is contained in:
2026-07-23 13:13:04 +02:00
parent 3ca63d278b
commit ebdc96316a
+20 -18
View File
@@ -147,26 +147,28 @@ function M.validate_diagnostics(content, workspace_types, root_dir)
end
if not in_var_section then
local hash_vars = {}
for var in line:gmatch("#[%w_]+") do
local var_name = var:sub(2)
local match_start = line:find(var, 1, true)
if not is_iec_literal_at(line, match_start) and not is_number_literal_at(line, match_start) then
hash_vars[var_name] = true
if not (trimmed:match("^%s*//") or trimmed:match("^%s*%(%*")) then
local hash_vars = {}
for var in line:gmatch("#[%w_]+") do
local var_name = var:sub(2)
local match_start = line:find(var, 1, true)
if not is_iec_literal_at(line, match_start) and not is_number_literal_at(line, match_start) then
hash_vars[var_name] = true
end
end
end
for var_name, _ in pairs(hash_vars) do
if not variables[var_name] and not all_types[var_name] then
local var_start = line:find("#" .. var_name, 1, true)
if var_start then
table.insert(diagnostics, {
range = range_to_lsp(line_num, var_start - 1, line_num, var_start + #var_name - 1),
severity = DiagnosticSeverity.Error,
message = string.format("Undefined variable: %s", var_name),
code = "SCL001",
source = "tia_lsp",
})
for var_name, _ in pairs(hash_vars) do
if not variables[var_name] and not all_types[var_name] then
local var_start = line:find("#" .. var_name, 1, true)
if var_start then
table.insert(diagnostics, {
range = range_to_lsp(line_num, var_start - 1, line_num, var_start + #var_name - 1),
severity = DiagnosticSeverity.Error,
message = string.format("Undefined variable: %s", var_name),
code = "SCL001",
source = "tia_lsp",
})
end
end
end
end