Files
Language-Server/include/vls/modules/ModuleWorkQueue.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

58 lines
1.8 KiB
C++

#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