Commit 066db490 authored by Christoph Cullmann's avatar Christoph Cullmann

map LSPPosition and LSPRange to the KTextEditor equivalents, they have the...

map LSPPosition and LSPRange to the KTextEditor equivalents, they have the same data types (just two ints) and the same semantics, no need to convert around (and they have more helper functions)
parent cca3290a
......@@ -196,21 +196,20 @@ public:
if (defs.count()) {
auto &def = defs.at(0);
auto &pos = def.range.start;
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)
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);
activeView->setCursorPosition(pos);
} else {
KTextEditor::View *view = m_mainWindow->openUrl(def.uri);
if (view) {
view->setCursorPosition(cdef);
view->setCursorPosition(pos);
}
}
}
......@@ -235,11 +234,20 @@ public:
void highlight()
{
auto h = [this] (const QList<LSPDocumentHighlight> & defs)
// construct handler, remember view we did the request for
const QPointer<KTextEditor::View> viewForRequest(m_mainWindow->activeView());
auto h = [this, viewForRequest] (const QList<LSPDocumentHighlight> & occurences)
{
// TODO add another (bottom) view to display definitions
// in case too late or multiple ones have been found
// (also adjust timeout then ...)
// abort if the view we requested this for is away!
if (!viewForRequest)
return;
// highlight all occurences
for (const auto &occurence : occurences) {
}
#if 0
if (defs.count()) {
auto &def = defs.at(0);
......
......@@ -25,6 +25,9 @@
#include <QList>
#include <QVector>
#include <ktexteditor/cursor.h>
#include <ktexteditor/range.h>
enum class LSPErrorCode
{
// Defined by JSON RPC
......@@ -90,19 +93,19 @@ struct LSPMarkupContent
QString value;
};
struct LSPPosition
{
// both are 0-based
// (negative if optional/non-present)
int line;
int column;
};
/**
* Language Server Protocol Position
* line + column, 0 based, negative for invalid
* maps 1:1 to KTextEditor::Cursor
*/
using LSPPosition = KTextEditor::Cursor;
struct LSPRange
{
LSPPosition start;
LSPPosition end;
};
/**
* Language Server Protocol Range
* start + end tuple of LSPPosition
* maps 1:1 to KTextEditor::Range
*/
using LSPRange = KTextEditor::Range;
struct LSPLocation
{
......
......@@ -92,8 +92,8 @@ textDocumentPositionParams(const QUrl & document, LSPPosition pos)
{
auto params = textDocumentParams(document);
params[MEMBER_POSITION] = QJsonObject {
{ MEMBER_LINE, pos.line },
{ MEMBER_CHARACTER, pos.column }
{ MEMBER_LINE, pos.line() },
{ MEMBER_CHARACTER, pos.column() }
};
return params;
}
......@@ -576,7 +576,7 @@ parsePosition(const QJsonObject & m)
static bool
isPositionValid(const LSPPosition & pos)
{ return pos.line >= 0 && pos.column >=0; }
{ return pos.isValid(); }
static LSPRange
parseRange(const QJsonObject & range)
......@@ -673,7 +673,7 @@ parseDocumentSymbols(const QJsonValue & result)
const auto& mrange = symbol.contains(MEMBER_RANGE) ?
symbol.value(MEMBER_RANGE) : location.value(MEMBER_RANGE);
auto range = parseRange(mrange.toObject());
if (isPositionValid(range.start) && isPositionValid(range.end)) {
if (isPositionValid(range.start()) && isPositionValid(range.end())) {
list->push_back({name, kind, range});
index[name] = &list->back();
// proceed recursively
......
......@@ -240,8 +240,8 @@ public:
auto detail = show_detail ? symbol.detail : QStringLiteral("");
node->setText(0, symbol.name + detail);
node->setIcon(0, *icon);
node->setText(1, QString::number(symbol.range.start.line, 10));
node->setText(2, QString::number(symbol.range.end.line, 10));
node->setText(1, QString::number(symbol.range.start().line(), 10));
node->setText(2, QString::number(symbol.range.end().line(), 10));
// recurse children
makeNodes(symbol.children, tree, show_detail, widget, node, details);
}
......
add_executable(lsptestapp lsptestapp.cpp ../lspclientserver.cpp
${lspclientplugin_debug_SRCS})
target_link_libraries(lsptestapp Qt5::Core)
target_link_libraries(lsptestapp KF5::TextEditor Qt5::Core)
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