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 <christian.kandeler@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2022-10-18 14:58:00 +02:00
parent ada6989079
commit 638e73e4f8
7 changed files with 50 additions and 3 deletions

View File

@@ -18,18 +18,20 @@
#include "tasktimers.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <cplusplus/AST.h>
#include <cplusplus/ASTPath.h>
#include <cplusplus/Icons.h>
#include <cppeditor/cppcodemodelsettings.h>
#include <cppeditor/cppeditorconstants.h>
#include <cppeditor/cppeditorwidget.h>
#include <cppeditor/cppmodelmanager.h>
#include <cppeditor/cpprefactoringchanges.h>
#include <cppeditor/cppsemanticinfo.h>
#include <cppeditor/cpptoolsreuse.h>
#include <cppeditor/cppvirtualfunctionassistprovider.h>
#include <cppeditor/cppvirtualfunctionproposalitem.h>
#include <cppeditor/semantichighlighter.h>
#include <cppeditor/cppsemanticinfo.h>
#include <languageclient/diagnosticmanager.h>
#include <languageclient/languageclienthoverhandler.h>
#include <languageclient/languageclientinterface.h>
@@ -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)
{

View File

@@ -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;

View File

@@ -59,6 +59,9 @@ public:
QSize sizeHint() const override;
bool isCancelEnabled() const;
void setCancelEnabled(bool enabled);
signals:
void clicked();
void finished();

View File

@@ -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<void()> &handler)
{
d->m_progressManager.setClickHandlerForToken(token, handler);
}
void Client::handleMessage(const LanguageServerProtocol::JsonRpcMessage &message)
{
LanguageClientManager::logJsonRpcMessage(LspLogMessage::ServerMessage, name(), message);

View File

@@ -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<void()> &handler);
void handleMessage(const LanguageServerProtocol::JsonRpcMessage &message);
virtual void handleDiagnostics(const LanguageServerProtocol::PublishDiagnosticsParams &params);
virtual DiagnosticManager *createDiagnosticManager();

View File

@@ -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<void()> &handler)
{
m_clickHandlers.insert(token, handler);
}
void ProgressManager::reset()
{
const QList<ProgressToken> &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<void()> 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();

View File

@@ -27,6 +27,8 @@ public:
void handleProgress(const LanguageServerProtocol::ProgressParams &params);
void setTitleForToken(const LanguageServerProtocol::ProgressToken &token,
const QString &message);
void setClickHandlerForToken(const LanguageServerProtocol::ProgressToken &token,
const std::function<void()> &handler);
void reset();
static bool isProgressEndMessage(const LanguageServerProtocol::ProgressParams &params);
@@ -48,6 +50,7 @@ private:
QMap<LanguageServerProtocol::ProgressToken, LanguageClientProgress> m_progress;
QMap<LanguageServerProtocol::ProgressToken, QString> m_titles;
QMap<LanguageServerProtocol::ProgressToken, QElapsedTimer> m_timer;
QMap<LanguageServerProtocol::ProgressToken, std::function<void()>> m_clickHandlers;
};
} // namespace LanguageClient