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:
1 parent
ca04975d54
commit
da8003f6d4
310 files changed
+47552
-480
No files matched your search
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/LanguageServer/Documents/DocumentStore.hpp>
|
||||
#include <Void/LanguageServer/Protocol/Json.hpp>
|
||||
|
||||
namespace vls {
|
||||
|
||||
[[nodiscard]] Void::LanguageServer::Documents::PositionEncoding
|
||||
negotiate_position_encoding(const Void::LanguageServer::Protocol::Json &initialize_params);
|
||||
|
||||
void reject_change_envelope(Void::LanguageServer::Documents::DocumentStore &store,
|
||||
const Void::LanguageServer::Protocol::Json *params);
|
||||
|
||||
[[nodiscard]] std::expected<void, std::string>
|
||||
synchronize_document(Void::LanguageServer::Documents::DocumentStore &store, std::string_view method,
|
||||
const Void::LanguageServer::Protocol::Json *params);
|
||||
|
||||
} // namespace vls
|
||||
+4
-18
@@ -1,25 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <expected>
|
||||
#include <iosfwd>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <Void/LanguageServer/Protocol/Framing.hpp>
|
||||
|
||||
namespace vls {
|
||||
|
||||
struct FrameLimits {
|
||||
std::size_t header_bytes{8192};
|
||||
std::size_t body_bytes{16777216};
|
||||
};
|
||||
|
||||
// A disengaged optional means EOF between frames. Framing errors are fatal: the
|
||||
// caller must not attempt to find another frame in an untrusted byte stream.
|
||||
[[nodiscard]] std::expected<std::optional<std::string>, std::string>
|
||||
read_frame(std::istream &input, FrameLimits limits = {});
|
||||
|
||||
[[nodiscard]] std::expected<void, std::string> write_frame(std::ostream &output,
|
||||
std::string_view body);
|
||||
using Void::LanguageServer::Protocol::FrameLimits;
|
||||
using Void::LanguageServer::Protocol::read_frame;
|
||||
using Void::LanguageServer::Protocol::write_frame;
|
||||
|
||||
} // namespace vls
|
||||
+27
-14
@@ -1,23 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Data/StrictJson.hpp>
|
||||
#include <Void/LanguageServer/Protocol/Json.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <variant>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
namespace vls {
|
||||
|
||||
using Json = Void::Json::Strict::Value;
|
||||
using RequestId = std::variant<std::int32_t, std::string>;
|
||||
using Void::LanguageServer::Protocol::Json;
|
||||
using Void::LanguageServer::Protocol::parse_json;
|
||||
using Void::LanguageServer::Protocol::request_id;
|
||||
using Void::LanguageServer::Protocol::RequestId;
|
||||
|
||||
[[nodiscard]] std::expected<Json, std::string> parse_json(std::string_view text,
|
||||
std::size_t maximum_depth = 64);
|
||||
[[nodiscard]] std::expected<RequestId, std::string> request_id(const Json &value);
|
||||
[[nodiscard]] std::string quote_json(std::string_view text);
|
||||
[[nodiscard]] std::string encode_id(const RequestId &id);
|
||||
namespace detail {
|
||||
|
||||
inline std::string require_json_encoding(std::expected<std::string, std::string> encoded) {
|
||||
if (!encoded) {
|
||||
throw std::invalid_argument{encoded.error()};
|
||||
}
|
||||
return std::move(*encoded);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
[[nodiscard]] inline std::string quote_json(std::string_view text) {
|
||||
return detail::require_json_encoding(
|
||||
Void::LanguageServer::Protocol::serialize_json(Json{std::string{text}}));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline std::string encode_id(const RequestId &id) {
|
||||
return detail::require_json_encoding(Void::LanguageServer::Protocol::serialize_json(
|
||||
Void::LanguageServer::Protocol::request_id_json(id)));
|
||||
}
|
||||
|
||||
} // namespace vls
|
||||
+13
-1
@@ -1,32 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/LanguageServer/Documents/DocumentStore.hpp>
|
||||
#include <vls/Framing.hpp>
|
||||
#include <vls/WorkspaceSession.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace vls {
|
||||
namespace semantic {
|
||||
class EditorDiagnostics;
|
||||
}
|
||||
|
||||
inline constexpr std::string_view server_version = "0.1.0";
|
||||
|
||||
struct DispatchResult {
|
||||
std::optional<std::string> response;
|
||||
std::optional<int> exit_code;
|
||||
std::string diagnostic{};
|
||||
};
|
||||
|
||||
class Server {
|
||||
public:
|
||||
explicit Server(WorkspaceLaunch launch = {}, std::function<bool(std::string)> send = {});
|
||||
~Server();
|
||||
[[nodiscard]] DispatchResult handle(std::string_view body);
|
||||
|
||||
private:
|
||||
enum class State { awaiting_initialize, running, shutdown };
|
||||
State state_{State::awaiting_initialize};
|
||||
Void::LanguageServer::Documents::DocumentStore documents_;
|
||||
WorkspaceSession workspace_;
|
||||
std::unique_ptr<semantic::EditorDiagnostics> diagnostics_;
|
||||
};
|
||||
|
||||
// Thin transport loop shared by the executable and stream-failure unit tests.
|
||||
[[nodiscard]] int run_stdio(std::istream &input, std::ostream &output, std::ostream &diagnostics,
|
||||
FrameLimits limits = {});
|
||||
FrameLimits limits = {}, WorkspaceLaunch launch = {});
|
||||
|
||||
} // namespace vls
|
||||
@@ -0,0 +1,90 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/LanguageServer/Build/Providers.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace vls {
|
||||
|
||||
namespace semantic {
|
||||
class GccProfile;
|
||||
}
|
||||
|
||||
struct WorkspaceLaunch {
|
||||
std::optional<std::filesystem::path> root, build_root, producer_cwd;
|
||||
std::optional<Void::LanguageServer::Workspace::PartialWorkspaceSettings> user_settings,
|
||||
cli_settings;
|
||||
std::shared_ptr<const semantic::GccProfile> diagnostics_profile{};
|
||||
};
|
||||
|
||||
struct SemanticDriver {
|
||||
std::filesystem::path executable;
|
||||
Void::LanguageServer::Workspace::CompilerDriver family{
|
||||
Void::LanguageServer::Workspace::CompilerDriver::unknown};
|
||||
};
|
||||
|
||||
enum class SemanticContextIssue { unavailable, disabled, no_command, wrong_command, superseded };
|
||||
|
||||
struct SemanticContextError {
|
||||
SemanticContextIssue issue;
|
||||
std::string message;
|
||||
};
|
||||
|
||||
struct SemanticLeaseData;
|
||||
class SemanticContextLease {
|
||||
public:
|
||||
[[nodiscard]] const Void::LanguageServer::Build::Selection &selection() const;
|
||||
[[nodiscard]] const Void::LanguageServer::Build::SelectionState &selection_state() const;
|
||||
[[nodiscard]] const Void::LanguageServer::Build::DriverInput &driver() const;
|
||||
[[nodiscard]] std::uint64_t configuration_generation() const;
|
||||
[[nodiscard]] std::uint32_t worker_memory_limit_mib() const;
|
||||
[[nodiscard]] const std::string &document_uri() const;
|
||||
|
||||
private:
|
||||
friend class WorkspaceSession;
|
||||
explicit SemanticContextLease(std::shared_ptr<const SemanticLeaseData> data);
|
||||
std::shared_ptr<const SemanticLeaseData> data_;
|
||||
};
|
||||
|
||||
class WorkspaceSession {
|
||||
public:
|
||||
// The optional test hook runs after observation and before the publication checks.
|
||||
explicit WorkspaceSession(WorkspaceLaunch = {}, std::function<void()> before_publish = {});
|
||||
~WorkspaceSession();
|
||||
|
||||
// The client settings object contains defaults and optional `workspaces`
|
||||
// overrides keyed by a folder's admitted or canonical file URI.
|
||||
[[nodiscard]] std::expected<void, std::string>
|
||||
initialize(const Void::LanguageServer::Protocol::Json ¶ms);
|
||||
[[nodiscard]] std::expected<void, std::string>
|
||||
update_folders(const Void::LanguageServer::Protocol::Json *params);
|
||||
[[nodiscard]] std::expected<void, std::string>
|
||||
configure(const Void::LanguageServer::Protocol::Json *params);
|
||||
[[nodiscard]] std::expected<Void::LanguageServer::Protocol::Json, std::string>
|
||||
provider_status(const Void::LanguageServer::Protocol::Json *params);
|
||||
|
||||
// The caller explicitly selects the launcher driver. The lease retains the ordered
|
||||
// original and checked command in selection()->selected, and its immutable generation.
|
||||
[[nodiscard]] std::expected<SemanticContextLease, SemanticContextError>
|
||||
acquire_semantic_context(std::string_view document_uri,
|
||||
std::optional<std::string_view> workspace_uri,
|
||||
const SemanticDriver &selected_driver);
|
||||
[[nodiscard]] std::expected<void, SemanticContextError>
|
||||
validate_semantic_context(const SemanticContextLease &lease);
|
||||
|
||||
// Invalidates launcher authority and in-flight observations for an admitted root.
|
||||
void revoke_root_authority(const std::filesystem::path &root);
|
||||
|
||||
private:
|
||||
struct State;
|
||||
std::unique_ptr<State> state_;
|
||||
};
|
||||
|
||||
} // namespace vls
|
||||
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/LanguageServer/Protocol/Json.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace vls::gcc {
|
||||
class ReplayRecording;
|
||||
}
|
||||
|
||||
namespace vls::debug {
|
||||
namespace Protocol = Void::LanguageServer::Protocol;
|
||||
using Json = Protocol::Json;
|
||||
|
||||
// DAP and the versioned inspection requests share the same cursor and generation.
|
||||
class ReplaySession {
|
||||
public:
|
||||
static std::expected<ReplaySession, std::string> open(const std::filesystem::path &path);
|
||||
ReplaySession(const ReplaySession &) = delete;
|
||||
ReplaySession &operator=(const ReplaySession &) = delete;
|
||||
ReplaySession(ReplaySession &&) noexcept = default;
|
||||
ReplaySession &operator=(ReplaySession &&) = delete;
|
||||
|
||||
[[nodiscard]] Json::Object identity() const;
|
||||
[[nodiscard]] Json::Object describe() const;
|
||||
[[nodiscard]] bool matches(const Json::Object &arguments) const;
|
||||
[[nodiscard]] std::expected<Json::Object, std::string> timeline(std::size_t start,
|
||||
std::size_t count) const;
|
||||
[[nodiscard]] std::expected<Json::Object, std::string> frames(std::size_t start,
|
||||
std::size_t count) const;
|
||||
|
||||
// A false result represents the boundary in the requested direction. It preserves the cursor.
|
||||
[[nodiscard]] std::expected<bool, std::string> initial_position();
|
||||
[[nodiscard]] std::expected<bool, std::string> move_to_value(bool forward);
|
||||
[[nodiscard]] std::expected<void, std::string> seek(std::uint32_t sequence);
|
||||
void finish();
|
||||
[[nodiscard]] bool paused() const { return sequence_.has_value(); }
|
||||
[[nodiscard]] std::string_view pause_kind() const { return pause_kind_; }
|
||||
[[nodiscard]] bool source_available() const { return source_available_; }
|
||||
[[nodiscard]] std::string_view source_bytes() const;
|
||||
[[nodiscard]] std::size_t frame_count() const;
|
||||
[[nodiscard]] const Json &frame(std::size_t top_first_index) const;
|
||||
[[nodiscard]] std::int64_t frame_handle(std::size_t index) const;
|
||||
[[nodiscard]] std::int64_t scope_handle(std::size_t index) const;
|
||||
[[nodiscard]] std::optional<std::size_t> handle_index(std::int64_t handle, bool scope) const;
|
||||
|
||||
private:
|
||||
ReplaySession(std::shared_ptr<const gcc::ReplayRecording> recording, std::string id);
|
||||
std::shared_ptr<const gcc::ReplayRecording> recording_;
|
||||
std::string id_;
|
||||
bool source_available_;
|
||||
bool finished_{};
|
||||
std::int64_t generation_{};
|
||||
std::int64_t next_handle_{1};
|
||||
std::int64_t frame_base_{1};
|
||||
std::optional<std::uint32_t> sequence_;
|
||||
std::string_view pause_kind_{"none"};
|
||||
Json cursor_{nullptr};
|
||||
};
|
||||
} // namespace vls::debug
|
||||
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/LanguageServer/Protocol/Json.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace vls::debug::live {
|
||||
|
||||
enum class State { idle, running, stopped, completed, failed, cancelled };
|
||||
|
||||
struct Stop {
|
||||
std::uint64_t generation{};
|
||||
std::uint32_t sequence{};
|
||||
};
|
||||
|
||||
struct Options {
|
||||
std::filesystem::path worker; // vls_gcc_probe
|
||||
std::filesystem::path compiler;
|
||||
std::string compiler_sha256;
|
||||
std::filesystem::path source;
|
||||
std::filesystem::path trace;
|
||||
bool stepping{true};
|
||||
std::chrono::milliseconds deadline{60000};
|
||||
std::size_t max_notice_bytes{64 * 1024};
|
||||
};
|
||||
|
||||
// One live private-compiler session speaking the supervisor notice protocol.
|
||||
// Control actions are serialized; an inspection snapshot belongs to the stop
|
||||
// generation that requested it and is not reused after the session moves.
|
||||
class LiveSession {
|
||||
public:
|
||||
explicit LiveSession(Options);
|
||||
~LiveSession();
|
||||
LiveSession(const LiveSession &) = delete;
|
||||
LiveSession &operator=(const LiveSession &) = delete;
|
||||
LiveSession(LiveSession &&) = delete;
|
||||
LiveSession &operator=(LiveSession &&) = delete;
|
||||
|
||||
// Spawns the worker and waits for the first stop.
|
||||
[[nodiscard]] std::expected<Stop, std::string> start();
|
||||
// At a stop: single-step. Returns the next stop or nullopt when finished.
|
||||
[[nodiscard]] std::expected<std::optional<Stop>, std::string> step();
|
||||
[[nodiscard]] std::expected<std::optional<Stop>, std::string> continue_run();
|
||||
// Requests cancellation and reaps the worker.
|
||||
[[nodiscard]] std::expected<void, std::string> cancel();
|
||||
// Read-only bounded snapshot at the current stop.
|
||||
[[nodiscard]] std::expected<Void::LanguageServer::Protocol::Json, std::string> inspect();
|
||||
|
||||
[[nodiscard]] State state() const;
|
||||
[[nodiscard]] std::optional<Stop> stop() const;
|
||||
[[nodiscard]] std::string outcome() const;
|
||||
[[nodiscard]] std::string reason() const;
|
||||
|
||||
private:
|
||||
struct State_;
|
||||
std::unique_ptr<State_> state_;
|
||||
};
|
||||
|
||||
} // namespace vls::debug::live
|
||||
@@ -0,0 +1,95 @@
|
||||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::features::completion {
|
||||
|
||||
// Candidate origin is explicit: this slice ranks workspace symbols from the
|
||||
// analysis index and never claims compiler-native completion.
|
||||
enum class Kind { unknown, function, type, variable, field, namespace_, module, keyword };
|
||||
|
||||
struct Limits {
|
||||
std::size_t candidates{200};
|
||||
std::size_t labelBytes{256};
|
||||
std::size_t detailBytes{512};
|
||||
std::size_t provenanceBytes{128};
|
||||
};
|
||||
|
||||
// Stable identity of one completion candidate across a later resolve request.
|
||||
struct Identity {
|
||||
std::string name;
|
||||
std::string path;
|
||||
std::uint32_t line{}, character{};
|
||||
auto operator<=>(const Identity &) const = default;
|
||||
};
|
||||
|
||||
struct Candidate {
|
||||
std::string label;
|
||||
Kind kind{Kind::unknown};
|
||||
std::string detail;
|
||||
std::string provenance;
|
||||
Identity identity;
|
||||
auto operator<=>(const Candidate &) const = default;
|
||||
};
|
||||
|
||||
struct Item {
|
||||
std::string label;
|
||||
Kind kind{Kind::unknown};
|
||||
std::string detail;
|
||||
std::string provenance;
|
||||
std::string sort_text;
|
||||
Identity identity;
|
||||
// Byte offsets of the identifier prefix the item replaces.
|
||||
std::size_t replacement_start{}, replacement_end{};
|
||||
auto operator<=>(const Item &) const = default;
|
||||
};
|
||||
|
||||
struct Result {
|
||||
std::vector<Item> items;
|
||||
// True until compiler-native completion exists; index candidates are not
|
||||
// authoritative for visibility or accessibility.
|
||||
bool incomplete{true};
|
||||
std::string backend{"symbol-index"};
|
||||
};
|
||||
|
||||
// Longest ASCII identifier prefix ending at the byte offset. Empty when the
|
||||
// preceding text is not an identifier or the prefix starts with a digit.
|
||||
[[nodiscard]] std::string_view prefix_at(std::string_view text, std::size_t offset);
|
||||
|
||||
// Filters candidates whose label starts with the prefix, deduplicates by label
|
||||
// and kind, ranks deterministically (kind priority, shorter label, label) and
|
||||
// bounds every field. The replacement range covers the prefix.
|
||||
[[nodiscard]] Result complete(std::span<const Candidate>, std::string_view text, std::size_t offset,
|
||||
const Limits & = Limits{});
|
||||
|
||||
// A candidate as the current index generation reports it.
|
||||
struct Detail {
|
||||
Identity identity;
|
||||
Kind kind{Kind::unknown};
|
||||
std::string detail;
|
||||
std::string provenance;
|
||||
auto operator<=>(const Detail &) const = default;
|
||||
};
|
||||
|
||||
struct Resolved {
|
||||
enum class Status { resolved, stale, unknown };
|
||||
Status status{Status::unknown};
|
||||
std::string documentation;
|
||||
std::string detail;
|
||||
};
|
||||
|
||||
// Resolves a captured candidate identity against the current generation.
|
||||
// A changed generation is stale and an absent identity is unknown; neither
|
||||
// ever returns details for a different entity. Documentation is bounded and
|
||||
// fenced so that editor rendering cannot be escaped by the content.
|
||||
[[nodiscard]] Resolved resolve(const Identity &, std::uint64_t captured_generation,
|
||||
std::uint64_t current_generation, std::span<const Detail>,
|
||||
const Limits & = Limits{});
|
||||
|
||||
} // namespace vls::features::completion
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/index/SymbolIndex.hpp>
|
||||
#include <vls/navigation/Navigation.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace vls::features {
|
||||
|
||||
// What the caller currently knows about one source path. Content identity is
|
||||
// the same opaque value the index stored; an empty identity means the caller
|
||||
// cannot prove the file's current content, so its facts stay non-editable.
|
||||
struct IndexedSource {
|
||||
std::string path;
|
||||
std::string content;
|
||||
bool editable{};
|
||||
};
|
||||
|
||||
// Merges one published index generation into a navigation fact set.
|
||||
//
|
||||
// Contexts the set does not know yet are added with the index's completeness.
|
||||
// Each record's use location and every proven reference become facts whose
|
||||
// binding joins on name and definition. Facts are deduplicated by binding,
|
||||
// source and use; an existing fact always wins, so compiler-derived content
|
||||
// identities are never replaced by weaker index data. A record whose source
|
||||
// is unknown stays in the set as a non-editable fact: rename then refuses
|
||||
// instead of editing an unverified file. Returns the number of added facts.
|
||||
std::size_t ingest_index_facts(navigation::FactSet &, const index::Generation &,
|
||||
std::span<const IndexedSource>, std::size_t limit = 65536);
|
||||
|
||||
} // namespace vls::features
|
||||
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::features::signature {
|
||||
|
||||
struct Limits {
|
||||
std::size_t signatures{8};
|
||||
std::size_t parameters{64};
|
||||
std::size_t labelBytes{1024};
|
||||
std::size_t parameterBytes{256};
|
||||
std::size_t scanBytes{64 * 1024};
|
||||
};
|
||||
|
||||
struct Parameter {
|
||||
std::string label;
|
||||
// Byte range of label within the signature label, when it can be located.
|
||||
std::optional<std::pair<std::uint32_t, std::uint32_t>> range;
|
||||
auto operator<=>(const Parameter &) const = default;
|
||||
};
|
||||
|
||||
struct Signature {
|
||||
std::string label;
|
||||
std::vector<Parameter> parameters;
|
||||
auto operator<=>(const Signature &) const = default;
|
||||
};
|
||||
|
||||
struct Result {
|
||||
std::vector<Signature> signatures;
|
||||
std::uint32_t active_signature{};
|
||||
std::uint32_t active_parameter{};
|
||||
};
|
||||
|
||||
// Splits one compiler signature into a label and its parameter list. Commas
|
||||
// nested in (), [], {} or a plausible template argument list do not separate
|
||||
// parameters. A signature without a parameter list keeps an empty list.
|
||||
[[nodiscard]] Signature parse(std::string_view signature, const Limits & = Limits{});
|
||||
|
||||
// Number of the active parameter at the byte offset: top-level commas between
|
||||
// the innermost open parenthesis and the offset, ignoring literals, comments
|
||||
// and nested brackets. The backward scan is bounded by the limit.
|
||||
[[nodiscard]] std::uint32_t active_parameter(std::string_view text, std::size_t offset,
|
||||
const Limits & = Limits{});
|
||||
|
||||
// True when the offset lies inside the argument list opened after the callee
|
||||
// span [use_start, use_end): the first '(' after the span and its matching ')'
|
||||
// must enclose the offset. The scan is bounded and ignores literals/comments.
|
||||
[[nodiscard]] bool in_call(std::string_view text, std::size_t use_start, std::size_t use_end,
|
||||
std::size_t offset, const Limits & = Limits{});
|
||||
|
||||
// Complete signature help for a call site. Empty or malformed signatures are
|
||||
// skipped; an empty result means no signature is available.
|
||||
[[nodiscard]] Result build(std::span<const std::string> signatures, std::string_view text,
|
||||
std::size_t offset, const Limits & = Limits{});
|
||||
|
||||
} // namespace vls::features::signature
|
||||
@@ -0,0 +1,158 @@
|
||||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::index {
|
||||
|
||||
// Zero-based LSP-style character coordinates within one physical line.
|
||||
struct Location {
|
||||
std::string path;
|
||||
std::uint32_t line{}, character{};
|
||||
std::uint32_t endLine{}, endCharacter{};
|
||||
auto operator<=>(const Location &) const = default;
|
||||
};
|
||||
|
||||
enum class SymbolKind { unknown, function, type, variable, field, namespace_, module };
|
||||
|
||||
struct SymbolRecord {
|
||||
std::string name;
|
||||
SymbolKind kind{SymbolKind::unknown};
|
||||
Location location; // declaration or definition
|
||||
std::optional<Location> definition;
|
||||
std::vector<Location> references;
|
||||
std::string provenance;
|
||||
auto operator<=>(const SymbolRecord &) const = default;
|
||||
};
|
||||
|
||||
struct Limits {
|
||||
std::size_t contexts{64};
|
||||
std::size_t records{65536};
|
||||
std::size_t recordsPerContext{16384};
|
||||
std::size_t referencesPerRecord{256};
|
||||
std::size_t nameBytes{256};
|
||||
std::size_t pathBytes{4096};
|
||||
std::size_t snapshotBytes{32 * 1024 * 1024};
|
||||
};
|
||||
|
||||
struct ContextInput {
|
||||
std::string context; // Build::ContextKey alternative
|
||||
std::vector<std::string> dependencies;
|
||||
// Path and content identity of every source this context consumed.
|
||||
std::vector<std::pair<std::string, std::string>> sources;
|
||||
std::vector<SymbolRecord> records;
|
||||
bool complete{true};
|
||||
std::string reason;
|
||||
};
|
||||
|
||||
struct Coverage {
|
||||
bool indexed{}; // at least one context or overlay was considered
|
||||
bool complete{};
|
||||
std::vector<std::string> incomplete; // context names, sorted
|
||||
auto operator<=>(const Coverage &) const = default;
|
||||
};
|
||||
|
||||
struct Query {
|
||||
std::string name;
|
||||
bool substring{};
|
||||
std::optional<std::string> context;
|
||||
std::size_t limit{100};
|
||||
};
|
||||
|
||||
struct Result {
|
||||
std::vector<SymbolRecord> symbols;
|
||||
Coverage coverage;
|
||||
bool truncated{};
|
||||
};
|
||||
|
||||
// Immutable published snapshot. Readers keep it alive across later publications
|
||||
// and evictions.
|
||||
class Generation {
|
||||
public:
|
||||
[[nodiscard]] std::uint64_t number() const noexcept { return number_; }
|
||||
[[nodiscard]] const std::vector<SymbolRecord> &symbols() const noexcept { return records_; }
|
||||
[[nodiscard]] const std::vector<std::pair<std::string, Coverage>> &contexts() const noexcept {
|
||||
return contexts_;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class SymbolIndex;
|
||||
Generation(std::uint64_t number, std::vector<SymbolRecord> records,
|
||||
std::vector<std::pair<std::string, Coverage>> contexts)
|
||||
: number_(number), records_(std::move(records)), contexts_(std::move(contexts)) {}
|
||||
std::uint64_t number_;
|
||||
std::vector<SymbolRecord> records_;
|
||||
std::vector<std::pair<std::string, Coverage>> contexts_;
|
||||
};
|
||||
|
||||
// Context-aware, bounded symbol index. Committed records belong to explicit
|
||||
// analysis contexts; unsaved document overlays shadow committed records for
|
||||
// the same path and are reconciled on save/close. A changed, deleted or
|
||||
// renamed source marks dependent contexts incomplete without discarding the
|
||||
// last-good records (degraded navigation, never an authoritative rename).
|
||||
class SymbolIndex {
|
||||
public:
|
||||
explicit SymbolIndex(Limits = Limits{});
|
||||
~SymbolIndex();
|
||||
SymbolIndex(const SymbolIndex &) = delete;
|
||||
SymbolIndex &operator=(const SymbolIndex &) = delete;
|
||||
|
||||
// Atomically replaces one context and publishes a new generation.
|
||||
[[nodiscard]] bool publish(const ContextInput &);
|
||||
[[nodiscard]] bool remove(std::string_view context);
|
||||
|
||||
// Unsaved document records. The newest overlay for a path shadows the
|
||||
// committed records of that path until it is cleared.
|
||||
[[nodiscard]] bool set_overlay(std::string path, std::string content,
|
||||
std::vector<SymbolRecord> records);
|
||||
[[nodiscard]] bool clear_overlay(std::string_view path);
|
||||
|
||||
// A new content (or absence) invalidates every context that consumed the
|
||||
// path. Matching content is a no-op.
|
||||
[[nodiscard]] std::size_t invalidate(std::string_view path,
|
||||
const std::optional<std::string> &content);
|
||||
|
||||
[[nodiscard]] Result find(const Query &) const;
|
||||
[[nodiscard]] Coverage coverage() const;
|
||||
[[nodiscard]] std::shared_ptr<const Generation> current() const;
|
||||
[[nodiscard]] std::uint64_t generation() const;
|
||||
[[nodiscard]] std::size_t records() const;
|
||||
[[nodiscard]] const Limits &limits() const noexcept;
|
||||
|
||||
// Versioned persistence. restore() classifies the snapshot; incompatible or
|
||||
// corrupt bytes are quarantined and the index rebuilds into a new generation.
|
||||
enum class LoadStatus { loaded, missing, incompatible, corrupt, oversized };
|
||||
struct LoadResult {
|
||||
LoadStatus status{LoadStatus::missing};
|
||||
std::uint64_t generation{};
|
||||
std::optional<std::filesystem::path> quarantine;
|
||||
// True when a schema-1 snapshot was accepted and upgraded in memory.
|
||||
bool migrated{};
|
||||
};
|
||||
// Writes the versioned snapshot (schema 2 with a canonical payload digest).
|
||||
// restore() also accepts schema 1 and reports the upgrade as migrated.
|
||||
[[nodiscard]] bool save(const std::filesystem::path &) const;
|
||||
[[nodiscard]] std::expected<LoadResult, std::string> restore(const std::filesystem::path &);
|
||||
// True only when a compatible snapshot was loaded.
|
||||
[[nodiscard]] bool load(const std::filesystem::path &);
|
||||
// Generation-directory backend: each save keeps the previous generation for
|
||||
// crash recovery, CURRENT selects the newest, and a legacy index.json is
|
||||
// migrated on the first restore.
|
||||
[[nodiscard]] bool save_generation(const std::filesystem::path &);
|
||||
[[nodiscard]] std::expected<LoadResult, std::string>
|
||||
restore_generation(const std::filesystem::path &);
|
||||
|
||||
private:
|
||||
struct State;
|
||||
std::shared_ptr<State> state_;
|
||||
};
|
||||
|
||||
} // namespace vls::index
|
||||
@@ -0,0 +1,83 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/modules/ModuleGraph.hpp>
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
// Identity of one private module artifact. Compatibility covers frontend,
|
||||
// target ABI, stdlib and flags; context names the producer; inputs binds the
|
||||
// exact command, source and textual closure; kind distinguishes CMI/object.
|
||||
struct ArtifactKey {
|
||||
std::string compatibility, context, inputs, kind;
|
||||
auto operator<=>(const ArtifactKey &) const = default;
|
||||
[[nodiscard]] std::string identity() const;
|
||||
};
|
||||
|
||||
struct ArtifactEntry {
|
||||
ArtifactKey key;
|
||||
std::filesystem::path path;
|
||||
std::string sha256;
|
||||
};
|
||||
|
||||
// An immutable, completely published generation. Readers retain it while
|
||||
// eviction removes only generations no reader references.
|
||||
class ArtifactGeneration {
|
||||
public:
|
||||
[[nodiscard]] const std::string &id() const noexcept { return id_; }
|
||||
[[nodiscard]] const std::filesystem::path &root() const noexcept { return root_; }
|
||||
[[nodiscard]] std::optional<ArtifactEntry> find(const ArtifactKey &key) const;
|
||||
|
||||
private:
|
||||
friend class ArtifactCache;
|
||||
ArtifactGeneration(std::string id, std::filesystem::path root,
|
||||
std::map<ArtifactKey, ArtifactEntry> entries)
|
||||
: id_(std::move(id)), root_(std::move(root)), entries_(std::move(entries)) {}
|
||||
std::string id_;
|
||||
std::filesystem::path root_;
|
||||
std::map<ArtifactKey, ArtifactEntry> entries_;
|
||||
};
|
||||
|
||||
// Private artifact cache. Publication is all-or-nothing and content addressed;
|
||||
// a failed publication leaves no generation behind.
|
||||
class ArtifactCache {
|
||||
public:
|
||||
explicit ArtifactCache(std::filesystem::path root, std::size_t retained = 2);
|
||||
~ArtifactCache();
|
||||
ArtifactCache(const ArtifactCache &) = delete;
|
||||
ArtifactCache &operator=(const ArtifactCache &) = delete;
|
||||
|
||||
[[nodiscard]] std::expected<std::shared_ptr<const ArtifactGeneration>, std::string>
|
||||
publish(const std::map<ArtifactKey, std::filesystem::path> &artifacts);
|
||||
[[nodiscard]] std::shared_ptr<const ArtifactGeneration> current() const;
|
||||
// Removes unreferenced generations beyond the retained limit.
|
||||
std::size_t collect();
|
||||
[[nodiscard]] std::size_t generations() const;
|
||||
|
||||
private:
|
||||
struct State;
|
||||
std::shared_ptr<State> state_;
|
||||
};
|
||||
|
||||
// Produces one artifact per planned unit in dependency order. Any failure or
|
||||
// cancellation removes the staging directory and publishes nothing.
|
||||
using ArtifactWork = std::function<std::expected<std::filesystem::path, std::string>(
|
||||
std::stop_token, const Build::ContextKey &, const std::filesystem::path &output)>;
|
||||
|
||||
[[nodiscard]] std::expected<std::shared_ptr<const ArtifactGeneration>, std::string>
|
||||
produce_module_artifacts(const ModulePlan &plan, ArtifactCache &cache,
|
||||
const std::filesystem::path &staging, ArtifactWork work,
|
||||
std::stop_token stop = std::stop_token{});
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/modules/ArtifactCache.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
struct ModuleCommand {
|
||||
std::filesystem::path working_directory;
|
||||
// Absolute compiler path first. Arguments must not depend on the caller's
|
||||
// working directory: the work runs in a private directory.
|
||||
std::vector<std::string> arguments;
|
||||
};
|
||||
|
||||
using ModuleCommandLookup = std::function<std::optional<ModuleCommand>(const Build::ContextKey &)>;
|
||||
|
||||
struct GccArtifactOptions {
|
||||
std::chrono::milliseconds deadline{60000};
|
||||
std::size_t max_output_bytes{64 * 1024 * 1024};
|
||||
std::size_t max_artifact_bytes{512 * 1024 * 1024};
|
||||
};
|
||||
|
||||
// Real GCC module artifact production for one planned unit: runs the looked-up
|
||||
// command in a private working directory with a private module cache, requires
|
||||
// exactly one verified CMI and copies it to `output`. Tool authority, the
|
||||
// command's environment and its provenance are the caller's responsibility.
|
||||
[[nodiscard]] ArtifactWork
|
||||
gcc_module_artifact_work(ModuleCommandLookup lookup,
|
||||
GccArtifactOptions options = GccArtifactOptions{});
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/modules/ModuleGraph.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
struct ScanCommand {
|
||||
std::filesystem::path working_directory;
|
||||
// Absolute compiler first. Must contain exactly one absolute -fdeps-file=.
|
||||
std::vector<std::string> arguments;
|
||||
ExpectedOutput output;
|
||||
};
|
||||
|
||||
using ScanCommandLookup = std::function<std::optional<ScanCommand>(const Build::ContextKey &)>;
|
||||
|
||||
struct ScanProduct {
|
||||
std::string p1689;
|
||||
std::optional<ScanRule> rule;
|
||||
};
|
||||
|
||||
struct ScanOptions {
|
||||
std::filesystem::path directory; // private output directory
|
||||
std::chrono::milliseconds deadline{60000};
|
||||
std::size_t max_bytes{max_scan_bytes};
|
||||
};
|
||||
|
||||
// Runs one checked P1689 scan command and decodes its dependency file. The
|
||||
// product is filled only on success; a failure throws so the scheduler records
|
||||
// a failed task. No compiler option comes from project metadata here.
|
||||
[[nodiscard]] std::function<std::string(std::stop_token)>
|
||||
gcc_module_scan_work(ScanCommandLookup lookup, Build::ContextKey context,
|
||||
std::shared_ptr<ScanProduct> product, ScanOptions options = ScanOptions{});
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,227 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/LanguageServer/Build/Model.hpp>
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
namespace Build = Void::LanguageServer::Build;
|
||||
|
||||
inline constexpr std::size_t max_scan_bytes = 256 * 1024, max_scan_depth = 16;
|
||||
inline constexpr std::size_t max_field_bytes = 4096, max_rule_items = 512;
|
||||
inline constexpr std::size_t max_units = 4096, max_graph_items = 32768;
|
||||
inline constexpr std::size_t max_graph_bytes = 16 * 1024 * 1024;
|
||||
|
||||
struct ExpectedOutput {
|
||||
std::filesystem::path working_directory;
|
||||
std::string spelling;
|
||||
bool operator==(const ExpectedOutput &other) const {
|
||||
return working_directory.native() == other.working_directory.native() &&
|
||||
spelling == other.spelling;
|
||||
}
|
||||
};
|
||||
|
||||
enum class LookupMethod { by_name, include_angle, include_quote };
|
||||
struct ModuleDescription {
|
||||
std::string logical_name;
|
||||
std::optional<std::string> source_path, compiled_module_path;
|
||||
bool unique_on_source_path{};
|
||||
auto operator<=>(const ModuleDescription &) const = default;
|
||||
};
|
||||
struct ProvidedModule : ModuleDescription {
|
||||
bool is_interface{true};
|
||||
auto operator<=>(const ProvidedModule &) const = default;
|
||||
};
|
||||
struct RequiredModule : ModuleDescription {
|
||||
LookupMethod lookup{LookupMethod::by_name};
|
||||
auto operator<=>(const RequiredModule &) const = default;
|
||||
};
|
||||
|
||||
enum class ScanError {
|
||||
invalid_json,
|
||||
invalid_shape,
|
||||
unsupported_version,
|
||||
unsupported_field,
|
||||
invalid_invocation,
|
||||
wrong_directory,
|
||||
wrong_output,
|
||||
limit
|
||||
};
|
||||
|
||||
// GCC 16.2 single-rule version 0, revision 0. Only the decoder constructs rules.
|
||||
class ScanRule {
|
||||
public:
|
||||
const ExpectedOutput &output() const { return output_; }
|
||||
const auto &additional_outputs() const { return additional_outputs_; }
|
||||
const auto &provides() const { return provides_; }
|
||||
const auto &requirements() const { return requirements_; }
|
||||
std::size_t wire_bytes() const { return wire_bytes_; }
|
||||
|
||||
private:
|
||||
friend std::expected<ScanRule, ScanError> decode_scan(std::string_view, const ExpectedOutput &);
|
||||
ScanRule() = default;
|
||||
ExpectedOutput output_;
|
||||
std::vector<std::string> additional_outputs_;
|
||||
std::vector<ProvidedModule> provides_;
|
||||
std::vector<RequiredModule> requirements_;
|
||||
std::size_t wire_bytes_{};
|
||||
};
|
||||
using ScanResult = std::expected<ScanRule, ScanError>;
|
||||
[[nodiscard]] ScanResult decode_scan(std::string_view bytes, const ExpectedOutput &expected);
|
||||
|
||||
// The input owner admits this compatible set. Compatibility identifies frontend, target ABI,
|
||||
// stdlib, flags/environment affecting module interchange. Lookup covers all ordered search
|
||||
// roots, including misses, shadowing, overlays and generated inputs.
|
||||
struct ModuleDomain {
|
||||
Build::Generation generation;
|
||||
std::string compatibility, lookup;
|
||||
bool operator==(const ModuleDomain &) const = default;
|
||||
};
|
||||
|
||||
// Collision-checked identities for the exact invocation, owning source and immutable transitive
|
||||
// inputs. textual_closure includes header contents behind staged imports and their relevant
|
||||
// artifact generations. A user-only depfile additionally needs independently sealed system inputs.
|
||||
struct UnitInputs {
|
||||
std::string command, source, textual_closure;
|
||||
std::optional<std::string> system_closure;
|
||||
bool operator==(const UnitInputs &) const = default;
|
||||
};
|
||||
|
||||
// Provenance from staging an immutable header CMI. The scanner separately identifies the
|
||||
// generation it actually consumed. source_identity names the resolved header across spellings.
|
||||
struct StagedHeader {
|
||||
std::string generation, source_identity;
|
||||
ModuleDomain domain;
|
||||
Build::ContextKey producer;
|
||||
UnitInputs inputs;
|
||||
bool operator==(const StagedHeader &) const = default;
|
||||
};
|
||||
|
||||
struct CensusMember {
|
||||
Build::ContextKey context;
|
||||
ExpectedOutput output;
|
||||
UnitInputs inputs;
|
||||
// Changes on scanner replacement, even for equal source/command or a formerly absent rule.
|
||||
std::string scan_revision;
|
||||
std::optional<StagedHeader> staged_header;
|
||||
bool operator==(const CensusMember &) const = default;
|
||||
};
|
||||
struct ModuleCensus {
|
||||
ModuleDomain domain;
|
||||
std::string revision;
|
||||
bool closed{};
|
||||
// All eligible commands in this dependency domain. Other BuildGeneration alternatives
|
||||
// remain invisible. Distinct visibility sets require distinct censuses.
|
||||
std::vector<CensusMember> members;
|
||||
};
|
||||
|
||||
enum class ScanMethod { unknown, preprocess_md, preprocess_mmd, missing_allowed };
|
||||
enum class UnitKind {
|
||||
unknown,
|
||||
ordinary,
|
||||
implementation,
|
||||
primary_interface,
|
||||
interface_partition,
|
||||
internal_partition,
|
||||
header_unit
|
||||
};
|
||||
struct HeaderProvision {
|
||||
std::size_t index{}; // Index in ScanRule::provides().
|
||||
std::string source_identity;
|
||||
};
|
||||
struct HeaderUse {
|
||||
std::size_t index{}; // Index in ScanRule::requirements().
|
||||
std::string source_identity;
|
||||
std::optional<std::string> loaded_generation;
|
||||
};
|
||||
struct ScanEvidence {
|
||||
ModuleDomain domain;
|
||||
Build::ContextKey context;
|
||||
UnitInputs inputs;
|
||||
std::string scan_revision;
|
||||
std::optional<int> exit_status;
|
||||
std::optional<ScanResult> rule;
|
||||
ScanMethod method{ScanMethod::unknown};
|
||||
// The owner proves a complete pass under these inputs (including generated inputs) and
|
||||
// classifies every header-unit provision from its actual invocation and resolved source.
|
||||
bool complete{};
|
||||
// Implementation and ordinary importer can have identical rules. Only independent frontend
|
||||
// evidence can set one of these two kinds on an import-only TU.
|
||||
UnitKind import_only_kind{UnitKind::unknown};
|
||||
std::vector<HeaderProvision> provided_headers;
|
||||
// Engaged empty means the owner positively established absence of header-unit imports.
|
||||
// Bindings attest every reported lookup/source spelling to the resolved source identity.
|
||||
std::optional<std::vector<HeaderUse>> header_uses;
|
||||
// Verified writer identities in primary-output, then additional_outputs() order. An
|
||||
// isolated invocation can bind the same spelling to a different private destination.
|
||||
std::vector<std::string> writers;
|
||||
};
|
||||
|
||||
enum class PlanIssue {
|
||||
incomplete_census,
|
||||
invalid_context,
|
||||
wrong_domain,
|
||||
duplicate_member,
|
||||
missing_scan,
|
||||
duplicate_scan,
|
||||
scan_failed,
|
||||
missing_rule,
|
||||
invalid_rule,
|
||||
stale_scan,
|
||||
missing_source,
|
||||
incomplete_inputs,
|
||||
incomplete_scan,
|
||||
unproven_mapping,
|
||||
missing_provider,
|
||||
duplicate_provider,
|
||||
stale_header,
|
||||
writer_collision,
|
||||
cycle,
|
||||
limit
|
||||
};
|
||||
struct Blocker {
|
||||
PlanIssue code{};
|
||||
std::optional<std::size_t> unit; // Index in ModulePlan::units, when available.
|
||||
std::string detail;
|
||||
std::optional<ScanError> scan_error;
|
||||
auto operator<=>(const Blocker &) const = default;
|
||||
};
|
||||
struct PlannedUnit {
|
||||
CensusMember member;
|
||||
UnitKind kind{UnitKind::unknown};
|
||||
// Indices in ModulePlan::units. These are direct consumers across the admitted census.
|
||||
std::vector<std::size_t> consumers;
|
||||
};
|
||||
struct ModulePlan {
|
||||
ModuleDomain domain;
|
||||
std::string census_revision;
|
||||
std::vector<PlannedUnit> units; // Ascending ContextKey order.
|
||||
// Prerequisites first, requested TU last. Failure leaves the order empty.
|
||||
std::vector<Build::ContextKey> order;
|
||||
std::vector<Blocker> blockers;
|
||||
// All eligible scans can establish provider claims. A complete census may still have
|
||||
// missing imports, duplicate providers, conflicting writers or cycles. Unproven claims
|
||||
// withhold unit kinds and reverse edges.
|
||||
bool claims_complete{};
|
||||
[[nodiscard]] bool ready() const {
|
||||
return claims_complete && !order.empty() && blockers.empty();
|
||||
}
|
||||
// Also checks non-reachable members. A renamed or newly visible provider can change a
|
||||
// previous successful or missing lookup without having had any positive reverse edge.
|
||||
[[nodiscard]] bool matches_census(const ModuleCensus ¤t) const;
|
||||
};
|
||||
|
||||
[[nodiscard]] ModulePlan build_module_plan(const ModuleCensus &census,
|
||||
std::span<const ScanEvidence> scans,
|
||||
const Build::ContextKey &requested);
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/scheduler/Scheduler.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
enum class ModuleWorkKind { scan, artifact };
|
||||
|
||||
struct ModuleTaskResult {
|
||||
std::string document;
|
||||
ModuleWorkKind kind{ModuleWorkKind::scan};
|
||||
std::uint64_t revision{};
|
||||
scheduler::Outcome outcome{scheduler::Outcome::failed};
|
||||
std::string detail;
|
||||
};
|
||||
|
||||
using ModuleWork = std::function<std::string(std::stop_token)>;
|
||||
|
||||
// Editor-facing module work admission on the shared bounded scheduler.
|
||||
// Scans run at background priority and artifact preparation at artifact
|
||||
// priority, so neither delays foreground editor requests. A newer revision of
|
||||
// one kind supersedes queued work and cancels running work; closing or editing
|
||||
// a document cancels both kinds.
|
||||
class ModuleWorkQueue {
|
||||
public:
|
||||
explicit ModuleWorkQueue(scheduler::Scheduler &scheduler);
|
||||
ModuleWorkQueue(const ModuleWorkQueue &) = delete;
|
||||
ModuleWorkQueue &operator=(const ModuleWorkQueue &) = delete;
|
||||
|
||||
// False for a stale revision, an empty key or a refused scheduler admission.
|
||||
[[nodiscard]] bool submit(
|
||||
std::string document, ModuleWorkKind kind, std::uint64_t revision, ModuleWork work,
|
||||
std::function<void(ModuleTaskResult)> completion = std::function<void(ModuleTaskResult)>{});
|
||||
void cancel(std::string_view document);
|
||||
void cancel_all();
|
||||
|
||||
struct Counts {
|
||||
std::uint64_t submitted{}, completed{}, cancelled{}, failed{};
|
||||
};
|
||||
[[nodiscard]] Counts counts() const;
|
||||
|
||||
private:
|
||||
[[nodiscard]] static std::string key(std::string_view document, ModuleWorkKind kind);
|
||||
scheduler::Scheduler &scheduler_;
|
||||
mutable std::mutex mutex_;
|
||||
std::map<std::string, std::uint64_t> revisions_[2];
|
||||
Counts counts_;
|
||||
};
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/modules/ModuleGraph.hpp>
|
||||
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
enum class ScanCommandError {
|
||||
invalid_context,
|
||||
missing_source,
|
||||
duplicate_source,
|
||||
relative_dependency_file,
|
||||
limit
|
||||
};
|
||||
|
||||
struct ScanInvocation {
|
||||
// Driver first, then the original checked arguments with the scan options
|
||||
// appended. The owning source is the final operand.
|
||||
std::vector<std::string> arguments;
|
||||
};
|
||||
|
||||
// Derives a P1689 scan command from a checked compiler context. The driver and
|
||||
// owning source come from the context itself; the dependency file must be
|
||||
// absolute. Existing output, preprocess and dependency options are removed so
|
||||
// project metadata cannot select or duplicate the scan outputs.
|
||||
[[nodiscard]] std::expected<ScanInvocation, ScanCommandError>
|
||||
build_scan_invocation(const Build::BuildContext &context, const ExpectedOutput &output,
|
||||
const std::filesystem::path &dependency_file);
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/modules/ArtifactCache.hpp>
|
||||
#include <vls/scheduler/Scheduler.hpp>
|
||||
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
// Produces the planned units in dependency order through the shared scheduler
|
||||
// at artifact priority. A superseded, cancelled, timed-out or failed unit
|
||||
// publishes nothing; the staging directory is always removed.
|
||||
[[nodiscard]] std::expected<std::shared_ptr<const ArtifactGeneration>, std::string>
|
||||
produce_module_artifacts_scheduled(const ModulePlan &plan, ArtifactCache &cache,
|
||||
const std::filesystem::path &staging, ArtifactWork work,
|
||||
scheduler::Scheduler &scheduler,
|
||||
std::stop_token stop = std::stop_token{});
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::navigation {
|
||||
|
||||
struct Position {
|
||||
std::uint32_t line{}, character{};
|
||||
auto operator<=>(const Position &) const = default;
|
||||
};
|
||||
struct Range {
|
||||
Position start, end;
|
||||
auto operator<=>(const Range &) const = default;
|
||||
};
|
||||
struct Location {
|
||||
std::string path;
|
||||
Range range;
|
||||
auto operator<=>(const Location &) const = default;
|
||||
};
|
||||
|
||||
// Semantic identity of one binding. The definition location joins equal
|
||||
// symbols across analysis contexts; the name distinguishes unrelated symbols
|
||||
// without a proven definition.
|
||||
struct Binding {
|
||||
std::string name;
|
||||
std::optional<Location> definition;
|
||||
auto operator<=>(const Binding &) const = default;
|
||||
};
|
||||
|
||||
struct Fact {
|
||||
Binding binding;
|
||||
std::string context;
|
||||
std::string source; // use file
|
||||
std::string content; // content identity of the observed source
|
||||
Range use;
|
||||
bool editable{};
|
||||
std::string provenance;
|
||||
};
|
||||
|
||||
struct ContextState {
|
||||
std::string context;
|
||||
bool complete{};
|
||||
std::string reason;
|
||||
};
|
||||
|
||||
struct FactSet {
|
||||
std::string backend;
|
||||
std::uint64_t generation{};
|
||||
std::vector<Fact> facts;
|
||||
std::vector<ContextState> contexts;
|
||||
std::map<std::string, std::string> current_sources; // path -> current content
|
||||
};
|
||||
|
||||
enum class Refusal {
|
||||
none,
|
||||
unknown_binding,
|
||||
ambiguous_binding,
|
||||
incomplete_coverage,
|
||||
stale_source,
|
||||
non_editable_origin,
|
||||
generated_name,
|
||||
invalid_name,
|
||||
unchanged_name,
|
||||
multi_file_without_transaction,
|
||||
};
|
||||
|
||||
struct References {
|
||||
std::vector<Location> locations;
|
||||
bool coverage_complete{};
|
||||
std::vector<std::string> incomplete_contexts;
|
||||
bool truncated{};
|
||||
};
|
||||
|
||||
struct Edit {
|
||||
std::string path;
|
||||
Range range;
|
||||
std::string replacement;
|
||||
std::string content; // content identity the edit was prepared against
|
||||
};
|
||||
|
||||
struct RenamePlan {
|
||||
Refusal refusal{Refusal::none};
|
||||
std::string detail;
|
||||
std::vector<Edit> edits;
|
||||
[[nodiscard]] bool ready() const { return refusal == Refusal::none && !edits.empty(); }
|
||||
};
|
||||
|
||||
// Resolves the unique binding at a position. Overlapping distinct bindings are
|
||||
// ambiguous and never resolved by iteration order.
|
||||
[[nodiscard]] std::expected<Binding, Refusal> binding_at(const FactSet &, std::string_view path,
|
||||
Position);
|
||||
|
||||
// All proven uses. Partial locations are retained for diagnosis, but
|
||||
// coverage_complete is false whenever any context is incomplete.
|
||||
[[nodiscard]] References references(const FactSet &, const Binding &, std::size_t limit = 512);
|
||||
|
||||
// Only a ready plan may be applied. Refusals are explicit for incomplete
|
||||
// coverage, stale sources, non-editable origins, ambiguous bindings,
|
||||
// generated/invalid names and multi-file edits without a transactional client.
|
||||
[[nodiscard]] RenamePlan prepare_rename(const FactSet &, std::string_view path, Position,
|
||||
std::string_view replacement, bool transactional_client);
|
||||
|
||||
} // namespace vls::navigation
|
||||
@@ -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
|
||||
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace vls::scheduler {
|
||||
|
||||
enum class Priority { artifact = 0, background = 1, foreground = 2 };
|
||||
|
||||
struct Budget {
|
||||
std::size_t foreground{4};
|
||||
std::size_t background{2};
|
||||
std::size_t artifact{1};
|
||||
std::size_t queued{64};
|
||||
std::size_t memory_mib{1024};
|
||||
std::chrono::milliseconds watchdog{30000};
|
||||
|
||||
[[nodiscard]] bool valid() const noexcept;
|
||||
};
|
||||
|
||||
enum class Outcome { completed, failed, cancelled, timed_out };
|
||||
|
||||
struct Estimate {
|
||||
Priority priority{Priority::background};
|
||||
std::string key;
|
||||
std::uint64_t revision{};
|
||||
std::size_t memory_mib{};
|
||||
};
|
||||
|
||||
struct Result {
|
||||
std::string key;
|
||||
std::uint64_t revision{};
|
||||
Outcome outcome{Outcome::failed};
|
||||
std::string detail;
|
||||
};
|
||||
|
||||
struct Metrics {
|
||||
std::uint64_t accepted{}, completed{}, failed{}, cancelled{}, timed_out{}, rejected{};
|
||||
std::size_t queued_peak{}, running_peak{}, running_memory_peak{};
|
||||
std::uint64_t queue_nanoseconds{}, run_nanoseconds{};
|
||||
};
|
||||
|
||||
// Work returns a detail string on success or throws on failure. It must honor
|
||||
// the stop token so cancellation and the running watchdog stay bounded.
|
||||
using Work = std::function<std::string(std::stop_token)>;
|
||||
using Completion = std::function<void(Result)>;
|
||||
|
||||
// Bounded, priority-separated executor. Foreground, background and artifact
|
||||
// pools have reserved capacity, so a saturated background queue never delays a
|
||||
// foreground request. Every accepted submission receives exactly one terminal
|
||||
// completion; a refused submission receives none and returns false.
|
||||
class Scheduler {
|
||||
public:
|
||||
explicit Scheduler(Budget = Budget{});
|
||||
~Scheduler();
|
||||
Scheduler(const Scheduler &) = delete;
|
||||
Scheduler &operator=(const Scheduler &) = delete;
|
||||
Scheduler(Scheduler &&) = delete;
|
||||
Scheduler &operator=(Scheduler &&) = delete;
|
||||
|
||||
// A newer revision of the same key supersedes queued work immediately and
|
||||
// requests cooperative cancellation of running work.
|
||||
[[nodiscard]] bool submit(Estimate, Work, Completion);
|
||||
void cancel(std::string_view key);
|
||||
void cancel_all();
|
||||
// Waits until every accepted submission has reached a terminal result.
|
||||
void drain();
|
||||
[[nodiscard]] Metrics metrics() const;
|
||||
[[nodiscard]] const Budget &budget() const noexcept;
|
||||
|
||||
private:
|
||||
struct State;
|
||||
std::unique_ptr<State> state_;
|
||||
};
|
||||
|
||||
} // namespace vls::scheduler
|
||||
@@ -0,0 +1,109 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/LanguageServer/Documents/DocumentSnapshot.hpp>
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::semantic {
|
||||
namespace Documents = Void::LanguageServer::Documents;
|
||||
using DiagnosticSnapshot = std::shared_ptr<const Documents::DocumentSnapshot>;
|
||||
|
||||
// GCC can emit literal filenames, including percent signs. These spellings are
|
||||
// supplied by the launcher and are compared exactly, without URL decoding.
|
||||
struct ArtifactName {
|
||||
std::string uri, base_uri;
|
||||
auto operator<=>(const ArtifactName &) const = default;
|
||||
};
|
||||
struct DiagnosticArtifact {
|
||||
ArtifactName name;
|
||||
DiagnosticSnapshot snapshot;
|
||||
};
|
||||
struct ReportedRegion {
|
||||
std::uint32_t first_line, first_column, last_line, end_column;
|
||||
};
|
||||
enum class ColumnUnit { ascii_consensus, utf8_bytes, gcc_display };
|
||||
enum class FirstLineBom { unknown, counted, skipped };
|
||||
struct CoordinatePolicy {
|
||||
ColumnUnit unit{ColumnUnit::ascii_consensus};
|
||||
unsigned tabstop{8};
|
||||
FirstLineBom bom{FirstLineBom::unknown};
|
||||
};
|
||||
struct LocationRequest {
|
||||
const DiagnosticArtifact &artifact;
|
||||
ReportedRegion region;
|
||||
std::size_t result_index, location_index;
|
||||
bool related;
|
||||
};
|
||||
|
||||
struct DiagnosticJob {
|
||||
std::string invocation_id, input_view_id;
|
||||
DiagnosticSnapshot owner;
|
||||
std::vector<DiagnosticArtifact> artifacts;
|
||||
// The input owner accounts for unresolved includes and lookup dependencies.
|
||||
bool inputs_complete{};
|
||||
// Return a policy only for a proven physical location in the immutable
|
||||
// inputs. A matching snippet cannot establish the origin of a #line remap.
|
||||
std::function<std::optional<CoordinatePolicy>(const LocationRequest &)> physical_origin;
|
||||
};
|
||||
struct DiagnosticOutput {
|
||||
std::string_view invocation_id, input_view_id;
|
||||
std::optional<int> exit_code;
|
||||
bool stream_complete{};
|
||||
std::string_view sarif;
|
||||
};
|
||||
enum class DiagnosticError {
|
||||
invalid_job,
|
||||
wrong_capture,
|
||||
incomplete_stream,
|
||||
failed_process,
|
||||
malformed_report,
|
||||
unsupported_report,
|
||||
wrong_owner,
|
||||
tool_failure,
|
||||
resource_limit
|
||||
};
|
||||
enum class LocationGap {
|
||||
none,
|
||||
no_location,
|
||||
unknown_artifact,
|
||||
artifact_mismatch,
|
||||
incomplete_region,
|
||||
unproven_origin,
|
||||
ambiguous_column
|
||||
};
|
||||
struct DiagnosticLocation {
|
||||
LocationGap gap{LocationGap::no_location};
|
||||
DiagnosticSnapshot snapshot;
|
||||
std::optional<Documents::Range> range;
|
||||
};
|
||||
struct RelatedLocation {
|
||||
std::string message;
|
||||
DiagnosticLocation location;
|
||||
};
|
||||
enum class DiagnosticSeverity { error, warning, information, hint };
|
||||
struct CompilerDiagnostic {
|
||||
DiagnosticSeverity severity;
|
||||
std::string message, rule;
|
||||
DiagnosticLocation location;
|
||||
std::vector<RelatedLocation> related;
|
||||
};
|
||||
struct DiagnosticBatch {
|
||||
std::string invocation_id, input_view_id;
|
||||
DiagnosticSnapshot owner;
|
||||
std::vector<CompilerDiagnostic> diagnostics;
|
||||
// The publisher must still validate that this invocation is current.
|
||||
bool complete_for_owner{};
|
||||
};
|
||||
|
||||
[[nodiscard]] std::expected<DiagnosticBatch, DiagnosticError>
|
||||
decode_gcc_diagnostics(const DiagnosticJob &, const DiagnosticOutput &);
|
||||
} // namespace vls::semantic
|
||||
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/semantic/StockCompiler.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace vls::semantic {
|
||||
|
||||
// The input thread brackets document and workspace transitions. The analysis worker
|
||||
// publishes through the same ordered output queue as request responses.
|
||||
class EditorDiagnostics {
|
||||
public:
|
||||
using Send = std::function<bool(std::string)>;
|
||||
EditorDiagnostics(const std::filesystem::path &root, std::shared_ptr<const GccProfile>,
|
||||
WorkspaceSession &, const Documents::DocumentStore &, Send);
|
||||
~EditorDiagnostics();
|
||||
void set_version_support(bool);
|
||||
void begin_update();
|
||||
void finish_update(bool workspace_changed = false);
|
||||
void stop();
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json status(std::string_view uri) const;
|
||||
[[nodiscard]] bool supports_occurrences() const noexcept;
|
||||
// Bounded workspace symbol search over the context-aware index.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
workspace_symbols(std::string_view query) const;
|
||||
// Index-backed completion for the identifier prefix before the position.
|
||||
// Items are explicitly marked incomplete until compiler-native completion
|
||||
// exists; visibility is not proven by the index.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
completion(std::string_view uri, Documents::Position position) const;
|
||||
// Compiler-provided call signature at the position, or null when no
|
||||
// verified occurrence carries one.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
signature_help(std::string_view uri, Documents::Position position) const;
|
||||
// Deferred completion detail. The item's data carries the captured
|
||||
// identity and index generation; a changed generation returns the item
|
||||
// without details rather than details for a different entity.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
completion_resolve(const Void::LanguageServer::Protocol::Json &item) const;
|
||||
|
||||
struct NavigationReply {
|
||||
Void::LanguageServer::Protocol::Json result;
|
||||
std::optional<std::string> refusal;
|
||||
};
|
||||
// A refusal means the answer would be incomplete or unsafe; the result is
|
||||
// retained for diagnosis but must not be presented as complete.
|
||||
[[nodiscard]] NavigationReply references(std::string_view uri,
|
||||
Documents::Position position) const;
|
||||
[[nodiscard]] NavigationReply prepare_rename(std::string_view uri,
|
||||
Documents::Position position) const;
|
||||
[[nodiscard]] NavigationReply rename(std::string_view uri, Documents::Position position,
|
||||
std::string_view replacement) const;
|
||||
void set_transactional_rename(bool supported);
|
||||
// Answers are null when no verified occurrence covers the requested position.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json hover(std::string_view uri,
|
||||
Documents::Position position) const;
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
definition(std::string_view uri, Documents::Position position) const;
|
||||
|
||||
private:
|
||||
struct State;
|
||||
std::unique_ptr<State> state_;
|
||||
};
|
||||
|
||||
} // namespace vls::semantic
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/semantic/Diagnostics.hpp>
|
||||
#include <vls/semantic/SourceCatalog.hpp>
|
||||
|
||||
#include <expected>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::semantic {
|
||||
|
||||
// A compiler-owned direct-call fact. Byte spans from the stock observer are
|
||||
// already converted to the captured snapshot's negotiated character positions.
|
||||
struct Occurrence {
|
||||
std::string name, type, canonical_type, signature;
|
||||
DiagnosticSnapshot use_file;
|
||||
Documents::Range use;
|
||||
DiagnosticSnapshot definition_file;
|
||||
Documents::Range definition;
|
||||
|
||||
[[nodiscard]] bool has_definition() const noexcept { return definition_file != nullptr; }
|
||||
};
|
||||
|
||||
struct OccurrenceReport {
|
||||
std::vector<Occurrence> occurrences;
|
||||
bool complete{};
|
||||
bool partial{};
|
||||
std::string reason;
|
||||
};
|
||||
|
||||
enum class OccurrenceError { invalid_report, wrong_nonce };
|
||||
|
||||
// Decode a stock-observer report against the exact capture that was compiled.
|
||||
// Unknown paths, byte spans that do not match the captured bytes, duplicates
|
||||
// and malformed envelopes reject the whole report.
|
||||
[[nodiscard]] std::expected<OccurrenceReport, OccurrenceError>
|
||||
decode_occurrences(std::string_view report, std::string_view nonce,
|
||||
std::span<const CapturedSource> capture);
|
||||
|
||||
} // namespace vls::semantic
|
||||
@@ -0,0 +1,118 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/LanguageServer/Build/Model.hpp>
|
||||
#include <Void/LanguageServer/Documents/DocumentStore.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::semantic {
|
||||
namespace Documents = Void::LanguageServer::Documents;
|
||||
|
||||
struct SourceScope {
|
||||
Void::LanguageServer::Build::WorkspaceIdentity workspace;
|
||||
std::uint64_t configuration, trust;
|
||||
bool operator==(const SourceScope &) const = default;
|
||||
};
|
||||
|
||||
enum class SourceIssue {
|
||||
wrong_authority,
|
||||
invalid_path,
|
||||
outside_scope,
|
||||
unsupported_route,
|
||||
conflicting_names,
|
||||
missing,
|
||||
missing_parent,
|
||||
not_regular,
|
||||
hard_link,
|
||||
unavailable,
|
||||
unavailable_overlay,
|
||||
invalid_text,
|
||||
changed,
|
||||
resource_limit
|
||||
};
|
||||
|
||||
struct SourceError {
|
||||
SourceIssue issue;
|
||||
std::filesystem::path path;
|
||||
};
|
||||
|
||||
struct SourceRequest {
|
||||
std::filesystem::path path;
|
||||
bool allow_missing{};
|
||||
// Observe a file, directory or missing route without opening file payloads.
|
||||
bool lookup_only{};
|
||||
};
|
||||
|
||||
struct SourceLimits {
|
||||
std::size_t files{1024};
|
||||
std::size_t name_bytes{512 * 1024};
|
||||
std::size_t file_bytes{16 * 1024 * 1024};
|
||||
std::size_t total_bytes{32 * 1024 * 1024};
|
||||
std::size_t descriptors{256};
|
||||
};
|
||||
|
||||
enum class SourceNode { missing, directory, regular };
|
||||
struct CapturedSource {
|
||||
std::filesystem::path logical_path;
|
||||
// Content requests retain the selected snapshot. Lookup-only requests retain the node kind.
|
||||
std::shared_ptr<const Documents::DocumentSnapshot> snapshot;
|
||||
SourceNode node{SourceNode::missing};
|
||||
// GCC's __TIMESTAMP__ depends on the input file's modification time in seconds.
|
||||
std::optional<std::time_t> modified_at{};
|
||||
};
|
||||
|
||||
struct SourceGrant;
|
||||
using InstalledSourceGrant = std::shared_ptr<const SourceGrant>;
|
||||
struct SourceEvidence;
|
||||
struct SourceAccounting;
|
||||
|
||||
class SourceCapture {
|
||||
public:
|
||||
SourceCapture(const SourceCapture &) = delete;
|
||||
[[nodiscard]] std::span<const CapturedSource> entries() const noexcept { return entries_; }
|
||||
|
||||
private:
|
||||
friend class SourceCatalog;
|
||||
explicit SourceCapture(std::shared_ptr<SourceEvidence> evidence);
|
||||
std::shared_ptr<SourceEvidence> evidence_;
|
||||
std::vector<CapturedSource> entries_;
|
||||
};
|
||||
|
||||
// The workspace owner installs only its explicitly authorized source directories.
|
||||
// Captures witness the requested names. A worker must separately establish lookup closure.
|
||||
class SourceCatalog {
|
||||
public:
|
||||
// The owning session keeps its document store alive for the catalog's lifetime.
|
||||
explicit SourceCatalog(const Documents::DocumentStore &documents,
|
||||
std::function<void()> before_capture_validation = {});
|
||||
[[nodiscard]] std::expected<InstalledSourceGrant, SourceError>
|
||||
install(const SourceScope &scope, std::span<const std::filesystem::path> directories);
|
||||
void revoke();
|
||||
|
||||
[[nodiscard]] std::expected<std::shared_ptr<const SourceCapture>, SourceError>
|
||||
capture(const SourceScope &job, const InstalledSourceGrant &grant,
|
||||
const Documents::FileOverlayInventory &census, std::span<const SourceRequest> requests,
|
||||
SourceLimits limits = {}) const;
|
||||
|
||||
[[nodiscard]] std::expected<void, SourceError> validate(const SourceScope &job,
|
||||
const SourceCapture &capture) const;
|
||||
|
||||
private:
|
||||
const Documents::DocumentStore &documents_;
|
||||
std::mutex installations_;
|
||||
std::atomic<InstalledSourceGrant> installed_;
|
||||
std::shared_ptr<SourceAccounting> accounting_;
|
||||
std::function<void()> before_capture_validation_;
|
||||
};
|
||||
|
||||
} // namespace vls::semantic
|
||||
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/WorkspaceSession.hpp>
|
||||
#include <vls/semantic/Diagnostics.hpp>
|
||||
#include <vls/semantic/Occurrences.hpp>
|
||||
#include <vls/semantic/SourceCatalog.hpp>
|
||||
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::semantic {
|
||||
|
||||
class GccProfile {
|
||||
public:
|
||||
// Only the launcher selects this file for its explicitly selected workspace.
|
||||
static std::expected<std::shared_ptr<const GccProfile>, std::string>
|
||||
load(const std::filesystem::path &file);
|
||||
// Prepares the profile in process from the selected GCC driver. No
|
||||
// external script or pre-generated JSON is required.
|
||||
static std::expected<std::shared_ptr<const GccProfile>, std::string>
|
||||
prepare(const std::filesystem::path &driver);
|
||||
std::filesystem::path driver, frontend, bubblewrap, strace, prlimit;
|
||||
std::vector<std::filesystem::path> mounts;
|
||||
// Optional launcher-selected occurrence observer. Its exact bytes are
|
||||
// re-verified for every job; metadata cannot select or alter it.
|
||||
std::filesystem::path observer;
|
||||
std::string observer_identity;
|
||||
std::string target, flags, identity;
|
||||
|
||||
[[nodiscard]] bool observes() const noexcept { return !observer.empty(); }
|
||||
|
||||
private:
|
||||
GccProfile() = default;
|
||||
};
|
||||
|
||||
struct StockAnalysis {
|
||||
DiagnosticBatch batch;
|
||||
std::shared_ptr<const SourceCapture> sources;
|
||||
Void::LanguageServer::Build::Revision revision;
|
||||
// Present only when the launcher-selected observer produced a verified report.
|
||||
std::optional<OccurrenceReport> occurrences;
|
||||
// Why occurrence facts are unavailable when the observer was selected.
|
||||
std::string occurrence_detail;
|
||||
// Hints for the next run. Each new job reacquires and verifies all positive and negative
|
||||
// inputs.
|
||||
std::vector<std::filesystem::path> lookups;
|
||||
std::size_t compiler_runs{};
|
||||
std::optional<std::filesystem::path> unproven_location_origin;
|
||||
};
|
||||
|
||||
// One job owns an isolated filesystem and runs the regular GCC frontend. Caller revalidates
|
||||
// the lease and capture before delivering diagnostics to an editor.
|
||||
[[nodiscard]] std::expected<StockAnalysis, std::string>
|
||||
analyze_with_gcc(const GccProfile &profile, const SemanticContextLease &lease,
|
||||
const Documents::DocumentStore &documents, const SourceCatalog &catalog,
|
||||
const InstalledSourceGrant &grant, std::uint64_t sequence,
|
||||
std::span<const std::filesystem::path> previous_lookups, std::stop_token stop);
|
||||
|
||||
struct StockScan {
|
||||
std::vector<std::string> provides, imports;
|
||||
bool complete{};
|
||||
};
|
||||
|
||||
// Runs the checked P1689 scan for the selected translation unit in the same
|
||||
// isolated compiler view. The caller owns admission and cancellation.
|
||||
[[nodiscard]] std::expected<StockScan, std::string>
|
||||
scan_modules_with_gcc(const GccProfile &profile, const SemanticContextLease &lease,
|
||||
const Documents::DocumentStore &documents, const SourceCatalog &catalog,
|
||||
const InstalledSourceGrant &grant,
|
||||
std::span<const std::filesystem::path> previous_lookups,
|
||||
std::stop_token stop);
|
||||
|
||||
} // namespace vls::semantic
|
||||
Reference in new issue
Block a user