Commit Graph
49 Commits
Author SHA1 Message Date
lazar f219a8662f fix: guard vim.lsp.diagnostics.refresh() against nil
Neovim 0.12+ restructured LSP internals; vim.lsp.diagnostics no
longer exists as a submodule. Guard the call so :SCLRescanWorkspaceTypes
doesn't crash on startup.
2026-07-24 12:35:36 +02:00
lazar a9c1b8db16 docs: update reference project path in AGENTS.md 2026-07-24 11:57:50 +02:00
lazar a4400106db refactor: collapse all {} blocks in declaration section, drop pattern filtering 2026-07-24 09:54:22 +02:00
lazar b86ce08426 fix: bridge :SCLRescanWorkspaceTypes to LSP server + refresh diagnostics 2026-07-23 13:55:04 +02:00
lazar 0a0b5c9bf1 fix: DB completion path parsing, array-of-UDT resolution, blink source registration
- Fix path extraction pattern (missing closing quote, extra capture group)
- Add Array[..] of "UdtName" detection for nested member resolution
- Remove vim.schedule_wrap from DB member callback (causes blink.cmp timeout)
- Add built-in instruction parameter fallback (IEC_TIMER IN/PT/Q/ET)
- Ensure DB cache is populated on demand in completion source
- Make try_register() succeed without cmp.add_source_provider API
- docs: add blink.cmp source config steps to installation guide
2026-07-22 20:26:16 +02:00
lazar 3776ce33ff refactor: change the default path for local dev env 2026-07-20 17:01:37 +02:00
lazar 1acac2b73c docs: rewrite installation with architecture overview, troubleshooting, and cross-references 2026-07-19 15:09:58 +02:00
lazar 03548dab7d feat: comprehensive query files for all block types and VAR sections (Phase 3)
Update all 5 tree-sitter query files to cover the full grammar:

highlights.scm:
- Add highlights for new literals (binary, octal, date, bool, typed_int,
  wstring, char)
- Add highlights for block names (organization_block, function_block,
  function, data_block, type_definition)
- Add highlights for return_statement, goto_statement, title_statement
- Add highlights for bit_access, method_callee
- Add compound assignment operators (+=, -=, *=, /=, etc.)

indents.scm:
- Add function, type_definition, data_block to @indent.begin
- Add all var_*_declaration variants to @indent.begin
- Add struct_type to @indent.begin
- Add END_FUNCTION, END_TYPE, END_DATA_BLOCK, END_STRUCT to @indent.end

folds.scm:
- Add function, type_definition, data_block to @fold
- Add all var_*_declaration variants to @fold
- Add struct_type to @fold

locals.scm:
- Add function, type_definition, data_block as @local.scope
- Add all var_*_declaration variants as @local.scope
- Add struct_type as @local.scope
- Add block name definitions (@definition.function, @definition.class,
  @definition.type)
- Narrow @reference to prefixed_identifier only (reduces noise)

tags.scm:
- Add function, data_block, type_definition tags
- Add FB call references
- Add region_statement as @definition.module
2026-07-18 19:20:33 +02:00
lazar aebffc34e7 fix: load compiled parser.so via vim.treesitter.language.add
nvim-treesitter's :TSInstall reloads the parsers module from source
(package.loaded['nvim-treesitter.parsers'] = nil), which wipes runtime
config modifications. The old get_parser_configs() approach no longer
works for registering custom parsers with :TSInstall.

New approach:
- The mason build script now compiles parser.c into parser.so during
  :MasonInstall tia-lsp (requires cc/gcc)
- The plugin's setup_syntax finds parser.so via:
  1. opts.ts_parser_path (explicit override)
  2. Mason package dir (resolved from exepath('tia-lsp'))
  3. ~/dev/tia-lsp/parser.so (local dev fallback)
- Loads it with vim.treesitter.language.add('scl', { path = parser.so })
- Starts highlighting via vim.treesitter.start(bufnr, 'scl') in the
  FileType autocmd
- Falls back to notifying the user if no parser.so is found
- Still registers with nvim-treesitter's parsers table as best-effort
  for :TSInstall support (won't survive reload, but works in-session)
2026-07-18 18:01:32 +02:00
lazar bd50f7b459 fix: update tree-sitter parser URL to Gitea
Change the default ts_parser_url from the local file:// path to the
Gitea-hosted tia-lsp repository, so :TSInstall scl works out of the
box after the repo split.
2026-07-18 11:49:16 +02:00
lazar 8255db7f64 chore: adjust for plugin-only scope after split
After splitting from the original scl_lsp repo, update for plugin-only scope:

- README.md: focused on Neovim plugin installation, configuration,
  commands, keybindings, and editor features
- AGENTS.md: plugin-only project structure and conventions
- test/run_tests.lua: run only plugin tests (udt, db, fb, integration)
- test/test_integration.lua: remove plc_json dependency (server module)
- queries/: move from queries/*.scm to queries/scl/*.scm (nvim-treesitter
  per-language convention)
- ftdetect/scl.vim: add filetype detection for .scl/.udt/.db files
2026-07-18 11:46:18 +02:00
lazar 8c6a050efb refactor: rename scl_lsp → tia_lsp (project umbrella for future STL/LAD/FBD)
Rename the project from scl_lsp to tia_lsp to future-proof for additional
TIA Portal languages (STL/AWL, LAD, FBD). The 'scl' language name is kept
as-is for the SCL filetype and tree-sitter parser; future languages get
their own names (stl, lad, fbd).

Project-wide changes:
- lua/scl_lsp/ → lua/tia_lsp/  (plugin entry point)
- lua/scl/     → lua/tia/      (language modules, shared across TIA langs)
- require('scl.*')    → require('tia.*')
- require('scl_lsp')  → require('tia_lsp')
- LSP client name:    'scl_lsp' → 'tia_lsp'
- Diagnostic source:  'scl_lsp' → 'tia_lsp'  (src/diagnostics.lua)
- package.json name:  'scl-language-server' → 'tia-lsp'

lua/tia_lsp/init.lua:
- Add vim.fn.exepath('tia-lsp') detection so the plugin prefers the
  mason-installed executable and falls back to { 'lua', server_path }
  for manual installs.
- Add opts.ts_parser_url to configure the tree-sitter parser source.
- Remove hardcoded ~/dev/scl_lsp paths in favor of ~/dev/tia-lsp and
  the new ts_parser_url option.

Cleanup:
- Delete lua/tia/init.lua (dead code, unreferenced duplicate of tia_lsp).
- Delete scl_lsp.sh (replaced by the mason-installed bin/tia-lsp wrapper).
- Update README.md and AGENTS.md to reflect the two-repo split
  (tia-lsp server + tia-lsp.nvim plugin) and document Mason installation.

Unchanged (intentional):
- grammar.js, src/grammar.json, src/parser.c: tree-sitter language name
  remains 'scl' (it's the language, not the project).
- Filetype patterns ('scl', 'udt', 'db') in autocmds.
- :SCL* command names (per-filetype prefix; future :STL* etc.).

Tests pass with the same pre-existing failures as before the rename
(formatter VAR_INPUT test, udt_parser line 199 const-variable bug,
plc_json reference-project-missing). No new failures introduced.
2026-07-18 11:30:55 +02:00
lazar 137eda3e77 fix: Attribute block expand/collapse, TIME literal diagnostics, and formatter bugs
- SCLFormat: Remove clear_buffer_state() call that was preventing
       expand after formatting (attr_toggle state now preserved)
     - Diagnostics: Fix false 'Undefined variable' for IEC literals
       like T#2s, D#1d, S5T#1s (TIME, DATE, S5TIME types)
     - Formatter: Fix block comments (* ... *) being misidentified as
       FB calls in VAR_IN_OUT/VAR_INPUT/VAR_OUTPUT sections
     - Formatter: Fix array-based FB calls like instTimers[idx].TON()
       not being properly formatted with aligned parameters
2026-02-24 15:27:58 +01:00
lazar 15b0e5360a 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
2026-02-23 17:40:44 +01:00
lazar bfdec0c4b1 test: add formatter tests
- Add comprehensive formatter test suite with 38 tests
- Test multiline assignments, FB calls, control structures
- Test IF, FOR, WHILE, CASE, REPEAT statements
- Test regions, structs, var sections
- Update AGENTS.md with formatter test command
2026-02-23 14:16:46 +01:00
lazar 4471d9e1d9 Merge branch 'feat/testing_framework' into develop 2026-02-23 13:36:49 +01:00
lazar eb10b1c0df feat: add testing framework with reference project integration
- Add test/ directory with test harness and test files
- Add UDT, DB, FB parser tests
- Add PLC JSON and integration tests
- Test against reference project (239 UDTs, 12 DBs, 37 SCL, 13 XML)
- Fix attribute parsing to handle underscores (S7_SetPoint)
- Add ORGANIZATION_BLOCK support to FB parser
2026-02-23 13:29:38 +01:00
lazar 5ca5628d39 Merge branch 'feat/scl_formatter' into develop 2026-02-23 10:30:32 +01:00
lazar 3dfca6bba3 feat: improve formatter and attribute block handling
- Format multi-line assignments with proper alignment
- Format FB calls in multiline style with parameter alignment
- Auto-expand collapsed attribute blocks before save
- Rename command from LspSCLFormat to SCLFormat
- Condense AGENTS.md and add testing section with reference project
2026-02-23 10:29:05 +01:00
lazar 15f88d110b docs: add auto-editing features section to AGENTS.md 2026-02-21 01:50:39 +01:00
lazar 0f829552c2 fix: limit auto-semicolon to control structure END_* keywords only
- Only auto-add semicolon for END_IF, END_FOR, END_WHILE, END_REPEAT, END_CASE
- Exclude block definitions (END_FUNCTION, END_FUNCTION_BLOCK, END_VAR, etc.)
2026-02-21 01:50:39 +01:00
lazar 97176508d3 feat: auto-uppercase keywords and auto-semicolon for END_* keywords
- Auto-uppercase SCL keywords (IF, CASE, FOR, NOT, AND, etc.) when typing space
- Auto-add semicolon after END_* keywords (END_IF, END_FOR, etc.) when:
  - Leaving insert mode on a line ending with END_*
  - Pressing Enter after typing END_*
- Added complete keyword list including TYPE, STRUCT, DATA_BLOCK, etc.
- Works for .scl, .udt, and .db files
2026-02-21 01:50:39 +01:00
lazar 06e36a0b4b docs: update collapse patterns documentation in AGENTS.md 2026-02-20 23:53:55 +01:00
lazar a8559a17ef Merge branch 'feat/db_udt_interactive_colapse_extend' into develop 2026-02-20 23:53:10 +01:00
lazar d1078b0214 fix: improve attribute block collapse for .udt and .db files
- Add case-insensitive pattern matching for attributes
- Add patterns for NonRetain and Retain attributes
- Add generic patterns for key := value and single word attributes
- Fix BufUnload autocmd to also handle *.udt and *.db files
2026-02-20 23:52:33 +01:00
lazar 69f5c7b215 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 2cd59f572f 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 4f25a15936 Merge branch 'feat/lsp_goto' into develop 2026-02-20 09:40:45 +01:00
lazar c4d65d5c87 docs: add filetype detection section to AGENTS.md 2026-02-20 09:01:06 +01:00
lazar ff311b88b9 docs: update README with goto declaration feature 2026-02-19 18:07:04 +01:00
lazar 35eae17f4f 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 e0db21381a docs(README): clarify formatter attribute collapsing behavior 2026-02-19 11:24:45 +01:00
lazar 212d4b710d docs: document formatter collapseAttributes default change 2026-02-19 11:24:22 +01:00
lazar b663fd6b4b docs: document attr_toggle behavior after formatting 2026-02-19 11:18:16 +01:00
lazar becf45d348 fix: clear attr_toggle state after formatting
When :LspSCLFormat is used, line numbers and positions change,
but the attr_toggle module stores state based on old positions.
This caused toggle/expand/collapse to not work after formatting.

Now clears the attr_toggle buffer state after formatting so that
users can collapse blocks fresh after formatting.
2026-02-19 11:17:59 +01:00
lazar 35bf9ab781 Merge branch 'feat/scl_formatter' into develop 2026-02-19 10:24:38 +01:00
lazar ce1e27a42d docs: update README with attribute block toggle feature
Add documentation for new attribute block toggle feature including:
- New commands: SCLToggleAttrBlock, SCLExpandAllAttrBlocks, SCLCollapseAllAttrBlocks
- New keybindings: <Leader>xa, <Leader>xae, <Leader>xac
- Feature description and usage example
2026-02-19 10:13:43 +01:00
lazar 74e521fe04 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 246fa85442 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 b5d50384fb docs(AGENTS.md): Update AGENTS.md
The new AGENTS.md includes:
- Reference project for testing
- Build/test commands (LSP and tree-sitter)
- Condensed project structure
- Code style guidelines (module pattern, naming, imports, comments)
- Parser module API convention
- Cache management patterns
- Error handling patterns (return pattern, pcall, validation)
- Completion system documentation
- Commands table
2026-02-18 10:25:35 +01:00
lazar a79082b64e fix(multiline_paras): <Tab> behavior outside of fb/function
The function searches for := or => patterns anywhere in the code,
without verifying that the cursor is inside an FB/Function call context

Added is_inside_fb_call() function (lines 133-176):
- Traces backwards from cursor position
- Tracks parenthesis depth to skip nested calls
- Finds the opening ( of an FB call and checks if the name before it is a known variable
- Returns true only if cursor is inside an FB/Function call

Modified jump_to_next_param() (lines 178-189):
- Now returns false immediately if not inside an FB call context
- This causes the keymap to fall back to normal <Tab> behavior

Result:
- Inside FB call: <Tab> jumps to next := or =>
- Outside FB call: <Tab> behaves normally (inserts tab character)
2026-02-18 10:04:41 +01:00
lazar 1e50b596de fix(blink_cmp_source): Handling of DB patterns after operators
The completion now correctly handles DB patterns after any operator
(:=, =>, =, <>, >=, <=, >, <, AND, OR, NOT) by finding the last operator
and only matching DB patterns in the active portion after it.
2026-02-18 09:21:38 +01:00
lazar 7d54578406 docs: Update AGENTS.md with comprehensive feature documentation 2026-02-17 15:30:30 +01:00
lazar 8933b9315d Merge branch 'feat/db_workspace_scope_recognition' into develop 2026-02-17 15:22:05 +01:00
lazar 7db896b84c feat: Add Global Data Block recognition in workspace scope
- Add db_parser.lua to parse .db files (DATA_BLOCK with VAR sections)
- Update workspace_types.lua to scan for .db files in project
- Update blink_cmp_source.lua to provide DB auto-completion:
  - DB names available in general completion (without quotes)
  - Type quote to get DB members
  - Multi-level nested member access support
- Add DB count to workspace commands
- Update README with Global DB documentation
2026-02-17 15:06:36 +01:00
lazar a3ea6e6c0a Add multiline params documentation 2026-02-17 12:36:17 +01:00
lazar c1500f954b Fix multiline params feature and auto-prefix
- Fix FB/function call parameter detection to prevent incorrect # prefixing
- Preserve # prefix when filling multiline params
- Add comma after first parameter and closing bracket on last param line
- Fix Tab navigation to position cursor after :=/=> operators
- Clean up dead code in multiline_params.lua
- Add setup functions for multiline params feature in both scl and scl_lsp
2026-02-17 12:34:59 +01:00
lazar 802fe93fb7 Added .gitignore 2026-02-14 15:06:54 +01:00
lazar fbbd357ee2 Inintal commit 2026-02-14 15:05:12 +01:00