Serve type hierarchy from observer class facts

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.
This commit is contained in:
faumaray committed 2026-12-05 23:36:05 +03:00
1 parent b1c8a4a625
commit 86b9923532
14 files changed
+357 -15

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)
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)
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)
@@ -134,13 +134,19 @@ def analyze(work, nonce, admitted, complete=True, partial=None):
check(isinstance(occurrence, dict), "occurrence is not an object")
check({"name", "type", "canonicalType", "use", "definition"} <= set(occurrence)
and set(occurrence) <= {"name", "type", "canonicalType", "signature",
"use", "definition"},
"use", "definition", "resultTypeUid"},
f"unexpected occurrence keys {sorted(occurrence)}")
name = occurrence["name"]
check(re.fullmatch(r"[A-Za-z_]\w{0,63}", name, re.ASCII), f"bad name {name!r}")
check(isinstance(occurrence["type"], str) and occurrence["type"], "bad type")
check(isinstance(occurrence["canonicalType"], str) and occurrence["canonicalType"],
"bad canonical type")
if "resultTypeUid" in occurrence:
uid = occurrence["resultTypeUid"]
check(type(uid) is int and uid > 0, f"bad resultTypeUid {uid!r}")
check(any(reference["uid"] == uid
for entry in report["types"] for reference in [entry["self"]]),
f"resultTypeUid {uid} has no type entry")
if "signature" in occurrence:
signature = occurrence["signature"]
check(isinstance(signature, str) and 0 < len(signature) <= 300, "bad signature")
+50
View File
@@ -0,0 +1,50 @@
#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);
}