Commit cca3290a authored by Christoph Cullmann's avatar Christoph Cullmann

start to implement textDocument/documentHighlight, send request + parse results work

parent ea47b456
......@@ -235,6 +235,37 @@ public:
void highlight()
{
auto h = [this] (const QList<LSPDocumentHighlight> & defs)
{
// TODO add another (bottom) view to display definitions
// in case too late or multiple ones have been found
// (also adjust timeout then ...)
#if 0
if (defs.count()) {
auto &def = defs.at(0);
auto &pos = def.range.start;
KTextEditor::View *activeView = m_mainWindow->activeView();
// it's not nice to jump to some location if we are too late
if (!activeView || m_req_timeout || pos.line < 0 || pos.column < 0)
return;
KTextEditor::Document *document = activeView->document();
KTextEditor::Cursor cdef(pos.line, pos.column);
if (document && def.uri == document->url()) {
activeView->setCursorPosition(cdef);
} else {
KTextEditor::View *view = m_mainWindow->openUrl(def.uri);
if (view) {
view->setCursorPosition(cdef);
}
}
}
#endif
};
positionRequest<DocumentHighlightReplyHandler>(&LSPClientServer::documentHighlight, h);
}
void hover()
......
......@@ -110,6 +110,19 @@ struct LSPLocation
LSPRange range;
};
enum class LSPDocumentHighlightKind
{
Text = 1,
Read = 2,
Write = 3
};
struct LSPDocumentHighlight
{
LSPRange range;
LSPDocumentHighlightKind kind;
};
struct LSPHover
{
LSPMarkupContent contents;
......
......@@ -496,6 +496,13 @@ public:
return send(init_request(QStringLiteral("textDocument/hover"), params), h);
}
RequestHandle documentHighlight(const QUrl & document, const LSPPosition & pos,
const GenericReplyHandler & h)
{
auto params = textDocumentPositionParams(document, pos);
return send(init_request(QStringLiteral("textDocument/documentHighlight"), params), h);
}
RequestHandle documentCompletion(const QUrl & document, const LSPPosition & pos,
const GenericReplyHandler & h)
{
......@@ -587,6 +594,31 @@ parseLocation(const QJsonObject & loc)
return {QUrl(uri), range};
}
static LSPDocumentHighlight
parseDocumentHighlight(const QJsonValue & result)
{
auto hover = result.toObject();
auto range = parseRange(hover.value(MEMBER_RANGE).toObject());
auto kind = (LSPDocumentHighlightKind)hover.value(MEMBER_KIND).toInt((int)LSPDocumentHighlightKind::Text); // default is DocumentHighlightKind.Text
return {range, kind};
}
static QList<LSPDocumentHighlight>
parseDocumentHighlightList(const QJsonValue & result)
{
QList<LSPDocumentHighlight> ret;
// could be array
if (result.isArray()) {
for (const auto & def : result.toArray()) {
ret.push_back(parseDocumentHighlight(def));
}
} else if (result.isObject()) {
// or a single value
ret.push_back(parseDocumentHighlight(result));
}
return ret;
}
static LSPHover
parseHover(const QJsonValue & result)
{
......@@ -809,6 +841,11 @@ LSPClientServer::documentHover(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentHoverReplyHandler & h)
{ return d->documentHover(document, pos, make_handler(h, context, parseHover)); }
LSPClientServer::RequestHandle
LSPClientServer::documentHighlight(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentHighlightReplyHandler & h)
{ return d->documentHighlight(document, pos, make_handler(h, context, parseDocumentHighlightList)); }
LSPClientServer::RequestHandle
LSPClientServer::documentCompletion(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentCompletionReplyHandler & h)
......
......@@ -59,6 +59,7 @@ using ReplyHandler = std::function<void(const T &)>;
using DocumentSymbolsReplyHandler = ReplyHandler<QList<LSPSymbolInformation>>;
using DocumentDefinitionReplyHandler = ReplyHandler<QList<LSPLocation>>;
using DocumentHighlightReplyHandler = ReplyHandler<QList<LSPDocumentHighlight>>;
using DocumentHoverReplyHandler = ReplyHandler<LSPHover>;
using DocumentCompletionReplyHandler = ReplyHandler<QList<LSPCompletionItem>>;
using SignatureHelpReplyHandler = ReplyHandler<LSPSignatureHelp>;
......@@ -117,6 +118,8 @@ public:
const QObject *context, const DocumentDefinitionReplyHandler & h);
RequestHandle documentDeclaration(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentDefinitionReplyHandler & h);
RequestHandle documentHighlight(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentHighlightReplyHandler & h);
RequestHandle documentHover(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentHoverReplyHandler & h);
RequestHandle documentCompletion(const QUrl & document, const LSPPosition & pos,
......
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