Files
Language-Server/tests/features/IndexNavigationTests.cpp
T
faumaray da8003f6d4 Implement the VLS roadmap on the native VBS build
Native VBS and CMake builds of the server and every registered suite:
protocol and document sync, VBS/compdb providers, stock GCC diagnostics
(including in-process default profile preparation), the stock occurrence
observer and hover/definition, the bounded Scheduler, C++ module graph,
scan and artifact cache with real CMI production, the context-aware
symbol index with schema-2 snapshot migration, navigation and guarded
rename, reflection provenance with splice-origin extraction, index-backed
completion and signature help, live GCC worker control with a registered
DAP suite, and the Neovim and VS Code clients.

VoidLibrary follows main. The private GCC 16.2.0 frontend is reproduced
from the versioned patches and verified stepping reflection/template code
with projected values 17/34 and 41/82.
2026-12-05 14:06:50 +03:00

158 lines
7.1 KiB
C++

#include <vls/features/IndexNavigation.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <algorithm>
#include <string>
#include <vector>
namespace {
using namespace vls;
using Void::Testing::expect;
using Void::Testing::require;
index::SymbolRecord record(std::string name, std::string path, std::uint32_t line,
std::optional<index::Location> definition = std::nullopt) {
return {std::move(name),
index::SymbolKind::function,
index::Location{std::move(path), line, 4, line, 8},
std::move(definition),
{},
"gcc"};
}
index::ContextInput context(std::string name, std::vector<index::SymbolRecord> records,
bool complete = true) {
index::ContextInput input;
input.context = std::move(name);
input.records = std::move(records);
input.complete = complete;
if (!complete)
input.reason = "the observer could not complete this context";
input.sources = {{"/project/a.cpp", "content-a"}, {"/project/b.cpp", "content-b"}};
input.dependencies = {"/project/a.cpp", "/project/b.cpp"};
return input;
}
std::vector<features::IndexedSource> sources(bool editable = true) {
return {{"/project/a.cpp", "content-a", editable}, {"/project/b.cpp", "content-b", editable}};
}
navigation::Position at(std::uint32_t line, std::uint32_t character) { return {line, character}; }
} // namespace
VOID_TEST(IndexNavigation, cross_file_rename_is_ready_from_index_data) {
index::SymbolIndex symbols;
const index::Location definition{"/project/def.cpp", 10, 0, 10, 1};
require(symbols.publish(context("debug:a", {record("f", "/project/a.cpp", 3, definition)})));
require(symbols.publish(context("debug:b", {record("f", "/project/b.cpp", 7, definition)})));
const auto generation = symbols.current();
require(generation != nullptr);
navigation::FactSet set;
require(features::ingest_index_facts(set, *generation, sources()) == 2);
const auto binding = navigation::binding_at(set, "/project/a.cpp", at(3, 5));
require(binding.has_value());
expect(binding->name == "f");
require(binding->definition.has_value());
expect(binding->definition->path == "/project/def.cpp");
const auto refused = navigation::prepare_rename(set, "/project/a.cpp", at(3, 5), "g", false);
expect(refused.refusal == navigation::Refusal::multi_file_without_transaction);
const auto plan = navigation::prepare_rename(set, "/project/a.cpp", at(3, 5), "g", true);
require(plan.ready());
require(plan.edits.size() == 2);
expect(plan.edits[0].path == "/project/a.cpp");
expect(plan.edits[1].path == "/project/b.cpp");
expect(plan.edits[1].range.start.line == 7);
}
VOID_TEST(IndexNavigation, existing_facts_win_over_index_duplicates) {
index::SymbolIndex symbols;
require(symbols.publish(context("debug:a", {record("f", "/project/a.cpp", 3)})));
const auto generation = symbols.current();
require(generation != nullptr);
navigation::FactSet set;
set.facts.push_back(navigation::Fact{.binding = {.name = "f", .definition = std::nullopt},
.context = "debug:a",
.source = "/project/a.cpp",
.content = "content-a",
.use = {{3, 4}, {3, 8}},
.editable = true,
.provenance = "stock-observer"});
expect(features::ingest_index_facts(set, *generation, sources()) == 0);
require(set.facts.size() == 1);
expect(set.facts.front().provenance == "stock-observer");
}
VOID_TEST(IndexNavigation, unknown_or_non_editable_sources_block_rename) {
index::SymbolIndex symbols;
require(symbols.publish(context("debug:a", {record("f", "/project/a.cpp", 3)})));
const auto generation = symbols.current();
require(generation != nullptr);
navigation::FactSet set;
require(features::ingest_index_facts(set, *generation, {}) == 1);
expect(!set.facts.front().editable);
const auto unknown = navigation::prepare_rename(set, "/project/a.cpp", at(3, 5), "g", true);
expect(unknown.refusal == navigation::Refusal::non_editable_origin);
navigation::FactSet read_only;
require(features::ingest_index_facts(read_only, *generation, sources(false)) == 1);
const auto refused =
navigation::prepare_rename(read_only, "/project/a.cpp", at(3, 5), "g", true);
expect(refused.refusal == navigation::Refusal::non_editable_origin);
}
VOID_TEST(IndexNavigation, stale_index_content_is_detected) {
index::SymbolIndex symbols;
require(symbols.publish(context("debug:a", {record("f", "/project/a.cpp", 3)})));
const auto generation = symbols.current();
require(generation != nullptr);
navigation::FactSet set;
require(features::ingest_index_facts(set, *generation, sources()) == 1);
set.current_sources["/project/a.cpp"] = "content-changed";
const auto stale = navigation::prepare_rename(set, "/project/a.cpp", at(3, 5), "g", true);
expect(stale.refusal == navigation::Refusal::stale_source);
}
VOID_TEST(IndexNavigation, incomplete_context_blocks_rename) {
index::SymbolIndex symbols;
require(symbols.publish(context("debug:a", {record("f", "/project/a.cpp", 3)}, false)));
const auto generation = symbols.current();
require(generation != nullptr);
navigation::FactSet set;
require(features::ingest_index_facts(set, *generation, sources()) == 1);
const auto plan = navigation::prepare_rename(set, "/project/a.cpp", at(3, 5), "g", true);
expect(plan.refusal == navigation::Refusal::incomplete_coverage);
expect(plan.detail.find("debug:a") != std::string::npos);
}
VOID_TEST(IndexNavigation, known_contexts_keep_their_own_completeness) {
index::SymbolIndex symbols;
require(symbols.publish(context("debug:a", {record("f", "/project/a.cpp", 3)})));
const auto generation = symbols.current();
require(generation != nullptr);
navigation::FactSet set;
set.contexts.push_back({"debug:a", false, "occurrence coverage was partial"});
require(features::ingest_index_facts(set, *generation, sources()) == 1);
require(set.contexts.size() == 1);
expect(!set.contexts.front().complete);
expect(set.contexts.front().reason == "occurrence coverage was partial");
}
VOID_TEST(IndexNavigation, references_join_across_files) {
index::SymbolIndex symbols;
const index::Location definition{"/project/def.cpp", 10, 0, 10, 1};
auto first = record("f", "/project/a.cpp", 3, definition);
first.references.push_back(index::Location{"/project/b.cpp", 7, 4, 7, 8});
require(symbols.publish(context("debug:a", {first})));
const auto generation = symbols.current();
require(generation != nullptr);
navigation::FactSet set;
require(features::ingest_index_facts(set, *generation, sources()) == 2);
const auto binding = navigation::binding_at(set, "/project/a.cpp", at(3, 5));
require(binding.has_value());
const auto result = navigation::references(set, *binding);
expect(result.coverage_complete);
require(result.locations.size() == 2);
}