CIRCT 22.0.0git
|
Thread-safe accumulator + debouncer for text document changes. More...
#include <PendingChanges.h>
Public Member Functions | |
PendingChangesMap (unsigned maxThreads=std::thread::hardware_concurrency()) | |
void | abort () |
Call during server shutdown; Erase all file changes, then clear file map. | |
void | erase (llvm::StringRef key) |
Remove all pending edits for a document key. | |
void | erase (const llvm::lsp::URIForFile &uri) |
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 | enqueueChange (const llvm::lsp::DidChangeTextDocumentParams ¶ms) |
Append new edits for a document key. | |
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. | |
Private Member Functions | |
PendingChanges & | getOrCreateEntry (std::string_view key) |
NOT thread-safe; caller must hold mu. | |
std::unique_ptr< PendingChanges > | takeAndErase (llvm::StringMap< PendingChanges >::iterator it) |
NOT thread-safe; caller must hold mu. | |
Private Attributes | |
llvm::StringMap< PendingChanges > | pending |
Per-document edit bursts, keyed by file string. | |
std::mutex | mu |
Guards pending . | |
llvm::StdThreadPool | pool |
Internal concurrency used for sleeps + checks. | |
llvm::ThreadPoolTaskGroup | tasks |
Thread-safe accumulator + debouncer for text document changes.
Definition at line 55 of file PendingChanges.h.
|
inlineexplicit |
Definition at line 57 of file PendingChanges.h.
void circt::lsp::PendingChangesMap::abort | ( | ) |
Call during server shutdown; Erase all file changes, then clear file map.
Thread-safe.
Definition at line 24 of file PendingChanges.cpp.
void circt::lsp::PendingChangesMap::debounceAndThen | ( | const llvm::lsp::DidChangeTextDocumentParams & | params, |
DebounceOptions | options, | ||
std::function< void(std::unique_ptr< PendingChanges >)> | cb | ||
) |
Schedule a debounce check on the internal pool and call cb
when ready.
If the task becomes obsolete (newer edits arrive before the quiet window, and max cap not reached), cb(nullptr)
is invoked. Thread-safe.
Definition at line 69 of file PendingChanges.cpp.
References circt::lsp::DebounceOptions::debounceMaxMs, circt::lsp::DebounceOptions::debounceMinMs, circt::lsp::DebounceOptions::disableDebounce, circt::lsp::PendingChanges::firstChangeTime, circt::lsp::PendingChanges::lastChangeTime, mu, pending, takeAndErase(), and tasks.
Referenced by debounceAndUpdate().
void circt::lsp::PendingChangesMap::debounceAndUpdate | ( | const llvm::lsp::DidChangeTextDocumentParams & | params, |
DebounceOptions | options, | ||
std::function< void(std::unique_ptr< PendingChanges >)> | cb | ||
) |
Append new edits for a document key, then start a debounced update thread.
Thread-safe.
Definition at line 41 of file PendingChanges.cpp.
References debounceAndThen(), and enqueueChange().
void circt::lsp::PendingChangesMap::enqueueChange | ( | const llvm::lsp::DidChangeTextDocumentParams & | params | ) |
Append new edits for a document key.
Thread-safe.
Definition at line 49 of file PendingChanges.cpp.
References getOrCreateEntry(), mu, and pending.
Referenced by debounceAndUpdate().
void circt::lsp::PendingChangesMap::erase | ( | const llvm::lsp::URIForFile & | uri | ) |
Definition at line 35 of file PendingChanges.cpp.
References erase().
void circt::lsp::PendingChangesMap::erase | ( | llvm::StringRef | key | ) |
Remove all pending edits for a document key.
Safe to call from the LSP thread when a file closes. Thread-safe.
Definition at line 30 of file PendingChanges.cpp.
Referenced by erase().
|
private |
NOT thread-safe; caller must hold mu.
Definition at line 130 of file PendingChanges.cpp.
References pending.
Referenced by enqueueChange().
|
private |
NOT thread-safe; caller must hold mu.
Definition at line 139 of file PendingChanges.cpp.
References pending.
Referenced by debounceAndThen().
|
private |
Guards pending
.
Definition at line 104 of file PendingChanges.h.
Referenced by abort(), debounceAndThen(), enqueueChange(), and erase().
|
private |
Per-document edit bursts, keyed by file string.
Stored by value; safe to move out when flushing.
Definition at line 102 of file PendingChanges.h.
Referenced by abort(), debounceAndThen(), enqueueChange(), erase(), getOrCreateEntry(), and takeAndErase().
|
private |
Internal concurrency used for sleeps + checks.
Definition at line 107 of file PendingChanges.h.
Referenced by abort().
|
private |
Definition at line 108 of file PendingChanges.h.
Referenced by debounceAndThen().