forked from qt-creator/qt-creator
LanguageServerProtocol: add progress support
Change-Id: I8d3ccf0626ccde39516bbd024ed6e2da0380e4de Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -22,5 +22,6 @@ add_qtc_plugin(LanguageClient
|
||||
languageclient_global.h
|
||||
locatorfilter.cpp locatorfilter.h
|
||||
lspinspector.cpp lspinspector.h
|
||||
progressmanager.cpp progressmanager.h
|
||||
semantichighlightsupport.cpp semantichighlightsupport.h
|
||||
)
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <languageserverprotocol/messages.h>
|
||||
#include <languageserverprotocol/servercapabilities.h>
|
||||
#include <languageserverprotocol/workspace.h>
|
||||
#include <languageserverprotocol/progresssupport.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <texteditor/codeassist/documentcontentcompletion.h>
|
||||
@@ -54,6 +55,7 @@
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QLoggingCategory>
|
||||
@@ -246,6 +248,10 @@ static ClientCapabilities generateClientCapabilities()
|
||||
documentCapabilities.setOnTypeFormatting(allowDynamicRegistration);
|
||||
capabilities.setTextDocument(documentCapabilities);
|
||||
|
||||
WindowClientClientCapabilities window;
|
||||
window.setWorkDoneProgress(true);
|
||||
capabilities.setWindow(window);
|
||||
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
@@ -1110,6 +1116,16 @@ void Client::handleMethod(const QString &method, const MessageId &id, const ICon
|
||||
}
|
||||
response.setResult(result);
|
||||
sendContent(response);
|
||||
} else if (method == WorkDoneProgressCreateRequest::methodName) {
|
||||
sendContent(WorkDoneProgressCreateRequest::Response(
|
||||
dynamic_cast<const WorkDoneProgressCreateRequest *>(content)->id()));
|
||||
} else if (method == ProgressNotification::methodName) {
|
||||
if (Utils::optional<ProgressParams> params
|
||||
= dynamic_cast<const ProgressNotification *>(content)->params()) {
|
||||
if (!params->isValid())
|
||||
logError(*params);
|
||||
m_progressManager.handleProgress(*params);
|
||||
}
|
||||
} else if (id.isValid()) {
|
||||
Response<JsonObject, JsonObject> response(id);
|
||||
ResponseError<JsonObject> error;
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "languageclientquickfix.h"
|
||||
#include "languageclientsettings.h"
|
||||
#include "languageclientsymbolsupport.h"
|
||||
#include "progressmanager.h"
|
||||
|
||||
#include <coreplugin/messagemanager.h>
|
||||
|
||||
@@ -47,6 +48,7 @@
|
||||
#include <languageserverprotocol/initializemessages.h>
|
||||
#include <languageserverprotocol/languagefeatures.h>
|
||||
#include <languageserverprotocol/messages.h>
|
||||
#include <languageserverprotocol/progresssupport.h>
|
||||
#include <languageserverprotocol/shutdownmessages.h>
|
||||
#include <languageserverprotocol/textsynchronization.h>
|
||||
|
||||
@@ -237,6 +239,7 @@ private:
|
||||
const ProjectExplorer::Project *m_project = nullptr;
|
||||
QSet<TextEditor::IAssistProcessor *> m_runningAssistProcessors;
|
||||
SymbolSupport m_symbolSupport;
|
||||
ProgressManager m_progressManager;
|
||||
};
|
||||
|
||||
} // namespace LanguageClient
|
||||
|
||||
@@ -22,7 +22,8 @@ HEADERS += \
|
||||
languageclientutils.h \
|
||||
locatorfilter.h \
|
||||
lspinspector.h \
|
||||
semantichighlightsupport.h
|
||||
progressmanager.h \
|
||||
semantichighlightsupport.h \
|
||||
|
||||
|
||||
SOURCES += \
|
||||
@@ -44,7 +45,8 @@ SOURCES += \
|
||||
languageclientutils.cpp \
|
||||
locatorfilter.cpp \
|
||||
lspinspector.cpp \
|
||||
semantichighlightsupport.cpp
|
||||
progressmanager.cpp \
|
||||
semantichighlightsupport.cpp \
|
||||
|
||||
RESOURCES += \
|
||||
languageclient.qrc
|
||||
|
||||
@@ -52,6 +52,8 @@ QtcPlugin {
|
||||
"locatorfilter.h",
|
||||
"lspinspector.cpp",
|
||||
"lspinspector.h",
|
||||
"progressmanager.cpp",
|
||||
"progressmanager.h",
|
||||
"semantichighlightsupport.cpp",
|
||||
"semantichighlightsupport.h",
|
||||
]
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <coreplugin/find/searchresultwindow.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <languageserverprotocol/messages.h>
|
||||
#include <languageserverprotocol/progresssupport.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/session.h>
|
||||
@@ -67,6 +68,8 @@ LanguageClientManager::LanguageClientManager(QObject *parent)
|
||||
JsonRpcMessageHandler::registerMessageProvider<WorkSpaceFolderRequest>();
|
||||
JsonRpcMessageHandler::registerMessageProvider<RegisterCapabilityRequest>();
|
||||
JsonRpcMessageHandler::registerMessageProvider<UnregisterCapabilityRequest>();
|
||||
JsonRpcMessageHandler::registerMessageProvider<WorkDoneProgressCreateRequest>();
|
||||
JsonRpcMessageHandler::registerMessageProvider<ProgressNotification>();
|
||||
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
||||
this, &LanguageClientManager::editorOpened);
|
||||
connect(EditorManager::instance(), &EditorManager::documentOpened,
|
||||
|
||||
119
src/plugins/languageclient/progressmanager.cpp
Normal file
119
src/plugins/languageclient/progressmanager.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "progressmanager.h"
|
||||
|
||||
#include <coreplugin/progressmanager/futureprogress.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <languageserverprotocol/progresssupport.h>
|
||||
|
||||
using namespace LanguageServerProtocol;
|
||||
|
||||
namespace LanguageClient {
|
||||
|
||||
ProgressManager::ProgressManager()
|
||||
{}
|
||||
|
||||
ProgressManager::~ProgressManager()
|
||||
{
|
||||
for (const ProgressToken &token : m_progress.keys())
|
||||
endProgress(token);
|
||||
}
|
||||
|
||||
void ProgressManager::handleProgress(const LanguageServerProtocol::ProgressParams ¶ms)
|
||||
{
|
||||
const ProgressToken &token = params.token();
|
||||
ProgressParams::ProgressType value = params.value();
|
||||
if (auto begin = Utils::get_if<WorkDoneProgressBegin>(&value))
|
||||
beginProgress(token, *begin);
|
||||
else if (auto report = Utils::get_if<WorkDoneProgressReport>(&value))
|
||||
reportProgress(token, *report);
|
||||
else if (auto end = Utils::get_if<WorkDoneProgressEnd>(&value))
|
||||
endProgress(token, *end);
|
||||
}
|
||||
|
||||
Utils::Id languageClientProgressId(const ProgressToken &token)
|
||||
{
|
||||
constexpr char k_LanguageClientProgressId[] = "LanguageClient.ProgressId.";
|
||||
auto toString = [](const ProgressToken &token){
|
||||
if (Utils::holds_alternative<int>(token))
|
||||
return QString::number(Utils::get<int>(token));
|
||||
return Utils::get<QString>(token);
|
||||
};
|
||||
return Utils::Id(k_LanguageClientProgressId).withSuffix(toString(token));
|
||||
}
|
||||
|
||||
void ProgressManager::beginProgress(const ProgressToken &token, const WorkDoneProgressBegin &begin)
|
||||
{
|
||||
auto interface = new QFutureInterface<void>();
|
||||
interface->reportStarted();
|
||||
interface->setProgressRange(0, 100); // LSP always reports percentage of the task
|
||||
Core::FutureProgress *progress = Core::ProgressManager::addTask(
|
||||
interface->future(), begin.title(), languageClientProgressId(token));
|
||||
m_progress[token] = {progress, interface};
|
||||
reportProgress(token, begin);
|
||||
}
|
||||
|
||||
void ProgressManager::reportProgress(const ProgressToken &token,
|
||||
const WorkDoneProgressReport &report)
|
||||
{
|
||||
const LanguageClientProgress &progress = m_progress.value(token);
|
||||
if (progress.progressInterface) {
|
||||
const Utils::optional<QString> &message = report.message();
|
||||
if (message.has_value()) {
|
||||
progress.progressInterface->setSubtitle(*message);
|
||||
const bool showSubtitle = !message->isEmpty();
|
||||
progress.progressInterface->setSubtitleVisibleInStatusBar(showSubtitle);
|
||||
}
|
||||
}
|
||||
if (progress.futureInterface) {
|
||||
const Utils::optional<int> &progressValue = report.percentage();
|
||||
if (progressValue.has_value())
|
||||
progress.futureInterface->setProgressValue(*progressValue);
|
||||
}
|
||||
}
|
||||
|
||||
void ProgressManager::endProgress(const ProgressToken &token, const WorkDoneProgressEnd &end)
|
||||
{
|
||||
const LanguageClientProgress &progress = m_progress.value(token);
|
||||
const QString &message = end.message().value_or(QString());
|
||||
if (!message.isEmpty() && progress.progressInterface) {
|
||||
progress.progressInterface->setKeepOnFinish(
|
||||
Core::FutureProgress::KeepOnFinishTillUserInteraction);
|
||||
progress.progressInterface->setSubtitle(message);
|
||||
progress.progressInterface->setSubtitleVisibleInStatusBar(true);
|
||||
}
|
||||
endProgress(token);
|
||||
}
|
||||
|
||||
void ProgressManager::endProgress(const ProgressToken &token)
|
||||
{
|
||||
const LanguageClientProgress &progress = m_progress.take(token);
|
||||
if (progress.futureInterface)
|
||||
progress.futureInterface->reportFinished();
|
||||
delete progress.futureInterface;
|
||||
}
|
||||
|
||||
} // namespace LanguageClient
|
||||
65
src/plugins/languageclient/progressmanager.h
Normal file
65
src/plugins/languageclient/progressmanager.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QFutureInterface>
|
||||
|
||||
namespace Core { class FutureProgress; }
|
||||
namespace LanguageServerProtocol {
|
||||
class ProgressParams;
|
||||
class ProgressToken;
|
||||
class WorkDoneProgressBegin;
|
||||
class WorkDoneProgressReport;
|
||||
class WorkDoneProgressEnd;
|
||||
} // namespace LanguageServerProtocol
|
||||
|
||||
namespace LanguageClient {
|
||||
|
||||
class ProgressManager
|
||||
{
|
||||
public:
|
||||
ProgressManager();
|
||||
~ProgressManager();
|
||||
void handleProgress(const LanguageServerProtocol::ProgressParams ¶ms);
|
||||
|
||||
private:
|
||||
void beginProgress(const LanguageServerProtocol::ProgressToken &token,
|
||||
const LanguageServerProtocol::WorkDoneProgressBegin &begin);
|
||||
void reportProgress(const LanguageServerProtocol::ProgressToken &token,
|
||||
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;
|
||||
QFutureInterface<void> *futureInterface = nullptr;
|
||||
};
|
||||
|
||||
QMap<LanguageServerProtocol::ProgressToken, LanguageClientProgress> m_progress;
|
||||
};
|
||||
|
||||
} // namespace LanguageClient
|
||||
Reference in New Issue
Block a user