Files
qt-creator/src/libs/languageserverprotocol/languagefeatures.cpp

445 lines
14 KiB
C++
Raw Normal View History

Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
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"
#include <cstddef>
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
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[];
HoverContent LanguageServerProtocol::Hover::content() const
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
{
return HoverContent(value(contentsKey));
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
}
void Hover::setContent(const HoverContent &content)
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
{
if (auto val = Utils::get_if<MarkedString>(&content))
insert(contentsKey, *val);
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
else if (auto val = Utils::get_if<MarkupContent>(&content))
insert(contentsKey, *val);
else if (auto val = Utils::get_if<QList<MarkedString>>(&content))
insert(contentsKey, LanguageClientArray<MarkedString>(*val).toJson());
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
else
QTC_ASSERT_STRING("LanguageClient Using unknown type Hover::setContent");
}
HoverRequest::HoverRequest(const TextDocumentPositionParams &params)
: Request(methodName, params)
{ }
Utils::optional<MarkupOrString> ParameterInformation::documentation() const
{
QJsonValue documentation = value(documentationKey);
if (documentation.isUndefined())
return Utils::nullopt;
return MarkupOrString(documentation);
}
bool SignatureHelp::isValid(QStringList *error) const
{
return checkArray<SignatureInformation>(error, signaturesKey);
}
GotoDefinitionRequest::GotoDefinitionRequest(const TextDocumentPositionParams &params)
: Request(methodName, params)
{ }
GotoTypeDefinitionRequest::GotoTypeDefinitionRequest(const TextDocumentPositionParams &params)
: Request(methodName, params)
{ }
GotoImplementationRequest::GotoImplementationRequest(const TextDocumentPositionParams &params)
: Request(methodName, params)
{ }
FindReferencesRequest::FindReferencesRequest(const ReferenceParams &params)
: Request(methodName, params)
{ }
DocumentHighlightsRequest::DocumentHighlightsRequest(const TextDocumentPositionParams &params)
: Request(methodName, params)
{ }
DocumentSymbolsRequest::DocumentSymbolsRequest(const DocumentSymbolParams &params)
: Request(methodName, params)
{ }
Utils::optional<QList<CodeActionKind> > CodeActionParams::CodeActionContext::only() const
{
return optionalArray<CodeActionKind>(onlyKey);
}
void CodeActionParams::CodeActionContext::setOnly(const QList<CodeActionKind> &only)
{
insertArray(onlyKey, only);
}
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
bool CodeActionParams::CodeActionContext::isValid(QStringList *error) const
{
return checkArray<Diagnostic>(error, diagnosticsKey);
}
bool CodeActionParams::isValid(QStringList *error) const
{
return check<TextDocumentIdentifier>(error, textDocumentKey)
&& check<Range>(error, rangeKey)
&& check<CodeActionContext>(error, contextKey);
}
CodeActionRequest::CodeActionRequest(const CodeActionParams &params)
: Request(methodName, params)
{ }
CodeLensRequest::CodeLensRequest(const CodeLensParams &params)
: Request(methodName, params)
{ }
CodeLensResolveRequest::CodeLensResolveRequest(const CodeLens &params)
: Request(methodName, params)
{ }
DocumentLinkRequest::DocumentLinkRequest(const DocumentLinkParams &params)
: Request(methodName, params)
{ }
DocumentLinkResolveRequest::DocumentLinkResolveRequest(const DocumentLink &params)
: Request(methodName, params)
{ }
DocumentColorRequest::DocumentColorRequest(const DocumentColorParams &params)
: Request(methodName, params)
{ }
bool Color::isValid(QStringList *error) const
{
return check<int>(error, redKey)
&& check<int>(error, greenKey)
&& check<int>(error, blueKey)
&& check<int>(error, alphaKey);
}
bool ColorPresentationParams::isValid(QStringList *error) const
{
return check<TextDocumentIdentifier>(error, textDocumentKey)
&& check<Color>(error, colorInfoKey)
&& check<Range>(error, rangeKey);
}
ColorPresentationRequest::ColorPresentationRequest(const ColorPresentationParams &params)
: 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);
}
bool FormattingOptions::isValid(QStringList *error) const
{
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);
});
}
bool DocumentFormattingParams::isValid(QStringList *error) const
{
return check<TextDocumentIdentifier>(error, textDocumentKey)
&& check<FormattingOptions>(error, optionsKey);
}
DocumentFormattingRequest::DocumentFormattingRequest(const DocumentFormattingParams &params)
: Request(methodName, params)
{ }
bool DocumentRangeFormattingParams::isValid(QStringList *error) const
{
return check<TextDocumentIdentifier>(error, textDocumentKey)
&& check<Range>(error, rangeKey)
&& check<FormattingOptions>(error, optionsKey);
}
DocumentRangeFormattingRequest::DocumentRangeFormattingRequest(
const DocumentFormattingParams &params)
: Request(methodName, params)
{ }
bool DocumentOnTypeFormattingParams::isValid(QStringList *error) const
{
return check<TextDocumentIdentifier>(error, textDocumentKey)
&& check<Position>(error, positionKey)
&& check<QString>(error, chKey)
&& check<FormattingOptions>(error, optionsKey);
}
DocumentOnTypeFormattingRequest::DocumentOnTypeFormattingRequest(
const DocumentFormattingParams &params)
: Request(methodName, params)
{ }
bool RenameParams::isValid(QStringList *error) const
{
return check<TextDocumentIdentifier>(error, textDocumentKey)
&& check<Position>(error, positionKey)
&& check<QString>(error, newNameKey);
}
RenameRequest::RenameRequest(const RenameParams &params)
: 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);
}
}
template<typename Symbol>
QList<Symbol> documentSymbolsResultArray(const QJsonArray &array)
{
QList<Symbol> ret;
for (const auto &arrayValue : array) {
if (arrayValue.isObject())
ret << Symbol(arrayValue.toObject());
}
return ret;
}
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
DocumentSymbolsResult::DocumentSymbolsResult(const QJsonValue &value)
{
if (value.isArray()) {
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);
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
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)
{
if (value.isObject()) {
MarkedLanguageString string(value.toObject());
if (string.isValid(nullptr))
emplace<MarkedLanguageString>(string);
} else if (value.isString()) {
emplace<QString>(value.toString());
}
}
LanguageServerProtocol::MarkedString::operator const QJsonValue() const
{
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)
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
{
if (value.isArray()) {
emplace<QList<MarkedString>>(LanguageClientArray<MarkedString>(value).toList());
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
} else if (value.isObject()) {
const QJsonObject &object = value.toObject();
MarkedLanguageString markedLanguageString(object);
if (markedLanguageString.isValid(nullptr))
emplace<MarkedString>(markedLanguageString);
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
else
emplace<MarkupContent>(MarkupContent(object));
} else if (value.isString()) {
emplace<MarkedString>(MarkedString(value.toString()));
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
}
}
bool HoverContent::isValid(QStringList *errorHierarchy) const
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
{
if (Utils::holds_alternative<MarkedString>(*this)
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
|| Utils::holds_alternative<MarkupContent>(*this)
|| Utils::holds_alternative<QList<MarkedString>>(*this)) {
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
return true;
}
if (errorHierarchy) {
*errorHierarchy << QCoreApplication::translate(
"LanguageServerProtocol::HoverContent",
"HoverContent should be either MarkedString, "
"MarkupContent, or QList<MarkedString>.");
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
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();
}
bool DocumentFormattingProperty::isValid(QStringList *error) const
{
if (Utils::holds_alternative<bool>(*this)
|| Utils::holds_alternative<double>(*this)
|| Utils::holds_alternative<QString>(*this)) {
return true;
}
if (error) {
*error << QCoreApplication::translate(
"LanguageServerProtocol::MarkedString",
"DocumentFormattingProperty should be either bool, double, or QString.");
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
}
return false;
}
SignatureHelpRequest::SignatureHelpRequest(const TextDocumentPositionParams &params)
: Request(methodName, params)
{ }
CodeActionResult::CodeActionResult(const QJsonValue &val)
{
using ResultArray = QList<Utils::variant<Command, CodeAction>>;
if (val.isArray()) {
const QJsonArray array = val.toArray();
ResultArray result;
for (const QJsonValue &val : array) {
Command command(val);
if (command.isValid(nullptr))
result << command;
else
result << CodeAction(val);
}
emplace<ResultArray>(result);
return;
}
emplace<std::nullptr_t>(nullptr);
}
bool CodeAction::isValid(QStringList *error) const
{
return check<QString>(error, titleKey)
&& checkOptional<CodeActionKind>(error, codeActionKindKey)
&& checkOptionalArray<Diagnostic>(error, diagnosticsKey)
&& checkOptional<WorkspaceEdit>(error, editKey)
&& checkOptional<Command>(error, commandKey);
}
Introduce a basic client for the language server protocol The language server protocol is used to transport language specific information needed to efficiently edit source files. For example completion, go to operations and symbol information. These information are transferred via JSON-RPC. The complete definition can be found under https://microsoft.github.io/language-server-protocol/specification. This language server protocol support consists of two major parts, the C++ representation of the language server protocol, and the client part for the communication with an external language server. The TypeScript definitions of the protocol interfaces are transferred to C++ classes. Those classes have getter and setter for every interface value. Optional values from the protocol are represented by Utils::optional<ValueType>. The JSON objects that are used to transfer the data between client and server are hidden by a specialized JsonObject class derived from QJsonObject. Additionally this JsonObject provides a validity check that is capable of creating a detailed error message for malformed, or at least unexpected JSON representation of the protocol. The client is the interface between Qt Creator and language server functionality, like completion, diagnostics, document and workspace synchronization. The base client converts the data that is sent from/to the server between the raw byte array and the corresponding C++ objects. The transportat layer is defined in a specialized base client (this initial change will only support stdio language server). The running clients are handled inside the language client manager, which is also used to connect global and exclusive Qt Creator functionality to the clients. Task-number: QTCREATORBUG-20284 Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-07-13 12:33:46 +02:00
} // namespace LanguageServerProtocol