Occurrences carry their result type uid, decoded types are retained per editor entry, and a bounded core selects direct bases and inverse subtypes. The server advertises typeHierarchyProvider and serves prepareTypeHierarchy, supertypes and subtypes. Registered feature tests cover the selection; a real stdio session prepared DerivedA and returned Base as supertype and DerivedA/DerivedB as subtypes of Base.
51 lines
2.0 KiB
C++
51 lines
2.0 KiB
C++
#include <vls/features/TypeHierarchy.hpp>
|
|
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <vector>
|
|
|
|
namespace {
|
|
using namespace vls::features::type_hierarchy;
|
|
using Void::Testing::expect;
|
|
using Void::Testing::require;
|
|
|
|
TypeRef ref(std::uint32_t uid, std::string name) {
|
|
return {uid, std::move(name), "/p/a.cpp", {{0, 0}, {0, 4}}};
|
|
}
|
|
|
|
Type type(std::uint32_t uid, std::string name, std::vector<TypeRef> bases = {}) {
|
|
return {ref(uid, std::move(name)), std::move(bases)};
|
|
}
|
|
} // namespace
|
|
|
|
VOID_TEST(TypeHierarchy, supertypes_follow_direct_bases) {
|
|
const std::vector<Type> types{type(1, "Base"), type(2, "Derived", {ref(1, "Base")}),
|
|
type(3, "More", {ref(2, "Derived")})};
|
|
const auto result = supertypes(types, ref(2, "Derived"));
|
|
require(result.size() == 1);
|
|
expect(result.front().name == "Base");
|
|
expect(supertypes(types, ref(1, "Base")).empty());
|
|
expect(supertypes(types, ref(9, "Absent")).empty());
|
|
}
|
|
|
|
VOID_TEST(TypeHierarchy, subtypes_invert_the_base_relation) {
|
|
const std::vector<Type> types{type(1, "Base"), type(2, "Derived", {ref(1, "Base")}),
|
|
type(3, "Other", {ref(1, "Base")})};
|
|
const auto result = subtypes(types, ref(1, "Base"));
|
|
require(result.size() == 2);
|
|
expect(result[0].name == "Derived");
|
|
expect(result[1].name == "Other");
|
|
expect(subtypes(types, ref(2, "Derived")).empty());
|
|
}
|
|
|
|
VOID_TEST(TypeHierarchy, duplicates_are_removed_and_results_bounded) {
|
|
const std::vector<Type> types{type(1, "Base"),
|
|
type(2, "Derived", {ref(1, "Base"), ref(1, "Base")}),
|
|
type(3, "Other", {ref(1, "Base")})};
|
|
expect(subtypes(types, ref(1, "Base")).size() == 2);
|
|
expect(subtypes(types, ref(1, "Base"), Limits{.items = 1}).size() == 1);
|
|
const std::vector<Type> repeated{type(2, "Derived", {ref(1, "Base"), ref(1, "Base")})};
|
|
expect(supertypes(repeated, ref(2, "Derived")).size() == 1);
|
|
}
|