feat: smart PCH rebuild, #include/import completion, rapid-edit robustness (#394)
## 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>
This commit is contained in:
@@ -289,5 +289,135 @@ int x;
|
||||
|
||||
}; // TEST_SUITE(PreambleBound)
|
||||
|
||||
TEST_SUITE(PreambleComplete) {
|
||||
|
||||
// --- #include completeness ---
|
||||
|
||||
TEST_CASE(CompleteQuotedInclude) {
|
||||
llvm::StringRef content = "#include \"foo.h\"\nint x;";
|
||||
auto bound = compute_preamble_bound(content);
|
||||
EXPECT_TRUE(is_preamble_complete(content, bound));
|
||||
}
|
||||
|
||||
TEST_CASE(CompleteAngledInclude) {
|
||||
llvm::StringRef content = "#include <vector>\nint x;";
|
||||
auto bound = compute_preamble_bound(content);
|
||||
EXPECT_TRUE(is_preamble_complete(content, bound));
|
||||
}
|
||||
|
||||
TEST_CASE(IncompleteQuotedInclude) {
|
||||
llvm::StringRef content = "#include \"foo\nint x;";
|
||||
auto bound = compute_preamble_bound(content);
|
||||
EXPECT_FALSE(is_preamble_complete(content, bound));
|
||||
}
|
||||
|
||||
TEST_CASE(IncompleteAngledInclude) {
|
||||
llvm::StringRef content = "#include <sys/\nint x;";
|
||||
auto bound = compute_preamble_bound(content);
|
||||
EXPECT_FALSE(is_preamble_complete(content, bound));
|
||||
}
|
||||
|
||||
TEST_CASE(IncludeWithNoPath) {
|
||||
llvm::StringRef content = "#include \nint x;";
|
||||
auto bound = compute_preamble_bound(content);
|
||||
EXPECT_FALSE(is_preamble_complete(content, bound));
|
||||
}
|
||||
|
||||
TEST_CASE(IncludeMacroUsage) {
|
||||
llvm::StringRef content = "#include FOO\nint x;";
|
||||
auto bound = compute_preamble_bound(content);
|
||||
EXPECT_TRUE(is_preamble_complete(content, bound));
|
||||
}
|
||||
|
||||
TEST_CASE(MultipleIncludesAllComplete) {
|
||||
llvm::StringRef content = "#include <vector>\n#include \"foo.h\"\nint x;";
|
||||
auto bound = compute_preamble_bound(content);
|
||||
EXPECT_TRUE(is_preamble_complete(content, bound));
|
||||
}
|
||||
|
||||
TEST_CASE(MultipleIncludesLastIncomplete) {
|
||||
llvm::StringRef content = "#include <vector>\n#include \"foo\nint x;";
|
||||
auto bound = compute_preamble_bound(content);
|
||||
EXPECT_FALSE(is_preamble_complete(content, bound));
|
||||
}
|
||||
|
||||
// --- C++20 module statements ---
|
||||
// Note: compute_preamble_bound does not include import/export lines in its
|
||||
// bound, so we pass manual bounds covering the relevant lines.
|
||||
|
||||
TEST_CASE(CompleteImport) {
|
||||
llvm::StringRef content = "import std;\nint x;";
|
||||
// Bound covers "import std;\n".
|
||||
EXPECT_TRUE(is_preamble_complete(content, 12));
|
||||
}
|
||||
|
||||
TEST_CASE(ImportMissingSemicolon) {
|
||||
llvm::StringRef content = "import std\nint x;";
|
||||
// Bound covers "import std\n".
|
||||
EXPECT_FALSE(is_preamble_complete(content, 11));
|
||||
}
|
||||
|
||||
TEST_CASE(ImportWithNothing) {
|
||||
llvm::StringRef content = "import \nint x;";
|
||||
// Bound covers "import \n".
|
||||
EXPECT_FALSE(is_preamble_complete(content, 8));
|
||||
}
|
||||
|
||||
TEST_CASE(CompleteExportModule) {
|
||||
llvm::StringRef content = "export module foo;\nint x;";
|
||||
// Bound covers "export module foo;\n".
|
||||
EXPECT_TRUE(is_preamble_complete(content, 19));
|
||||
}
|
||||
|
||||
TEST_CASE(ExportModuleMissingSemicolon) {
|
||||
llvm::StringRef content = "export module foo\nint x;";
|
||||
// Bound covers "export module foo\n".
|
||||
EXPECT_FALSE(is_preamble_complete(content, 18));
|
||||
}
|
||||
|
||||
TEST_CASE(CompleteExportImport) {
|
||||
llvm::StringRef content = "export import std;\nint x;";
|
||||
// Bound covers "export import std;\n".
|
||||
EXPECT_TRUE(is_preamble_complete(content, 19));
|
||||
}
|
||||
|
||||
// --- Edge cases ---
|
||||
|
||||
TEST_CASE(EmptyPreamble) {
|
||||
llvm::StringRef content = "int x;";
|
||||
EXPECT_TRUE(is_preamble_complete(content, 0));
|
||||
}
|
||||
|
||||
TEST_CASE(NonImportIncludeLinesIgnored) {
|
||||
llvm::StringRef content = "#define FOO 1\n#ifdef BAR\n#endif\nint x;";
|
||||
auto bound = compute_preamble_bound(content);
|
||||
EXPECT_TRUE(is_preamble_complete(content, bound));
|
||||
}
|
||||
|
||||
TEST_CASE(ImportantDoesNotMatchImport) {
|
||||
// "important" starts with "import" but should NOT be treated as an import.
|
||||
llvm::StringRef content = "#include <vector>\nint x;";
|
||||
auto bound = compute_preamble_bound(content);
|
||||
// Manually test with content that has "important" within the preamble region.
|
||||
// Since compute_preamble_bound won't include non-directive lines, we test
|
||||
// is_preamble_complete directly with a crafted bound.
|
||||
llvm::StringRef crafted = "important = 1;\n";
|
||||
EXPECT_TRUE(is_preamble_complete(crafted, crafted.size()));
|
||||
}
|
||||
|
||||
TEST_CASE(PreprocessorDirectivesIgnored) {
|
||||
llvm::StringRef content = "#ifdef FOO\n#define BAR 1\n#endif\nint x;";
|
||||
auto bound = compute_preamble_bound(content);
|
||||
EXPECT_TRUE(is_preamble_complete(content, bound));
|
||||
}
|
||||
|
||||
TEST_CASE(MixedIncludeAndImportAllComplete) {
|
||||
llvm::StringRef content = "#include <vector>\nimport std;\nint x;";
|
||||
auto bound = compute_preamble_bound(content);
|
||||
EXPECT_TRUE(is_preamble_complete(content, bound));
|
||||
}
|
||||
|
||||
}; // TEST_SUITE(PreambleComplete)
|
||||
|
||||
} // namespace
|
||||
} // namespace clice::testing
|
||||
|
||||
Reference in New Issue
Block a user