forked from qt-creator/qt-creator
LanguageClient: Add LanguageClientManager::clientAdded() signal
For consumption by interested parties. Change-Id: I0cbecb4ce99cdd208fc3ff019d4f0ea672dcf752 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -192,7 +192,7 @@ ClangModelManagerSupport::ClangModelManagerSupport()
|
|||||||
connect(modelManager, &CppModelManager::fallbackProjectPartUpdated, this, [this] {
|
connect(modelManager, &CppModelManager::fallbackProjectPartUpdated, this, [this] {
|
||||||
if (ClangdClient * const fallbackClient = clientForProject(nullptr)) {
|
if (ClangdClient * const fallbackClient = clientForProject(nullptr)) {
|
||||||
LanguageClientManager::shutdownClient(fallbackClient);
|
LanguageClientManager::shutdownClient(fallbackClient);
|
||||||
claimNonProjectSources(createClient(nullptr, {}));
|
claimNonProjectSources(new ClangdClient(nullptr, {}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ ClangModelManagerSupport::ClangModelManagerSupport()
|
|||||||
this, &ClangModelManagerSupport::onClangdSettingsChanged);
|
this, &ClangModelManagerSupport::onClangdSettingsChanged);
|
||||||
|
|
||||||
if (CppEditor::ClangdSettings::instance().useClangd())
|
if (CppEditor::ClangdSettings::instance().useClangd())
|
||||||
createClient(nullptr, {});
|
new ClangdClient(nullptr, {});
|
||||||
|
|
||||||
m_generatorSynchronizer.setCancelOnWait(true);
|
m_generatorSynchronizer.setCancelOnWait(true);
|
||||||
new ClangdQuickFixFactory(); // memory managed by CppEditor::g_cppQuickFixFactories
|
new ClangdQuickFixFactory(); // memory managed by CppEditor::g_cppQuickFixFactories
|
||||||
@@ -388,7 +388,7 @@ void ClangModelManagerSupport::updateLanguageClient(
|
|||||||
}
|
}
|
||||||
if (Client * const oldClient = clientForProject(project))
|
if (Client * const oldClient = clientForProject(project))
|
||||||
LanguageClientManager::shutdownClient(oldClient);
|
LanguageClientManager::shutdownClient(oldClient);
|
||||||
ClangdClient * const client = createClient(project, jsonDbDir);
|
ClangdClient * const client = new ClangdClient(project, jsonDbDir);
|
||||||
connect(client, &Client::initialized, this, [this, client, project, projectInfo, jsonDbDir] {
|
connect(client, &Client::initialized, this, [this, client, project, projectInfo, jsonDbDir] {
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
if (!SessionManager::hasProject(project))
|
if (!SessionManager::hasProject(project))
|
||||||
@@ -521,14 +521,6 @@ ClangdClient *ClangModelManagerSupport::clientForFile(const Utils::FilePath &fil
|
|||||||
return qobject_cast<ClangdClient *>(LanguageClientManager::clientForFilePath(file));
|
return qobject_cast<ClangdClient *>(LanguageClientManager::clientForFilePath(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangdClient *ClangModelManagerSupport::createClient(ProjectExplorer::Project *project,
|
|
||||||
const Utils::FilePath &jsonDbDir)
|
|
||||||
{
|
|
||||||
const auto client = new ClangdClient(project, jsonDbDir);
|
|
||||||
emit createdClient(client);
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClangModelManagerSupport::claimNonProjectSources(ClangdClient *client)
|
void ClangModelManagerSupport::claimNonProjectSources(ClangdClient *client)
|
||||||
{
|
{
|
||||||
if (!client)
|
if (!client)
|
||||||
@@ -780,7 +772,7 @@ void ClangModelManagerSupport::onClangdSettingsChanged()
|
|||||||
ClangdClient * const fallbackClient = clientForProject(nullptr);
|
ClangdClient * const fallbackClient = clientForProject(nullptr);
|
||||||
const ClangdSettings &settings = ClangdSettings::instance();
|
const ClangdSettings &settings = ClangdSettings::instance();
|
||||||
const auto startNewFallbackClient = [this] {
|
const auto startNewFallbackClient = [this] {
|
||||||
claimNonProjectSources(createClient(nullptr, {}));
|
claimNonProjectSources(new ClangdClient(nullptr, {}));
|
||||||
};
|
};
|
||||||
if (!fallbackClient) {
|
if (!fallbackClient) {
|
||||||
if (settings.useClangd())
|
if (settings.useClangd())
|
||||||
|
@@ -71,9 +71,6 @@ public:
|
|||||||
|
|
||||||
static ClangModelManagerSupport *instance();
|
static ClangModelManagerSupport *instance();
|
||||||
|
|
||||||
signals:
|
|
||||||
void createdClient(ClangdClient *client);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void followSymbol(const CppEditor::CursorInEditor &data,
|
void followSymbol(const CppEditor::CursorInEditor &data,
|
||||||
const Utils::LinkHandler &processLinkCallback, bool resolveTarget,
|
const Utils::LinkHandler &processLinkCallback, bool resolveTarget,
|
||||||
@@ -110,7 +107,6 @@ private:
|
|||||||
|
|
||||||
void updateLanguageClient(ProjectExplorer::Project *project,
|
void updateLanguageClient(ProjectExplorer::Project *project,
|
||||||
const CppEditor::ProjectInfo::ConstPtr &projectInfo);
|
const CppEditor::ProjectInfo::ConstPtr &projectInfo);
|
||||||
ClangdClient *createClient(ProjectExplorer::Project *project, const Utils::FilePath &jsonDbDir);
|
|
||||||
void claimNonProjectSources(ClangdClient *client);
|
void claimNonProjectSources(ClangdClient *client);
|
||||||
void watchForExternalChanges();
|
void watchForExternalChanges();
|
||||||
void watchForInternalChanges();
|
void watchForInternalChanges();
|
||||||
|
@@ -61,6 +61,7 @@
|
|||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace CppEditor::Tests;
|
using namespace CppEditor::Tests;
|
||||||
|
using namespace LanguageClient;
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
@@ -104,12 +105,11 @@ void ClangdTest::waitForNewClient(bool withIndex)
|
|||||||
// Setting up the project should result in a clangd client being created.
|
// Setting up the project should result in a clangd client being created.
|
||||||
// Wait until that has happened.
|
// Wait until that has happened.
|
||||||
m_client = nullptr;
|
m_client = nullptr;
|
||||||
const auto modelManagerSupport = ClangModelManagerSupport::instance();
|
m_client = ClangModelManagerSupport::clientForProject(project());
|
||||||
m_client = modelManagerSupport->clientForProject(project());
|
|
||||||
if (!m_client) {
|
if (!m_client) {
|
||||||
QVERIFY(waitForSignalOrTimeout(modelManagerSupport,
|
QVERIFY(waitForSignalOrTimeout(LanguageClientManager::instance(),
|
||||||
&ClangModelManagerSupport::createdClient, timeOutInMs()));
|
&LanguageClientManager::clientAdded, timeOutInMs()));
|
||||||
m_client = modelManagerSupport->clientForProject(m_project);
|
m_client = ClangModelManagerSupport::clientForProject(project());
|
||||||
}
|
}
|
||||||
QVERIFY(m_client);
|
QVERIFY(m_client);
|
||||||
m_client->enableTesting();
|
m_client->enableTesting();
|
||||||
@@ -1878,8 +1878,8 @@ void ClangdTestCompletion::testCompleteAfterProjectChange()
|
|||||||
QString saveError;
|
QString saveError;
|
||||||
QVERIFY2(proFileEditor->document()->save(&saveError), qPrintable(saveError));
|
QVERIFY2(proFileEditor->document()->save(&saveError), qPrintable(saveError));
|
||||||
QVERIFY(waitForSignalOrTimeout(project(), &Project::anyParsingFinished, timeOutInMs()));
|
QVERIFY(waitForSignalOrTimeout(project(), &Project::anyParsingFinished, timeOutInMs()));
|
||||||
QVERIFY(waitForSignalOrTimeout(LanguageClient::LanguageClientManager::instance(),
|
QVERIFY(waitForSignalOrTimeout(LanguageClientManager::instance(),
|
||||||
&LanguageClient::LanguageClientManager::clientRemoved,
|
&LanguageClientManager::clientRemoved,
|
||||||
timeOutInMs()));
|
timeOutInMs()));
|
||||||
|
|
||||||
// Waiting for the index will cause highlighting info collection to start too late,
|
// Waiting for the index will cause highlighting info collection to start too late,
|
||||||
@@ -2026,8 +2026,8 @@ void ClangdTestExternalChanges::test()
|
|||||||
header.close();
|
header.close();
|
||||||
ClangdClient * const oldClient = client();
|
ClangdClient * const oldClient = client();
|
||||||
QVERIFY(oldClient);
|
QVERIFY(oldClient);
|
||||||
waitForSignalOrTimeout(ClangModelManagerSupport::instance(),
|
waitForSignalOrTimeout(LanguageClientManager::instance(),
|
||||||
&ClangModelManagerSupport::createdClient, timeOutInMs());
|
&LanguageClientManager::clientAdded, timeOutInMs());
|
||||||
QCOMPARE(client(), oldClient);
|
QCOMPARE(client(), oldClient);
|
||||||
QCOMPARE(client(), ClangModelManagerSupport::clientForProject(project()));
|
QCOMPARE(client(), ClangModelManagerSupport::clientForProject(project()));
|
||||||
const TextDocument * const curDoc = document("main.cpp");
|
const TextDocument * const curDoc = document("main.cpp");
|
||||||
@@ -2042,8 +2042,8 @@ void ClangdTestExternalChanges::test()
|
|||||||
QVERIFY(otherSource.open(QIODevice::WriteOnly));
|
QVERIFY(otherSource.open(QIODevice::WriteOnly));
|
||||||
otherSource.write("blubb");
|
otherSource.write("blubb");
|
||||||
otherSource.close();
|
otherSource.close();
|
||||||
QVERIFY(waitForSignalOrTimeout(ClangModelManagerSupport::instance(),
|
QVERIFY(waitForSignalOrTimeout(LanguageClientManager::instance(),
|
||||||
&ClangModelManagerSupport::createdClient, timeOutInMs()));
|
&LanguageClientManager::clientAdded, timeOutInMs()));
|
||||||
ClangdClient * const newClient = ClangModelManagerSupport::clientForProject(project());
|
ClangdClient * const newClient = ClangModelManagerSupport::clientForProject(project());
|
||||||
QVERIFY(newClient);
|
QVERIFY(newClient);
|
||||||
QVERIFY(newClient != oldClient);
|
QVERIFY(newClient != oldClient);
|
||||||
|
@@ -118,6 +118,7 @@ void LanguageClient::LanguageClientManager::addClient(Client *client)
|
|||||||
[client](const DynamicCapabilities &capabilities) {
|
[client](const DynamicCapabilities &capabilities) {
|
||||||
managerInstance->m_inspector.updateCapabilities(client->name(), capabilities);
|
managerInstance->m_inspector.updateCapabilities(client->name(), capabilities);
|
||||||
});
|
});
|
||||||
|
emit managerInstance->clientAdded(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanguageClientManager::clientStarted(Client *client)
|
void LanguageClientManager::clientStarted(Client *client)
|
||||||
|
@@ -103,6 +103,7 @@ public:
|
|||||||
static void showInspector();
|
static void showInspector();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void clientAdded(Client *client);
|
||||||
void clientRemoved(Client *client);
|
void clientRemoved(Client *client);
|
||||||
void shutdownFinished();
|
void shutdownFinished();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user