More LSP work.

This commit is contained in:
Martín Lucas Golini
2022-10-30 15:49:02 -03:00
parent 79b1aeb725
commit ec847e8678
12 changed files with 251 additions and 59 deletions

View File

@@ -39,9 +39,10 @@ LSPClientServerManager::supportsLSP( const std::shared_ptr<TextDocument>& doc )
return lsps;
}
std::shared_ptr<LSPClientServer>
LSPClientServerManager::runLSPServer( const LSPDefinition& lsp, const std::string& rootPath ) {
auto server = std::make_shared<LSPClientServer>( lsp, rootPath );
std::unique_ptr<LSPClientServer>
LSPClientServerManager::runLSPServer( const String::HashType& id, const LSPDefinition& lsp,
const std::string& rootPath ) {
auto server = std::make_unique<LSPClientServer>( this, id, lsp, rootPath );
server->start();
return server;
}
@@ -76,17 +77,23 @@ void LSPClientServerManager::tryRunServer( const std::shared_ptr<TextDocument>&
auto lspName = lsp.name.empty() ? lsp.command : lsp.name;
String::HashType id = String::hash( lspName + "|" + lsp.language + "|" + rootPath );
auto clientIt = mClients.find( id );
std::shared_ptr<LSPClientServer> server;
LSPClientServer* server = nullptr;
if ( clientIt == mClients.end() ) {
server = runLSPServer( lsp, rootPath );
if ( server.use_count() )
mClients[id] = server;
std::unique_ptr<LSPClientServer> serverUP = runLSPServer( id, lsp, rootPath );
if ( ( server = serverUP.get() ) )
mClients[id] = std::move( serverUP );
} else {
server = clientIt->second;
server = clientIt->second.get();
}
if ( server.use_count() ) {
if ( server )
server->registerDoc( doc );
}
}
}
void LSPClientServerManager::notifyClose( const String::HashType& id ) {
auto it = mClients.find( id );
if ( it != mClients.end() ) {
mClients.erase( it );
}
}
@@ -98,4 +105,13 @@ size_t LSPClientServerManager::clientCount() const {
return mClients.size();
}
const std::shared_ptr<ThreadPool>& LSPClientServerManager::getThreadPool() const {
return mPool;
}
void LSPClientServerManager::updateDirty() {
for ( auto& server : mClients )
server.second->updateDirty();
}
} // namespace ecode