ClangCodeModel: reuse Id for restarted clients

This is needed to keep annotations hidden after the restart of clangd if
the user disabled them in the text mark tooltip.

Change-Id: I69a668f2ba71f1dda83eca74a064af7ec1f92e77
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2023-01-11 13:24:49 +01:00
parent 7c35363cda
commit 3677932266
5 changed files with 15 additions and 10 deletions

View File

@@ -355,8 +355,8 @@ static void addCompilationDb(QJsonObject &parentObject, const QJsonObject &cdb)
parentObject.insert("compilationDatabaseChanges", cdb); parentObject.insert("compilationDatabaseChanges", cdb);
} }
ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir) ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir, const Id &id)
: Client(clientInterface(project, jsonDbDir)), d(new Private(this, project)) : Client(clientInterface(project, jsonDbDir), id), d(new Private(this, project))
{ {
setName(tr("clangd")); setName(tr("clangd"));
LanguageFilter langFilter; LanguageFilter langFilter;

View File

@@ -41,7 +41,9 @@ class ClangdClient : public LanguageClient::Client
{ {
Q_OBJECT Q_OBJECT
public: public:
ClangdClient(ProjectExplorer::Project *project, const Utils::FilePath &jsonDbDir); ClangdClient(ProjectExplorer::Project *project,
const Utils::FilePath &jsonDbDir,
const Utils::Id &id = {});
~ClangdClient() override; ~ClangdClient() override;
bool isFullyIndexed() const; bool isFullyIndexed() const;

View File

@@ -494,9 +494,12 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
.arg(result.error)); .arg(result.error));
return; return;
} }
if (Client * const oldClient = clientForProject(project)) Utils::Id previousId;
if (Client * const oldClient = clientForProject(project)) {
previousId = oldClient->id();
LanguageClientManager::shutdownClient(oldClient); LanguageClientManager::shutdownClient(oldClient);
ClangdClient * const client = new ClangdClient(project, jsonDbDir); }
ClangdClient * const client = new ClangdClient(project, jsonDbDir, previousId);
connect(client, &Client::shadowDocumentSwitched, this, [](const Utils::FilePath &fp) { connect(client, &Client::shadowDocumentSwitched, this, [](const Utils::FilePath &fp) {
ClangdClient::handleUiHeaderChange(fp.fileName()); ClangdClient::handleUiHeaderChange(fp.fileName());
}); });

View File

@@ -130,9 +130,9 @@ class ClientPrivate : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
ClientPrivate(Client *client, BaseClientInterface *clientInterface) ClientPrivate(Client *client, BaseClientInterface *clientInterface, const Utils::Id &id)
: q(client) : q(client)
, m_id(Utils::Id::fromString(QUuid::createUuid().toString())) , m_id(id.isValid() ? id : Utils::Id::fromString(QUuid::createUuid().toString()))
, m_clientCapabilities(q->defaultClientCapabilities()) , m_clientCapabilities(q->defaultClientCapabilities())
, m_clientInterface(new InterfaceController(clientInterface)) , m_clientInterface(new InterfaceController(clientInterface))
, m_documentSymbolCache(q) , m_documentSymbolCache(q)
@@ -333,8 +333,8 @@ public:
const Utils::FilePath m_serverDeviceTemplate; const Utils::FilePath m_serverDeviceTemplate;
}; };
Client::Client(BaseClientInterface *clientInterface) Client::Client(BaseClientInterface *clientInterface, const Utils::Id &id)
: d(new ClientPrivate(this, clientInterface)) : d(new ClientPrivate(this, clientInterface, id))
{} {}
Id Client::id() const Id Client::id() const

View File

@@ -49,7 +49,7 @@ class LANGUAGECLIENT_EXPORT Client : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit Client(BaseClientInterface *clientInterface); // takes ownership explicit Client(BaseClientInterface *clientInterface, const Utils::Id &id = {}); // takes ownership
~Client() override; ~Client() override;
Client(const Client &) = delete; Client(const Client &) = delete;