LSP: add support for hierarchical document symbols

The result of the document symbol request was a flat list of symbols
until version 3.10.0 of the Protocol. The new result type also added
whether a symbol is deprecated and what text should get selected
when a symbol is activated in the IDE UI.

Change-Id: Id30366c44198434c240f3a21b8b237bf6819a425
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2018-11-21 13:59:52 +01:00
parent d7e249a5e1
commit 696dedefa1
4 changed files with 59 additions and 6 deletions

View File

@@ -277,15 +277,30 @@ GotoResult::GotoResult(const QJsonValue &value)
}
}
template<typename Symbol>
QList<Symbol> documentSymbolsResultArray(const QJsonArray &array)
{
QList<Symbol> ret;
for (auto arrayValue : array) {
if (arrayValue.isObject())
ret << Symbol(arrayValue.toObject());
}
return ret;
}
DocumentSymbolsResult::DocumentSymbolsResult(const QJsonValue &value)
{
if (value.isArray()) {
QList<SymbolInformation> symbols;
for (auto arrayValue : value.toArray()) {
if (arrayValue.isObject())
symbols.append(SymbolInformation(arrayValue.toObject()));
QJsonArray array = value.toArray();
if (array.isEmpty()) {
*this = QList<SymbolInformation>();
} else {
QJsonObject arrayObject = array.first().toObject();
if (arrayObject.contains(rangeKey))
*this = documentSymbolsResultArray<DocumentSymbol>(array);
else
*this = documentSymbolsResultArray<SymbolInformation>(array);
}
*this = symbols;
} else {
*this = nullptr;
}