25 std::scoped_lock lock(
mu);
31 std::scoped_lock lock(
mu);
36 auto file = uri.file();
42 const llvm::lsp::DidChangeTextDocumentParams ¶ms,
44 std::function<
void(std::unique_ptr<PendingChanges>)> cb) {
50 const llvm::lsp::DidChangeTextDocumentParams ¶ms) {
53 const auto now = std::chrono::steady_clock::now();
54 const std::string key = params.textDocument.uri.file().str();
56 std::scoped_lock lock(
mu);
59 pending.changes.insert(
pending.changes.end(), params.contentChanges.begin(),
60 params.contentChanges.end());
61 pending.version = params.textDocument.version;
65 if (
pending.changes.size() == params.contentChanges.size())
70 const llvm::lsp::DidChangeTextDocumentParams ¶ms,
72 std::function<
void(std::unique_ptr<PendingChanges>)> cb) {
73 const std::string key = params.textDocument.uri.file().str();
74 const auto scheduleTime = std::chrono::steady_clock::now();
78 std::scoped_lock lock(
mu);
86 tasks.async([
this, key, scheduleTime, options, cb = std::move(cb)]() {
90 std::this_thread::sleep_for(
93 std::unique_ptr<PendingChanges>
97 std::scoped_lock lock(
mu);
101 const auto now = std::chrono::steady_clock::now();
105 const bool quietSinceSchedule = (pc.
lastChangeTime <= scheduleTime);
109 bool maxWaitExpired =
false;
111 const auto elapsedMs =
112 std::chrono::duration_cast<std::chrono::milliseconds>(
119 if (quietSinceSchedule || maxWaitExpired)
126 cb(std::move(result));
134 auto inserted =
pending.try_emplace(key);
135 return inserted.first->second;
138std::unique_ptr<PendingChanges>
140 auto out = std::make_unique<PendingChanges>(std::move(it->second));
void debounceAndThen(const llvm::lsp::DidChangeTextDocumentParams ¶ms, DebounceOptions options, std::function< void(std::unique_ptr< PendingChanges >)> cb)
Schedule a debounce check on the internal pool and call cb when ready.
std::mutex mu
Guards pending.
llvm::ThreadPoolTaskGroup tasks
llvm::StdThreadPool pool
Internal concurrency used for sleeps + checks.
std::unique_ptr< PendingChanges > takeAndErase(llvm::StringMap< PendingChanges >::iterator it)
NOT thread-safe; caller must hold mu.
llvm::StringMap< PendingChanges > pending
Per-document edit bursts, keyed by file string.
void abort()
Call during server shutdown; Erase all file changes, then clear file map.
void enqueueChange(const llvm::lsp::DidChangeTextDocumentParams ¶ms)
Append new edits for a document key.
void debounceAndUpdate(const llvm::lsp::DidChangeTextDocumentParams ¶ms, DebounceOptions options, std::function< void(std::unique_ptr< PendingChanges >)> cb)
Append new edits for a document key, then start a debounced update thread.
void erase(llvm::StringRef key)
Remove all pending edits for a document key.
PendingChanges & getOrCreateEntry(std::string_view key)
NOT thread-safe; caller must hold mu.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Debounce tuning for document-change bursts.
uint64_t debounceMinMs
Minimum quiet time before we flush.
static DebounceOptions fromLSPOptions(const circt::lsp::LSPServerOptions &opts)
Factory: build from server options. Keep mapping 1:1 for clarity.
bool disableDebounce
If true, flush immediately (no sleep/check).
uint64_t debounceMaxMs
Maximum total burst time (0 = no cap).
const unsigned debounceMinMs
Minimum debounce delay in milliseconds.
const unsigned debounceMaxMs
Maximum debounce delay in milliseconds.
const bool disableDebounce
Disable debouncing entirely (updates applied synchronously).
Accumulated edits + timing for a single document key.
std::chrono::steady_clock::time_point firstChangeTime
std::chrono::steady_clock::time_point lastChangeTime