5#include <QtCore/qstring.h>
9using namespace Qt::StringLiterals;
13QQmlProgressSupport::QQmlProgressSupport(QmlLsp::QQmlCodeModelManager *manager)
14 : m_codeModelManager(manager)
20 return "QQmlProgress"_L1;
24 QLanguageServerProtocol *protocol)
26 m_protocol = protocol;
27 QObject::connect(server, &QLanguageServer::clientInitialized,
this,
28 &QQmlProgressSupport::clientInitialized);
33 if (
auto window = server->clientInfo().capabilities.window;
34 !window || !window->value(
"workDoneProgress"_L1).toBool(
false)) {
38 QObject::connect(m_codeModelManager, &QmlLsp::QQmlCodeModelManager::backgroundBuildStarted,
39 this, &QQmlProgressSupport::onBackgroundBuildStarted);
40 QObject::connect(m_codeModelManager, &QmlLsp::QQmlCodeModelManager::backgroundBuildFinished,
41 this, &QQmlProgressSupport::onBackgroundBuildDone);
43 QObject::connect(server->notifySignals(),
44 &QLspNotifySignals::receivedWorkDoneProgressCancelNotification,
this,
45 &QQmlProgressSupport::onBackgroundBuildCancelRequested);
50 const int token = m_idForBackgroundBuilds++;
51 m_tokens.append({ uri, token });
57 QLspSpecification::Requests::WorkDoneProgressCreateParamsType p;
58 const int token = createUniqueToken(uri);
60 m_protocol->requestWorkDoneProgressCreate(p, [
this, uri, token]() {
61 QLspSpecification::ProgressParams beginParams{ token };
62 QLspSpecification::WorkDoneProgressBegin workDoneProgressBegin{};
63 workDoneProgressBegin.title =
"Qmlls running background build";
64 workDoneProgressBegin.cancellable =
true;
65 workDoneProgressBegin.message =
66 "Building \"" + QUrl::fromEncoded(uri).toLocalFile().toUtf8() +
"\"";
67 workDoneProgressBegin.cancellable =
true;
68 beginParams.value = workDoneProgressBegin;
69 m_protocol->notifyProgress(beginParams);
76 std::find_if(m_tokens.begin(), m_tokens.end(), [uri](
const UriWithToken &uriWithToken) {
77 return uriWithToken.uri == uri;
80 if (it == m_tokens.end())
83 QLspSpecification::WorkDoneProgressEnd workDoneProgressEnd;
84 workDoneProgressEnd.message =
"Build terminated";
85 const QLspSpecification::ProgressParams endParams{ it->token, workDoneProgressEnd };
86 m_protocol->notifyProgress(endParams);
91 const QLspSpecification::Notifications::WorkDoneProgressCancelParamsType &p)
93 const auto token = std::get_if<
int>(&p.token);
97 const auto it = std::find_if(
98 m_tokens.begin(), m_tokens.end(),
99 [token](
const UriWithToken &uriWithToken) {
return uriWithToken.token == *token; });
101 if (it == m_tokens.end())
104 m_codeModelManager->cancelBackgroundBuild(it->uri);
109 QLspSpecification::InitializeResult &)
Implements a server for the language server protocol.
void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) final
QQmlProgressSupport(QmlLsp::QQmlCodeModelManager *manager)
QString name() const final
void setupCapabilities(const QLspSpecification::InitializeParams &clientInfo, QLspSpecification::InitializeResult &) final