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:
@@ -43,6 +43,7 @@ constexpr char changeKey[] = "change";
|
||||
constexpr char changeNotificationsKey[] = "changeNotifications";
|
||||
constexpr char changesKey[] = "changes";
|
||||
constexpr char characterKey[] = "character";
|
||||
constexpr char childrenKey[] = "children";
|
||||
constexpr char codeActionKey[] = "codeAction";
|
||||
constexpr char codeActionProviderKey[] = "codeActionProvider";
|
||||
constexpr char codeKey[] = "code";
|
||||
@@ -73,6 +74,7 @@ constexpr char dataKey[] = "data";
|
||||
constexpr char defaultCharset[] = "utf-8";
|
||||
constexpr char definitionKey[] = "definition";
|
||||
constexpr char definitionProviderKey[] = "definitionProvider";
|
||||
constexpr char deprecatedKey[] = "deprecated";
|
||||
constexpr char detailKey[] = "detail";
|
||||
constexpr char diagnosticsKey[] = "diagnostics";
|
||||
constexpr char didChangeConfigurationKey[] = "didChangeConfiguration";
|
||||
@@ -160,6 +162,7 @@ constexpr char saveKey[] = "save";
|
||||
constexpr char schemeKey[] = "scheme";
|
||||
constexpr char scopeUriKey[] = "scopeUri";
|
||||
constexpr char sectionKey[] = "section";
|
||||
constexpr char selectionRangeKey[] = "selectionRange";
|
||||
constexpr char settingsKey[] = "settings";
|
||||
constexpr char severityKey[] = "severity";
|
||||
constexpr char signatureHelpKey[] = "signatureHelp";
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -323,7 +323,7 @@ public:
|
||||
using DocumentSymbolParams = TextDocumentParams;
|
||||
|
||||
class LANGUAGESERVERPROTOCOL_EXPORT DocumentSymbolsResult
|
||||
: public Utils::variant<QList<SymbolInformation>, std::nullptr_t>
|
||||
: public Utils::variant<QList<SymbolInformation>, QList<DocumentSymbol>, std::nullptr_t>
|
||||
{
|
||||
public:
|
||||
using variant::variant;
|
||||
|
@@ -430,6 +430,10 @@ public:
|
||||
int kind() const { return typedValue<int>(kindKey); }
|
||||
void setKind(int kind) { insert(kindKey, kind); }
|
||||
|
||||
Utils::optional<bool> deprecated() const { return optionalValue<bool>(deprecatedKey); }
|
||||
void setDeprecated(bool deprecated) { insert(deprecatedKey, deprecated); }
|
||||
void clearDeprecated() { remove(deprecatedKey); }
|
||||
|
||||
Location location() const { return typedValue<Location>(locationKey); }
|
||||
void setLocation(const Location &location) { insert(locationKey, location); }
|
||||
|
||||
@@ -441,6 +445,37 @@ public:
|
||||
bool isValid(QStringList *error) const override;
|
||||
};
|
||||
|
||||
class LANGUAGESERVERPROTOCOL_EXPORT DocumentSymbol : public JsonObject
|
||||
{
|
||||
public:
|
||||
using JsonObject::JsonObject;
|
||||
|
||||
QString name() const { return typedValue<QString>(nameKey); }
|
||||
void setName(const QString &name) { insert(nameKey, name); }
|
||||
|
||||
Utils::optional<QString> detail() const { return optionalValue<QString>(detailKey); }
|
||||
void setDetail(const QString &detail) { insert(detailKey, detail); }
|
||||
void clearDetail() { remove(detailKey); }
|
||||
|
||||
int kind() const { return typedValue<int>(kindKey); }
|
||||
void setKind(int kind) { insert(kindKey, kind); }
|
||||
|
||||
Utils::optional<bool> deprecated() const { return optionalValue<bool>(deprecatedKey); }
|
||||
void setDeprecated(bool deprecated) { insert(deprecatedKey, deprecated); }
|
||||
void clearDeprecated() { remove(deprecatedKey); }
|
||||
|
||||
Range range() const { return typedValue<Range>(rangeKey); }
|
||||
void setRange(Range range) { insert(rangeKey, range); }
|
||||
|
||||
Range selectionRange() const { return typedValue<Range>(selectionRangeKey); }
|
||||
void setSelectionRange(Range selectionRange) { insert(selectionRangeKey, selectionRange); }
|
||||
|
||||
Utils::optional<QList<DocumentSymbol>> children() const
|
||||
{ return optionalArray<DocumentSymbol>(childrenKey); }
|
||||
void setChildren(QList<DocumentSymbol> children) { insertArray(childrenKey, children); }
|
||||
void clearChildren() { remove(childrenKey); }
|
||||
};
|
||||
|
||||
enum class SymbolKind {
|
||||
File = 1,
|
||||
FirstSymbolKind = File,
|
||||
|
Reference in New Issue
Block a user