Commit 479c3962 authored by Mark Nauwelaerts's avatar Mark Nauwelaerts
Browse files

lspclient: add action to query clangd internal memory usage

parent de555d54
Pipeline #73238 passed with stage
in 5 minutes and 55 seconds
......@@ -41,6 +41,7 @@
#include <QHBoxLayout>
#include <QHeaderView>
#include <QInputDialog>
#include <QJsonDocument>
#include <QJsonObject>
#include <QKeyEvent>
#include <QMenu>
......@@ -399,6 +400,7 @@ class LSPClientActionView : public QObject
QPointer<QAction> m_restartAll;
QPointer<QAction> m_switchSourceHeader;
QPointer<QAction> m_quickFix;
QPointer<QAction> m_memoryUsage;
QPointer<KActionMenu> m_requestCodeAction;
// toolview
......@@ -588,6 +590,10 @@ public:
m_messages->setText(i18n("Show messages"));
m_messages->setCheckable(true);
// extra
m_memoryUsage = actionCollection()->addAction(QStringLiteral("lspclient_clangd_memoryusage"), this, &self_type::clangdMemoryUsage);
m_memoryUsage->setText(i18n("Server memory usage"));
// server control and misc actions
m_closeDynamic = actionCollection()->addAction(QStringLiteral("lspclient_close_dynamic"), this, &self_type::closeDynamic);
m_closeDynamic->setText(i18n("Close all dynamic reference tabs"));
......@@ -637,6 +643,8 @@ public:
moreOptions->addAction(m_diagnosticsHover);
moreOptions->addSeparator();
moreOptions->addAction(m_messages);
moreOptions->addSeparator();
moreOptions->addAction(m_memoryUsage);
// sync with plugin settings if updated
connect(m_plugin, &LSPClientPlugin::update, this, &self_type::configUpdated);
......@@ -1979,6 +1987,32 @@ public:
server->clangdSwitchSourceHeader(document->url(), this, h);
}
void clangdMemoryUsage()
{
KTextEditor::View *activeView = m_mainWindow->activeView();
auto server = m_serverManager->findServer(activeView);
if (!server)
return;
auto h = [this](const QJsonValue &reply) {
auto view = m_mainWindow->openUrl(QUrl());
if (view) {
QJsonDocument json(reply.toObject());
auto doc = view->document();
doc->setText(QString::fromUtf8(json.toJson()));
// position at top
view->setCursorPosition({0, 0});
// adjust mode
const QString mode = QStringLiteral("JSON");
doc->setHighlightingMode(mode);
doc->setMode(mode);
// no save file dialog when closing
doc->setModified(false);
}
};
server->clangdMemoryUsage(this, h);
}
void gotoWorkSpaceSymbol()
{
KTextEditor::View *activeView = m_mainWindow->activeView();
......@@ -2458,6 +2492,8 @@ public:
}
m_switchSourceHeader->setEnabled(isClangd);
m_switchSourceHeader->setVisible(isClangd);
m_memoryUsage->setEnabled(isClangd);
m_memoryUsage->setVisible(isClangd);
// update completion with relevant server
m_completion->setServer(server);
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="lspclient" library="lspclient" version="18" translationDomain="lspclient">
<gui name="lspclient" library="lspclient" version="19" translationDomain="lspclient">
<MenuBar>
<Menu name="LSPClient Menubar">
<text>LSP Client</text>
......@@ -42,6 +42,8 @@
<Action name="lspclient_diagnostics_hover"/>
<Separator/>
<Action name="lspclient_messages"/>
<Separator/>
<Action name="lspclient_clangd_memoryusage"/>
</Menu>
</Menu>
</MenuBar>
......
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