CIRCT 22.0.0git
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
circt::lsp::PendingChangesMap Class Reference

Thread-safe accumulator + debouncer for text document changes. More...

#include <PendingChanges.h>

Collaboration diagram for circt::lsp::PendingChangesMap:
Collaboration graph
[legend]

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 &params, 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 &params)
 Append new edits for a document key.
 
void 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.
 

Private Member Functions

PendingChangesgetOrCreateEntry (std::string_view key)
 NOT thread-safe; caller must hold mu.
 
std::unique_ptr< PendingChangestakeAndErase (llvm::StringMap< PendingChanges >::iterator it)
 NOT thread-safe; caller must hold mu.
 

Private Attributes

llvm::StringMap< PendingChangespending
 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
 

Detailed Description

Thread-safe accumulator + debouncer for text document changes.

Definition at line 55 of file PendingChanges.h.

Constructor & Destructor Documentation

◆ PendingChangesMap()

circt::lsp::PendingChangesMap::PendingChangesMap ( unsigned  maxThreads = std::thread::hardware_concurrency())
inlineexplicit

Definition at line 57 of file PendingChanges.h.

Member Function Documentation

◆ abort()

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.

References mu, pending, and pool.

◆ debounceAndThen()

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().

◆ 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().

◆ 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().

◆ erase() [1/2]

void circt::lsp::PendingChangesMap::erase ( const llvm::lsp::URIForFile &  uri)

Definition at line 35 of file PendingChanges.cpp.

References erase().

◆ erase() [2/2]

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.

References mu, and pending.

Referenced by erase().

◆ getOrCreateEntry()

PendingChanges & circt::lsp::PendingChangesMap::getOrCreateEntry ( std::string_view  key)
private

NOT thread-safe; caller must hold mu.

Definition at line 130 of file PendingChanges.cpp.

References pending.

Referenced by enqueueChange().

◆ takeAndErase()

std::unique_ptr< PendingChanges > circt::lsp::PendingChangesMap::takeAndErase ( llvm::StringMap< PendingChanges >::iterator  it)
private

NOT thread-safe; caller must hold mu.

Definition at line 139 of file PendingChanges.cpp.

References pending.

Referenced by debounceAndThen().

Member Data Documentation

◆ mu

std::mutex circt::lsp::PendingChangesMap::mu
private

Guards pending.

Definition at line 104 of file PendingChanges.h.

Referenced by abort(), debounceAndThen(), enqueueChange(), and erase().

◆ pending

llvm::StringMap<PendingChanges> circt::lsp::PendingChangesMap::pending
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().

◆ pool

llvm::StdThreadPool circt::lsp::PendingChangesMap::pool
private

Internal concurrency used for sleeps + checks.

Definition at line 107 of file PendingChanges.h.

Referenced by abort().

◆ tasks

llvm::ThreadPoolTaskGroup circt::lsp::PendingChangesMap::tasks
private

Definition at line 108 of file PendingChanges.h.

Referenced by debounceAndThen().


The documentation for this class was generated from the following files: