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 bfdec0c4b1
commit 15b0e5360a
4 changed files with 66 additions and 1 deletions
+29
View File
@@ -1,5 +1,11 @@
-- Multiline parameter filling for SCL function block calls
-- Automatically expands FB calls to multi-line format with all parameters
local M = {}
--- Get interface for built-in FB types (TON, TOF, etc.)
--- @param var_type string The FB type name
--- @return table|nil Interface with inputs, outputs, inouts
local function get_builtin_interface(var_type)
local builtin = require("scl.builtin_instructions")
local clean_type = var_type:gsub('"', ''):gsub("#", ""):upper()
@@ -14,6 +20,9 @@ local function get_builtin_interface(var_type)
return nil
end
--- Get interface for custom FB types from workspace
--- @param var_type string The FB type name
--- @return table|nil Interface with inputs, outputs, inouts
local function get_fb_interface(var_type)
local fb_parser = require("scl.fb_parser")
local clean_type = var_type:gsub('"', '')
@@ -26,6 +35,9 @@ local function get_fb_interface(var_type)
return fb_parser.get_fb_interface(clean_type)
end
--- Check if a type is a known FB type
--- @param var_type string The type name to check
--- @return boolean True if type is an FB
local function is_fb_type(var_type)
local fb_parser = require("scl.fb_parser")
local clean_type = var_type:gsub('"', '')
@@ -38,6 +50,9 @@ local function is_fb_type(var_type)
return fb_parser.is_fb_type(clean_type)
end
--- Get list of known local variable names
--- @param bufnr number Buffer number
--- @return table Set of variable names
local function get_known_variables(bufnr)
local scl_vars = require("scl.variables")
local variables = scl_vars.extract_variables(bufnr)
@@ -48,11 +63,17 @@ local function get_known_variables(bufnr)
return known
end
--- Get the type of a variable by name
--- @param var_name string Variable name
--- @param bufnr number Buffer number
--- @return string|nil Variable type, or nil if not found
local function get_variable_type(var_name, bufnr)
local scl_vars = require("scl.variables")
return scl_vars.get_variable_type(var_name, bufnr)
end
--- Fill multiline parameters for FB call at cursor
--- Expands single-line call to multi-line with all parameters
function M.fill_multiline_params()
local bufnr = vim.api.nvim_get_current_buf()
local cursor = vim.api.nvim_win_get_cursor(0)
@@ -169,6 +190,11 @@ function M.fill_multiline_params()
vim.api.nvim_win_set_cursor(0, { new_cursor_row, new_cursor_col })
end
--- Check if cursor is inside an FB call parameter list
--- @param bufnr number Buffer number
--- @param cursor_row number Current row (1-based)
--- @param cursor_col number Current column (1-based)
--- @return boolean True if inside FB call params
local function is_inside_fb_call(bufnr, cursor_row, cursor_col)
local function get_line_text(rownum)
return vim.api.nvim_buf_get_lines(bufnr, rownum - 1, rownum, false)[1] or ""
@@ -214,6 +240,9 @@ local function is_inside_fb_call(bufnr, cursor_row, cursor_col)
return false
end
--- Jump to next parameter in FB call
--- Used for Tab navigation within parameter lists
--- @return boolean True if jumped to next param, false otherwise
function M.jump_to_next_param()
local cursor = vim.api.nvim_win_get_cursor(0)
local row = cursor[1]