diff options
author | David Schulz <[email protected]> | 2018-11-21 13:59:52 +0100 |
---|---|---|
committer | David Schulz <[email protected]> | 2018-12-03 11:50:13 +0000 |
commit | 696dedefa14d46e4227b4c7b1e68e258ad1b68c8 (patch) | |
tree | 0bb90c3bdb028bce966648d01c7cded26fcd92aa /src/libs/languageserverprotocol/languagefeatures.cpp | |
parent | d7e249a5e1c293a3441250ee079a27d7417a2efe (diff) |
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 <[email protected]>
Diffstat (limited to 'src/libs/languageserverprotocol/languagefeatures.cpp')
-rw-r--r-- | src/libs/languageserverprotocol/languagefeatures.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/libs/languageserverprotocol/languagefeatures.cpp b/src/libs/languageserverprotocol/languagefeatures.cpp index 8009ed1ebd4..bcff1385c05 100644 --- a/src/libs/languageserverprotocol/languagefeatures.cpp +++ b/src/libs/languageserverprotocol/languagefeatures.cpp @@ -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; } |