2018-07-13 12:33:46 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** 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 "languagefeatures.h"
|
|
|
|
|
|
2019-02-08 10:54:32 +01:00
|
|
|
#include <cstddef>
|
|
|
|
|
|
2018-07-13 12:33:46 +02:00
|
|
|
namespace LanguageServerProtocol {
|
|
|
|
|
|
|
|
|
|
constexpr const char HoverRequest::methodName[];
|
|
|
|
|
constexpr const char GotoDefinitionRequest::methodName[];
|
|
|
|
|
constexpr const char GotoTypeDefinitionRequest::methodName[];
|
|
|
|
|
constexpr const char GotoImplementationRequest::methodName[];
|
|
|
|
|
constexpr const char FindReferencesRequest::methodName[];
|
|
|
|
|
constexpr const char DocumentHighlightsRequest::methodName[];
|
|
|
|
|
constexpr const char DocumentSymbolsRequest::methodName[];
|
|
|
|
|
constexpr const char CodeActionRequest::methodName[];
|
|
|
|
|
constexpr const char CodeLensRequest::methodName[];
|
|
|
|
|
constexpr const char CodeLensResolveRequest::methodName[];
|
|
|
|
|
constexpr const char DocumentLinkRequest::methodName[];
|
|
|
|
|
constexpr const char DocumentLinkResolveRequest::methodName[];
|
|
|
|
|
constexpr const char DocumentColorRequest::methodName[];
|
|
|
|
|
constexpr const char ColorPresentationRequest::methodName[];
|
|
|
|
|
constexpr const char DocumentFormattingRequest::methodName[];
|
|
|
|
|
constexpr const char DocumentRangeFormattingRequest::methodName[];
|
|
|
|
|
constexpr const char DocumentOnTypeFormattingRequest::methodName[];
|
|
|
|
|
constexpr const char RenameRequest::methodName[];
|
|
|
|
|
constexpr const char SignatureHelpRequest::methodName[];
|
2019-06-12 12:55:06 +02:00
|
|
|
constexpr const char SemanticHighlightNotification::methodName[];
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2019-05-15 11:19:31 +02:00
|
|
|
HoverContent LanguageServerProtocol::Hover::content() const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
2019-05-15 11:19:31 +02:00
|
|
|
return HoverContent(value(contentsKey));
|
2018-07-13 12:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-15 11:19:31 +02:00
|
|
|
void Hover::setContent(const HoverContent &content)
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
2019-05-15 11:19:31 +02:00
|
|
|
if (auto val = Utils::get_if<MarkedString>(&content))
|
|
|
|
|
insert(contentsKey, *val);
|
2018-07-13 12:33:46 +02:00
|
|
|
else if (auto val = Utils::get_if<MarkupContent>(&content))
|
2019-05-15 11:19:31 +02:00
|
|
|
insert(contentsKey, *val);
|
|
|
|
|
else if (auto val = Utils::get_if<QList<MarkedString>>(&content))
|
|
|
|
|
insert(contentsKey, LanguageClientArray<MarkedString>(*val).toJson());
|
2018-07-13 12:33:46 +02:00
|
|
|
else
|
|
|
|
|
QTC_ASSERT_STRING("LanguageClient Using unknown type Hover::setContent");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HoverRequest::HoverRequest(const TextDocumentPositionParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
Utils::optional<MarkupOrString> ParameterInformation::documentation() const
|
|
|
|
|
{
|
|
|
|
|
QJsonValue documentation = value(documentationKey);
|
|
|
|
|
if (documentation.isUndefined())
|
|
|
|
|
return Utils::nullopt;
|
|
|
|
|
return MarkupOrString(documentation);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool SignatureHelp::isValid(ErrorHierarchy *error) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
return checkArray<SignatureInformation>(error, signaturesKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GotoDefinitionRequest::GotoDefinitionRequest(const TextDocumentPositionParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
GotoTypeDefinitionRequest::GotoTypeDefinitionRequest(const TextDocumentPositionParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
GotoImplementationRequest::GotoImplementationRequest(const TextDocumentPositionParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
FindReferencesRequest::FindReferencesRequest(const ReferenceParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
DocumentHighlightsRequest::DocumentHighlightsRequest(const TextDocumentPositionParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
DocumentSymbolsRequest::DocumentSymbolsRequest(const DocumentSymbolParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
2019-01-25 09:48:44 +01:00
|
|
|
Utils::optional<QList<CodeActionKind> > CodeActionParams::CodeActionContext::only() const
|
|
|
|
|
{
|
|
|
|
|
return optionalArray<CodeActionKind>(onlyKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CodeActionParams::CodeActionContext::setOnly(const QList<CodeActionKind> &only)
|
|
|
|
|
{
|
|
|
|
|
insertArray(onlyKey, only);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool CodeActionParams::CodeActionContext::isValid(ErrorHierarchy *error) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
return checkArray<Diagnostic>(error, diagnosticsKey);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool CodeActionParams::isValid(ErrorHierarchy *error) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
return check<TextDocumentIdentifier>(error, textDocumentKey)
|
|
|
|
|
&& check<Range>(error, rangeKey)
|
|
|
|
|
&& check<CodeActionContext>(error, contextKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CodeActionRequest::CodeActionRequest(const CodeActionParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
CodeLensRequest::CodeLensRequest(const CodeLensParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
CodeLensResolveRequest::CodeLensResolveRequest(const CodeLens ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
DocumentLinkRequest::DocumentLinkRequest(const DocumentLinkParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
DocumentLinkResolveRequest::DocumentLinkResolveRequest(const DocumentLink ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
DocumentColorRequest::DocumentColorRequest(const DocumentColorParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool Color::isValid(ErrorHierarchy *error) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
return check<int>(error, redKey)
|
|
|
|
|
&& check<int>(error, greenKey)
|
|
|
|
|
&& check<int>(error, blueKey)
|
|
|
|
|
&& check<int>(error, alphaKey);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool ColorPresentationParams::isValid(ErrorHierarchy *error) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
return check<TextDocumentIdentifier>(error, textDocumentKey)
|
|
|
|
|
&& check<Color>(error, colorInfoKey)
|
|
|
|
|
&& check<Range>(error, rangeKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ColorPresentationRequest::ColorPresentationRequest(const ColorPresentationParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
QHash<QString, DocumentFormattingProperty> FormattingOptions::properties() const
|
|
|
|
|
{
|
|
|
|
|
QHash<QString, DocumentFormattingProperty> ret;
|
|
|
|
|
for (const QString &key : keys()) {
|
|
|
|
|
if (key == tabSizeKey || key == insertSpaceKey)
|
|
|
|
|
continue;
|
|
|
|
|
QJsonValue property = value(key);
|
|
|
|
|
if (property.isBool())
|
|
|
|
|
ret[key] = property.toBool();
|
|
|
|
|
if (property.isDouble())
|
|
|
|
|
ret[key] = property.toDouble();
|
|
|
|
|
if (property.isString())
|
|
|
|
|
ret[key] = property.toString();
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormattingOptions::setProperty(const QString &key, const DocumentFormattingProperty &property)
|
|
|
|
|
{
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
if (auto val = get_if<double>(&property))
|
|
|
|
|
insert(key, *val);
|
|
|
|
|
else if (auto val = get_if<QString>(&property))
|
|
|
|
|
insert(key, *val);
|
|
|
|
|
else if (auto val = get_if<bool>(&property))
|
|
|
|
|
insert(key, *val);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool FormattingOptions::isValid(ErrorHierarchy *error) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
return Utils::allOf(keys(), [this, &error](auto key){
|
|
|
|
|
return (key == tabSizeKey && this->check<int>(error, key))
|
|
|
|
|
|| (key == insertSpaceKey && this->check<bool>(error, key))
|
|
|
|
|
|| this->check<DocumentFormattingProperty>(error, key);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool DocumentFormattingParams::isValid(ErrorHierarchy *error) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
return check<TextDocumentIdentifier>(error, textDocumentKey)
|
|
|
|
|
&& check<FormattingOptions>(error, optionsKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DocumentFormattingRequest::DocumentFormattingRequest(const DocumentFormattingParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool DocumentRangeFormattingParams::isValid(ErrorHierarchy *error) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
return check<TextDocumentIdentifier>(error, textDocumentKey)
|
|
|
|
|
&& check<Range>(error, rangeKey)
|
|
|
|
|
&& check<FormattingOptions>(error, optionsKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DocumentRangeFormattingRequest::DocumentRangeFormattingRequest(
|
2020-01-08 11:13:58 +01:00
|
|
|
const DocumentRangeFormattingParams ¶ms)
|
2018-07-13 12:33:46 +02:00
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool DocumentOnTypeFormattingParams::isValid(ErrorHierarchy *error) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
return check<TextDocumentIdentifier>(error, textDocumentKey)
|
|
|
|
|
&& check<Position>(error, positionKey)
|
|
|
|
|
&& check<QString>(error, chKey)
|
|
|
|
|
&& check<FormattingOptions>(error, optionsKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DocumentOnTypeFormattingRequest::DocumentOnTypeFormattingRequest(
|
|
|
|
|
const DocumentFormattingParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool RenameParams::isValid(ErrorHierarchy *error) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
return check<TextDocumentIdentifier>(error, textDocumentKey)
|
|
|
|
|
&& check<Position>(error, positionKey)
|
|
|
|
|
&& check<QString>(error, newNameKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RenameRequest::RenameRequest(const RenameParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
Utils::optional<DocumentUri> DocumentLink::target() const
|
|
|
|
|
{
|
|
|
|
|
Utils::optional<QString> optionalTarget = optionalValue<QString>(targetKey);
|
|
|
|
|
return optionalTarget.has_value()
|
|
|
|
|
? Utils::make_optional(DocumentUri::fromProtocol(optionalTarget.value()))
|
|
|
|
|
: Utils::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextDocumentParams::TextDocumentParams()
|
|
|
|
|
: TextDocumentParams(TextDocumentIdentifier())
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
TextDocumentParams::TextDocumentParams(const TextDocumentIdentifier &identifier)
|
|
|
|
|
: JsonObject()
|
|
|
|
|
{
|
|
|
|
|
setTextDocument(identifier);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GotoResult::GotoResult(const QJsonValue &value)
|
|
|
|
|
{
|
|
|
|
|
if (value.isArray()) {
|
|
|
|
|
QList<Location> locations;
|
|
|
|
|
for (auto arrayValue : value.toArray()) {
|
|
|
|
|
if (arrayValue.isObject())
|
|
|
|
|
locations.append(Location(arrayValue.toObject()));
|
|
|
|
|
}
|
|
|
|
|
emplace<QList<Location>>(locations);
|
|
|
|
|
} else if (value.isObject()) {
|
|
|
|
|
emplace<Location>(value.toObject());
|
|
|
|
|
} else {
|
|
|
|
|
emplace<std::nullptr_t>(nullptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 13:59:52 +01:00
|
|
|
template<typename Symbol>
|
|
|
|
|
QList<Symbol> documentSymbolsResultArray(const QJsonArray &array)
|
|
|
|
|
{
|
|
|
|
|
QList<Symbol> ret;
|
2019-01-16 14:47:24 +01:00
|
|
|
for (const auto &arrayValue : array) {
|
2018-11-21 13:59:52 +01:00
|
|
|
if (arrayValue.isObject())
|
|
|
|
|
ret << Symbol(arrayValue.toObject());
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 12:33:46 +02:00
|
|
|
DocumentSymbolsResult::DocumentSymbolsResult(const QJsonValue &value)
|
|
|
|
|
{
|
|
|
|
|
if (value.isArray()) {
|
2018-11-21 13:59:52 +01:00
|
|
|
QJsonArray array = value.toArray();
|
|
|
|
|
if (array.isEmpty()) {
|
|
|
|
|
*this = QList<SymbolInformation>();
|
|
|
|
|
} else {
|
|
|
|
|
QJsonObject arrayObject = array.first().toObject();
|
|
|
|
|
if (arrayObject.contains(rangeKey))
|
|
|
|
|
*this = documentSymbolsResultArray<DocumentSymbol>(array);
|
|
|
|
|
else
|
|
|
|
|
*this = documentSymbolsResultArray<SymbolInformation>(array);
|
2018-07-13 12:33:46 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
*this = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DocumentHighlightsResult::DocumentHighlightsResult(const QJsonValue &value)
|
|
|
|
|
{
|
|
|
|
|
if (value.isArray()) {
|
|
|
|
|
QList<DocumentHighlight> highlights;
|
|
|
|
|
for (auto arrayValue : value.toArray()) {
|
|
|
|
|
if (arrayValue.isObject())
|
|
|
|
|
highlights.append(DocumentHighlight(arrayValue.toObject()));
|
|
|
|
|
}
|
|
|
|
|
*this = highlights;
|
|
|
|
|
} else {
|
|
|
|
|
*this = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MarkedString::MarkedString(const QJsonValue &value)
|
2019-05-15 11:19:31 +02:00
|
|
|
{
|
|
|
|
|
if (value.isObject()) {
|
|
|
|
|
MarkedLanguageString string(value.toObject());
|
|
|
|
|
if (string.isValid(nullptr))
|
|
|
|
|
emplace<MarkedLanguageString>(string);
|
|
|
|
|
} else if (value.isString()) {
|
|
|
|
|
emplace<QString>(value.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-17 13:09:15 +02:00
|
|
|
LanguageServerProtocol::MarkedString::operator QJsonValue() const
|
2019-05-15 11:19:31 +02:00
|
|
|
{
|
|
|
|
|
if (auto val = Utils::get_if<QString>(this))
|
|
|
|
|
return *val;
|
|
|
|
|
if (auto val = Utils::get_if<MarkedLanguageString>(this))
|
|
|
|
|
return QJsonValue(*val);
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HoverContent::HoverContent(const QJsonValue &value)
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
if (value.isArray()) {
|
2019-05-15 11:19:31 +02:00
|
|
|
emplace<QList<MarkedString>>(LanguageClientArray<MarkedString>(value).toList());
|
2018-07-13 12:33:46 +02:00
|
|
|
} else if (value.isObject()) {
|
|
|
|
|
const QJsonObject &object = value.toObject();
|
|
|
|
|
MarkedLanguageString markedLanguageString(object);
|
|
|
|
|
if (markedLanguageString.isValid(nullptr))
|
2019-05-15 11:19:31 +02:00
|
|
|
emplace<MarkedString>(markedLanguageString);
|
2018-07-13 12:33:46 +02:00
|
|
|
else
|
|
|
|
|
emplace<MarkupContent>(MarkupContent(object));
|
2019-05-15 11:19:31 +02:00
|
|
|
} else if (value.isString()) {
|
|
|
|
|
emplace<MarkedString>(MarkedString(value.toString()));
|
2018-07-13 12:33:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool HoverContent::isValid(ErrorHierarchy *errorHierarchy) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
2019-05-15 11:19:31 +02:00
|
|
|
if (Utils::holds_alternative<MarkedString>(*this)
|
2018-07-13 12:33:46 +02:00
|
|
|
|| Utils::holds_alternative<MarkupContent>(*this)
|
2019-05-15 11:19:31 +02:00
|
|
|
|| Utils::holds_alternative<QList<MarkedString>>(*this)) {
|
2018-07-13 12:33:46 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (errorHierarchy) {
|
2020-02-10 10:31:32 +01:00
|
|
|
errorHierarchy->setError(
|
|
|
|
|
QCoreApplication::translate("LanguageServerProtocol::HoverContent",
|
|
|
|
|
"HoverContent should be either MarkedString, "
|
|
|
|
|
"MarkupContent, or QList<MarkedString>."));
|
2018-07-13 12:33:46 +02:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DocumentFormattingProperty::DocumentFormattingProperty(const QJsonValue &value)
|
|
|
|
|
{
|
|
|
|
|
if (value.isBool())
|
|
|
|
|
*this = value.toBool();
|
|
|
|
|
if (value.isDouble())
|
|
|
|
|
*this = value.toDouble();
|
|
|
|
|
if (value.isString())
|
|
|
|
|
*this = value.toString();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool DocumentFormattingProperty::isValid(ErrorHierarchy *error) const
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
if (Utils::holds_alternative<bool>(*this)
|
|
|
|
|
|| Utils::holds_alternative<double>(*this)
|
|
|
|
|
|| Utils::holds_alternative<QString>(*this)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (error) {
|
2020-02-10 10:31:32 +01:00
|
|
|
error->setError(QCoreApplication::translate(
|
|
|
|
|
"LanguageServerProtocol::MarkedString",
|
|
|
|
|
"DocumentFormattingProperty should be either bool, double, or QString."));
|
2018-07-13 12:33:46 +02:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SignatureHelpRequest::SignatureHelpRequest(const TextDocumentPositionParams ¶ms)
|
|
|
|
|
: Request(methodName, params)
|
|
|
|
|
{ }
|
|
|
|
|
|
2019-01-25 09:48:44 +01:00
|
|
|
CodeActionResult::CodeActionResult(const QJsonValue &val)
|
|
|
|
|
{
|
|
|
|
|
using ResultArray = QList<Utils::variant<Command, CodeAction>>;
|
|
|
|
|
if (val.isArray()) {
|
2019-02-08 11:19:19 +01:00
|
|
|
const QJsonArray array = val.toArray();
|
2019-01-25 09:48:44 +01:00
|
|
|
ResultArray result;
|
|
|
|
|
for (const QJsonValue &val : array) {
|
|
|
|
|
Command command(val);
|
|
|
|
|
if (command.isValid(nullptr))
|
|
|
|
|
result << command;
|
|
|
|
|
else
|
|
|
|
|
result << CodeAction(val);
|
|
|
|
|
}
|
|
|
|
|
emplace<ResultArray>(result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-02-08 10:54:32 +01:00
|
|
|
emplace<std::nullptr_t>(nullptr);
|
2019-01-25 09:48:44 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool CodeAction::isValid(ErrorHierarchy *error) const
|
2019-01-25 09:48:44 +01:00
|
|
|
{
|
|
|
|
|
return check<QString>(error, titleKey)
|
|
|
|
|
&& checkOptional<CodeActionKind>(error, codeActionKindKey)
|
|
|
|
|
&& checkOptionalArray<Diagnostic>(error, diagnosticsKey)
|
|
|
|
|
&& checkOptional<WorkspaceEdit>(error, editKey)
|
|
|
|
|
&& checkOptional<Command>(error, commandKey);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 12:55:06 +02:00
|
|
|
Utils::optional<QList<SemanticHighlightToken>> SemanticHighlightingInformation::tokens() const
|
|
|
|
|
{
|
|
|
|
|
QList<SemanticHighlightToken> resultTokens;
|
|
|
|
|
|
|
|
|
|
const QByteArray tokensByteArray = QByteArray::fromBase64(
|
|
|
|
|
typedValue<QString>(tokensKey).toLocal8Bit());
|
|
|
|
|
constexpr int tokensByteSize = 8;
|
|
|
|
|
int index = 0;
|
|
|
|
|
while (index + tokensByteSize <= tokensByteArray.size()) {
|
|
|
|
|
resultTokens << SemanticHighlightToken(tokensByteArray.mid(index, tokensByteSize));
|
|
|
|
|
index += tokensByteSize;
|
|
|
|
|
}
|
|
|
|
|
return Utils::make_optional(resultTokens);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SemanticHighlightingInformation::setTokens(const QList<SemanticHighlightToken> &tokens)
|
|
|
|
|
{
|
|
|
|
|
QByteArray byteArray;
|
|
|
|
|
byteArray.reserve(8 * tokens.size());
|
|
|
|
|
for (const SemanticHighlightToken &token : tokens)
|
|
|
|
|
token.appendToByteArray(byteArray);
|
|
|
|
|
insert(tokensKey, QString::fromLocal8Bit(byteArray.toBase64()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SemanticHighlightToken::SemanticHighlightToken(const QByteArray &token)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(token.size() == 8, return );
|
|
|
|
|
character = ( quint32(token.at(0)) << 24
|
|
|
|
|
| quint32(token.at(1)) << 16
|
|
|
|
|
| quint32(token.at(2)) << 8
|
|
|
|
|
| quint32(token.at(3)));
|
|
|
|
|
|
|
|
|
|
length = quint16(token.at(4) << 8 | token.at(5));
|
|
|
|
|
|
|
|
|
|
scope = quint16(token.at(6) << 8 | token.at(7));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SemanticHighlightToken::appendToByteArray(QByteArray &byteArray) const
|
|
|
|
|
{
|
|
|
|
|
byteArray.append(char((character & 0xff000000) >> 24));
|
|
|
|
|
byteArray.append(char((character & 0x00ff0000) >> 16));
|
|
|
|
|
byteArray.append(char((character & 0x0000ff00) >> 8));
|
|
|
|
|
byteArray.append(char((character & 0x000000ff)));
|
|
|
|
|
byteArray.append(char((length & 0xff00) >> 8));
|
|
|
|
|
byteArray.append(char((length & 0x00ff)));
|
|
|
|
|
byteArray.append(char((scope & 0xff00) >> 8));
|
|
|
|
|
byteArray.append(char((scope & 0x00ff)));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 10:31:32 +01:00
|
|
|
bool SemanticHighlightingParams::isValid(ErrorHierarchy *error) const
|
2019-06-12 12:55:06 +02:00
|
|
|
{
|
|
|
|
|
return check<VersionedTextDocumentIdentifier>(error, textDocumentKey)
|
|
|
|
|
&& checkArray<SemanticHighlightingInformation>(error, linesKey);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 12:33:46 +02:00
|
|
|
} // namespace LanguageServerProtocol
|