fix: skip commented lines in undefined variable diagnostic
This commit is contained in:
+20
-18
@@ -147,26 +147,28 @@ function M.validate_diagnostics(content, workspace_types, root_dir)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not in_var_section then
|
if not in_var_section then
|
||||||
local hash_vars = {}
|
if not (trimmed:match("^%s*//") or trimmed:match("^%s*%(%*")) then
|
||||||
for var in line:gmatch("#[%w_]+") do
|
local hash_vars = {}
|
||||||
local var_name = var:sub(2)
|
for var in line:gmatch("#[%w_]+") do
|
||||||
local match_start = line:find(var, 1, true)
|
local var_name = var:sub(2)
|
||||||
if not is_iec_literal_at(line, match_start) and not is_number_literal_at(line, match_start) then
|
local match_start = line:find(var, 1, true)
|
||||||
hash_vars[var_name] = 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
|
||||||
end
|
|
||||||
|
|
||||||
for var_name, _ in pairs(hash_vars) do
|
for var_name, _ in pairs(hash_vars) do
|
||||||
if not variables[var_name] and not all_types[var_name] then
|
if not variables[var_name] and not all_types[var_name] then
|
||||||
local var_start = line:find("#" .. var_name, 1, true)
|
local var_start = line:find("#" .. var_name, 1, true)
|
||||||
if var_start then
|
if var_start then
|
||||||
table.insert(diagnostics, {
|
table.insert(diagnostics, {
|
||||||
range = range_to_lsp(line_num, var_start - 1, line_num, var_start + #var_name - 1),
|
range = range_to_lsp(line_num, var_start - 1, line_num, var_start + #var_name - 1),
|
||||||
severity = DiagnosticSeverity.Error,
|
severity = DiagnosticSeverity.Error,
|
||||||
message = string.format("Undefined variable: %s", var_name),
|
message = string.format("Undefined variable: %s", var_name),
|
||||||
code = "SCL001",
|
code = "SCL001",
|
||||||
source = "tia_lsp",
|
source = "tia_lsp",
|
||||||
})
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user