LSP: Prevent soft asserts in LanguageClientArray::toList

Change-Id: Icb935137d389c223ac1360b4a7e0af5c303b793c
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2021-03-25 13:14:09 +01:00
parent 9d0c3dc3d6
commit bd47caa348

View File

@@ -175,15 +175,20 @@ Utils::optional<LanguageClientValue<T>> JsonObject::optionalClientValue(const QS
template<typename T>
QList<T> JsonObject::array(const QString &key) const
{
return LanguageClientArray<T>(value(key)).toList();
const Utils::optional<QList<T>> &array = optionalArray<T>(key);
if (array.has_value())
return array.value();
qCDebug(conversionLog) << QString("Expected array under %1 in:").arg(key) << *this;
return {};
}
template<typename T>
Utils::optional<QList<T>> JsonObject::optionalArray(const QString &key) const
{
using Result = Utils::optional<QList<T>>;
return contains(key) ? Result(LanguageClientArray<T>(value(key)).toList())
: Result(Utils::nullopt);
const QJsonValue &jsonValue = value(key);
if (jsonValue.isUndefined())
return Utils::nullopt;
return Utils::transform<QList<T>>(jsonValue.toArray(), &fromJsonValue<T>);
}
template<typename T>