Commit 78fef2e6 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

workspace/symbols response parsing


Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent 6b80bd9a
......@@ -162,9 +162,22 @@ enum class LSPSymbolKind {
Number = 16,
Boolean = 17,
Array = 18,
Object = 19,
Key = 20,
Null = 21,
EnumMember = 22,
Struct = 23,
Event = 24,
Operator = 25,
TypeParameter = 26,
};
enum class LSPSymbolTag : uint8_t {
Deprecated = 1,
};
struct LSPSymbolInformation {
LSPSymbolInformation() = default;
LSPSymbolInformation(const QString &_name, LSPSymbolKind _kind, LSPRange _range, const QString &_detail)
: name(_name)
, detail(_detail)
......@@ -175,7 +188,10 @@ struct LSPSymbolInformation {
QString name;
QString detail;
LSPSymbolKind kind;
QUrl url;
LSPRange range;
double score = 0.0;
LSPSymbolTag tags;
QList<LSPSymbolInformation> children;
};
......
......@@ -804,10 +804,35 @@ static LSPShowMessageParams parseMessage(const QJsonObject &result)
return ret;
}
static QString parseWorkspaceSymbols(const QJsonValue &result)
static std::vector<LSPSymbolInformation> parseWorkspaceSymbols(const QJsonValue &result)
{
// result has an array in it
return {};
auto res = result.toArray();
std::vector<LSPSymbolInformation> symbols;
symbols.reserve(res.size());
std::transform(res.cbegin(), res.cend(), std::back_inserter(symbols), [](const QJsonValue &jv) {
auto symbol = jv.toObject();
LSPSymbolInformation symInfo;
const auto location = symbol.value(MEMBER_LOCATION).toObject();
const auto mrange = symbol.contains(MEMBER_RANGE) ? symbol.value(MEMBER_RANGE) : location.value(MEMBER_RANGE);
symInfo.name = symbol.value(QStringLiteral("name")).toString();
symInfo.kind = (LSPSymbolKind)symbol.value(MEMBER_KIND).toInt();
symInfo.range = parseRange(mrange.toObject());
symInfo.url = QUrl(location.value(MEMBER_URI).toString());
symInfo.score = symbol.value(QStringLiteral("score")).toDouble();
symInfo.tags = (LSPSymbolTag)symbol.value(QStringLiteral("tags")).toInt();
return symInfo;
});
std::sort(symbols.begin(), symbols.end(), [](const LSPSymbolInformation &l, const LSPSymbolInformation &r) {
return l.score > r.score;
});
return symbols;
}
using GenericReplyType = QJsonValue;
......@@ -1645,7 +1670,7 @@ void LSPClientServer::didChangeConfiguration(const QJsonValue &settings)
return d->didChangeConfiguration(settings);
}
void LSPClientServer::workspaceSymbol(const QString &symbol, const QObject *context, const ReplyHandler<QString> &h)
void LSPClientServer::workspaceSymbol(const QString &symbol, const QObject *context, const WorkspaceSymbolsReplyHandler &h)
{
return d->workspaceSymbol(symbol, make_handler(h, context, parseWorkspaceSymbols));
}
......@@ -65,6 +65,7 @@ using WorkspaceEditReplyHandler = ReplyHandler<LSPWorkspaceEdit>;
using ApplyEditReplyHandler = ReplyHandler<LSPApplyWorkspaceEditResponse>;
using SwitchSourceHeaderHandler = ReplyHandler<QString>;
using SemanticTokensDeltaReplyHandler = ReplyHandler<LSPSemanticTokensDelta>;
using WorkspaceSymbolsReplyHandler = ReplyHandler<std::vector<LSPSymbolInformation>>;
class LSPClientPlugin;
......@@ -169,7 +170,7 @@ public:
void didChangeConfiguration(const QJsonValue &settings);
// workspace
void workspaceSymbol(const QString &symbol, const QObject *context, const ReplyHandler<QString> &h);
void workspaceSymbol(const QString &symbol, const QObject *context, const WorkspaceSymbolsReplyHandler &h);
// notification = signal
Q_SIGNALS:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment