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:
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user