fix: handle line comments and := operator in type extraction
- Skip // line comments when finding type separator colon - Only match : that is NOT followed by = (avoid := assignment) - Remove line comments from type_part before extraction - Fixes false 'Unknown data type' warnings in VAR sections
This commit is contained in:
+13
-6
@@ -118,11 +118,16 @@ function M.validate_diagnostics(content, workspace_types, root_dir)
|
|||||||
local type_part = nil
|
local type_part = nil
|
||||||
local brace_depth = 0
|
local brace_depth = 0
|
||||||
local comment_depth = 0
|
local comment_depth = 0
|
||||||
local last_colon = nil
|
local line_comment = false
|
||||||
|
local type_colon = nil
|
||||||
for i = 1, #line do
|
for i = 1, #line do
|
||||||
local c = line:sub(i, i)
|
local c = line:sub(i, i)
|
||||||
local next_c = line:sub(i+1, i+1)
|
local next_c = line:sub(i+1, i+1)
|
||||||
if c == "(" and next_c == "*" then
|
if c == "/" and next_c == "/" then
|
||||||
|
line_comment = true
|
||||||
|
elseif line_comment then
|
||||||
|
-- Skip everything after //
|
||||||
|
elseif c == "(" and next_c == "*" then
|
||||||
comment_depth = comment_depth + 1
|
comment_depth = comment_depth + 1
|
||||||
elseif c == "*" and next_c == ")" and comment_depth > 0 then
|
elseif c == "*" and next_c == ")" and comment_depth > 0 then
|
||||||
comment_depth = comment_depth - 1
|
comment_depth = comment_depth - 1
|
||||||
@@ -130,15 +135,17 @@ function M.validate_diagnostics(content, workspace_types, root_dir)
|
|||||||
brace_depth = brace_depth + 1
|
brace_depth = brace_depth + 1
|
||||||
elseif c == "}" and comment_depth == 0 then
|
elseif c == "}" and comment_depth == 0 then
|
||||||
brace_depth = brace_depth - 1
|
brace_depth = brace_depth - 1
|
||||||
elseif c == ":" and brace_depth == 0 and comment_depth == 0 then
|
elseif c == ":" and brace_depth == 0 and comment_depth == 0 and next_c ~= "=" then
|
||||||
last_colon = i
|
-- Only capture colon that's NOT followed by = (not := assignment)
|
||||||
|
type_colon = i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if last_colon then
|
if type_colon then
|
||||||
type_part = line:sub(last_colon + 1)
|
type_part = line:sub(type_colon + 1)
|
||||||
end
|
end
|
||||||
if type_part then
|
if type_part then
|
||||||
type_part = type_part:gsub("%s*%(%*.-%*%)", "") -- Remove block comments (* ... *) with leading whitespace
|
type_part = type_part:gsub("%s*%(%*.-%*%)", "") -- Remove block comments (* ... *) with leading whitespace
|
||||||
|
type_part = type_part:gsub("%s*//.*$", "") -- Remove line comments // ...
|
||||||
type_part = type_part:gsub("%s*:=.*$", "")
|
type_part = type_part:gsub("%s*:=.*$", "")
|
||||||
type_part = type_part:gsub("%s*;.*$", "") -- Remove trailing semicolon
|
type_part = type_part:gsub("%s*;.*$", "") -- Remove trailing semicolon
|
||||||
type_part = type_part:gsub("%s*$", "")
|
type_part = type_part:gsub("%s*$", "")
|
||||||
|
|||||||
Reference in New Issue
Block a user