Add .def navigation helpers and tests #47

Merged
Christoph merged 1 commits from bug_fix into main 2026-09-24 21:01:33 +00:00
Owner

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).
Christoph added 1 commit 2026-09-24 21:01:29 +00:00
Add tools/def_navigation.py providing utilities to locate .def symbols
and occurrences, produce definition/reference locations, build hover
Markdown for addresses (property table with format links and modality
labels), and compute workspace edits for renames (only when a
declaration exists). Helpers include def_symbol_at, def_definition_locations,
def_reference_locations, tcl_def_occurrences, all_def_target_locations,
def_rename_edits and def_hover_markdown, plus small formatting helpers.

Also add server/tests/python_tests/test_def_navigation.py exercising
go-to-definition, hover, references and rename behavior between Tcl and
.def files, including use of unsaved text and ensuring undeclared names
are not renamed. Tests assert address property ordering, modality labels,
and correct edit ordering for workspace edits.
Christoph merged commit bd9c73452e into main 2026-09-24 21:01:33 +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#47