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.
This commit is contained in:
faumaray committed 2026-12-05 14:06:50 +03:00
1 parent ca04975d54
commit da8003f6d4
310 files changed
+47552 -480

No files matched your search

+243
View File
@@ -0,0 +1,243 @@
#pragma once
#include <compare>
#include <cstddef>
#include <cstdint>
#include <expected>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <vector>
namespace vls::reflection {
// Version of the provenance/value snapshot schema. Derived index and trace
// renderers must reject an incompatible version rather than reinterpret it.
inline constexpr std::uint32_t schema_version = 1;
// Canonical, context-qualified semantic identity of one reflected or generated
// entity. It is assigned by the extractor from compiler state; this library
// never invents an identity from a source string.
using EntityId = std::string;
struct Range {
std::string path;
std::uint32_t line{}, character{}, endLine{}, endCharacter{};
auto operator<=>(const Range &) const = default;
};
// What one link of a provenance chain represents. A spelling is an editable
// token; expansion and splice sites are the generated constructs that produced
// a token; a reflected declaration is the original entity behind a splice; a
// synthesized entity has no editable spelling at all.
enum class OriginKind {
spelling,
expansion,
splice,
reflected_declaration,
synthesized,
};
struct Origin {
OriginKind kind{OriginKind::synthesized};
std::optional<Range> range; // absent when the compiler gave no location
std::optional<EntityId> entity; // reflected or generated entity identity
std::string note; // proposal/facility or instantiation context
auto operator<=>(const Origin &) const = default;
};
// Innermost origin first. A generated entity can stay navigable through the
// chain while remaining non-editable: generated names without a reliable
// editable origin are never automatically renameable.
struct Provenance {
std::vector<Origin> origins;
bool gap{}; // at least one link in the chain is unavailable
std::string context; // snapshot/instantiation identity
[[nodiscard]] bool navigable() const; // some origin carries a real range
[[nodiscard]] bool editable() const; // complete chain rooted at a spelling
auto operator<=>(const Provenance &) const = default;
};
enum class ValueKind {
integral,
text,
boolean,
entity,
opaque, // a real value the compiler cannot render; text is the reason
unavailable, // the value could not be obtained; text is the reason
};
struct Value {
ValueKind kind{ValueKind::unavailable};
std::int64_t integral{};
bool boolean{};
std::string text; // text value, or the reason for opaque/unavailable
std::string type; // canonical type spelling when the compiler provides it
EntityId entity; // referenced entity when kind is entity
auto operator<=>(const Value &) const = default;
};
struct Member {
std::string name;
Value value;
auto operator<=>(const Member &) const = default;
};
// One real reflected or synthesized entity. Members may reference other
// entities; expansion resolves those references lazily and boundedly.
struct Entity {
EntityId id;
std::string name;
std::string type;
std::vector<Member> members;
Provenance provenance;
bool synthesized{};
auto operator<=>(const Entity &) const = default;
};
struct Limits {
std::size_t entities{4096};
std::size_t membersPerEntity{64};
std::size_t originsPerProvenance{16};
std::size_t nameBytes{256};
std::size_t typeBytes{1024};
std::size_t textBytes{4096};
std::size_t contextBytes{1024};
std::size_t snapshotBytes{8 * 1024 * 1024};
std::size_t expansionDepth{8};
std::size_t expansionValues{1024};
std::size_t capabilities{256};
};
// Flattened, depth-first expansion of one entity. Cycles and limit cuts are
// explicit paths, never silently omitted values.
struct Expansion {
struct Entry {
std::string path; // member path from the root, e.g. "outer.inner"
std::size_t depth{};
ValueKind kind{ValueKind::unavailable};
std::string type;
std::string text;
EntityId entity;
std::optional<Range> link; // source range of the referenced entity
auto operator<=>(const Entry &) const = default;
};
std::vector<Entry> entries;
std::vector<std::string> cycles; // repeated entity on the current path
std::vector<std::string> truncated; // cut by depth or value count
[[nodiscard]] bool complete() const { return cycles.empty() && truncated.empty(); }
};
// One explanation line of a virtual generated view. A line is a semantic
// explanation, never compilable text: it may be indented prose with a source
// link, and consumers must never feed it back to a compiler.
struct VirtualLine {
std::string text;
std::size_t depth{};
std::optional<Range> link;
auto operator<=>(const VirtualLine &) const = default;
};
struct VirtualView {
std::vector<VirtualLine> lines;
bool truncated{};
// Virtual generated views are read-only explanations by construction.
[[nodiscard]] bool compilable() const { return false; }
};
// LSP-shaped hover for one entity: a semantic explanation plus the source
// links it explains. The markup is Markdown but never compilable text.
struct Hover {
std::string markup;
std::optional<Range> range;
auto operator<=>(const Hover &) const = default;
};
// Navigation targets in provenance-chain order, deduplicated and bounded.
// A generated entity stays navigable through the chain that produced it.
[[nodiscard]] std::vector<Range> locations(const Provenance &, std::size_t limit = 16);
// Renders one entity and its bounded expansion as a read-only semantic
// explanation with source links. Cycles, truncation and opaque values stay
// explicit; the result is never compilable text.
[[nodiscard]] VirtualView render(const Entity &, const Expansion &, const Limits & = Limits{});
// LSP-shaped hover markup for one entity and its expansion, with the entity's
// first source range. The markup lists the virtual view and its source links.
[[nodiscard]] Hover hover(const Entity &, const Expansion &, const Limits & = Limits{});
// Bounded snapshot of one analysis generation. Serialization is versioned and
// every consumer validates its own limits before trusting the bytes.
class Snapshot {
public:
explicit Snapshot(Limits = Limits{});
// Rejects duplicates, oversized strings, too many entities or members.
[[nodiscard]] bool add(Entity);
[[nodiscard]] bool contains(const EntityId &) const;
[[nodiscard]] const Entity *find(const EntityId &) const;
[[nodiscard]] const std::vector<Entity> &entities() const noexcept;
[[nodiscard]] std::size_t size() const;
[[nodiscard]] const Limits &limits() const noexcept;
// Depth-first expansion of one entity. Unknown identities are an error.
[[nodiscard]] std::expected<Expansion, std::string>
expand(const EntityId &, std::optional<std::size_t> depth = std::nullopt) const;
[[nodiscard]] std::expected<std::string, std::string> serialize() const;
[[nodiscard]] static std::expected<Snapshot, std::string> parse(std::string_view,
Limits = Limits{});
private:
Limits limits_;
std::vector<Entity> entities_;
};
// Proposal/facility support declared by the accepted backend. An unknown entry
// is an explicit capability error; it never falls back to a lexical answer.
struct Capability {
std::string proposal; // e.g. "P2996"
std::string facility; // e.g. "splices"
bool supported{};
std::string reason; // required when unsupported
auto operator<=>(const Capability &) const = default;
};
class Capabilities {
public:
explicit Capabilities(Limits = Limits{});
// Rejects duplicates, oversized fields and an unsupported entry without a
// reason.
[[nodiscard]] bool add(Capability);
[[nodiscard]] std::expected<Capability, std::string> query(std::string_view proposal,
std::string_view facility) const;
[[nodiscard]] std::size_t size() const;
private:
Limits limits_;
std::vector<Capability> entries_;
};
// One splice origin reported by the compiler: the splice site and the entity
// it designates. Columns are 1-based UTF-8 byte offsets. The compiler reports
// a start coordinate only, so ranges are zero-width until an end is available.
struct SpliceOrigin {
std::string source;
std::uint32_t line{}, byteColumn{};
std::string targetKind; // "declaration", "type" or "value"
std::string targetName;
std::string targetSource;
std::optional<std::uint32_t> targetLine, targetByteColumn;
};
// Composes entities from compiler-reported splice origins. Identity is
// composed from the reported target kind, name and declaration location; the
// provenance chain is the splice site followed by the reflected declaration,
// or an explicit gap when the compiler reported no target location. The first
// chain for an identity wins and the result stays within the snapshot limits.
[[nodiscard]] Snapshot snapshot_from_splices(std::span<const SpliceOrigin>, Limits = Limits{});
} // namespace vls::reflection