forked from qt-creator/qt-creator
LSP: remove incorrect soft asserts
Remove or replace soft asserts that can be triggered by the language server with categorized debug messages. Change-Id: I07caeeee7ca57d5195a0a7479a4959b579c8d208 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -53,8 +53,8 @@ Utils::optional<Diagnostic::Code> Diagnostic::code() const
|
|||||||
if (codeValue.isUndefined())
|
if (codeValue.isUndefined())
|
||||||
return Utils::nullopt;
|
return Utils::nullopt;
|
||||||
QJsonValue::Type type = it.value().type();
|
QJsonValue::Type type = it.value().type();
|
||||||
QTC_ASSERT(type == QJsonValue::String || type == QJsonValue::Double,
|
if (type != QJsonValue::String && type != QJsonValue::Double)
|
||||||
return Utils::make_optional(Code(QString())));
|
return Utils::make_optional(Code(QString()));
|
||||||
return Utils::make_optional(codeValue.isDouble() ? Code(codeValue.toInt())
|
return Utils::make_optional(codeValue.isDouble() ? Code(codeValue.toInt())
|
||||||
: Code(codeValue.toString()));
|
: Code(codeValue.toString()));
|
||||||
}
|
}
|
||||||
@@ -81,8 +81,7 @@ Utils::optional<WorkspaceEdit::Changes> WorkspaceEdit::changes() const
|
|||||||
auto it = find(changesKey);
|
auto it = find(changesKey);
|
||||||
if (it == end())
|
if (it == end())
|
||||||
return Utils::nullopt;
|
return Utils::nullopt;
|
||||||
QTC_ASSERT(it.value().type() == QJsonValue::Object, return Changes());
|
const QJsonObject &changesObject = it.value().toObject();
|
||||||
QJsonObject changesObject(it.value().toObject());
|
|
||||||
Changes changesResult;
|
Changes changesResult;
|
||||||
for (const QString &key : changesObject.keys())
|
for (const QString &key : changesObject.keys())
|
||||||
changesResult[DocumentUri::fromProtocol(key)] = LanguageClientArray<TextEdit>(changesObject.value(key)).toList();
|
changesResult[DocumentUri::fromProtocol(key)] = LanguageClientArray<TextEdit>(changesObject.value(key)).toList();
|
||||||
@@ -122,11 +121,13 @@ MarkupOrString::MarkupOrString(const MarkupContent &val)
|
|||||||
|
|
||||||
MarkupOrString::MarkupOrString(const QJsonValue &val)
|
MarkupOrString::MarkupOrString(const QJsonValue &val)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(val.isString() | val.isObject(), return);
|
if (val.isString()) {
|
||||||
if (val.isString())
|
|
||||||
emplace<QString>(val.toString());
|
emplace<QString>(val.toString());
|
||||||
else
|
} else {
|
||||||
emplace<MarkupContent>(MarkupContent(val.toObject()));
|
MarkupContent markupContent(val.toObject());
|
||||||
|
if (markupContent.isValid(nullptr))
|
||||||
|
emplace<MarkupContent>(MarkupContent(val.toObject()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MarkupOrString::isValid(QStringList *error) const
|
bool MarkupOrString::isValid(QStringList *error) const
|
||||||
@@ -401,9 +402,7 @@ Utils::Link Location::toLink() const
|
|||||||
|
|
||||||
DocumentUri::DocumentUri(const QString &other)
|
DocumentUri::DocumentUri(const QString &other)
|
||||||
: QUrl(QUrl::fromPercentEncoding(other.toLocal8Bit()))
|
: QUrl(QUrl::fromPercentEncoding(other.toLocal8Bit()))
|
||||||
{
|
{ }
|
||||||
QTC_ASSERT(isValid(), qWarning() << other);
|
|
||||||
}
|
|
||||||
|
|
||||||
DocumentUri::DocumentUri(const Utils::FileName &other)
|
DocumentUri::DocumentUri(const Utils::FileName &other)
|
||||||
: QUrl(QUrl::fromLocalFile(other.toString()))
|
: QUrl(QUrl::fromLocalFile(other.toString()))
|
||||||
|
@@ -28,42 +28,50 @@
|
|||||||
#include <utils/mimetypes/mimedatabase.h>
|
#include <utils/mimetypes/mimedatabase.h>
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QLoggingCategory>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
namespace LanguageServerProtocol {
|
namespace LanguageServerProtocol {
|
||||||
|
|
||||||
|
Q_LOGGING_CATEGORY(conversionLog, "qtc.languageserverprotocol.conversion", QtWarningMsg)
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
QString fromJsonValue<QString>(const QJsonValue &value)
|
QString fromJsonValue<QString>(const QJsonValue &value)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(value.isString(), return QString());
|
if (conversionLog().isDebugEnabled() && !value.isString())
|
||||||
|
qCDebug(conversionLog) << "Expected String in json value but got: " << value;
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
int fromJsonValue<int>(const QJsonValue &value)
|
int fromJsonValue<int>(const QJsonValue &value)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(value.isDouble(), return 0);
|
if (conversionLog().isDebugEnabled() && !value.isDouble())
|
||||||
return int(value.toDouble());
|
qCDebug(conversionLog) << "Expected double in json value but got: " << value;
|
||||||
|
return value.toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
double fromJsonValue<double>(const QJsonValue &value)
|
double fromJsonValue<double>(const QJsonValue &value)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(value.isDouble(), return 0);
|
if (conversionLog().isDebugEnabled() && !value.isDouble())
|
||||||
|
qCDebug(conversionLog) << "Expected double in json value but got: " << value;
|
||||||
return value.toDouble();
|
return value.toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
bool fromJsonValue<bool>(const QJsonValue &value)
|
bool fromJsonValue<bool>(const QJsonValue &value)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(value.isBool(), return false);
|
if (conversionLog().isDebugEnabled() && !value.isBool())
|
||||||
|
qCDebug(conversionLog) << "Expected bool in json value but got: " << value;
|
||||||
return value.toBool();
|
return value.toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
QJsonArray fromJsonValue<QJsonArray>(const QJsonValue &value)
|
QJsonArray fromJsonValue<QJsonArray>(const QJsonValue &value)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(value.isArray(), return QJsonArray());
|
if (conversionLog().isDebugEnabled() && !value.isArray())
|
||||||
|
qCDebug(conversionLog) << "Expected Array in json value but got: " << value;
|
||||||
return value.toArray();
|
return value.toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,13 +35,17 @@
|
|||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QLoggingCategory>
|
||||||
|
|
||||||
namespace LanguageServerProtocol {
|
namespace LanguageServerProtocol {
|
||||||
|
|
||||||
|
LANGUAGESERVERPROTOCOL_EXPORT Q_DECLARE_LOGGING_CATEGORY(conversionLog)
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T fromJsonValue(const QJsonValue &value)
|
T fromJsonValue(const QJsonValue &value)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(value.isObject(), return T());
|
if (conversionLog().isDebugEnabled() && !value.isObject())
|
||||||
|
qCDebug(conversionLog) << "Expected Object in json value but got: " << value;
|
||||||
return T(value.toObject());
|
return T(value.toObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user