/**************************************************************************** ** ** Copyright (C) 2018 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 "servercapabilities.h" namespace LanguageServerProtocol { Utils::optional ServerCapabilities::textDocumentSync() const { const QJsonValue &sync = value(textDocumentSyncKey); if (sync.isUndefined()) return Utils::nullopt; return Utils::make_optional(sync.isDouble() ? TextDocumentSync(sync.toInt()) : TextDocumentSync(TextDocumentSyncOptions(sync.toObject()))); } void ServerCapabilities::setTextDocumentSync(const ServerCapabilities::TextDocumentSync &textDocumentSync) { if (auto val = Utils::get_if(&textDocumentSync)) insert(textDocumentSyncKey, *val); else if (auto val = Utils::get_if(&textDocumentSync)) insert(textDocumentSyncKey, *val); } TextDocumentSyncKind ServerCapabilities::textDocumentSyncKindHelper() { Utils::optional sync = textDocumentSync(); if (sync.has_value()) { if (auto kind = Utils::get_if(&sync.value())) return static_cast(*kind); if (auto options = Utils::get_if(&sync.value())) { if (const Utils::optional &change = options->change()) return static_cast(change.value()); } } return TextDocumentSyncKind::None; } Utils::optional> ServerCapabilities::typeDefinitionProvider() const { using RetType = Utils::variant; QJsonValue provider = value(typeDefinitionProviderKey); if (provider.isUndefined() || !(provider.isBool() || provider.isObject())) return Utils::nullopt; return Utils::make_optional(provider.isBool() ? RetType(provider.toBool()) : RetType(RegistrationOptions(provider.toObject()))); } void ServerCapabilities::setTypeDefinitionProvider( const Utils::variant &typeDefinitionProvider) { if (auto activated = Utils::get_if(&typeDefinitionProvider)) insert(typeDefinitionProviderKey, *activated); else if (auto options = Utils::get_if(&typeDefinitionProvider)) insert(typeDefinitionProviderKey, *options); } Utils::optional> ServerCapabilities::implementationProvider() const { using RetType = Utils::variant; QJsonValue provider = value(implementationProviderKey); if (provider.isUndefined() || !(provider.isBool() || provider.isObject())) return Utils::nullopt; return Utils::make_optional(provider.isBool() ? RetType(provider.toBool()) : RetType(RegistrationOptions(provider.toObject()))); } void ServerCapabilities::setImplementationProvider( const Utils::variant &implementationProvider) { if (Utils::holds_alternative(implementationProvider)) insert(implementationProviderKey, Utils::get(implementationProvider)); else insert(implementationProviderKey, Utils::get(implementationProvider)); } Utils::optional> ServerCapabilities::codeActionProvider() const { QJsonValue provider = value(codeActionProviderKey); if (provider.isBool()) return Utils::make_optional(Utils::variant(provider.toBool())); if (provider.isObject()) { CodeActionOptions options(provider); if (options.isValid(nullptr)) return Utils::make_optional(Utils::variant(options)); } return Utils::nullopt; } bool ServerCapabilities::isValid(QStringList *error) const { return checkOptional(error, textDocumentSyncKey) && checkOptional(error, hoverProviderKey) && checkOptional(error, completionProviderKey) && checkOptional(error, signatureHelpProviderKey) && checkOptional(error, definitionProviderKey) && checkOptional(error, typeDefinitionProviderKey) && checkOptional(error, implementationProviderKey) && checkOptional(error, referencesProviderKey) && checkOptional(error, documentHighlightProviderKey) && checkOptional(error, documentSymbolProviderKey) && checkOptional(error, workspaceSymbolProviderKey) && checkOptional(error, codeActionProviderKey) && checkOptional(error, codeLensProviderKey) && checkOptional(error, documentFormattingProviderKey) && checkOptional(error, documentRangeFormattingProviderKey) && checkOptional(error, renameProviderKey) && checkOptional(error, documentLinkProviderKey) && checkOptional(error, colorProviderKey) && checkOptional(error, executeCommandProviderKey) && checkOptional(error, workspaceKey); } Utils::optional > ServerCapabilities::WorkspaceServerCapabilities::WorkspaceFoldersCapabilities::changeNotifications() const { using RetType = Utils::variant; QJsonValue provider = value(implementationProviderKey); if (provider.isUndefined()) return Utils::nullopt; return Utils::make_optional(provider.isBool() ? RetType(provider.toBool()) : RetType(provider.toString())); } void ServerCapabilities::WorkspaceServerCapabilities::WorkspaceFoldersCapabilities::setChangeNotifications( Utils::variant changeNotifications) { if (auto val = Utils::get_if(&changeNotifications)) insert(changeNotificationsKey, *val); else if (auto val = Utils::get_if(&changeNotifications)) insert(changeNotificationsKey, *val); } bool ServerCapabilities::WorkspaceServerCapabilities::WorkspaceFoldersCapabilities::isValid(QStringList *error) const { return checkOptional(error, supportedKey) && checkOptional(error, changeNotificationsKey); } bool TextDocumentRegistrationOptions::filterApplies(const Utils::FileName &fileName, const Utils::MimeType &mimeType) const { const LanguageClientArray &selector = documentSelector(); return selector.isNull() || selector.toList().isEmpty() || Utils::anyOf(selector.toList(), [&](auto filter){ return filter.applies(fileName, mimeType); }); } bool TextDocumentSyncOptions::isValid(QStringList *error) const { return checkOptional(error, openCloseKey) && checkOptional(error, changeKey) && checkOptional(error, willSaveKey) && checkOptional(error, willSaveWaitUntilKey) && checkOptional(error, saveKey); } } // namespace LanguageServerProtocol