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

+195
View File
@@ -0,0 +1,195 @@
#include <vls/semantic/Occurrences.hpp>
#include <Void/LanguageServer/Protocol/Json.hpp>
#include <algorithm>
#include <cstdint>
#include <limits>
#include <optional>
#include <set>
#include <tuple>
namespace vls::semantic {
namespace P = Void::LanguageServer::Protocol;
using Json = P::Json;
namespace {
constexpr std::size_t max_report = 1024 * 1024;
constexpr std::size_t max_occurrences = 256;
constexpr std::size_t max_name = 64;
constexpr std::size_t max_type = 160;
constexpr std::size_t max_signature = 300;
constexpr std::size_t max_reason = 128;
constexpr std::size_t max_path = 4095;
bool plain(std::string_view text, std::size_t limit) {
return text.size() <= limit &&
std::ranges::none_of(text, [](unsigned char c) { return c < 32 || c == 127; });
}
bool identifier(std::string_view name) {
if (name.empty() || name.size() > max_name)
return false;
for (std::size_t i = 0; i != name.size(); ++i) {
const char c = name[i];
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' ||
(i && c >= '0' && c <= '9')))
return false;
}
return true;
}
const Json *member(const Json &value, std::string_view key) {
const auto *object = P::as_object(&value);
return object ? P::find_member(*object, key) : nullptr;
}
std::optional<std::int64_t> integer(const Json *value) {
if (!value)
return {};
if (const auto *number = std::get_if<std::int64_t>(&value->value))
return *number;
return {};
}
struct RawSpan {
std::string path;
std::uint32_t line, start, end;
};
std::optional<RawSpan> span(const Json *value) {
const auto *object = value ? P::as_object(value) : nullptr;
if (!object || object->size() != 4)
return {};
const auto *path = P::as_string(P::find_member(*object, "path"));
const auto line = integer(P::find_member(*object, "line"));
const auto start = integer(P::find_member(*object, "startByte"));
const auto end = integer(P::find_member(*object, "endByte"));
constexpr auto maximum = std::numeric_limits<std::int32_t>::max();
if (!path || !plain(*path, max_path) || path->find('\0') != path->npos || !line || !start ||
!end || *line < 1 || *line > maximum || *start < 1 || *end <= *start || *end > maximum)
return {};
return RawSpan{*path, static_cast<std::uint32_t>(*line), static_cast<std::uint32_t>(*start),
static_cast<std::uint32_t>(*end)};
}
bool captured(std::span<const CapturedSource> capture, const std::string &path) {
return std::ranges::any_of(capture, [&](const auto &entry) {
return entry.snapshot && entry.logical_path.native() == path;
});
}
// Bind a physical byte span to the captured snapshot and convert it through the
// snapshot's negotiated encoding. The sliced bytes must be exactly the declared
// name and both endpoints must fall on UTF-8 boundaries.
std::optional<std::pair<DiagnosticSnapshot, Documents::Range>>
bind_span(const RawSpan &raw, std::string_view name, std::span<const CapturedSource> capture) {
for (const auto &entry : capture) {
if (!entry.snapshot || entry.logical_path.native() != raw.path)
continue;
const auto &snapshot = entry.snapshot;
const std::string_view text = snapshot->text;
std::size_t line_start = 0;
for (std::uint32_t line = 1; line != raw.line; ++line) {
const auto newline = text.find('\n', line_start);
if (newline == std::string_view::npos)
return {};
line_start = newline + 1;
}
auto line_end = text.find('\n', line_start);
if (line_end == std::string_view::npos)
line_end = text.size();
const std::size_t width = line_end - line_start;
if (raw.start - 1 > width || raw.end - 1 > width)
return {};
const std::size_t begin = line_start + raw.start - 1;
const std::size_t end = line_start + raw.end - 1;
if (text.substr(begin, name.size()) != name)
return {};
if (begin && (static_cast<unsigned char>(text[begin - 1]) & 0xC0) == 0x80)
return {};
if (end < text.size() && (static_cast<unsigned char>(text[end]) & 0xC0) == 0x80)
return {};
const auto start = snapshot->offset_to_position(begin);
const auto finish = snapshot->offset_to_position(end);
if (!start || !finish || !(*start < *finish))
return {};
return std::pair{snapshot, Documents::Range{*start, *finish}};
}
return {};
}
} // namespace
std::expected<OccurrenceReport, OccurrenceError>
decode_occurrences(std::string_view report, std::string_view nonce,
std::span<const CapturedSource> capture) {
if (report.empty() || report.size() > max_report)
return std::unexpected{OccurrenceError::invalid_report};
auto parsed = P::parse_json(report, 8);
if (!parsed)
return std::unexpected{OccurrenceError::invalid_report};
const auto *root = P::as_object(&*parsed);
if (!root || root->size() != 6)
return std::unexpected{OccurrenceError::invalid_report};
const auto schema = integer(P::find_member(*root, "schema"));
const auto *nonce_text = P::as_string(P::find_member(*root, "nonce"));
const auto complete = P::as_bool(P::find_member(*root, "complete"));
const auto partial = P::as_bool(P::find_member(*root, "partial"));
const auto *reason = P::as_string(P::find_member(*root, "reason"));
const auto *items = P::as_array(P::find_member(*root, "occurrences"));
if (!schema || *schema != 1 || !nonce_text || !complete || !partial || !reason ||
!plain(*reason, max_reason) || !items || items->size() > max_occurrences)
return std::unexpected{OccurrenceError::invalid_report};
if (*nonce_text != nonce)
return std::unexpected{OccurrenceError::wrong_nonce};
OccurrenceReport result{{}, *complete, *partial, *reason};
if (!*complete)
return result;
std::set<std::tuple<const void *, std::uint32_t, std::uint32_t>> uses;
for (const auto &item : *items) {
const auto *fields = P::as_object(&item);
if (!fields || (fields->size() != 5 && fields->size() != 6))
return std::unexpected{OccurrenceError::invalid_report};
const auto *name = P::as_string(P::find_member(*fields, "name"));
const auto *type = P::as_string(P::find_member(*fields, "type"));
const auto *canonical = P::as_string(P::find_member(*fields, "canonicalType"));
const auto *signature = P::as_string(P::find_member(*fields, "signature"));
if (!name || !identifier(*name) || !type || !plain(*type, max_type) || type->empty() ||
!canonical || !plain(*canonical, max_type) || canonical->empty() ||
(signature && (!plain(*signature, max_signature) || signature->empty())))
return std::unexpected{OccurrenceError::invalid_report};
const auto use_span = span(P::find_member(*fields, "use"));
if (!use_span)
return std::unexpected{OccurrenceError::invalid_report};
auto use = bind_span(*use_span, *name, capture);
if (!use)
return std::unexpected{OccurrenceError::invalid_report};
if (!uses.emplace(use->first.get(), use->second.start.line, use->second.start.character)
.second)
return std::unexpected{OccurrenceError::invalid_report};
Occurrence occurrence;
occurrence.name = *name;
occurrence.type = *type;
occurrence.canonical_type = *canonical;
if (signature)
occurrence.signature = *signature;
occurrence.use_file = use->first;
occurrence.use = use->second;
const auto *definition = P::find_member(*fields, "definition");
if (definition && !std::holds_alternative<std::nullptr_t>(definition->value)) {
const auto definition_span = span(definition);
if (!definition_span)
return std::unexpected{OccurrenceError::invalid_report};
if (captured(capture, definition_span->path)) {
auto bound = bind_span(*definition_span, *name, capture);
if (!bound)
return std::unexpected{OccurrenceError::invalid_report};
occurrence.definition_file = bound->first;
occurrence.definition = bound->second;
}
}
result.occurrences.push_back(std::move(occurrence));
}
return result;
}
} // namespace vls::semantic