Commit df48489b authored by Mark Nauwelaerts's avatar Mark Nauwelaerts

lspclient: add server support for references

parent fdcf9b3d
......@@ -99,6 +99,16 @@ textDocumentPositionParams(const QUrl & document, LSPPosition pos)
return params;
}
static QJsonObject
referenceParams(const QUrl & document, LSPPosition pos, bool decl)
{
auto params = textDocumentPositionParams(document, pos);
params[QStringLiteral("context")] = QJsonObject {
{ QStringLiteral("includeDeclaration"), decl }
};
return params;
}
static void
from_json(QVector<QChar> & trigger, const QJsonValue & json)
{
......@@ -504,6 +514,13 @@ public:
return send(init_request(QStringLiteral("textDocument/documentHighlight"), params), h);
}
RequestHandle documentReferences(const QUrl & document, const LSPPosition & pos, bool decl,
const GenericReplyHandler & h)
{
auto params = referenceParams(document, pos, decl);
return send(init_request(QStringLiteral("textDocument/references"), params), h);
}
RequestHandle documentCompletion(const QUrl & document, const LSPPosition & pos,
const GenericReplyHandler & h)
{
......@@ -866,6 +883,11 @@ LSPClientServer::documentHighlight(const QUrl & document, const LSPPosition & po
const QObject *context, const DocumentHighlightReplyHandler & h)
{ return d->documentHighlight(document, pos, make_handler(h, context, parseDocumentHighlightList)); }
LSPClientServer::RequestHandle
LSPClientServer::documentReferences(const QUrl & document, const LSPPosition & pos, bool decl,
const QObject *context, const DocumentDefinitionReplyHandler & h)
{ return d->documentReferences(document, pos, decl, make_handler(h, context, parseDocumentLocation)); }
LSPClientServer::RequestHandle
LSPClientServer::documentCompletion(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentCompletionReplyHandler & h)
......
......@@ -122,6 +122,8 @@ public:
const QObject *context, const DocumentHighlightReplyHandler & h);
RequestHandle documentHover(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentHoverReplyHandler & h);
RequestHandle documentReferences(const QUrl & document, const LSPPosition & pos, bool decl,
const QObject *context, const DocumentDefinitionReplyHandler & h);
RequestHandle documentCompletion(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentCompletionReplyHandler & h);
RequestHandle signatureHelp(const QUrl & document, const LSPPosition & pos,
......
......@@ -91,6 +91,13 @@ int main(int argc, char ** argv)
lsp.documentHover(document, {position[0].toInt(), position[1].toInt()}, &app, hover_h);
q.exec();
auto ref_h = [&q] (const QList<LSPLocation> & refs) {
std::cout << "refs: " << refs.length() << std::endl;
q.quit();
};
lsp.documentReferences(document, {position[0].toInt(), position[1].toInt()}, true, &app, ref_h);
q.exec();
// lsp.didOpen(document, 0, QStringLiteral("blah"));
lsp.didChange(document, 1, QStringLiteral("foo"));
lsp.didClose(document);
......
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