Consume a compiler-agnostic completion index

Under D-032, completion can now merge candidates from a documented,
versioned index file produced by any external tool. The bounded core
parses and selects the innermost covering scope, the server puts its
items ahead of index-backed ones and takes isIncomplete from the
scope's complete flag, and registered feature tests cover parsing,
selection and bounds. A real stdio session returned the provided
items first with isIncomplete false inside the scope and true outside.
This commit is contained in:
faumaray committed 2026-12-06 02:10:16 +03:00
1 parent 236c3c5718
commit 4a029152e9
13 files changed
+336 -11

No files matched your search

+1 -1
View File
@@ -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)
+84
View File
@@ -0,0 +1,84 @@
#include <vls/features/CompletionSource.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
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);
}