forked from qt-creator/qt-creator
ClangCodeModel: Allow cancelling the background index
Restarts the client with temporarily disabled indexing. The block is reset after starting clangd, so any subsequent changes to the configuration or the project will start the client again with indexing enabled. Change-Id: I16c975b6ef0b56f27ce5b2ced01f534f8ae0b4d3 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -47,11 +47,17 @@ void ProgressManager::setClickHandlerForToken(const LanguageServerProtocol::Prog
|
||||
m_clickHandlers.insert(token, handler);
|
||||
}
|
||||
|
||||
void ProgressManager::setCancelHandlerForToken(const LanguageServerProtocol::ProgressToken &token,
|
||||
const std::function<void ()> &handler)
|
||||
{
|
||||
m_cancelHandlers.insert(token, handler);
|
||||
}
|
||||
|
||||
void ProgressManager::reset()
|
||||
{
|
||||
const QList<ProgressToken> &tokens = m_progress.keys();
|
||||
for (const ProgressToken &token : tokens)
|
||||
endProgress(token);
|
||||
endProgressReport(token);
|
||||
}
|
||||
|
||||
bool ProgressManager::isProgressEndMessage(const LanguageServerProtocol::ProgressParams ¶ms)
|
||||
@@ -78,10 +84,14 @@ 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);
|
||||
const std::function<void()> cancelHandler = m_cancelHandlers.value(token);
|
||||
if (cancelHandler)
|
||||
QObject::connect(progress, &Core::FutureProgress::canceled, cancelHandler);
|
||||
else
|
||||
progress->setCancelEnabled(false);
|
||||
m_progress[token] = {progress, interface};
|
||||
if (LOGPROGRESS().isDebugEnabled())
|
||||
m_timer[token].start();
|
||||
@@ -125,10 +135,10 @@ void ProgressManager::endProgress(const ProgressToken &token, const WorkDoneProg
|
||||
.toString(Qt::ISODateWithMs));
|
||||
}
|
||||
}
|
||||
endProgress(token);
|
||||
endProgressReport(token);
|
||||
}
|
||||
|
||||
void ProgressManager::endProgress(const ProgressToken &token)
|
||||
void ProgressManager::endProgressReport(const ProgressToken &token)
|
||||
{
|
||||
const LanguageClientProgress &progress = m_progress.take(token);
|
||||
if (progress.futureInterface)
|
||||
|
||||
@@ -31,6 +31,10 @@ public:
|
||||
const QString &message);
|
||||
void setClickHandlerForToken(const LanguageServerProtocol::ProgressToken &token,
|
||||
const std::function<void()> &handler);
|
||||
void setCancelHandlerForToken(const LanguageServerProtocol::ProgressToken &token,
|
||||
const std::function<void()> &handler);
|
||||
void endProgressReport(const LanguageServerProtocol::ProgressToken &token);
|
||||
|
||||
void reset();
|
||||
|
||||
static bool isProgressEndMessage(const LanguageServerProtocol::ProgressParams ¶ms);
|
||||
@@ -42,7 +46,6 @@ private:
|
||||
const LanguageServerProtocol::WorkDoneProgressReport &report);
|
||||
void endProgress(const LanguageServerProtocol::ProgressToken &token,
|
||||
const LanguageServerProtocol::WorkDoneProgressEnd &end);
|
||||
void endProgress(const LanguageServerProtocol::ProgressToken &token);
|
||||
|
||||
struct LanguageClientProgress {
|
||||
QPointer<Core::FutureProgress> progressInterface = nullptr;
|
||||
@@ -53,6 +56,7 @@ private:
|
||||
QMap<LanguageServerProtocol::ProgressToken, QString> m_titles;
|
||||
QMap<LanguageServerProtocol::ProgressToken, QElapsedTimer> m_timer;
|
||||
QMap<LanguageServerProtocol::ProgressToken, std::function<void()>> m_clickHandlers;
|
||||
QMap<LanguageServerProtocol::ProgressToken, std::function<void()>> m_cancelHandlers;
|
||||
};
|
||||
|
||||
} // namespace LanguageClient
|
||||
|
||||
Reference in New Issue
Block a user