feat(def-navigation): surface last-loaded .def declaration for hover/GoTo
When a block template or address is declared in multiple PSC layers, hover and Go to Definition now resolve to the effective declaration (the one from the last-loaded .def file). Find References and Rename still include all declarations. - add effective_def_locations(documents, target, uris) helper (returns the last declaration) - use effective_def_locations in lsp_server for goto/definition endpoints - change def_hover_markdown to show the effective declaration and append a short "_Overrides ..._" note listing overridden declarations - update changelog and add a test that verifies hover/GoTo reference the last loaded declaration while references include all declarations
This commit is contained in:
@@ -79,6 +79,13 @@ def def_definition_locations(
|
||||
]
|
||||
|
||||
|
||||
def effective_def_locations(
|
||||
documents: dict[str, DefDocument], target: DefTarget, uris: dict[str, str] | None = None
|
||||
) -> list[lsp.Location]:
|
||||
"""The declaration NX uses: ``documents`` follow the PSC layer order, the last one wins."""
|
||||
return def_definition_locations(documents, target, uris)[-1:]
|
||||
|
||||
|
||||
def def_reference_locations(
|
||||
documents: dict[str, DefDocument],
|
||||
target: DefTarget,
|
||||
@@ -170,6 +177,7 @@ def _address_table(declaration: DefDeclaration, formats: dict[str, DefDeclaratio
|
||||
|
||||
|
||||
def def_hover_markdown(documents: dict[str, DefDocument], target: DefTarget) -> str | None:
|
||||
"""Describe the effective (last loaded) declaration and name the ones it overrides."""
|
||||
declarations = def_declarations(documents, target)
|
||||
if not declarations:
|
||||
return None
|
||||
@@ -180,12 +188,14 @@ def def_hover_markdown(documents: dict[str, DefDocument], target: DefTarget) ->
|
||||
if declaration.kind == FORMAT
|
||||
}
|
||||
kind, name = target
|
||||
sections = []
|
||||
for path, declaration in declarations:
|
||||
header = f"**{_KIND_LABELS[kind]}** `{name}` — {Path(path).name}:{declaration.line + 1}"
|
||||
if kind == ADDRESS:
|
||||
body = _address_table(declaration, formats)
|
||||
else:
|
||||
body = f"```def\n{declaration.text}\n```"
|
||||
sections.append(f"{header}\n\n{body}")
|
||||
return "\n\n---\n\n".join(sections)
|
||||
path, declaration = declarations[-1]
|
||||
header = f"**{_KIND_LABELS[kind]}** `{name}` — {Path(path).name}:{declaration.line + 1}"
|
||||
if kind == ADDRESS:
|
||||
body = _address_table(declaration, formats)
|
||||
else:
|
||||
body = f"```def\n{declaration.text}\n```"
|
||||
markdown = f"{header}\n\n{body}"
|
||||
if len(declarations) > 1:
|
||||
overridden = ", ".join(f"{Path(other).name}:{item.line + 1}" for other, item in declarations[:-1])
|
||||
markdown += f"\n\n---\n\n_Overrides {overridden}_"
|
||||
return markdown
|
||||
|
||||
Reference in New Issue
Block a user