Add TclOO class completions, signature help and inlay hints #39

Merged
Christoph merged 0 commits from refs/pull/39/head into main 2026-09-11 21:39:35 +00:00
Christoph commented 2026-09-11 21:39:20 +00:00 (Migrated from git.cbsk-tech.de)

This change adds document-local, conservative TclOO support to the language server: completions for statically inferred object receivers, signature help for resolved TclOO methods/constructors, semantic highlighting for class declarations/references, and parameter inlay hints for resolved method calls.

What changed

  • Completion: on_completion now calls tcloo_completions which returns receiver-specific method completions for statically resolvable TclOO new/create instances and my/statically inferred return chains. Class names declared in the current document are also offered as CompletionItemKind.Class (tools/tcloo_completion.py and tools/tcloo_symbols.py). Class completion items are added to the local completion candidates and to the server's CompletionCollector.
  • Signature help: signature_help consults method_signature_help (tools/tcloo_arguments.py) to provide SignatureHelp for statically resolved TclOO calls and constructors. It uses a conservative cursor containment check and defers to nested command signature providers where appropriate.
  • Inlay hints: InlayHintGenerator now adds parameter inlay hints for resolved TclOO calls using method_parameters parsing and resolved_method_calls to supply labels and variadic/optional handling (tools/inlay_hint.py + tools/tcloo_arguments.py).
  • Semantic tokens: The syntax highlighter records class declarations and references (tools/tcloo_symbols.py) and merges them into semantic token output via a new highlight_classes call in semantic_tokens.
  • Robust parsing fallback: when the main AST parsing raises TclSyntaxError (e.g. during editing with unclosed delimiters), completion and signature help use a conservative parse_completion_source() that appends closing delimiters up to a fixed attempt limit to build an AST for local inference.
  • Tests: new unit tests were added to exercise method parameter parsing, signature help behavior and inlay hints for TclOO (server/tests/python_tests/test_tcloo_arguments.py and server/tests/python_tests/test_tcloo_completion.py). Several new tooling modules were added under server/src/tools: tcloo_completion.py, tcloo_arguments.py, tcloo_symbols.py.

Scope and rationale

  • The implementation performs document-local, static inference only (it does not execute Tcl code or use workspace-wide type unification). The inference is intentionally conservative: it only returns completions/signatures when a receiver or return chain can be resolved from the current document AST. This is visible in the code paths that build per-document class maps and only return completions when a matching receiver is found.
  • No external behavior or requirements were asserted beyond the code in the diff; the description above is limited to behavior observable from the changes.

Tests and CI

  • New tests were added (test_tcloo_arguments.py, test_tcloo_completion.py) and exercise parsing of parameter lists, signature help positions, and inlay hint output. No test execution results were provided.

Recommended reviewer checks

  1. Run the test suite: pytest server/tests/python_tests -q to verify the new tests pass in CI.
  2. Manually exercise LSP behavior with an editor or an LSP test harness: verify on_completion returns method completions for a local class instance (e.g. after creating a class with oo::class create), verify signature_help returns the expected SignatureInformation when the cursor is inside a resolved method call, and check inlay hints appear for the same call sites.
  3. Smoke-check editing/fallback parsing: open a buffer with an unfinished bracket or quote and confirm completions and signature help still behave (the code uses parse_completion_source as a fallback when TclSyntaxError is raised).

Notes and risks

  • The added inference is intentionally conservative and document-local. It adds new completion items of kind Class and new semantic token handling for class declarations/references. No configuration or migration steps are required by this patch.
  • No execution or performance measurements were supplied; if reviewers are concerned about cost, exercising semantic token requests and completion at scale in large files is a sensible performance check.

Files of interest (high level)

  • server/src/tools/tcloo_completion.py: main document-local class/method inference and completion provider.
  • server/src/tools/tcloo_arguments.py: parameter parsing and signature-help assembly for TclOO methods/constructors.
  • server/src/tools/tcloo_symbols.py and server/src/tools/semantic_tokens.py: class declaration/reference collection and token insertion.
  • server/src/lsp_server.py and server/src/lsp_tclserver.py: integration points for completion, signature help, inlay hints and semantic tokens.

No test execution results were provided.

This change adds document-local, conservative TclOO support to the language server: completions for statically inferred object receivers, signature help for resolved TclOO methods/constructors, semantic highlighting for class declarations/references, and parameter inlay hints for resolved method calls. What changed - Completion: on_completion now calls tcloo_completions which returns receiver-specific method completions for statically resolvable TclOO `new`/`create` instances and `my`/statically inferred return chains. Class names declared in the current document are also offered as CompletionItemKind.Class (tools/tcloo_completion.py and tools/tcloo_symbols.py). Class completion items are added to the local completion candidates and to the server's CompletionCollector. - Signature help: signature_help consults method_signature_help (tools/tcloo_arguments.py) to provide SignatureHelp for statically resolved TclOO calls and constructors. It uses a conservative cursor containment check and defers to nested command signature providers where appropriate. - Inlay hints: InlayHintGenerator now adds parameter inlay hints for resolved TclOO calls using method_parameters parsing and resolved_method_calls to supply labels and variadic/optional handling (tools/inlay_hint.py + tools/tcloo_arguments.py). - Semantic tokens: The syntax highlighter records class declarations and references (tools/tcloo_symbols.py) and merges them into semantic token output via a new highlight_classes call in semantic_tokens. - Robust parsing fallback: when the main AST parsing raises TclSyntaxError (e.g. during editing with unclosed delimiters), completion and signature help use a conservative parse_completion_source() that appends closing delimiters up to a fixed attempt limit to build an AST for local inference. - Tests: new unit tests were added to exercise method parameter parsing, signature help behavior and inlay hints for TclOO (server/tests/python_tests/test_tcloo_arguments.py and server/tests/python_tests/test_tcloo_completion.py). Several new tooling modules were added under server/src/tools: tcloo_completion.py, tcloo_arguments.py, tcloo_symbols.py. Scope and rationale - The implementation performs document-local, static inference only (it does not execute Tcl code or use workspace-wide type unification). The inference is intentionally conservative: it only returns completions/signatures when a receiver or return chain can be resolved from the current document AST. This is visible in the code paths that build per-document class maps and only return completions when a matching receiver is found. - No external behavior or requirements were asserted beyond the code in the diff; the description above is limited to behavior observable from the changes. Tests and CI - New tests were added (test_tcloo_arguments.py, test_tcloo_completion.py) and exercise parsing of parameter lists, signature help positions, and inlay hint output. No test execution results were provided. Recommended reviewer checks 1) Run the test suite: pytest server/tests/python_tests -q to verify the new tests pass in CI. 2) Manually exercise LSP behavior with an editor or an LSP test harness: verify on_completion returns method completions for a local class instance (e.g. after creating a class with oo::class create), verify signature_help returns the expected SignatureInformation when the cursor is inside a resolved method call, and check inlay hints appear for the same call sites. 3) Smoke-check editing/fallback parsing: open a buffer with an unfinished bracket or quote and confirm completions and signature help still behave (the code uses parse_completion_source as a fallback when TclSyntaxError is raised). Notes and risks - The added inference is intentionally conservative and document-local. It adds new completion items of kind Class and new semantic token handling for class declarations/references. No configuration or migration steps are required by this patch. - No execution or performance measurements were supplied; if reviewers are concerned about cost, exercising semantic token requests and completion at scale in large files is a sensible performance check. Files of interest (high level) - server/src/tools/tcloo_completion.py: main document-local class/method inference and completion provider. - server/src/tools/tcloo_arguments.py: parameter parsing and signature-help assembly for TclOO methods/constructors. - server/src/tools/tcloo_symbols.py and server/src/tools/semantic_tokens.py: class declaration/reference collection and token insertion. - server/src/lsp_server.py and server/src/lsp_tclserver.py: integration points for completion, signature help, inlay hints and semantic tokens. No test execution results were provided.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Christoph/nx_post_support!39
No description provided.