## Summary ### Preamble completeness check - `is_preamble_complete()` in `scan.cpp`: checks whether `#include`/`import`/`export module` directives in the preamble region are syntactically complete (have closing `>`/`"`/`;`) - `ensure_pch` defers PCH rebuild when preamble is incomplete (user still typing), reuses old PCH instead of failing ### #include / import completion - Master intercepts completion requests in `#include "..."` / `#include <...>` / `import ...` contexts before forwarding to worker - `complete_include()`: searches include paths (from compile args via `SearchConfig`) using `DirListingCache`, supports quoted/angled/multi-level paths - `complete_import()`: filters `path_to_module` map by prefix - Word boundary checks prevent false matches (e.g. `important` not treated as `import`) ### Detached compile task (rapid-edit fix) - Compile operations (`ensure_deps` + `send_stateful` + `publish_diagnostics`) run as detached tasks via `loop.schedule()`, independent of the LSP request coroutine chain - LSP `$/cancelRequest` can no longer kill in-flight compilations — previously, cancellation would destroy the `ensure_compiled` coroutine frame, leaving `doc.compiling` permanently set and hanging all subsequent requests - `CompileGuard` RAII ensures `doc.compiling` is always cleaned up even if the detached task fails - Stale feature requests (where `ast_dirty` became true after compile finished) are dropped before forwarding to worker ### Other fixes - `signal(SIGPIPE, SIG_IGN)` on POSIX: prevents server crash when LSP client disconnects mid-write - `CompilationUnitRef::file_path()` / `deps()`: null-check `FileEntryRef` to prevent segfault on invalid FileID - `stateless_worker.cpp`: log BuildPCH diagnostic errors for debuggability - Default worker counts changed to 2 stateful + 3 stateless - `logging_dir` default changed to `.clice/logs` in config ### Tests - 19 unit tests for `is_preamble_complete` (incomplete `#include`, `import`, `export module`, mixed cases) - Integration tests: `test_include_completion.py` (5 tests), `test_import_completion.py` (4 tests), `test_rapid_edit.py` (2 tests), `test_pch.py` (4 new tests) - Smoke test: `rapid_edit.jsonl` — recorded VSCode session with 40 rapid edits + 61 cancel requests ## Test plan - [x] Unit tests: 463 passed - [x] Integration tests: 104 passed - [x] Smoke test (rapid_edit.jsonl): PASS - [x] Manual VSCode testing with `#include <iostream>` project 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
166 lines
5.8 KiB
Python
166 lines
5.8 KiB
Python
"""Integration tests for #include completion in clice."""
|
|
|
|
import pytest
|
|
from lsprotocol.types import (
|
|
CompletionParams,
|
|
DidChangeTextDocumentParams,
|
|
DidCloseTextDocumentParams,
|
|
Position,
|
|
TextDocumentContentChangeWholeDocument,
|
|
TextDocumentIdentifier,
|
|
VersionedTextDocumentIdentifier,
|
|
)
|
|
|
|
|
|
def _doc(uri: str) -> TextDocumentIdentifier:
|
|
return TextDocumentIdentifier(uri=uri)
|
|
|
|
|
|
@pytest.mark.workspace("include_completion")
|
|
async def test_include_completion_quoted(client, workspace):
|
|
"""Completion after #include " should list local headers."""
|
|
uri, _ = await client.open_and_wait(workspace / "main.cpp")
|
|
|
|
# Update content to trigger include completion for "my" prefix.
|
|
client.text_document_did_change(
|
|
DidChangeTextDocumentParams(
|
|
text_document=VersionedTextDocumentIdentifier(uri=uri, version=1),
|
|
content_changes=[
|
|
TextDocumentContentChangeWholeDocument(text='#include "my')
|
|
],
|
|
)
|
|
)
|
|
|
|
result = await client.text_document_completion_async(
|
|
CompletionParams(
|
|
text_document=_doc(uri),
|
|
position=Position(line=0, character=12), # After "my"
|
|
)
|
|
)
|
|
|
|
assert result is not None
|
|
items = result.items if hasattr(result, "items") else result
|
|
labels = [item.label for item in items]
|
|
assert "myheader.h" in labels
|
|
|
|
client.text_document_did_close(DidCloseTextDocumentParams(text_document=_doc(uri)))
|
|
|
|
|
|
@pytest.mark.workspace("include_completion")
|
|
async def test_include_completion_subdirectory(client, workspace):
|
|
"""Completion for #include "subdir/ should list files in subdir."""
|
|
uri, _ = await client.open_and_wait(workspace / "main.cpp")
|
|
|
|
client.text_document_did_change(
|
|
DidChangeTextDocumentParams(
|
|
text_document=VersionedTextDocumentIdentifier(uri=uri, version=1),
|
|
content_changes=[
|
|
TextDocumentContentChangeWholeDocument(text='#include "subdir/')
|
|
],
|
|
)
|
|
)
|
|
|
|
result = await client.text_document_completion_async(
|
|
CompletionParams(
|
|
text_document=_doc(uri),
|
|
position=Position(line=0, character=17), # After "subdir/"
|
|
)
|
|
)
|
|
|
|
assert result is not None
|
|
items = result.items if hasattr(result, "items") else result
|
|
labels = [item.label for item in items]
|
|
assert "nested.h" in labels
|
|
|
|
client.text_document_did_close(DidCloseTextDocumentParams(text_document=_doc(uri)))
|
|
|
|
|
|
@pytest.mark.workspace("include_completion")
|
|
async def test_include_completion_angle_bracket(client, workspace):
|
|
"""Completion after #include < should list system headers."""
|
|
uri, _ = await client.open_and_wait(workspace / "main.cpp")
|
|
|
|
client.text_document_did_change(
|
|
DidChangeTextDocumentParams(
|
|
text_document=VersionedTextDocumentIdentifier(uri=uri, version=1),
|
|
content_changes=[
|
|
TextDocumentContentChangeWholeDocument(text="#include <cstd")
|
|
],
|
|
)
|
|
)
|
|
|
|
result = await client.text_document_completion_async(
|
|
CompletionParams(
|
|
text_document=_doc(uri),
|
|
position=Position(line=0, character=14), # After "cstd"
|
|
)
|
|
)
|
|
|
|
assert result is not None
|
|
items = result.items if hasattr(result, "items") else result
|
|
labels = [item.label for item in items]
|
|
# Should contain at least some standard library headers starting with "cstd".
|
|
cstd_labels = [name for name in labels if name.startswith("cstd")]
|
|
assert len(cstd_labels) > 0, f"Expected cstd* headers, got: {labels}"
|
|
|
|
client.text_document_did_close(DidCloseTextDocumentParams(text_document=_doc(uri)))
|
|
|
|
|
|
@pytest.mark.workspace("include_completion")
|
|
async def test_no_include_completion_on_regular_code(client, workspace):
|
|
"""Regular code should NOT trigger include completion (goes to worker)."""
|
|
uri, _ = await client.open_and_wait(workspace / "main.cpp")
|
|
|
|
client.text_document_did_change(
|
|
DidChangeTextDocumentParams(
|
|
text_document=VersionedTextDocumentIdentifier(uri=uri, version=1),
|
|
content_changes=[TextDocumentContentChangeWholeDocument(text="int x = ")],
|
|
)
|
|
)
|
|
|
|
result = await client.text_document_completion_async(
|
|
CompletionParams(
|
|
text_document=_doc(uri),
|
|
position=Position(line=0, character=8),
|
|
)
|
|
)
|
|
|
|
# Should return results from clang (keywords, etc.), not include paths.
|
|
# Verify none of the results look like header filenames.
|
|
assert result is not None
|
|
items = result.items if hasattr(result, "items") else result
|
|
labels = [item.label for item in items]
|
|
assert "myheader.h" not in labels
|
|
assert "nested.h" not in labels
|
|
|
|
client.text_document_did_close(DidCloseTextDocumentParams(text_document=_doc(uri)))
|
|
|
|
|
|
@pytest.mark.workspace("include_completion")
|
|
async def test_include_completion_empty_prefix(client, workspace):
|
|
"""Completion after #include " with no prefix should list all local headers."""
|
|
uri, _ = await client.open_and_wait(workspace / "main.cpp")
|
|
|
|
client.text_document_did_change(
|
|
DidChangeTextDocumentParams(
|
|
text_document=VersionedTextDocumentIdentifier(uri=uri, version=1),
|
|
content_changes=[TextDocumentContentChangeWholeDocument(text='#include "')],
|
|
)
|
|
)
|
|
|
|
result = await client.text_document_completion_async(
|
|
CompletionParams(
|
|
text_document=_doc(uri),
|
|
position=Position(line=0, character=10), # Right after the quote
|
|
)
|
|
)
|
|
|
|
assert result is not None
|
|
items = result.items if hasattr(result, "items") else result
|
|
labels = [item.label for item in items]
|
|
# With empty prefix, should list available headers including myheader.h
|
|
# and the subdir/ directory entry.
|
|
assert "myheader.h" in labels
|
|
|
|
client.text_document_did_close(DidCloseTextDocumentParams(text_document=_doc(uri)))
|