forked from qt-creator/qt-creator
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user