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
@@ -401,3 +401,62 @@ def test_call_hierarchy_item_uses_whole_proc_range(tmp_path: Path):
assert items[0].selection_range.start == lsp.Position(line=0, character=5)
assert items[0].range.start == lsp.Position(line=0, character=0)
assert items[0].range.end.line == 2
def test_document_highlight_marks_local_reads_and_writes(tmp_path: Path, monkeypatch):
source = """proc first {} {
set value 1
puts $value
incr value
}
proc second {} {
set value 2
puts $value
}
"""
document = _document(tmp_path / "highlights.tcl", source)
server = TclLanguageServer(name="highlight-test", version="1", max_workers=1)
assert server.update_poco_completion_for_file(document)
monkeypatch.setattr(lsp_server, "LSP_SERVER", server)
position = _position(source, "$value")
highlights = lsp_server.document_highlight(
lsp.DocumentHighlightParams(
text_document=lsp.TextDocumentIdentifier(uri=document.uri),
position=lsp.Position(position.line, position.character + 1),
)
)
assert len(highlights) == 3
assert [highlight.kind for highlight in highlights] == [
lsp.DocumentHighlightKind.Write,
lsp.DocumentHighlightKind.Read,
lsp.DocumentHighlightKind.Write,
]
assert all(_range_text(source, highlight.range) == "value" for highlight in highlights)
def test_document_highlight_marks_proc_definition_and_calls(tmp_path: Path, monkeypatch):
source = """proc target {} { return }
proc caller {} {
target
target
}
"""
document = _document(tmp_path / "proc_highlights.tcl", source)
server = TclLanguageServer(name="highlight-test", version="1", max_workers=1)
assert server.update_poco_completion_for_file(document)
monkeypatch.setattr(lsp_server, "LSP_SERVER", server)
highlights = lsp_server.document_highlight(
lsp.DocumentHighlightParams(
text_document=lsp.TextDocumentIdentifier(uri=document.uri),
position=_position(source, "target"),
)
)
assert len(highlights) == 3
assert all(
highlight.kind == lsp.DocumentHighlightKind.Text
for highlight in highlights
)