Commit Graph
27 Commits
Author SHA1 Message Date
lazar 99cf5d7732 fix: UDT type parsing and member access hover
- Fix UDT TYPE parsing: don't clear pending_type_name on VERSION/TITLE lines
- Fix UDT field type extraction: handle attribute blocks before colon
- Add comment capture for UDT type definitions
- Add better error messages when member resolution fails
- Handle quoted type names in field declarations
2026-02-21 00:51:27 +01:00
lazar d56ea306af fix: improve member access hover resolution
- Fix chain detection to properly extract #var and member path
- Check all type sources (doc.types, external_types, builtins) for resolution
- Return helpful error messages when type resolution fails
- Prevent fallthrough to type check when member access is detected
- Show which type couldn't be found in resolution chain
2026-02-21 00:32:55 +01:00
lazar 1606685a20 feat: add hover support for member access with comments
- Add member access chain resolution in hover handler
- Parse #var.member.submember notation and resolve type chain
- Show member comments in hover tooltip
- Extract comments from UDT and DB file fields
- Combine all type sources (doc.types, external_types, builtin)
2026-02-21 00:13:52 +01:00
lazar 7b25cf6202 feat: add TYPE/STRUCT and DATA_BLOCK support to tree-sitter grammar
- Add type_definition rule for UDT files (TYPE/STRUCT/END_STRUCT/END_TYPE)
- Add data_block rule for DB files (DATA_BLOCK/BEGIN/END_DATA_BLOCK)
- Add NON_RETAIN and RETAIN modifiers support in data blocks
- Keywords now highlighted correctly in .udt and .db files
2026-02-20 23:42:28 +01:00
lazar 553192e7a1 feat: improve tree-sitter syntax highlighting with named nodes
- Add aliases for keywords (VAR_INPUT, BEGIN, IF, etc.) as named nodes
- Add aliases for built-in types (INT, BOOL, STRING, etc.) as type_builtin
- Add aliases for constants (TRUE, FALSE)
- Add aliases for operators (AND, OR, NOT, MOD)
- Add prefix node for # variable prefix highlighting
- Highlight FB instance names in calls
- Highlight FB parameter names as properties
- Update README with detailed syntax highlighting features
- Update .gitignore for *.wasm files
2026-02-20 23:29:26 +01:00
lazar dfa4ef3381 feat: add builtin types/functions to diagnostics and completions
Files Modified/Created:
- src/builtin_instructions.lua - NEW: Contains all TIA Portal built-in types, FBs, and functions
- src/diagnostics.lua - Added missing data types + builtin instruction checking
- src/main.lua - Added completion support for built-in types/F Bs/functions
- src/plc_json.lua - Added .db file parsing + BOM handling fixes
- lua/scl/blink_cmp_source.lua - Extended completion with all built-in types/F Bs/functions
- src/node-types.json - Added node types for parser
- AGENTS.md - Updated documentation
Features Added:
1. Diagnostics - No more false "Unknown data type" warnings for:
   - All elementary types (USINT, SINT, UINT, UDINT, LINT, ULINT, TOD, DTL, etc.)
   - Timer/counter types (IEC_TON, TOF, TP, CTU, CTD, CTUD)
   - TIA Portal built-in FBs and functions
2. Auto-completion - Shows in VAR section after ::
   - 28 elementary data types
   - 23 built-in function blocks (TON, TOF, TP, CTU, CTD, CTUD, R_TRIG, F_TRIG, etc.)
   - 80+ built-in functions (ADD, SUB, MUL, DIV, SIN, COS, SQRT, etc.)
2026-02-20 13:08:28 +01:00
lazar 1f9c99272c fix(parser): add support for .udt and .db file parsing and goto declaration
- extract_variables: Parse STRUCT fields in TYPE sections for .udt files
- extract_types: Handle quoted type names and multiple type definitions
- declaration handler: Extract quoted type names for goto declaration
- Add filetype detection for .udt and .db files in nvim config
2026-02-20 08:59:54 +01:00
lazar 577ffa5213 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
2026-02-19 18:01:30 +01:00
lazar cb0b24d47b feat(lsp): add references provider for goto references
Add referencesProvider capability and handler to support LSP
references (gr keybinding in LazyVim). Searches all occurrences
of a symbol in the current document.
2026-02-19 14:10:14 +01:00
lazar e002e7f56d fix(diagnostics): correctly validate array element types
Extract actual element type for array declarations like 'Array[0..3] OF
IEC_TIMER' instead of incorrectly flagging 'Array' as unknown.
2026-02-19 13:33:52 +01:00
lazar 9f67b4828c fix(lsp): disable semantic tokens to prevent errors
The semantic tokens were causing 'Invalid line: out of range' errors
when opening certain files. This appears to be related to the delta
mode not being properly handled. Disabled semantic tokens for now
to prevent the errors.
2026-02-19 12:06:33 +01:00
lazar d94cb62e0b fix(lsp): add more robust validation in semantic tokens
- Wrap token generation in pcall to catch any errors
- Add validation for all token parameters (line, startChar, length)
- Validate deltaStart is non-negative
- Return empty tokens if any error occurs
- This should prevent the 'Invalid line: out of range' errors
2026-02-19 12:01:33 +01:00
lazar 1808edc1f0 fix(lsp): validate line numbers in semantic tokens and inlay hints
The error 'Invalid line: out of range' was caused by semantic tokens
and inlay hints using variable line numbers that might be out of bounds
for the current document content. This could happen when the cached
variables from a previous document version have line numbers that don't
match the current content.

Added validation to both textDocument_semanticTokensFull and
textDocument_inlayHint to ensure line numbers are within the valid
range (0 to total_lines - 1) before processing.
2026-02-19 11:56:09 +01:00
lazar ae75108f32 fix(formatter): disable automatic attribute collapsing by default
When the formatter automatically collapses attribute blocks, the
original content is lost and cannot be restored by the toggle
module. This broke the attribute expand/collapse functionality.

Changed default from collapseAttributes = true to false.

Users who want collapsing should:
1. Use :LspSCLFormat to format (preserves original content)
2. Then use :SCLCollapseAllAttrBlocks to collapse (stores original)
3. Now toggle/expand works correctly because content is stored
2026-02-19 11:24:08 +01:00
lazar 4ac49eeb95 fix(formatter): correctly indent variables in VAR_IN_OUT sections
The get_keyword() function was using pattern ^(%w+_%w+) which only
matched up to the second underscore, causing VAR_IN_OUT to be
extracted as VAR_IN. Since VAR_IN is not in VAR_KEYWORDS, the
VAR_IN_OUT block was not being pushed onto the stack.

Fixed by changing the pattern to ^([%w_]+) to capture the entire
keyword including all underscores.

This ensures variables inside VAR_IN_OUT, VAR_CONSTANT, and other
multi-underscore VAR sections are properly indented.
2026-02-19 11:10:04 +01:00
lazar cba10851d2 fix(parser): correctly extract type from VAR_CONSTANT with initialization
The parser was incorrectly finding the ':' inside attribute blocks like
{EXTERNALACCESSIBLE := 'false'} instead of the ':' after them.

Added 'break' after finding the first ':' outside braces to ensure
we get the correct type separator.

Fixes issue where variables like:
  STARTING_BASEPOS : Int := 30;
were showing data_type as '= 30' instead of 'Int'.
2026-02-19 10:57:17 +01:00
lazar 978e46ba45 feat: add interactive attribute block toggle with keybindings and commands
Add ability to expand/collapse SCL variable attribute blocks like {EXTERNALACCESSIBLE := 'false'} to {...}

Features:
- Per-variable collapse rules via collapseVariableRules option
- Interactive toggle with <Leader>xa keybinding
- Commands: SCLToggleAttrBlock, SCLExpandAllAttrBlocks, SCLCollapseAllAttrBlocks
- Keybindings: <Leader>xa (toggle), <Leader>xae (expand all), <Leader>xac (collapse all)
- Supports both formatter-collapsed and manually collapsed blocks

Also update AGENTS.md with new documentation and troubleshooting guide
2026-02-19 10:12:58 +01:00
lazar 37ab917422 Rewrite formatter with stack-based approach for proper nested structure handling 2026-02-18 19:08:54 +01:00
lazar 2c4815baec fix(formatter): Fix multi-line condition and END_IF indentation
- Multi-line IF conditions: continuation lines at +1 from IF
- END_IF now decreases indent (reverted previous wrong change)
- Track multi-line condition state separately from THEN tracking
- Now matches TIA Portal expected format
2026-02-18 15:35:35 +01:00
lazar 25c306efee fix(formatter): Handle THEN on separate line and multi-line conditions
- Track when IF has THEN on separate line
- Don't increase indent after IF until THEN is seen
- Increase indent after THEN for content
- Continuation lines in conditions stay at same level as IF
- END_IF stays at same level as content (TIA Portal style)
2026-02-18 15:26:05 +01:00
lazar 5bc6bb0750 fix(formatter): Keep END_IF at same indent level as content
Per TIA Portal standard, END_IF stays at the same indent level as the
code inside the IF block, rather than decreasing. This matches the
reference file Em101Sequence.scl where nested END_IF statements are
properly aligned.
2026-02-18 15:16:16 +01:00
lazar 5b5d9c46f6 fix(formatter): Fix FB call indentation logic
- Track first line of FB call separately with fb_call_first_line flag
- First line of FB call uses normal indent
- Continuation lines use continuation indent (base + fb_name_length + 2)
- Closing line uses normal indent
- Parameters now align correctly
2026-02-18 15:05:13 +01:00
lazar eb11380aea fix(formatter): Fix FB call continuation indent
- Use correct continuation indent formula (base + fb_name_length + 2)
- Fix closing line of FB call to use continuation indent
- Parameters on continuation lines are now aligned
2026-02-18 14:50:49 +01:00
lazar f977d1ea7c fix(formatter): Add comment re-indenting and FB call continuation support
- Re-indent comments to match current block level
- Add FB/function call continuation detection and alignment
- Support both #fbname and "FBName" syntax
- Fix FB call detection to exclude assignment statements
- Continuation lines get +1 indent level
2026-02-18 14:42:41 +01:00
lazar d8e50b3e23 fix(formatter): Implement TIA Portal-compliant SCL formatting
- Default to tabs (not spaces) per TIA Portal standard
- Fix block keyword handling (IF, FOR, WHILE, CASE, REGION, etc.)
- Handle VAR section indentation (variables indented inside VAR)
- Fix IF/ELSIF/ELSE indentation (ELSIF/ELSE at same level as IF)
- Handle CASE labels and nested CASE statements
- Add missing semicolons after END_IF, END_FOR, END_CASE Handle block, etc.
- enders (END_IF, END_REGION, etc.) correctly
- Support compound keywords (END_IF, END_FUNCTION_BLOCK, etc.)
2026-02-18 14:10:50 +01:00
lazar 96c0c4584f fix(lsp): Fix LSP server attachment and JSON parsing issues
- Replace lspconfig.scl_lsp registration with vim.lsp.start() + FileType autocmd
  for Neovim 0.11+ compatibility
- Fix Lua reserved keyword 'end' in tables (use bracket notation ['end'])
- Fix JSON decoder pattern matching bugs (s:find -> s:sub:match)
- Add LSP method name conversion (textDocument/didOpen -> textDocument_didOpen)
- Handle request vs notification correctly (only respond to requests with id)
- Strip CRLF line endings for Windows compatibility
- Add semantic token handler aliases
- Update documentation with implementation notes
2026-02-18 13:03:14 +01:00
lazar 625297106e Inintal commit 2026-02-14 15:05:12 +01:00