Index PSC scripts and add TclOO cross-file navigation/completions; handle CDL TOGGLE Off #40

Merged
Christoph merged 3 commits from add_class_support into main 2026-09-21 18:53:52 +00:00
Owner

This change set adds cross-file TclOO/PSC indexing and navigation/completion support, plus a small CDL event-handler improvement and a few editor/test-path updates.

Summary

  • Server: index PSC scripts and share TclOO class metadata across files

    • The language server now watches *.psc alongside *.tcl (createFileSystemWatcher("**/*.{tcl,psc}")) and refreshes the PSC index when .psc files change (did_change_watched_files -> _refresh_psc_index).
    • A new refresh helper walks workspace folders and calls LSP_SERVER.refresh_psc_scripts(roots, report=log_warning) to rebuild PSC script metadata.
    • TclOO completions/signatures/inlay hints/semantic highlighting use a per-document class snapshot: class_snapshot(document.path) is passed into tcloo_completions, method_signature_help, InlayHintGenerator, and hl (highlighter) calls. This enables completions, signature help, and go-to-definition to resolve classes/methods defined in indexed PSC/Tcl files across the workspace.
    • goto_definition first attempts to resolve TclOO declarations via tcloo_definition(document.source, document.uri, params.position, LSP_SERVER.class_snapshot(document.path)) and returns that location when found before falling back to the symbol index.
    • Many completion and ranking paths were adjusted to include class/completion items from the file-index snapshots and to combine command/variable candidates appropriately.
  • CDL event handler: detect "TOGGLE Off" and emit *_defined globals

    • The CDL event parser (cdlEventHandlerAtLine) now tokenizes event body braces and tracks PARAM entries and their TOGGLE tokens. When a TOGGLE Off appears for a parameter, that parameter name is recorded in toggleOffParameterNames.
    • createCdlEventHandlerSnippet uses that information to include both the MOM variable and an additional <var>_defined global when a parameter had TOGGLE Off.
    • Trigger example (before/after): previously a PARAM that included TOGGLE Off produced only the MOM variable in the generated snippet; now the snippet also supplies <variable>_defined.
  • Minor editor/test-path and docs updates

    • .vscode/launch.json and .gitignore were updated to reference test/postprocessor instead of test/test.tcl and to ignore /test/postprocessor/.
    • README.md and CHANGELOG.md were updated to mention the PSC/TclOO indexing and Go-to-definition support.
    • CDL completion categories now include INVALID for TYPE completions (categories = ["MILL", "LATHE", "DRILL", "INVALID"]).

Notes about scope and why it matters

  • The core behavior change is that class metadata extracted from indexed PSC/Tcl files is now available across files for completion, signature help, inlay hints, highlighting, and go-to-definition. This is enabled by adding .psc indexing, a refresh path for PSC changes, and plumbing class_snapshot(document.path) through the completion/signature/highlight/definition code.
  • The CDL change is narrowly scoped to event handler snippet generation: it only affects which globals are emitted when TOGGLE Off is present for a PARAM.
  • Other edits are formatting and small refactors in Python/TypeScript call sites to pass the new arguments or to keep style consistent; they do not add additional user-visible features beyond those summarized above.

Testing

No test execution results were provided.

Recommended focused checks for a reviewer or QA:

  • PSC/TclOO cross-file checks

    1. Open or add a PSC script (or a .tcl file referenced by a PSC layer) in a workspace folder different from the current file.
    2. Ensure the server indexes PSC scripts (watch the server output channel/logs for indexing or missing-script warnings).
    3. In a separate Tcl file, verify class/method completions, signature help, and parameter inlay hints for methods or constructors that are defined in the indexed PSC/Tcl files.
    4. Use "Go to Definition" on a class constructor or resolved method call and confirm it navigates to the indexed PSC/Tcl definition.
    5. Modify a .psc file and confirm the server refreshes the PSC index (file watcher should trigger _refresh_psc_index).
  • CDL event handler checks

    1. In a CDL file, create an event with a PARAM and include TOGGLE Off for that parameter.
    2. Use the snippet generation helper or trigger the generated snippet and confirm that both the MOM variable and <var>_defined globals are produced.
  • Misc checks

    • Verify completion for TYPE suggests INVALID.
    • Run the extension in the VS Code dev host (the updated launch.json now points to test/postprocessor).

Compatibility / reviewer notes

  • The server now treats .psc as an indexed script type; repository watchers and index refresh logic were added to handle .psc changes. Reviewers should confirm this is expected for any workspace that uses PSC layer scripts.
  • No tests were executed with this diff; the changes are primarily additive (indexing and additional completion/definition resolution) and local to the language server and client completion/snippet generation.

If you want, I can list the exact code paths where class_snapshot is passed through (completion, signature help, inlay hints, semantic highlighting, goto-definition) or point to the specific files changed for a quick scan.

This change set adds cross-file TclOO/PSC indexing and navigation/completion support, plus a small CDL event-handler improvement and a few editor/test-path updates. Summary - Server: index PSC scripts and share TclOO class metadata across files - The language server now watches `*.psc` alongside `*.tcl` (`createFileSystemWatcher("**/*.{tcl,psc}")`) and refreshes the PSC index when `.psc` files change (`did_change_watched_files` -> `_refresh_psc_index`). - A new refresh helper walks workspace folders and calls `LSP_SERVER.refresh_psc_scripts(roots, report=log_warning)` to rebuild PSC script metadata. - TclOO completions/signatures/inlay hints/semantic highlighting use a per-document class snapshot: `class_snapshot(document.path)` is passed into `tcloo_completions`, `method_signature_help`, `InlayHintGenerator`, and `hl` (highlighter) calls. This enables completions, signature help, and go-to-definition to resolve classes/methods defined in indexed PSC/Tcl files across the workspace. - `goto_definition` first attempts to resolve TclOO declarations via `tcloo_definition(document.source, document.uri, params.position, LSP_SERVER.class_snapshot(document.path))` and returns that location when found before falling back to the symbol index. - Many completion and ranking paths were adjusted to include class/completion items from the file-index snapshots and to combine command/variable candidates appropriately. - CDL event handler: detect "TOGGLE Off" and emit *_defined globals - The CDL event parser (`cdlEventHandlerAtLine`) now tokenizes event body braces and tracks PARAM entries and their TOGGLE tokens. When a `TOGGLE Off` appears for a parameter, that parameter name is recorded in `toggleOffParameterNames`. - `createCdlEventHandlerSnippet` uses that information to include both the MOM variable and an additional `<var>_defined` global when a parameter had `TOGGLE Off`. - Trigger example (before/after): previously a PARAM that included `TOGGLE Off` produced only the MOM variable in the generated snippet; now the snippet also supplies `<variable>_defined`. - Minor editor/test-path and docs updates - `.vscode/launch.json` and `.gitignore` were updated to reference `test/postprocessor` instead of `test/test.tcl` and to ignore `/test/postprocessor/`. - `README.md` and `CHANGELOG.md` were updated to mention the PSC/TclOO indexing and Go-to-definition support. - CDL completion categories now include `INVALID` for `TYPE` completions (`categories = ["MILL", "LATHE", "DRILL", "INVALID"]`). Notes about scope and why it matters - The core behavior change is that class metadata extracted from indexed PSC/Tcl files is now available across files for completion, signature help, inlay hints, highlighting, and go-to-definition. This is enabled by adding `.psc` indexing, a refresh path for PSC changes, and plumbing `class_snapshot(document.path)` through the completion/signature/highlight/definition code. - The CDL change is narrowly scoped to event handler snippet generation: it only affects which globals are emitted when `TOGGLE Off` is present for a PARAM. - Other edits are formatting and small refactors in Python/TypeScript call sites to pass the new arguments or to keep style consistent; they do not add additional user-visible features beyond those summarized above. Testing No test execution results were provided. Recommended focused checks for a reviewer or QA: - PSC/TclOO cross-file checks 1. Open or add a PSC script (or a `.tcl` file referenced by a PSC layer) in a workspace folder different from the current file. 2. Ensure the server indexes PSC scripts (watch the server output channel/logs for indexing or missing-script warnings). 3. In a separate Tcl file, verify class/method completions, signature help, and parameter inlay hints for methods or constructors that are defined in the indexed PSC/Tcl files. 4. Use "Go to Definition" on a class constructor or resolved method call and confirm it navigates to the indexed PSC/Tcl definition. 5. Modify a `.psc` file and confirm the server refreshes the PSC index (file watcher should trigger `_refresh_psc_index`). - CDL event handler checks 1. In a CDL file, create an event with a `PARAM` and include `TOGGLE Off` for that parameter. 2. Use the snippet generation helper or trigger the generated snippet and confirm that both the MOM variable and `<var>_defined` globals are produced. - Misc checks - Verify completion for `TYPE ` suggests `INVALID`. - Run the extension in the VS Code dev host (the updated `launch.json` now points to `test/postprocessor`). Compatibility / reviewer notes - The server now treats `.psc` as an indexed script type; repository watchers and index refresh logic were added to handle `.psc` changes. Reviewers should confirm this is expected for any workspace that uses PSC layer scripts. - No tests were executed with this diff; the changes are primarily additive (indexing and additional completion/definition resolution) and local to the language server and client completion/snippet generation. If you want, I can list the exact code paths where `class_snapshot` is passed through (completion, signature help, inlay hints, semantic highlighting, goto-definition) or point to the specific files changed for a quick scan.
Christoph added 3 commits 2026-09-21 18:53:39 +00:00
Add PSC (.psc) indexing and share TclOO class metadata across files so class
definitions discovered via PSC layers can be used for completions, signature
help, inlay hints, and "go to definition". Key behavior changes:

- Client file watcher now includes *.psc and .vscode launch paths/tests updated
  to use the postprocessor test folder; .gitignore updated to ignore that folder.
- Server watches .psc changes and refreshes a PSC script index; new
  tools/tcloo_navigation.py exposes tcloo_definition used by the language server
  to resolve cross-file class/constructor/method definitions.
- Language server uses class_snapshot(document.path) when producing TclOO
  completions, signature help, and inlay hints so resolved class metadata is
  available across files.

Also includes related docs/changelog updates, minor code formatting cleanups,
and added tests for PSC/TclOO behavior.
Record parameters marked with "TOGGLE Off" by adding an optional
toggleOffParameterNames field and including an extra <var>_defined global
for each such parameter in createCdlEventHandlerSnippet.

To support this, the parser was changed from a brace-delta approach to a
token-based scanner so nesting and the association between a PARAM and its
TOGGLE can be tracked reliably. Added unit tests that verify detection,
case-insensitivity, and ignoring TOGGLE occurrences inside comments/strings
or other events.
Accept "INVALID" as a valid token in the CATEGORY grammar rule (both the initial
and repeated entries). Also compacted several JSON objects (pattern includes
and "captures" entries) in syntaxes/cdl.tmLanguage.json; these formatting
changes are non-functional.
Christoph merged commit 5e5c7dcc42 into main 2026-09-21 18:53:52 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Christoph/nx_post_support#40