Commit 0d0f7294 authored by Mark Nauwelaerts's avatar Mark Nauwelaerts

lspclient: add server support for incremental document sync

parent 69a3e75d
......@@ -135,6 +135,12 @@ struct LSPLocation
LSPRange range;
};
struct LSPTextDocumentContentChangeEvent
{
LSPRange range;
QString text;
};
enum class LSPDocumentHighlightKind
{
Text = 1,
......
......@@ -133,6 +133,19 @@ to_json(const LSPDiagnostic & diagnostic)
return result;
}
static QJsonArray
to_json(const QList<LSPTextDocumentContentChangeEvent> & changes)
{
QJsonArray result;
for (const auto &change: changes) {
result.push_back(QJsonObject {
{MEMBER_RANGE, to_json(change.range)},
{MEMBER_TEXT, change.text}
});
}
return result;
}
static QJsonObject
versionedTextDocumentIdentifier(const QUrl & document, int version = -1)
{
......@@ -785,12 +798,14 @@ public:
send(init_request(QStringLiteral("textDocument/didOpen"), params));
}
void didChange(const QUrl & document, int version, const QString & text)
void didChange(const QUrl & document, int version, const QString & text,
const QList<LSPTextDocumentContentChangeEvent> & changes)
{
Q_ASSERT(text.size() == 0 || changes.size() == 0);
auto params = textDocumentParams(document, version);
params[QStringLiteral("contentChanges")] = QJsonArray {
QJsonObject {{MEMBER_TEXT, text}}
};
params[QStringLiteral("contentChanges")] = text.size()
? QJsonArray { QJsonObject {{MEMBER_TEXT, text}} }
: to_json(changes);
send(init_request(QStringLiteral("textDocument/didChange"), params));
}
......@@ -1356,8 +1371,9 @@ void LSPClientServer::executeCommand(const QString & command, const QJsonValue &
void LSPClientServer::didOpen(const QUrl & document, int version, const QString & langId, const QString & text)
{ return d->didOpen(document, version, langId, text); }
void LSPClientServer::didChange(const QUrl & document, int version, const QString & text)
{ return d->didChange(document, version, text); }
void LSPClientServer::didChange(const QUrl & document, int version, const QString & text,
const QList<LSPTextDocumentContentChangeEvent> & changes)
{ return d->didChange(document, version, text, changes); }
void LSPClientServer::didSave(const QUrl & document, const QString & text)
{ return d->didSave(document, text); }
......
......@@ -166,7 +166,9 @@ public:
// sync
void didOpen(const QUrl & document, int version, const QString & langId, const QString & text);
void didChange(const QUrl & document, int version, const QString & text);
// only 1 of text or changes should be non-empty and is considered
void didChange(const QUrl & document, int version, const QString & text,
const QList<LSPTextDocumentContentChangeEvent> & changes = {});
void didSave(const QUrl & document, const QString & text);
void didClose(const QUrl & 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