MCPcopy Create free account
hub / github.com/KDE/kate / format

Method format

addons/lspclient/lspclientpluginview.cpp:1758–1801  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1756 }
1757
1758 void format(QChar lastChar = QChar(), bool save = false)
1759 {
1760 KTextEditor::View *activeView = m_mainWindow->activeView();
1761 QPointer<KTextEditor::Document> document = activeView ? activeView->document() : nullptr;
1762 auto server = m_serverManager->findServer(activeView);
1763 if (!server || !document) {
1764 return;
1765 }
1766
1767 int tabSize = 4;
1768 bool insertSpaces = true;
1769 tabSize = document->configValue(QStringLiteral("tab-width")).toInt();
1770 insertSpaces = document->configValue(QStringLiteral("replace-tabs")).toBool();
1771
1772 // sigh, no move initialization capture ...
1773 // (again) assuming reply ranges wrt revisions submitted at this time
1774 std::shared_ptr<LSPClientRevisionSnapshot> snapshot(m_serverManager->snapshot(server.get()));
1775 auto h = [this, document, snapshot, lastChar, save](const QList<LSPTextEdit> &edits) {
1776 if (lastChar.isNull()) {
1777 checkEditResult(edits);
1778 }
1779 if (document) {
1780 // Must clear formatting triggers here otherwise on applying edits we
1781 // might end up triggering formatting again ending up in an infinite loop
1782 auto savedTriggers = m_onTypeFormattingTriggers;
1783 m_onTypeFormattingTriggers.clear();
1784 applyEdits(document, snapshot.get(), edits);
1785 m_onTypeFormattingTriggers = savedTriggers;
1786 if (save) {
1787 QObject::disconnect(m_formatOnSaveConnection);
1788 document->documentSave();
1789 m_formatOnSaveConnection =
1790 connect(document, &KTextEditor::Document::documentSavedOrUploaded, this, &self_type::formatOnSave, Qt::QueuedConnection);
1791 }
1792 }
1793 };
1794
1795 auto options = LSPFormattingOptions{.tabSize = tabSize, .insertSpaces = insertSpaces, .extra = QJsonObject()};
1796 auto handle = !lastChar.isNull()
1797 ? server->documentOnTypeFormatting(document->url(), activeView->cursorPosition(), lastChar, options, this, h)
1798 : (activeView->selection() ? server->documentRangeFormatting(document->url(), activeView->selectionRange(), options, this, h)
1799 : server->documentFormatting(document->url(), options, this, h));
1800 delayCancelRequest(std::move(handle));
1801 }
1802
1803 void rename()
1804 {

Callers

nothing calls this directly

Calls 13

applyEditsFunction · 0.85
documentMethod · 0.80
findServerMethod · 0.80
snapshotMethod · 0.80
isNullMethod · 0.80
urlMethod · 0.80
QJsonObjectClass · 0.50
activeViewMethod · 0.45
clearMethod · 0.45
selectionRangeMethod · 0.45

Tested by

no test coverage detected