LSP: Fix MarkedString fromJson

fromJsonValue<T>(...) (with T = MarkedString) always tried to convert
the json value toObject() first. Which is wrong since it can be an
object or a string.

Fixes the broken hover text for the json language server.

Change-Id: Id69b4270238bea7068936a7d2142f4f94918f96b
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-06-12 08:25:48 +02:00
parent f477ede697
commit e47c797dee
3 changed files with 10 additions and 1 deletions

View File

@@ -261,6 +261,12 @@ DocumentHighlightsResult::DocumentHighlightsResult(const QJsonValue &value)
} }
} }
template<>
MarkedString fromJsonValue<MarkedString>(const QJsonValue &value)
{
return MarkedString(value);
}
MarkedString::MarkedString(const QJsonValue &value) MarkedString::MarkedString(const QJsonValue &value)
{ {
if (value.isObject()) if (value.isObject())

View File

@@ -52,6 +52,9 @@ public:
operator QJsonValue() const; operator QJsonValue() const;
}; };
template<>
LANGUAGESERVERPROTOCOL_EXPORT MarkedString fromJsonValue<MarkedString>(const QJsonValue &value);
class LANGUAGESERVERPROTOCOL_EXPORT HoverContent class LANGUAGESERVERPROTOCOL_EXPORT HoverContent
: public std::variant<MarkedString, QList<MarkedString>, MarkupContent> : public std::variant<MarkedString, QList<MarkedString>, MarkupContent>
{ {

View File

@@ -68,7 +68,7 @@ public:
if (value.isArray()) { if (value.isArray()) {
QList<T> values; QList<T> values;
values.reserve(value.toArray().count()); values.reserve(value.toArray().count());
for (auto arrayValue : value.toArray()) for (const auto &arrayValue : value.toArray())
values << fromJsonValue<T>(arrayValue); values << fromJsonValue<T>(arrayValue);
*this = values; *this = values;
} else { } else {