Commit 294c3a17 authored by Mark Nauwelaerts's avatar Mark Nauwelaerts
Browse files

lspclient: deduplicate invocation of executeCommand

parent a88f95cf
......@@ -1150,16 +1150,7 @@ public:
auto &action = it->m_codeAction;
// apply edit before command
applyWorkspaceEdit(action.edit, it->m_snapshot.data());
auto &command = action.command;
if (command.command.size()) {
// accept edit requests that may be sent to execute command
m_accept_edit = true;
// but only for a short time
QTimer::singleShot(2000, this, [this] {
m_accept_edit = false;
});
server->executeCommand(command.command, command.arguments);
}
executeServerCommand(server, action.command);
// diagnostics are likely updated soon, but might be clicked again in meantime
// so clear once executed, so not executed again
action.edit.changes.clear();
......@@ -1663,20 +1654,26 @@ public:
auto text = action.kind.size() ? QStringLiteral("[%1] %2").arg(action.kind).arg(action.title) : action.title;
menu->addAction(text, this, [this, action, snapshot, server]() {
applyWorkspaceEdit(action.edit, snapshot.data());
auto &command = action.command;
if (!command.command.isEmpty()) {
// accept edit requests that may be sent to execute command
m_accept_edit = true;
// but only for a short time
QTimer::singleShot(2000, this, [this] { m_accept_edit = false; });
server->executeCommand(command.command, command.arguments);
}
executeServerCommand(server, action.command);
});
}
};
server->documentCodeAction(document->url(), range, {}, {}, this, h);
}
void executeServerCommand(QSharedPointer<LSPClientServer> server, const LSPCommand &command)
{
if (!command.command.isEmpty()) {
// accept edit requests that may be sent to execute command
m_accept_edit = true;
// but only for a short time
QTimer::singleShot(2000, this, [this] {
m_accept_edit = false;
});
server->executeCommand(command.command, command.arguments);
}
}
void applyEdits(KTextEditor::Document *doc, const LSPClientRevisionSnapshot *snapshot, const QList<LSPTextEdit> &edits)
{
KTextEditor::MovingInterface *miface = qobject_cast<KTextEditor::MovingInterface *>(doc);
......
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