docs: encourage adding comments; fix nested IF/ELSIF indentation

- Update AGENTS.md to encourage comments instead of forbidding them
- Add docstrings to all public functions in src/ modules
- Add module headers and function comments to lua/scl/ modules
- Fix formatter to properly indent multi-line IF/ELSIF conditions
- Fix FB call detection to not match IF statements with parentheses
This commit is contained in:
2026-02-23 17:40:44 +01:00
parent db69592cc1
commit 37f8d475f0
9 changed files with 301 additions and 18 deletions
+45
View File
@@ -1,5 +1,9 @@
-- TIA Portal built-in instructions for SCL LSP
-- Defines functions, function blocks, data types, and their parameters
local M = {}
-- Built-in functions (return values, no state)
M.FUNCTIONS = {
ADD = true,
SUB = true,
@@ -169,6 +173,7 @@ M.FUNCTIONS = {
DCP_CLIENT = true,
}
-- Built-in function blocks (have state, need instance)
M.FUNCTION_BLOCKS = {
TON = true,
TOF = true,
@@ -226,6 +231,8 @@ M.DATA_TYPES = {
DTL = true,
}
-- Parameter definitions for built-in instructions
-- Format: { inputs = { { name, type }, ... }, outputs = { { name, type }, ... } }
M.PARAMETERS = {
TON = { inputs = { { name = "IN", type = "BOOL" }, { name = "PT", type = "TIME" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "ET", type = "TIME" } } },
TOF = { inputs = { { name = "IN", type = "BOOL" }, { name = "PT", type = "TIME" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "ET", type = "TIME" } } },
@@ -283,10 +290,48 @@ M.PARAMETERS = {
I_BCD = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
}
-- Get parameter info for a built-in instruction
-- @param name string The instruction name
-- @return table|nil Parameter definition with inputs and outputs arrays
function M.get_parameters(name)
return M.PARAMETERS[name:upper()]
end
-- Check if name is a known function block
-- @param name string The name to check
-- @return boolean True if known function block
function M.is_known_function_block(name)
return M.FUNCTION_BLOCKS[name:upper()] or false
end
-- Check if name is a known function
-- @param name string The name to check
-- @return boolean True if known function
function M.is_known_function(name)
return M.FUNCTIONS[name:upper()] or false
end
-- Check if name is a known data type
-- @param name string The name to check
-- @return boolean True if known data type
function M.is_known_data_type(name)
return M.DATA_TYPES[name:upper()] or false
end
-- Check if name is a known instruction (function or function block)
-- @param name string The name to check
-- @return boolean True if known instruction
function M.is_known_instruction(name)
return M.is_known_function(name) or M.is_known_function_block(name) or false
end
-- Check if name is a known type or instruction
-- @param name string The name to check
-- @return boolean True if known type or instruction
function M.is_known_type_or_instruction(name)
return M.is_known_data_type(name) or M.is_known_instruction(name) or false
end
function M.is_known_function(name)
return M.FUNCTIONS[name:upper()] or false
end