Show effective (last-loaded) .def declaration in hover and GoTo #50

Merged
Christoph merged 0 commits from refs/pull/50/head into main 2026-09-25 19:39:34 +00:00
Christoph commented 2026-09-25 19:38:30 +00:00 (Migrated from git.cbsk-tech.de)

This change makes hover and Go To Definition return the effective declaration for DEF block templates/addresses — the declaration from the last-loaded .def file in PSC layer order — and names any declarations it overrides. Find References and Rename still operate across all declarations.

What changed

  • The LSP handlers that previously returned all matching .def definition locations now return only the effective (last-loaded) declaration for hover and GoTo behaviors. Concretely:
    • server/src/tools/def_navigation.py adds effective_def_locations(documents, target, uris) which returns the last item of def_definition_locations(...) (the declaration NX would use when multiple PSC layers declare the same name).
    • def_hover_markdown(...) now formats hover content using the effective declaration and, when there are multiple declarations, appends a short _Overrides ..._ note listing the overridden file:line locations.
    • server/src/lsp_server.py uses effective_def_locations(...) for the goto_definition and def_definition paths instead of the previous def_definition_locations(...) result.
  • CHANGELOG.md and server/tests/python_tests/test_def_navigation.py were updated: a new test test_template_in_several_layers_shows_the_last_loaded_one exercises layered PSC behavior (two .def files in different layers) and asserts that hover and goto point to the last-loaded declaration while references include all declarations.

Behavior before / after

  • Before: hover and Go To Definition could show multiple declarations when a name is declared in several PSC layers.
  • After: hover and Go To Definition show only the effective (last-loaded) declaration and append which earlier declarations it overrides. Find References and Rename continue to show/update all declarations.

The new test creates two layered .def files (ctrl/ctrl.def, oem/oem.def) with differing template text and a post.psc PSC ordering file; it asserts hover content begins with the effective file (oem.def), contains the effective declaration text, ends with an _Overrides ctrl.def:5_ note, that goto_definition resolves to oem/oem.def, and that references still returns both .def files plus the caller.

Tests

  • Tests were added/changed: server/tests/python_tests/test_def_navigation.py includes test_template_in_several_layers_shows_the_last_loaded_one covering hover, goto, and references for layered PSC.
  • No test execution results were provided.

Recommended checks for reviewers:

  1. Run the Python unit tests (or at least the updated test_def_navigation.py) to verify the new layered-PSC assertions.
  2. Manually exercise a layered PSC workspace with multiple .def declarations of the same name and confirm hover and Go To Definition show the last-loaded declaration and list overridden locations, while Find References returns all occurrences.

Compatibility / notes

  • This is a behavioral narrowing only for hover and Go To Definition: the server now reports the single effective declaration rather than all declarations. References and rename behavior are unchanged.
  • No configuration changes or migrations are required.
This change makes hover and Go To Definition return the effective declaration for DEF block templates/addresses — the declaration from the last-loaded `.def` file in PSC layer order — and names any declarations it overrides. Find References and Rename still operate across all declarations. ## What changed - The LSP handlers that previously returned all matching `.def` definition locations now return only the effective (last-loaded) declaration for hover and GoTo behaviors. Concretely: - `server/src/tools/def_navigation.py` adds `effective_def_locations(documents, target, uris)` which returns the last item of `def_definition_locations(...)` (the declaration NX would use when multiple PSC layers declare the same name). - `def_hover_markdown(...)` now formats hover content using the effective declaration and, when there are multiple declarations, appends a short `_Overrides ..._` note listing the overridden file:line locations. - `server/src/lsp_server.py` uses `effective_def_locations(...)` for the `goto_definition` and `def_definition` paths instead of the previous `def_definition_locations(...)` result. - `CHANGELOG.md` and `server/tests/python_tests/test_def_navigation.py` were updated: a new test `test_template_in_several_layers_shows_the_last_loaded_one` exercises layered PSC behavior (two `.def` files in different layers) and asserts that hover and goto point to the last-loaded declaration while references include all declarations. ## Behavior before / after - Before: hover and Go To Definition could show multiple declarations when a name is declared in several PSC layers. - After: hover and Go To Definition show only the effective (last-loaded) declaration and append which earlier declarations it overrides. Find References and Rename continue to show/update all declarations. The new test creates two layered `.def` files (`ctrl/ctrl.def`, `oem/oem.def`) with differing template text and a `post.psc` PSC ordering file; it asserts hover content begins with the effective file (`oem.def`), contains the effective declaration text, ends with an `_Overrides ctrl.def:5_` note, that `goto_definition` resolves to `oem/oem.def`, and that `references` still returns both `.def` files plus the caller. ## Tests - Tests were added/changed: `server/tests/python_tests/test_def_navigation.py` includes `test_template_in_several_layers_shows_the_last_loaded_one` covering hover, goto, and references for layered PSC. - No test execution results were provided. Recommended checks for reviewers: 1. Run the Python unit tests (or at least the updated `test_def_navigation.py`) to verify the new layered-PSC assertions. 2. Manually exercise a layered PSC workspace with multiple `.def` declarations of the same name and confirm hover and Go To Definition show the last-loaded declaration and list overridden locations, while Find References returns all occurrences. ## Compatibility / notes - This is a behavioral narrowing only for hover and Go To Definition: the server now reports the single effective declaration rather than all declarations. References and rename behavior are unchanged. - No configuration changes or migrations are required.
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!50
No description provided.