Files
Language-Server/include/vls/semantic/SourceCatalog.hpp
T
faumaray da8003f6d4 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.
2026-12-05 14:06:50 +03:00

119 lines
3.6 KiB
C++

#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