forked from qt-creator/qt-creator
Since we are now requiring macOS 10.14 we can remove our local implementation of optional and use std::optional for macOS too. Change-Id: I2bd018261b68da64f7f031a812045dd7784697e1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Marco Bubke <marco.bubke@qt.io>
60 lines
1.9 KiB
C++
60 lines
1.9 KiB
C++
// Copyright (C) 2018 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
|
|
|
#include "completion.h"
|
|
|
|
namespace LanguageServerProtocol {
|
|
|
|
constexpr const char CompletionRequest::methodName[];
|
|
constexpr const char CompletionItemResolveRequest::methodName[];
|
|
|
|
CompletionRequest::CompletionRequest(const CompletionParams ¶ms)
|
|
: Request(methodName, params)
|
|
{ }
|
|
|
|
std::optional<MarkupOrString> CompletionItem::documentation() const
|
|
{
|
|
QJsonValue documentation = value(documentationKey);
|
|
if (documentation.isUndefined())
|
|
return std::nullopt;
|
|
return MarkupOrString(documentation);
|
|
}
|
|
|
|
std::optional<CompletionItem::InsertTextFormat> CompletionItem::insertTextFormat() const
|
|
{
|
|
if (std::optional<int> value = optionalValue<int>(insertTextFormatKey))
|
|
return std::make_optional(CompletionItem::InsertTextFormat(*value));
|
|
return std::nullopt;
|
|
}
|
|
|
|
std::optional<QList<CompletionItem::CompletionItemTag>> CompletionItem::tags() const
|
|
{
|
|
if (const auto value = optionalValue<QJsonArray>(tagsKey)) {
|
|
QList<CompletionItemTag> tags;
|
|
for (auto it = value->cbegin(); it != value->cend(); ++it)
|
|
tags << static_cast<CompletionItemTag>(it->toInt());
|
|
return tags;
|
|
}
|
|
return {};
|
|
}
|
|
|
|
CompletionItemResolveRequest::CompletionItemResolveRequest(const CompletionItem ¶ms)
|
|
: Request(methodName, params)
|
|
{ }
|
|
|
|
CompletionResult::CompletionResult(const QJsonValue &value)
|
|
{
|
|
if (value.isNull()) {
|
|
emplace<std::nullptr_t>(nullptr);
|
|
} else if (value.isArray()) {
|
|
QList<CompletionItem> items;
|
|
for (auto arrayElement : value.toArray())
|
|
items << CompletionItem(arrayElement);
|
|
emplace<QList<CompletionItem>>(items);
|
|
} else if (value.isObject()) {
|
|
emplace<CompletionList>(CompletionList(value));
|
|
}
|
|
}
|
|
|
|
} // namespace LanguageServerProtocol
|