diff --git a/CMakeLists.txt b/CMakeLists.txt index c783b1c..2a0537f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ add_library(vls_protocol STATIC src/Protocol/Framing.cpp src/Protocol/Json.cpp src/Build/ProviderFile.cpp src/Build/CommandImport.cpp src/Build/VbsProvider.cpp src/Build/CompdbProvider.cpp src/DocumentSync.cpp src/WorkspaceSession.cpp src/Server.cpp src/semantic/Diagnostics.cpp src/semantic/SourceCatalog.cpp src/semantic/StockCompiler.cpp src/semantic/EditorDiagnostics.cpp src/semantic/Occurrences.cpp src/scheduler/Scheduler.cpp - src/modules/ModuleGraph.cpp src/modules/ArtifactCache.cpp src/modules/GccArtifacts.cpp src/modules/ScheduledArtifacts.cpp src/index/SymbolIndex.cpp src/navigation/Navigation.cpp src/reflection/Provenance.cpp src/features/Completion.cpp src/features/IndexNavigation.cpp src/features/SignatureHelp.cpp src/features/DocumentSymbols.cpp src/features/TextStructure.cpp src/features/CodeActions.cpp src/features/SemanticTokens.cpp src/features/InlayHints.cpp src/features/FileOperations.cpp src/features/IncludeUpdate.cpp src/features/CallHierarchy.cpp src/features/CodeLens.cpp src/features/DocumentLinks.cpp src/features/Formatting.cpp src/features/TypeHierarchy.cpp src/features/Outline.cpp src/debug/live/LiveSession.cpp src/modules/ModuleWorkQueue.cpp src/modules/GccScan.cpp src/modules/ScanCommand.cpp) + src/modules/ModuleGraph.cpp src/modules/ArtifactCache.cpp src/modules/GccArtifacts.cpp src/modules/ScheduledArtifacts.cpp src/index/SymbolIndex.cpp src/navigation/Navigation.cpp src/reflection/Provenance.cpp src/features/Completion.cpp src/features/IndexNavigation.cpp src/features/SignatureHelp.cpp src/features/DocumentSymbols.cpp src/features/TextStructure.cpp src/features/CodeActions.cpp src/features/SemanticTokens.cpp src/features/InlayHints.cpp src/features/FileOperations.cpp src/features/IncludeUpdate.cpp src/features/CallHierarchy.cpp src/features/CodeLens.cpp src/features/DocumentLinks.cpp src/features/Formatting.cpp src/features/TypeHierarchy.cpp src/features/Outline.cpp src/features/CompletionSource.cpp src/debug/live/LiveSession.cpp src/modules/ModuleWorkQueue.cpp src/modules/GccScan.cpp src/modules/ScanCommand.cpp) target_include_directories(vls_protocol PUBLIC "${PROJECT_SOURCE_DIR}/include") target_link_libraries(vls_protocol PUBLIC Void::Data PRIVATE Void::Unicode Void::Text Void::Crypto Void::System) target_compile_options(vls_protocol PUBLIC -freflection PRIVATE -Wall -Wextra -Wpedantic) diff --git a/build.cpp b/build.cpp index 96f3509..24e94a8 100644 --- a/build.cpp +++ b/build.cpp @@ -82,6 +82,7 @@ void build(Void::Build::Project &project) { "src/features/Formatting.cpp", "src/features/TypeHierarchy.cpp", "src/features/Outline.cpp", + "src/features/CompletionSource.cpp", "src/debug/live/LiveSession.cpp", "src/modules/ModuleWorkQueue.cpp", "src/modules/GccScan.cpp", @@ -166,7 +167,8 @@ void build(Void::Build::Project &project) { "tests/features/FileOperationsTests.cpp", "tests/features/IncludeUpdateTests.cpp", "tests/features/CallHierarchyTests.cpp", "tests/features/CodeLensTests.cpp", "tests/features/DocumentLinksTests.cpp", "tests/features/FormattingTests.cpp", - "tests/features/TypeHierarchyTests.cpp", "tests/features/OutlineTests.cpp"}); + "tests/features/TypeHierarchyTests.cpp", "tests/features/OutlineTests.cpp", + "tests/features/CompletionSourceTests.cpp"}); auto live_worker = project.executable("vls_live_worker_fixture"); live_worker.cxx_standard(CxxStandard::Cxx26) .sources({"tests/debug/LiveWorkerFixture.cpp"}) diff --git a/docs/agent-workflow/LSP-PARITY.md b/docs/agent-workflow/LSP-PARITY.md index 672dc23..4be1e26 100644 --- a/docs/agent-workflow/LSP-PARITY.md +++ b/docs/agent-workflow/LSP-PARITY.md @@ -35,7 +35,7 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints. | Capability | Notes | | --- | --- | -| Compiler-native completion with visibility proof | not pursued through a custom compiler (D-032); generic completion remains index-backed and incomplete | +| Compiler-native completion with visibility proof | provided through the compiler-agnostic `--completion-index` interface (D-032); visibility proof is the producer's claim. The built-in index-backed completion remains incomplete without it. | | Overload-set signature help | observed overloads are listed with the compiler-selected one first; visibility and overload resolution are not proven | | textDocument/formatting | needs a plan | | callHierarchy / typeHierarchy | prepare, incomingCalls and outgoingCalls are implemented and served; outgoing calls are verified over stdio now that the observer reports full function extents. Type hierarchy is open. | diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 630cd8e..98e84e0 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -62,7 +62,7 @@ suite covers stepping, inspection per generation, continue, cancel, refusal without a stop, malformed output and the deadline, and a real DAP transcript test drives the adapter end to end. -Completion is now served: `textDocument/completion` is advertised and answered from the symbol index through `EditorDiagnostics::completion`, with a bounded ranking core in `include/vls/features/` and registered `vls_feature_tests`. Results are explicitly incomplete because the index does not prove visibility; compiler-native completion, deferred detail resolution and signature help remain open. +A compiler-agnostic completion index (`--completion-index`) can supply proven candidates merged ahead of index-backed ones. Completion is now served: `textDocument/completion` is advertised and answered from the symbol index through `EditorDiagnostics::completion`, with a bounded ranking core in `include/vls/features/` and registered `vls_feature_tests`. Results are explicitly incomplete because the index does not prove visibility; compiler-native completion, deferred detail resolution and signature help remain open. Index-backed rename coverage is now merged into the navigation fact set (`vls/features/IndexNavigation.hpp`): persisted index contexts and records join the set with the index's completeness, existing compiler-derived facts win, and records without a known current content identity stay non-editable so rename refuses them. Multi-file rename can therefore be ready from real index data when a transactional client is present, proven by registered `vls_feature_tests` cases. diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index e96f612..39f5bfd 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -61,6 +61,25 @@ start coordinate only, so ranges are zero-width until an end is available. LSP adapters and index/rename/debugging integration remain open. `vbs test` passed all 17 native suites; CMake passed the reflection and trace suites. +## December 6 compiler-agnostic completion source + +Per D-032, completion can now consume a documented, compiler-agnostic index +(`--completion-index PATH`) produced by any external tool: +`{"schema":1,"scopes":[{"path","startLine","startCharacter","endLine", +"endCharacter","complete","items":[{"label","kind?","detail?","insertText?"}]}]}` +with the producer's visibility claim carried through unchanged. The bounded +core (`vls/features/CompletionSource.hpp`) parses and selects the innermost +covering scope; the server merges its candidates ahead of index-backed ones and +sets `isIncomplete` from the scope's `complete` flag. Registered +`vls_feature_tests` grew to 115 cases. + +Real stdio session: +``` +inside scope: isIncomplete = False items = ['alpha', 'beta', 'main'] +outside scope: isIncomplete = True +``` +All 18 native suites and all 18 CMake tests passed. + ## December 6 locality ranking in completion Completion candidates now carry whether they are declared in the requesting diff --git a/include/vls/Server.hpp b/include/vls/Server.hpp index f2b11af..297db85 100644 --- a/include/vls/Server.hpp +++ b/include/vls/Server.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -37,6 +38,7 @@ class Server { WorkspaceSession workspace_; std::unique_ptr diagnostics_; std::shared_ptr reflection_; + std::vector completion_scopes_; }; // Thin transport loop shared by the executable and stream-failure unit tests. diff --git a/include/vls/WorkspaceSession.hpp b/include/vls/WorkspaceSession.hpp index 63083ed..01620e2 100644 --- a/include/vls/WorkspaceSession.hpp +++ b/include/vls/WorkspaceSession.hpp @@ -24,6 +24,8 @@ struct WorkspaceLaunch { std::shared_ptr diagnostics_profile{}; // Versioned reflection provenance snapshot served as read-only hover. std::optional reflection_snapshot; + // A compiler-agnostic completion index produced outside VLS. + std::optional completion_index; }; struct SemanticDriver { diff --git a/include/vls/features/CompletionSource.hpp b/include/vls/features/CompletionSource.hpp new file mode 100644 index 0000000..1fbd3c5 --- /dev/null +++ b/include/vls/features/CompletionSource.hpp @@ -0,0 +1,59 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace vls::features::completion_source { + +// Positions are LSP positions in the document's negotiated encoding, so any +// producer can write them without knowing VLS internals. +struct Position { + std::uint32_t line{}, character{}; + auto operator<=>(const Position &) const = default; +}; + +struct Provided { + std::string label; + std::int64_t kind{1}; + std::string detail; + std::string insert_text; + auto operator<=>(const Provided &) const = default; +}; + +// One compiler-produced completion point: a position range with the +// candidates visible there. COMPLETE means the producer proved the list is +// exhaustive for the range (visibility proof is the producer's claim, carried +// through unchanged). +struct Scope { + std::string path; + Position start, end; + bool complete{}; + std::vector items; +}; + +struct Limits { + std::size_t scopes{1024}; + std::size_t items{4096}; + std::size_t itemsPerScope{256}; + std::size_t pathBytes{4096}; + std::size_t textBytes{1024}; + std::size_t fileBytes{8 * 1024 * 1024}; +}; + +// Parses the versioned completion index: +// {"schema":1,"scopes":[{"path":...,"startLine":..,"startCharacter":.., +// "endLine":..,"endCharacter":..,"complete":bool, +// "items":[{"label":..,"kind":int?,"detail":?,"insertText":?}]}]} +[[nodiscard]] std::expected, std::string> parse(std::string_view bytes, + const Limits & = Limits{}); + +// The innermost scope covering the position, or null. +[[nodiscard]] const Scope *at(const std::vector &, std::string_view path, Position); + +} // namespace vls::features::completion_source diff --git a/src/Server.cpp b/src/Server.cpp index 7e8c1bb..e546e58 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -136,6 +136,15 @@ DispatchResult error(const Json &id, std::int64_t code, std::string_view message } // namespace Server::Server(WorkspaceLaunch launch, std::function send) : workspace_(launch) { + if (launch.completion_index) { + std::ifstream stream{*launch.completion_index, std::ios::binary}; + std::string bytes{std::istreambuf_iterator{stream}, {}}; + if (!bytes.empty()) { + auto parsed = features::completion_source::parse(bytes); + if (parsed) + completion_scopes_ = std::move(*parsed); + } + } if (launch.reflection_snapshot) { std::ifstream stream{*launch.reflection_snapshot, std::ios::binary}; std::string bytes{std::istreambuf_iterator{stream}, {}}; @@ -733,10 +742,33 @@ DispatchResult Server::handle(std::string_view body) { *line_value > Void::LanguageServer::Documents::kMaxPositionValue || *character_value > Void::LanguageServer::Documents::kMaxPositionValue) return error(id, -32602, "Expected textDocument.uri and a bounded position"); - return reply( - id, "result", - diagnostics_->completion(*uri, {static_cast(*line_value), - static_cast(*character_value)})); + const Void::LanguageServer::Documents::Position selected{ + static_cast(*line_value), static_cast(*character_value)}; + auto result = diagnostics_->completion(*uri, selected); + const auto identity = Void::LanguageServer::Documents::normalize_uri(*uri); + if (!completion_scopes_.empty() && identity && identity->is_file_uri) { + if (const auto *scope = features::completion_source::at( + completion_scopes_, identity->canonical_path.native(), + {selected.line, selected.character})) { + auto &fields = std::get(result.value); + Json::Array merged; + for (const auto &provided : scope->items) { + Json::Object item{{"label", Json{provided.label}}, + {"kind", Json{provided.kind}}}; + if (!provided.detail.empty()) + item.emplace("detail", Json{provided.detail}); + if (!provided.insert_text.empty()) + item.emplace("insertText", Json{provided.insert_text}); + merged.push_back(Json{std::move(item)}); + } + if (const auto *existing = as_array(find_member(fields, "items"))) + for (const auto &entry : *existing) + merged.push_back(entry); + fields.insert_or_assign("items", Json{std::move(merged)}); + fields.insert_or_assign("isIncomplete", Json{!scope->complete}); + } + } + return reply(id, "result", std::move(result)); } if (*method == "textDocument/references" || *method == "textDocument/prepareRename" || *method == "textDocument/rename") { diff --git a/src/features/CompletionSource.cpp b/src/features/CompletionSource.cpp new file mode 100644 index 0000000..6d37387 --- /dev/null +++ b/src/features/CompletionSource.cpp @@ -0,0 +1,115 @@ +#include + +#include + +#include + +namespace vls::features::completion_source { +namespace P = Void::LanguageServer::Protocol; +using Json = P::Json; + +namespace { +std::optional coordinate(const Json *value) { + if (!value) + return std::nullopt; + const auto *number = std::get_if(&value->value); + if (!number || *number < 0) + return std::nullopt; + return static_cast(*number); +} + +std::optional text(const Json *value, std::size_t limit) { + const auto *string = value ? P::as_string(value) : nullptr; + if (!string || string->empty() || string->size() > limit || + string->find('\0') != std::string::npos) + return std::nullopt; + return *string; +} +} // namespace + +std::expected, std::string> parse(std::string_view bytes, const Limits &limits) { + if (bytes.size() > limits.fileBytes) + return std::unexpected("completion index exceeds its byte bound"); + auto parsed = P::parse_json(bytes, 16); + if (!parsed) + return std::unexpected("completion index is not valid JSON"); + const auto *root = P::as_object(&*parsed); + if (!root || root->size() != 2) + return std::unexpected("completion index is not an object"); + const auto schema = P::as_int64(P::find_member(*root, "schema")); + const auto *scopes = P::as_array(P::find_member(*root, "scopes")); + if (!schema || *schema != 1 || !scopes || scopes->size() > limits.scopes) + return std::unexpected("unsupported completion index"); + std::vector result; + for (const auto &item : *scopes) { + const auto *fields = P::as_object(&item); + if (!fields) + return std::unexpected("completion scope is not an object"); + const auto path = text(P::find_member(*fields, "path"), limits.pathBytes); + const auto start_line = coordinate(P::find_member(*fields, "startLine")); + const auto start_character = coordinate(P::find_member(*fields, "startCharacter")); + const auto end_line = coordinate(P::find_member(*fields, "endLine")); + const auto end_character = coordinate(P::find_member(*fields, "endCharacter")); + const auto complete = P::as_bool(P::find_member(*fields, "complete")); + const auto *items = P::as_array(P::find_member(*fields, "items")); + if (!path || !start_line || !start_character || !end_line || !end_character || !complete || + !items || items->size() > limits.itemsPerScope) + return std::unexpected("completion scope is incomplete"); + Scope scope{ + *path, {*start_line, *start_character}, {*end_line, *end_character}, *complete, {}}; + if (scope.end < scope.start) + return std::unexpected("completion scope range is reversed"); + for (const auto &entry : *items) { + if (result.size() + scope.items.size() >= limits.items) + return std::unexpected("completion index exceeds its item bound"); + const auto *candidate = P::as_object(&entry); + const auto label = candidate + ? text(P::find_member(*candidate, "label"), limits.textBytes) + : std::nullopt; + if (!label) + return std::unexpected("completion item lacks a label"); + Provided provided{*label, 1, {}, {}}; + if (const auto *kind = P::find_member(*candidate, "kind")) { + const auto *number = std::get_if(&kind->value); + if (!number || *number < 1 || *number > 26) + return std::unexpected("completion item kind is invalid"); + provided.kind = *number; + } + if (const auto *detail = P::find_member(*candidate, "detail")) { + auto value = text(detail, limits.textBytes); + if (!value) + return std::unexpected("completion item detail is invalid"); + provided.detail = std::move(*value); + } + if (const auto *insert = P::find_member(*candidate, "insertText")) { + auto value = text(insert, limits.textBytes); + if (!value) + return std::unexpected("completion item insertText is invalid"); + provided.insert_text = std::move(*value); + } + scope.items.push_back(std::move(provided)); + } + result.push_back(std::move(scope)); + } + return result; +} + +namespace { +std::uint64_t span_size(const Scope &scope) { + return (static_cast(scope.end.line) - scope.start.line) * 1'000'000 + + (static_cast(scope.end.character) - scope.start.character); +} +} // namespace + +const Scope *at(const std::vector &scopes, std::string_view path, Position position) { + const Scope *best{}; + for (const auto &scope : scopes) { + if (scope.path != path || position < scope.start || scope.end < position) + continue; + if (!best || span_size(scope) < span_size(*best)) + best = &scope; + } + return best; +} + +} // namespace vls::features::completion_source diff --git a/src/main.cpp b/src/main.cpp index 6686c9c..d4a6095 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,7 @@ namespace Workspace = Void::LanguageServer::Workspace; struct Options { std::optional root, user_file, provider, database, selector, build_root, - producer_cwd, profile, gcc_profile, reflection_snapshot; + producer_cwd, profile, gcc_profile, reflection_snapshot, completion_index; bool gcc_diagnostics{}; }; @@ -24,7 +24,7 @@ std::expected workspace_launch(const Options if (!options.root) { if (options.user_file || options.provider || options.database || options.selector || options.build_root || options.producer_cwd || options.profile || options.gcc_profile || - options.gcc_diagnostics || options.reflection_snapshot) + options.gcc_diagnostics || options.reflection_snapshot || options.completion_index) return std::unexpected{"workspace options require --workspace-root"}; return launch; } @@ -58,6 +58,13 @@ std::expected workspace_launch(const Options return std::unexpected{!build ? build.error() : producer.error()}; launch.build_root = std::move(*build); launch.producer_cwd = std::move(*producer); + if (options.completion_index) { + const fs::path selected{*options.completion_index}; + std::error_code index_error; + if (!selected.is_absolute() || !fs::is_regular_file(selected, index_error)) + return std::unexpected{"--completion-index requires an existing absolute file"}; + launch.completion_index = selected; + } if (options.reflection_snapshot) { const fs::path snapshot{*options.reflection_snapshot}; std::error_code snapshot_error; @@ -131,6 +138,9 @@ int main(int argc, char **argv) { "--gcc-profile", "", "enable stock GCC diagnostics for this workspace using an absolute prepared profile", options.gcc_profile); + parser.option("--completion-index", "", + "compiler-agnostic completion index served ahead of index candidates", + options.completion_index); parser.option("--reflection-snapshot", "", "versioned reflection provenance snapshot served as read-only hover", options.reflection_snapshot); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c36861d..4ad0156 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,7 +22,7 @@ vls_test_suite(vls_scheduler_tests scheduler/SchedulerTests.cpp) vls_test_suite(vls_index_tests index/SymbolIndexTests.cpp) vls_test_suite(vls_navigation_tests navigation/NavigationTests.cpp) vls_test_suite(vls_reflection_tests reflection/ProvenanceTests.cpp) -vls_test_suite(vls_feature_tests features/CompletionTests.cpp features/IndexNavigationTests.cpp features/SignatureHelpTests.cpp features/DocumentSymbolsTests.cpp features/TextStructureTests.cpp features/CodeActionsTests.cpp features/SemanticTokensTests.cpp features/InlayHintsTests.cpp features/FileOperationsTests.cpp features/IncludeUpdateTests.cpp features/CallHierarchyTests.cpp features/CodeLensTests.cpp features/DocumentLinksTests.cpp features/FormattingTests.cpp features/TypeHierarchyTests.cpp features/OutlineTests.cpp) +vls_test_suite(vls_feature_tests features/CompletionTests.cpp features/IndexNavigationTests.cpp features/SignatureHelpTests.cpp features/DocumentSymbolsTests.cpp features/TextStructureTests.cpp features/CodeActionsTests.cpp features/SemanticTokensTests.cpp features/InlayHintsTests.cpp features/FileOperationsTests.cpp features/IncludeUpdateTests.cpp features/CallHierarchyTests.cpp features/CodeLensTests.cpp features/DocumentLinksTests.cpp features/FormattingTests.cpp features/TypeHierarchyTests.cpp features/OutlineTests.cpp features/CompletionSourceTests.cpp) vls_test_suite(vls_live_tests debug/LiveSessionTests.cpp debug/LiveDapTests.cpp) target_link_libraries(vls_live_tests PRIVATE Void::System) add_dependencies(vls_live_tests vls_live_worker_fixture vls-dap) diff --git a/tests/features/CompletionSourceTests.cpp b/tests/features/CompletionSourceTests.cpp new file mode 100644 index 0000000..4a600a3 --- /dev/null +++ b/tests/features/CompletionSourceTests.cpp @@ -0,0 +1,84 @@ +#include + +#include +#include + +#include + +namespace { +using namespace vls::features::completion_source; +using Void::Testing::expect; +using Void::Testing::require; + +std::string index(std::string_view scopes) { + return R"({"schema":1,"scopes":[)" + std::string{scopes} + "]}"; +} + +std::string scope(std::string_view path, int start_line, int start_character, int end_line, + int end_character, bool complete, std::string_view items) { + return R"({"path":")" + std::string{path} + R"(","startLine":)" + std::to_string(start_line) + + R"(,"startCharacter":)" + std::to_string(start_character) + R"(,"endLine":)" + + std::to_string(end_line) + R"(,"endCharacter":)" + std::to_string(end_character) + + R"(,"complete":)" + (complete ? "true" : "false") + R"(,"items":[)" + + std::string{items} + "]}"; +} +} // namespace + +VOID_TEST(CompletionSource, parses_scopes_and_items) { + const auto bytes = index(scope( + "/p/a.cpp", 0, 0, 2, 0, true, + R"json({"label":"alpha","kind":12,"detail":"int alpha()","insertText":"alpha()"},{"label":"beta"})json")); + const auto parsed = parse(bytes); + require(parsed.has_value()); + require(parsed->size() == 1); + const auto &first = parsed->front(); + expect(first.path == "/p/a.cpp"); + expect(first.complete); + expect(first.start == Position{0, 0}); + expect(first.end == Position{2, 0}); + require(first.items.size() == 2); + expect(first.items[0].label == "alpha"); + expect(first.items[0].kind == 12); + expect(first.items[0].detail == "int alpha()"); + expect(first.items[0].insert_text == "alpha()"); + expect(first.items[1].kind == 1); +} + +VOID_TEST(CompletionSource, selects_the_innermost_covering_scope) { + const auto bytes = index(scope("/p/a.cpp", 0, 0, 10, 0, false, R"({"label":"outer"})") + "," + + scope("/p/a.cpp", 2, 0, 4, 0, true, R"({"label":"inner"})") + "," + + scope("/p/b.cpp", 0, 0, 10, 0, true, R"({"label":"other"})")); + const auto parsed = parse(bytes); + require(parsed.has_value()); + const auto *selected = at(*parsed, "/p/a.cpp", {3, 5}); + require(selected != nullptr); + expect(selected->items.front().label == "inner"); + expect(selected->complete); + expect(at(*parsed, "/p/a.cpp", {20, 0}) == nullptr); + expect(at(*parsed, "/p/missing.cpp", {1, 0}) == nullptr); +} + +VOID_TEST(CompletionSource, rejects_malformed_and_incomplete_scopes) { + expect(!parse("not json").has_value()); + expect(!parse(R"({"schema":2,"scopes":[]})").has_value()); + expect(!parse(R"({"schema":1})").has_value()); + expect(!parse(index(scope("/p/a.cpp", 1, 0, 0, 0, true, ""))).has_value()); + expect( + !parse( + index( + R"({"path":"/p/a.cpp","startLine":0,"startCharacter":0,"endLine":1,"endCharacter":0,"complete":true,"items":[{"kind":4}]})")) + .has_value()); + expect( + !parse( + index( + R"({"path":"/p/a.cpp","startLine":0,"startCharacter":0,"endLine":1,"endCharacter":0,"complete":true,"items":[{"label":"x","kind":99}]})")) + .has_value()); +} + +VOID_TEST(CompletionSource, is_bounded) { + const auto bytes = index(scope("/p/a.cpp", 0, 0, 1, 0, true, R"({"label":"a"},{"label":"b"})")); + expect(parse(bytes, Limits{.itemsPerScope = 1}).has_value() == false); + expect(parse(bytes, Limits{.scopes = 0}).has_value() == false); + expect(parse(bytes, Limits{.fileBytes = 8}).has_value() == false); + expect(parse(bytes, Limits{.textBytes = 0}).has_value() == false); +}