feat(lsp): add goto declaration for FB, DB, and UDT types

- Add declaration provider (gD) that finds definitions for:
  - Functions in .scl files
  - Function Blocks (FB) in .scl files
  - Data Blocks (DB) in .scl and .db files
  - User-Defined Types (UDT) in .scl and .udt files
- Implement project root detection for cross-directory searches
- Add duplicate location filtering to prevent multiple results
- Load UDT types from .udt files in plc_json
- Update documentation with goto declaration feature
This commit is contained in:
2026-02-19 18:01:30 +01:00
parent cb0b24d47b
commit 577ffa5213
4 changed files with 297 additions and 9 deletions
+7 -7
View File
@@ -17,22 +17,22 @@ function M.extract_variables(content)
local function process_line(line, line_num)
local trimmed = line:gsub("^%s+", ""):gsub("%s+$", "")
-- Detect block start
local fb_name = trimmed:match('FUNCTION_BLOCK%s+"([^"]+)"')
-- Detect block start (with or without quotes)
local fb_name = trimmed:match('FUNCTION_BLOCK%s+"([^"]+)"') or trimmed:match("^FUNCTION_BLOCK%s+([%w_]+)")
if fb_name then
current_block = { name = fb_name, kind = "function_block" }
in_var_section = false
return
end
local ob_name = trimmed:match('ORGANIZATION_BLOCK%s+"([^"]+)"')
local ob_name = trimmed:match('ORGANIZATION_BLOCK%s+"([^"]+)"') or trimmed:match("^ORGANIZATION_BLOCK%s+([%w_]+)")
if ob_name then
current_block = { name = ob_name, kind = "organization_block" }
in_var_section = false
return
end
local fn_name = trimmed:match('FUNCTION%s+"([^"]+)"')
local fn_name = trimmed:match('FUNCTION%s+"([^"]+)"') or trimmed:match("^FUNCTION%s+([%w_]+)")
if fn_name then
current_block = { name = fn_name, kind = "function" }
in_var_section = false
@@ -239,7 +239,7 @@ function M.extract_functions(content)
end
for i, line in ipairs(lines) do
local func_name = line:match('FUNCTION%s+"([^"]+)"')
local func_name = line:match('FUNCTION%s+"([^"]+)"') or line:match("^FUNCTION%s+([%w_]+)")
if func_name then
local end_line = find_block_end(i, "END_FUNCTION", { "END_FUNCTION" })
table.insert(functions, {
@@ -250,7 +250,7 @@ function M.extract_functions(content)
})
end
local fb_name = line:match('FUNCTION_BLOCK%s+"([^"]+)"')
local fb_name = line:match('FUNCTION_BLOCK%s+"([^"]+)"') or line:match("^FUNCTION_BLOCK%s+([%w_]+)")
if fb_name then
local end_line = find_block_end(i, "END_FUNCTION_BLOCK", { "END_FUNCTION_BLOCK" })
table.insert(functions, {
@@ -261,7 +261,7 @@ function M.extract_functions(content)
})
end
local ob_name = line:match('ORGANIZATION_BLOCK%s+"([^"]+)"')
local ob_name = line:match('ORGANIZATION_BLOCK%s+"([^"]+)"') or line:match("^ORGANIZATION_BLOCK%s+([%w_]+)")
if ob_name then
local end_line = find_block_end(i, "END_ORGANIZATION_BLOCK", { "END_ORGANIZATION_BLOCK" })
table.insert(functions, {