feat(lsp): add context-aware completion ranking and document highlights

Adds context-aware completion ranking and document highlights for Tcl.
Adds completion_context to distinguish variables and commands.
Wires per-file completion snapshots and ranking into the flow.
Adds document_highlight provider support and tests for highlights.

- Context-aware ranking of completion items using per-file snapshots
- Document highlight provider wired into initialization and tests
- Tests for completion context, ranking, and document highlights
This commit is contained in:
Christoph Brandau
2026-09-03 09:19:50 +02:00
parent 41d117fe2c
commit 89add18273
8 changed files with 421 additions and 44 deletions
+31
View File
@@ -522,6 +522,37 @@ def matching_occurrences(
return matches
def document_highlights(
index: FileSymbolIndex,
identity: SymbolIdentity,
definitions: set[SymbolIdentity],
) -> list[lsp.DocumentHighlight]:
"""Return all occurrences of one symbol in the active document."""
highlights = []
for occurrence in index.occurrences:
if resolve_identity(occurrence, definitions) != identity:
continue
kind = lsp.DocumentHighlightKind.Text
if identity.kind == "variable":
kind = (
lsp.DocumentHighlightKind.Write
if occurrence.is_definition
else lsp.DocumentHighlightKind.Read
)
highlights.append(lsp.DocumentHighlight(range=occurrence.range, kind=kind))
return sorted(
highlights,
key=lambda highlight: (
highlight.range.start.line,
highlight.range.start.character,
highlight.range.end.line,
highlight.range.end.character,
),
)
def workspace_symbols(
indexes: dict[str, FileSymbolIndex], query: str
) -> list[lsp.SymbolInformation]: