From 638e73e4f8ff183fbb76beda87ceaa6df7d66e12 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 18 Oct 2022 14:58:00 +0200 Subject: [PATCH] Clangd indexing: Hide cancel button, open settings on click Since we cannot reasonably "cancel" indexing, hide the cancel button from the progress indicator. Open the Clangd settings page when clicking on the progress indicator instead. Fixes: QTCREATORBUG-27744 Change-Id: I625464e7f7456bcf7f01ce7e52f6bd6b53e3d8b2 Reviewed-by: Christian Kandeler Reviewed-by: Reviewed-by: Qt CI Bot Reviewed-by: hjk Reviewed-by: David Schulz --- src/plugins/clangcodemodel/clangdclient.cpp | 12 ++++++++++-- .../progressmanager/futureprogress.cpp | 17 ++++++++++++++++- .../coreplugin/progressmanager/futureprogress.h | 3 +++ src/plugins/languageclient/client.cpp | 6 ++++++ src/plugins/languageclient/client.h | 2 ++ src/plugins/languageclient/progressmanager.cpp | 10 ++++++++++ src/plugins/languageclient/progressmanager.h | 3 +++ 7 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index b6693adf689..8ff6d34119b 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -18,18 +18,20 @@ #include "tasktimers.h" #include +#include #include #include #include #include +#include #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -389,6 +391,9 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir) setProgressTitleForToken(indexingToken(), project ? tr("Indexing %1 with clangd").arg(project->displayName()) : tr("Indexing session with clangd")); + setClickHandlerForToken(indexingToken(), [] { + ICore::showOptionsDialog(CppEditor::Constants::CPP_CLANGD_SETTINGS_ID); + }); setCurrentProject(project); setDocumentChangeUpdateThreshold(d->settings.documentUpdateThreshold); setSymbolStringifier(displayNameFromDocumentSymbol); @@ -430,7 +435,10 @@ ClangdClient::~ClangdClient() delete d; } -bool ClangdClient::isFullyIndexed() const { return d->isFullyIndexed; } +bool ClangdClient::isFullyIndexed() const +{ + return d->isFullyIndexed; +} void ClangdClient::openExtraFile(const Utils::FilePath &filePath, const QString &content) { diff --git a/src/plugins/coreplugin/progressmanager/futureprogress.cpp b/src/plugins/coreplugin/progressmanager/futureprogress.cpp index 55fc29225d9..b2ea4fdd96a 100644 --- a/src/plugins/coreplugin/progressmanager/futureprogress.cpp +++ b/src/plugins/coreplugin/progressmanager/futureprogress.cpp @@ -121,7 +121,12 @@ FutureProgress::FutureProgress(QWidget *parent) : this, &FutureProgress::setProgressValue); connect(&d->m_watcher, &QFutureWatcherBase::progressTextChanged, this, &FutureProgress::setProgressText); - connect(d->m_progress, &Internal::ProgressBar::clicked, this, &FutureProgress::cancel); + connect(d->m_progress, &Internal::ProgressBar::clicked, this, [this] { + if (isCancelEnabled()) + cancel(); + else + emit clicked(); + }); setMinimumWidth(100); setMaximumWidth(300); } @@ -373,6 +378,16 @@ QSize FutureProgress::sizeHint() const return QSize(QWidget::sizeHint().width(), minimumHeight()); } +bool FutureProgress::isCancelEnabled() const +{ + return d->m_progress->isCancelEnabled(); +} + +void FutureProgress::setCancelEnabled(bool enabled) +{ + d->m_progress->setCancelEnabled(enabled); +} + void FutureProgressPrivate::fadeAway() { m_isFading = true; diff --git a/src/plugins/coreplugin/progressmanager/futureprogress.h b/src/plugins/coreplugin/progressmanager/futureprogress.h index 5277ef66c4e..0f6630cd8c4 100644 --- a/src/plugins/coreplugin/progressmanager/futureprogress.h +++ b/src/plugins/coreplugin/progressmanager/futureprogress.h @@ -59,6 +59,9 @@ public: QSize sizeHint() const override; + bool isCancelEnabled() const; + void setCancelEnabled(bool enabled); + signals: void clicked(); void finished(); diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index d61f3c720a7..3911e422298 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -1573,6 +1573,12 @@ void Client::setProgressTitleForToken(const LanguageServerProtocol::ProgressToke d->m_progressManager.setTitleForToken(token, message); } +void Client::setClickHandlerForToken(const LanguageServerProtocol::ProgressToken &token, + const std::function &handler) +{ + d->m_progressManager.setClickHandlerForToken(token, handler); +} + void Client::handleMessage(const LanguageServerProtocol::JsonRpcMessage &message) { LanguageClientManager::logJsonRpcMessage(LspLogMessage::ServerMessage, name(), message); diff --git a/src/plugins/languageclient/client.h b/src/plugins/languageclient/client.h index 5f29f080590..7061b9514ec 100644 --- a/src/plugins/languageclient/client.h +++ b/src/plugins/languageclient/client.h @@ -197,6 +197,8 @@ protected: void setError(const QString &message); void setProgressTitleForToken(const LanguageServerProtocol::ProgressToken &token, const QString &message); + void setClickHandlerForToken(const LanguageServerProtocol::ProgressToken &token, + const std::function &handler); void handleMessage(const LanguageServerProtocol::JsonRpcMessage &message); virtual void handleDiagnostics(const LanguageServerProtocol::PublishDiagnosticsParams ¶ms); virtual DiagnosticManager *createDiagnosticManager(); diff --git a/src/plugins/languageclient/progressmanager.cpp b/src/plugins/languageclient/progressmanager.cpp index a2c6ae5ec2b..241c51b2937 100644 --- a/src/plugins/languageclient/progressmanager.cpp +++ b/src/plugins/languageclient/progressmanager.cpp @@ -41,6 +41,12 @@ void ProgressManager::setTitleForToken(const LanguageServerProtocol::ProgressTok m_titles.insert(token, message); } +void ProgressManager::setClickHandlerForToken(const LanguageServerProtocol::ProgressToken &token, + const std::function &handler) +{ + m_clickHandlers.insert(token, handler); +} + void ProgressManager::reset() { const QList &tokens = m_progress.keys(); @@ -72,6 +78,10 @@ void ProgressManager::beginProgress(const ProgressToken &token, const WorkDonePr const QString title = m_titles.value(token, begin.title()); Core::FutureProgress *progress = Core::ProgressManager::addTask( interface->future(), title, languageClientProgressId(token)); + progress->setCancelEnabled(false); + const std::function clickHandler = m_clickHandlers.value(token); + if (clickHandler) + QObject::connect(progress, &Core::FutureProgress::clicked, clickHandler); m_progress[token] = {progress, interface}; if (LOGPROGRESS().isDebugEnabled()) m_timer[token].start(); diff --git a/src/plugins/languageclient/progressmanager.h b/src/plugins/languageclient/progressmanager.h index 0a940a960b3..2170fb3f0d0 100644 --- a/src/plugins/languageclient/progressmanager.h +++ b/src/plugins/languageclient/progressmanager.h @@ -27,6 +27,8 @@ public: void handleProgress(const LanguageServerProtocol::ProgressParams ¶ms); void setTitleForToken(const LanguageServerProtocol::ProgressToken &token, const QString &message); + void setClickHandlerForToken(const LanguageServerProtocol::ProgressToken &token, + const std::function &handler); void reset(); static bool isProgressEndMessage(const LanguageServerProtocol::ProgressParams ¶ms); @@ -48,6 +50,7 @@ private: QMap m_progress; QMap m_titles; QMap m_timer; + QMap> m_clickHandlers; }; } // namespace LanguageClient