2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2018-07-13 12:33:46 +02:00
|
|
|
|
|
|
|
|
#include "dynamiccapabilities.h"
|
|
|
|
|
|
|
|
|
|
using namespace LanguageServerProtocol;
|
|
|
|
|
|
|
|
|
|
namespace LanguageClient {
|
|
|
|
|
|
|
|
|
|
void DynamicCapabilities::registerCapability(const QList<Registration> ®istrations)
|
|
|
|
|
{
|
|
|
|
|
for (const Registration& registration : registrations) {
|
|
|
|
|
const QString &method = registration.method();
|
|
|
|
|
m_capability[method].enable(registration.id(), registration.registerOptions());
|
|
|
|
|
m_methodForId.insert(registration.id(), method);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DynamicCapabilities::unregisterCapability(const QList<Unregistration> &unregistrations)
|
|
|
|
|
{
|
|
|
|
|
for (const Unregistration& unregistration : unregistrations) {
|
|
|
|
|
QString method = unregistration.method();
|
|
|
|
|
if (method.isEmpty())
|
|
|
|
|
method = m_methodForId[unregistration.id()];
|
|
|
|
|
m_capability[method].disable();
|
|
|
|
|
m_methodForId.remove(unregistration.id());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
std::optional<bool> DynamicCapabilities::isRegistered(const QString &method) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
if (!m_capability.contains(method))
|
2022-08-26 10:30:00 +02:00
|
|
|
return std::nullopt;
|
2018-07-13 12:33:46 +02:00
|
|
|
return m_capability[method].enabled();
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 09:32:11 +01:00
|
|
|
QStringList DynamicCapabilities::registeredMethods() const
|
|
|
|
|
{
|
|
|
|
|
return m_capability.keys();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 12:33:46 +02:00
|
|
|
void DynamicCapabilities::reset()
|
|
|
|
|
{
|
|
|
|
|
m_capability.clear();
|
|
|
|
|
m_methodForId.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace LanguageClient
|