mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-18 06:55:48 +03:00
Fix slowdown due to locking the main thread when sending text buffer changes to the LSP.
This commit is contained in:
@@ -1628,18 +1628,37 @@ LSPClientServer::didChange( TextDocument* doc, const std::vector<DocumentContent
|
||||
return LSPRequestHandle();
|
||||
}
|
||||
|
||||
void LSPClientServer::queueDidChange( const URI& document, int version, const std::string&,
|
||||
const std::vector<DocumentContentChange>& change ) {
|
||||
Lock l( mDidChangeMutex );
|
||||
mDidChangeQueue.push( { document, version, change } );
|
||||
void LSPClientServer::queueAndProcess( const URI& document, int version,
|
||||
const std::vector<DocumentContentChange>& change ) {
|
||||
bool shouldStartWorker = false;
|
||||
{
|
||||
Lock l( mDidChangeMutex );
|
||||
mDidChangeQueue.push( { document, version, change } );
|
||||
if ( !mIsProcessingQueue ) {
|
||||
mIsProcessingQueue = true;
|
||||
shouldStartWorker = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( shouldStartWorker ) {
|
||||
getThreadPool()->run( [this]() { this->processDidChangeQueue(); } );
|
||||
}
|
||||
}
|
||||
|
||||
void LSPClientServer::processDidChangeQueue() {
|
||||
Lock l( mDidChangeMutex );
|
||||
while ( !mDidChangeQueue.empty() ) {
|
||||
auto& change = mDidChangeQueue.front();
|
||||
while ( true ) {
|
||||
DidChangeQueue change;
|
||||
{
|
||||
Lock l( mDidChangeMutex );
|
||||
if ( mDidChangeQueue.empty() ) {
|
||||
mIsProcessingQueue = false;
|
||||
break;
|
||||
}
|
||||
change = mDidChangeQueue.front();
|
||||
mDidChangeQueue.pop();
|
||||
}
|
||||
// Process outside the lock to avoid blocking
|
||||
didChange( change.uri, change.version, "", change.change );
|
||||
mDidChangeQueue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user