feat(inlay-hints): add configurable parameter name hints
Adds configurable inlay hints for TCL procedures and merges signatures from built-ins and workspace files. The feature supports parameterNames and suppressWhenArgumentMatchesName and respects an optional range filter and current-file priority. - Introduces built-in and custom inlay hint builders - Honors inlayHints parameterNames and suppression options - Adds tests validating hints, ranges, and priority rules
This commit is contained in:
@@ -44,7 +44,11 @@ from pygls import uris, workspace
|
||||
from common.load_data import standard_items
|
||||
from tools.folding_ranges import build_folding_ranges
|
||||
from tools.semantic_tokens import _Highlighter, TOKEN_TYPES, TokenModifier
|
||||
from tools.inlay_hint import InlayHintGenerator
|
||||
from tools.inlay_hint import (
|
||||
InlayHintGenerator,
|
||||
build_builtin_inlay_signatures,
|
||||
build_custom_inlay_signatures,
|
||||
)
|
||||
from tools.navigation import (
|
||||
SymbolIdentity,
|
||||
definition_identities,
|
||||
@@ -333,20 +337,43 @@ def document_symbols(params: lsp.DocumentSymbolParams):
|
||||
|
||||
@LSP_SERVER.feature(lsp.TEXT_DOCUMENT_INLAY_HINT)
|
||||
def inlay_hints(params: lsp.InlayHintParams):
|
||||
if not GLOBAL_SETTINGS.get("inlayHint", False):
|
||||
return []
|
||||
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
|
||||
settings = _get_settings_by_document(document)
|
||||
if not settings.get("inlayHint", False):
|
||||
return []
|
||||
|
||||
inlay_settings = settings.get("inlayHints", {})
|
||||
parameter_names = inlay_settings.get("parameterNames", "all")
|
||||
if parameter_names == "none":
|
||||
return []
|
||||
|
||||
# Reuse cached AST
|
||||
tree = LSP_SERVER.get_tree(document)
|
||||
|
||||
# Merge proc signatures across files and traverse once
|
||||
merged_signatures = {}
|
||||
_, proc_signatures, _ = LSP_SERVER.index_snapshot()
|
||||
for sigs in proc_signatures.values():
|
||||
merged_signatures.update(sigs)
|
||||
# Built-in NX procedures are the fallback. Workspace procedures replace them,
|
||||
# and a declaration in the current file wins over duplicate workspace names.
|
||||
signatures = build_builtin_inlay_signatures(
|
||||
standard_items.json_data.get("MOM_procs", [])
|
||||
)
|
||||
_, proc_signatures, proc_docs = LSP_SERVER.index_snapshot()
|
||||
signatures.update(
|
||||
build_custom_inlay_signatures(
|
||||
proc_signatures,
|
||||
proc_docs,
|
||||
LSP_SERVER.navigation_snapshot(),
|
||||
document.path,
|
||||
)
|
||||
)
|
||||
|
||||
generator = InlayHintGenerator(merged_signatures)
|
||||
generator = InlayHintGenerator(
|
||||
document.source,
|
||||
signatures,
|
||||
requested_range=params.range,
|
||||
parameter_names=parameter_names,
|
||||
suppress_when_argument_matches_name=inlay_settings.get(
|
||||
"suppressWhenArgumentMatchesName", True
|
||||
),
|
||||
)
|
||||
tree.accept(generator, recurse=True)
|
||||
return generator.hints
|
||||
|
||||
@@ -769,6 +796,13 @@ def _get_global_defaults():
|
||||
"showNotifications": GLOBAL_SETTINGS.get("showNotifications", "off"),
|
||||
"formatter": GLOBAL_SETTINGS.get("formatter", True),
|
||||
"inlayHint": GLOBAL_SETTINGS.get("inlayHint", True),
|
||||
"inlayHints": GLOBAL_SETTINGS.get(
|
||||
"inlayHints",
|
||||
{
|
||||
"parameterNames": "all",
|
||||
"suppressWhenArgumentMatchesName": True,
|
||||
},
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user