Commit 73ab4f1d authored by Mark Nauwelaerts's avatar Mark Nauwelaerts
Browse files

lspclient: extend protocol WorkspaceEdit handling

parent 7e5207f7
......@@ -376,9 +376,15 @@ struct LSPCommand {
QJsonArray arguments;
};
struct LSPTextDocumentEdit {
LSPVersionedTextDocumentIdentifier textDocument;
QList<LSPTextEdit> edits;
};
struct LSPWorkspaceEdit {
// supported part for now
QHash<QUrl, QList<LSPTextEdit>> changes;
QList<LSPTextDocumentEdit> documentChanges;
};
struct LSPCodeAction {
......
......@@ -391,6 +391,15 @@ static QUrl normalizeUrl(const QUrl &url)
return url.adjusted(QUrl::NormalizePathSegments);
}
static void from_json(LSPVersionedTextDocumentIdentifier &id, const QJsonValue &json)
{
if (json.isObject()) {
auto ob = json.toObject();
id.uri = normalizeUrl(QUrl(ob.value(MEMBER_URI).toString()));
id.version = ob.value(MEMBER_VERSION).toInt(-1);
}
}
static LSPResponseError parseResponseError(const QJsonValue &v)
{
LSPResponseError ret;
......@@ -722,14 +731,28 @@ static QList<LSPTextEdit> parseTextEdit(const QJsonValue &result)
return ret;
}
static LSPTextDocumentEdit parseTextDocumentEdit(const QJsonValue &result)
{
LSPTextDocumentEdit ret;
auto ob = result.toObject();
from_json(ret.textDocument, ob.value(QStringLiteral("textDocument")));
ret.edits = parseTextEdit(ob.value(QStringLiteral("edits")));
return ret;
}
static LSPWorkspaceEdit parseWorkSpaceEdit(const QJsonValue &result)
{
QHash<QUrl, QList<LSPTextEdit>> ret;
LSPWorkspaceEdit ret;
auto changes = result.toObject().value(QStringLiteral("changes")).toObject();
for (auto it = changes.begin(); it != changes.end(); ++it) {
ret.insert(normalizeUrl(QUrl(it.key())), parseTextEdit(it.value()));
ret.changes.insert(normalizeUrl(QUrl(it.key())), parseTextEdit(it.value()));
}
auto documentChanges = result.toObject().value(QStringLiteral("documentChanges")).toArray();
// resourceOperations not supported for now
for (auto edit : documentChanges) {
ret.documentChanges.push_back(parseTextDocumentEdit(edit));
}
return {ret};
return ret;
}
static LSPCommand parseCommand(const QJsonObject &result)
......
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