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:
1 parent
b1c8a4a625
commit
86b9923532
14 files changed
+357
-15
No files matched your search
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::features::type_hierarchy {
|
||||
|
||||
struct Position {
|
||||
std::uint32_t line{}, character{};
|
||||
auto operator<=>(const Position &) const = default;
|
||||
};
|
||||
struct Range {
|
||||
Position start, end;
|
||||
auto operator<=>(const Range &) const = default;
|
||||
};
|
||||
// One compiler-proven type name occurrence.
|
||||
struct TypeRef {
|
||||
std::uint32_t uid{};
|
||||
std::string name;
|
||||
std::string path;
|
||||
Range range;
|
||||
auto operator<=>(const TypeRef &) const = default;
|
||||
};
|
||||
struct Type {
|
||||
TypeRef self;
|
||||
std::vector<TypeRef> bases;
|
||||
};
|
||||
struct Limits {
|
||||
std::size_t items{256};
|
||||
};
|
||||
|
||||
// Direct bases of TARGET, deduplicated by identity and bounded.
|
||||
[[nodiscard]] std::vector<TypeRef> supertypes(std::span<const Type>, const TypeRef &target,
|
||||
const Limits & = Limits{});
|
||||
|
||||
// Types whose direct bases contain TARGET, deduplicated by identity and bounded.
|
||||
[[nodiscard]] std::vector<TypeRef> subtypes(std::span<const Type>, const TypeRef &target,
|
||||
const Limits & = Limits{});
|
||||
|
||||
} // namespace vls::features::type_hierarchy
|
||||
@@ -81,6 +81,13 @@ class EditorDiagnostics {
|
||||
// Calls made inside a prepared item's function.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
call_hierarchy_outgoing(const Void::LanguageServer::Protocol::Json &item) const;
|
||||
// Type hierarchy at a call position and from a prepared item.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
prepare_type_hierarchy(std::string_view uri, Documents::Position position) const;
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
type_hierarchy_supertypes(const Void::LanguageServer::Protocol::Json &item) const;
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
type_hierarchy_subtypes(const Void::LanguageServer::Protocol::Json &item) const;
|
||||
// Parameter-type hints from the compiler signature, within the range.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json inlay_hints(std::string_view uri,
|
||||
Documents::Range range) const;
|
||||
|
||||
@@ -22,6 +22,8 @@ struct Occurrence {
|
||||
// Whole definition extent when the compiler reported one (function body
|
||||
// included). Call hierarchy uses it to attribute nested calls.
|
||||
std::optional<Documents::Range> extent;
|
||||
// Uid of the reported class type of this call's result, when present.
|
||||
std::uint32_t result_type_uid{};
|
||||
|
||||
[[nodiscard]] bool has_definition() const noexcept { return definition_file != nullptr; }
|
||||
};
|
||||
@@ -29,6 +31,7 @@ struct Occurrence {
|
||||
struct TypeRef {
|
||||
std::string name, path;
|
||||
Documents::Range range;
|
||||
std::uint32_t uid{};
|
||||
};
|
||||
// A class observed as a call's result type and its direct bases.
|
||||
struct ReflectedType {
|
||||
|
||||
Reference in new issue
Block a user