Commit 361dd43e authored by Mark Nauwelaerts's avatar Mark Nauwelaerts Committed by Christoph Cullmann
Browse files

lspclient: consider some additional server capabilities

parent 0d219dd5
......@@ -21,6 +21,8 @@
#include <KTextEditor/Cursor>
#include <KTextEditor/Range>
#include <optional>
// Following types roughly follow the types/interfaces as defined in LSP protocol spec
// although some deviation may arise where it has been deemed useful
// Moreover, to avoid introducing a custom 'optional' type, absence of an optional
......@@ -51,6 +53,16 @@ struct LSPResponseError {
enum class LSPDocumentSyncKind { None = 0, Full = 1, Incremental = 2 };
struct LSPSaveOptions {
bool includeText = false;
};
// only used parts for now
struct LSPTextDocumentSyncOptions {
LSPDocumentSyncKind change = LSPDocumentSyncKind::None;
std::optional<LSPSaveOptions> save;
};
struct LSPCompletionOptions {
bool provider = false;
bool resolveProvider = false;
......@@ -81,7 +93,7 @@ struct LSPWorkspaceFoldersServerCapabilities {
};
struct LSPServerCapabilities {
LSPDocumentSyncKind textDocumentSync = LSPDocumentSyncKind::None;
LSPTextDocumentSyncOptions textDocumentSync;
bool hoverProvider = false;
LSPCompletionOptions completionProvider;
LSPSignatureHelpOptions signatureHelpProvider;
......
......@@ -344,8 +344,15 @@ static void from_json(LSPServerCapabilities &caps, const QJsonObject &json)
};
auto sync = json.value(QStringLiteral("textDocumentSync"));
caps.textDocumentSync = static_cast<LSPDocumentSyncKind>(
caps.textDocumentSync.change = static_cast<LSPDocumentSyncKind>(
(sync.isObject() ? sync.toObject().value(QStringLiteral("change")) : sync).toInt(static_cast<int>(LSPDocumentSyncKind::None)));
if (sync.isObject()) {
auto syncObject = sync.toObject();
auto save = syncObject.value(QStringLiteral("save"));
if (save.isObject() || save.toBool()) {
caps.textDocumentSync.save = {save.toObject().value(QStringLiteral("includeText")).toBool()};
}
}
caps.hoverProvider = toBoolOrObject(json.value(QStringLiteral("hoverProvider")));
from_json(caps.completionProvider, json.value(QStringLiteral("completionProvider")));
from_json(caps.signatureHelpProvider, json.value(QStringLiteral("signatureHelpProvider")));
......
......@@ -931,7 +931,7 @@ private:
auto it = m_docs.find(doc);
if (it != m_docs.end() && it->server) {
const auto &caps = it->server->capabilities();
if (caps.textDocumentSync == LSPDocumentSyncKind::Incremental) {
if (caps.textDocumentSync.change == LSPDocumentSyncKind::Incremental) {
return &(*it);
}
}
......
Supports Markdown
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