#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include 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 snapshot; SourceNode node{SourceNode::missing}; // GCC's __TIMESTAMP__ depends on the input file's modification time in seconds. std::optional modified_at{}; }; struct SourceGrant; using InstalledSourceGrant = std::shared_ptr; struct SourceEvidence; struct SourceAccounting; class SourceCapture { public: SourceCapture(const SourceCapture &) = delete; [[nodiscard]] std::span entries() const noexcept { return entries_; } private: friend class SourceCatalog; explicit SourceCapture(std::shared_ptr evidence); std::shared_ptr evidence_; std::vector 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 before_capture_validation = {}); [[nodiscard]] std::expected install(const SourceScope &scope, std::span directories); void revoke(); [[nodiscard]] std::expected, SourceError> capture(const SourceScope &job, const InstalledSourceGrant &grant, const Documents::FileOverlayInventory &census, std::span requests, SourceLimits limits = {}) const; [[nodiscard]] std::expected validate(const SourceScope &job, const SourceCapture &capture) const; private: const Documents::DocumentStore &documents_; std::mutex installations_; std::atomic installed_; std::shared_ptr accounting_; std::function before_capture_validation_; }; } // namespace vls::semantic