aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2019-05-03 13:11:50 +0200
committerDavid Schulz <david.schulz@qt.io>2019-05-09 05:57:31 +0000
commit6b2e09b08ef7b21133186985e71933216dfe8dd8 (patch)
tree6f6d84617f33992d0762fc1a65c3daac5531eb7c /src/libs
parent97ae2d1ac0a58190131dd2469e28d1fe1adc3250 (diff)
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>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/languageserverprotocol/lsptypes.cpp21
-rw-r--r--src/libs/languageserverprotocol/lsputils.cpp20
-rw-r--r--src/libs/languageserverprotocol/lsputils.h6
3 files changed, 29 insertions, 18 deletions
diff --git a/src/libs/languageserverprotocol/lsptypes.cpp b/src/libs/languageserverprotocol/lsptypes.cpp
index 2b3e2628b3..991f7cc1f8 100644
--- a/src/libs/languageserverprotocol/lsptypes.cpp
+++ b/src/libs/languageserverprotocol/lsptypes.cpp
@@ -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,11 +121,13 @@ 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
- emplace<MarkupContent>(MarkupContent(val.toObject()));
+ } 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()))
diff --git a/src/libs/languageserverprotocol/lsputils.cpp b/src/libs/languageserverprotocol/lsputils.cpp
index 40d782c9f6..aceeed7392 100644
--- a/src/libs/languageserverprotocol/lsputils.cpp
+++ b/src/libs/languageserverprotocol/lsputils.cpp
@@ -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();
}
diff --git a/src/libs/languageserverprotocol/lsputils.h b/src/libs/languageserverprotocol/lsputils.h
index d7ae5525bb..ee98db37f4 100644
--- a/src/libs/languageserverprotocol/lsputils.h
+++ b/src/libs/languageserverprotocol/lsputils.h
@@ -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());
}