Add .def navigation helpers and tests #47

Merged
Christoph merged 0 commits from refs/pull/47/head into main 2026-09-24 21:01:33 +00:00
Christoph commented 2026-09-24 21:01:29 +00:00 (Migrated from git.cbsk-tech.de)

This change adds navigation and rename helper functions for .def files and corresponding unit tests.

The new module server/src/tools/def_navigation.py implements symbol lookup and cross-file navigation between .def declarations (formats, addresses, block templates) and Tcl callers. Key behaviors provided by the code:

  • Identify the .def symbol at a position (def_symbol_at) and produce an LSP range for it.
  • Collect declarations and references across parsed .def documents (def_declarations, def_definition_locations, def_reference_locations).
  • Find occurrences of .def symbols referenced from Tcl indexes (tcl_def_occurrences) and merge them with .def locations (all_def_target_locations).
  • Create workspace edits for renaming declared .def symbols across .def and Tcl files (def_rename_edits) — returns None when the target is not a declared symbol.
  • Produce Markdown hover content for declarations (def_hover_markdown), including a formatted table of address properties and modality annotations.
  • Helper utilities for URI mapping, range/position conversion, and escaping table cells.

Tests were added under server/tests/python_tests/test_def_navigation.py. The test suite covers:

  • Parsing .def documents to extract declarations and references.
  • Go-to-definition requests from Tcl files for templates and addresses.
  • Hover content for templates and address property formatting.
  • References requests including control of whether to include declarations.
  • Prepare-rename/rename behavior from Tcl callers and from .def-scoped requests.
  • Use of unsaved .def text when handling .def-specific requests.
  • Guarding renames so that undeclared or invalid names are not renamed.

Testing

  • The change adds tests but no test execution results were provided. The tests exercise LSP handlers exposed by lsp_server (goto_definition, hover, references, prepare_rename, rename) and the custom .def requests (def_definition, def_hover, def_references, def_prepare_rename, def_rename).

Recommended checks for reviewers:

  1. Run the new tests: pytest server/tests/python_tests/test_def_navigation.py (or run the whole test suite) and verify they pass in your environment.
  2. Start the language server against a small project fixture like the tests' PSC/DEF/TCL setup and exercise go-to-definition, hover and rename flows from an editor client to confirm handlers are wired correctly.

Compatibility and notes

  • def_rename_edits intentionally returns None when the target has no declaration (rename is only allowed for declared symbols).
  • Hover output for addresses builds a Markdown table from address properties and resolves format references when present.
  • No runtime or test execution logs were supplied with this change.

If you want, I can run through any specific function or test case in the diff during review or suggest additional edge-case tests (e.g. multiple declarations with the same name across documents, or overlapping edits across files).

This change adds navigation and rename helper functions for .def files and corresponding unit tests. The new module `server/src/tools/def_navigation.py` implements symbol lookup and cross-file navigation between .def declarations (formats, addresses, block templates) and Tcl callers. Key behaviors provided by the code: - Identify the .def symbol at a position (`def_symbol_at`) and produce an LSP range for it. - Collect declarations and references across parsed .def documents (`def_declarations`, `def_definition_locations`, `def_reference_locations`). - Find occurrences of .def symbols referenced from Tcl indexes (`tcl_def_occurrences`) and merge them with .def locations (`all_def_target_locations`). - Create workspace edits for renaming declared .def symbols across .def and Tcl files (`def_rename_edits`) — returns `None` when the target is not a declared symbol. - Produce Markdown hover content for declarations (`def_hover_markdown`), including a formatted table of address properties and modality annotations. - Helper utilities for URI mapping, range/position conversion, and escaping table cells. Tests were added under `server/tests/python_tests/test_def_navigation.py`. The test suite covers: - Parsing `.def` documents to extract declarations and references. - Go-to-definition requests from Tcl files for templates and addresses. - Hover content for templates and address property formatting. - References requests including control of whether to include declarations. - Prepare-rename/rename behavior from Tcl callers and from `.def`-scoped requests. - Use of unsaved `.def` text when handling `.def`-specific requests. - Guarding renames so that undeclared or invalid names are not renamed. ## Testing - The change adds tests but no test execution results were provided. The tests exercise LSP handlers exposed by `lsp_server` (`goto_definition`, `hover`, `references`, `prepare_rename`, `rename`) and the custom `.def` requests (`def_definition`, `def_hover`, `def_references`, `def_prepare_rename`, `def_rename`). Recommended checks for reviewers: 1. Run the new tests: `pytest server/tests/python_tests/test_def_navigation.py` (or run the whole test suite) and verify they pass in your environment. 2. Start the language server against a small project fixture like the tests' `PSC/DEF/TCL` setup and exercise go-to-definition, hover and rename flows from an editor client to confirm handlers are wired correctly. ## Compatibility and notes - `def_rename_edits` intentionally returns `None` when the target has no declaration (rename is only allowed for declared symbols). - Hover output for addresses builds a Markdown table from address properties and resolves format references when present. - No runtime or test execution logs were supplied with this change. If you want, I can run through any specific function or test case in the diff during review or suggest additional edge-case tests (e.g. multiple declarations with the same name across documents, or overlapping edits across files).
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!47
No description provided.