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())
|
||||
return Utils::nullopt;
|
||||
QJsonValue::Type type = it.value().type();
|
||||
QTC_ASSERT(type == QJsonValue::String || type == QJsonValue::Double,
|
||||
return Utils::make_optional(Code(QString())));
|
||||
if (type != QJsonValue::String && type != QJsonValue::Double)
|
||||
return Utils::make_optional(Code(QString()));
|
||||
return Utils::make_optional(codeValue.isDouble() ? Code(codeValue.toInt())
|
||||
: Code(codeValue.toString()));
|
||||
}
|
||||
@@ -81,8 +81,7 @@ Utils::optional<WorkspaceEdit::Changes> WorkspaceEdit::changes() const
|
||||
auto it = find(changesKey);
|
||||
if (it == end())
|
||||
return Utils::nullopt;
|
||||
QTC_ASSERT(it.value().type() == QJsonValue::Object, return Changes());
|
||||
QJsonObject changesObject(it.value().toObject());
|
||||
const QJsonObject &changesObject = it.value().toObject();
|
||||
Changes changesResult;
|
||||
for (const QString &key : changesObject.keys())
|
||||
changesResult[DocumentUri::fromProtocol(key)] = LanguageClientArray<TextEdit>(changesObject.value(key)).toList();
|
||||
@@ -122,12 +121,14 @@ MarkupOrString::MarkupOrString(const MarkupContent &val)
|
||||
|
||||
MarkupOrString::MarkupOrString(const QJsonValue &val)
|
||||
{
|
||||
QTC_ASSERT(val.isString() | val.isObject(), return);
|
||||
if (val.isString())
|
||||
if (val.isString()) {
|
||||
emplace<QString>(val.toString());
|
||||
else
|
||||
} else {
|
||||
MarkupContent markupContent(val.toObject());
|
||||
if (markupContent.isValid(nullptr))
|
||||
emplace<MarkupContent>(MarkupContent(val.toObject()));
|
||||
}
|
||||
}
|
||||
|
||||
bool MarkupOrString::isValid(QStringList *error) const
|
||||
{
|
||||
@@ -401,9 +402,7 @@ Utils::Link Location::toLink() const
|
||||
|
||||
DocumentUri::DocumentUri(const QString &other)
|
||||
: QUrl(QUrl::fromPercentEncoding(other.toLocal8Bit()))
|
||||
{
|
||||
QTC_ASSERT(isValid(), qWarning() << other);
|
||||
}
|
||||
{ }
|
||||
|
||||
DocumentUri::DocumentUri(const Utils::FileName &other)
|
||||
: QUrl(QUrl::fromLocalFile(other.toString()))
|
||||
|
@@ -28,42 +28,50 @@
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
|
||||
#include <QHash>
|
||||
#include <QLoggingCategory>
|
||||
#include <QVector>
|
||||
|
||||
namespace LanguageServerProtocol {
|
||||
|
||||
Q_LOGGING_CATEGORY(conversionLog, "qtc.languageserverprotocol.conversion", QtWarningMsg)
|
||||
|
||||
template<>
|
||||
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();
|
||||
}
|
||||
|
||||
template<>
|
||||
int fromJsonValue<int>(const QJsonValue &value)
|
||||
{
|
||||
QTC_ASSERT(value.isDouble(), return 0);
|
||||
return int(value.toDouble());
|
||||
if (conversionLog().isDebugEnabled() && !value.isDouble())
|
||||
qCDebug(conversionLog) << "Expected double in json value but got: " << value;
|
||||
return value.toInt();
|
||||
}
|
||||
|
||||
template<>
|
||||
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();
|
||||
}
|
||||
|
||||
template<>
|
||||
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();
|
||||
}
|
||||
|
||||
template<>
|
||||
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();
|
||||
}
|
||||
|
||||
|
@@ -35,13 +35,17 @@
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
namespace LanguageServerProtocol {
|
||||
|
||||
LANGUAGESERVERPROTOCOL_EXPORT Q_DECLARE_LOGGING_CATEGORY(conversionLog)
|
||||
|
||||
template <typename T>
|
||||
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());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user