summaryrefslogtreecommitdiff
path: root/src/plugins/cppeditor/cpprefactoringchanges.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2022-02-03 10:36:40 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2022-02-03 14:30:19 +0000
commit92156cc1d6290e71a7e591552132102457d7c926 (patch)
tree941b810aedcd534eea975d9eedcd93aa39a0cd01 /src/plugins/cppeditor/cpprefactoringchanges.cpp
parent9b7f580a1434795a40cccc0f3b9bb13befab7ee5 (diff)
downloadqt-creator-92156cc1d6290e71a7e591552132102457d7c926.tar.gz
LanguageClient: Indent code coming from the server
... if the client implementation requests it. The server is not necessarily aware of our indentation style, so we might have to apply it to the newly inserted code. Change-Id: I43518575c7124568da42be3b04a28d7f352f6dc2 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/cppeditor/cpprefactoringchanges.cpp')
-rw-r--r--src/plugins/cppeditor/cpprefactoringchanges.cpp105
1 files changed, 47 insertions, 58 deletions
diff --git a/src/plugins/cppeditor/cpprefactoringchanges.cpp b/src/plugins/cppeditor/cpprefactoringchanges.cpp
index 6e48ae1500..10ff7fc62f 100644
--- a/src/plugins/cppeditor/cpprefactoringchanges.cpp
+++ b/src/plugins/cppeditor/cpprefactoringchanges.cpp
@@ -28,8 +28,6 @@
#include "cppqtstyleindenter.h"
#include "cppcodeformatter.h"
#include "cppeditorconstants.h"
-#include "cppmodelmanager.h"
-#include "cppworkingcopy.h"
#include <projectexplorer/editorconfiguration.h>
@@ -45,63 +43,15 @@ using namespace CPlusPlus;
namespace CppEditor {
-class CppRefactoringChangesData : public TextEditor::RefactoringChangesData
+static std::unique_ptr<TextEditor::Indenter> createIndenter(const Utils::FilePath &filePath,
+ QTextDocument *textDocument)
{
- static std::unique_ptr<TextEditor::Indenter> createIndenter(const Utils::FilePath &filePath,
- QTextDocument *textDocument)
- {
- TextEditor::ICodeStylePreferencesFactory *factory
- = TextEditor::TextEditorSettings::codeStyleFactory(Constants::CPP_SETTINGS_ID);
- std::unique_ptr<TextEditor::Indenter> indenter(factory->createIndenter(textDocument));
- indenter->setFileName(filePath);
- return indenter;
- }
-
-public:
- explicit CppRefactoringChangesData(const Snapshot &snapshot)
- : m_snapshot(snapshot)
- , m_modelManager(CppModelManager::instance())
- , m_workingCopy(m_modelManager->workingCopy())
- {}
-
- void indentSelection(const QTextCursor &selection,
- const Utils::FilePath &filePath,
- const TextEditor::TextDocument *textDocument) const override
- {
- if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
- textDocument->indenter()->indent(selection, QChar::Null, textDocument->tabSettings());
- } else {
- const auto &tabSettings = ProjectExplorer::actualTabSettings(filePath.toString(),
- textDocument);
- auto indenter = createIndenter(filePath, selection.document());
- indenter->indent(selection, QChar::Null, tabSettings);
- }
- }
-
- void reindentSelection(const QTextCursor &selection,
- const Utils::FilePath &filePath,
- const TextEditor::TextDocument *textDocument) const override
- {
- if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
- textDocument->indenter()->reindent(selection, textDocument->tabSettings());
- } else {
- const auto &tabSettings = ProjectExplorer::actualTabSettings(filePath.toString(),
- textDocument);
- auto indenter = createIndenter(filePath, selection.document());
- indenter->reindent(selection, tabSettings);
- }
- }
-
- void fileChanged(const Utils::FilePath &filePath) override
- {
- m_modelManager->updateSourceFiles({filePath.toString()});
- }
-
- Snapshot m_snapshot;
- CppModelManager *m_modelManager;
- WorkingCopy m_workingCopy;
-
-};
+ TextEditor::ICodeStylePreferencesFactory *factory
+ = TextEditor::TextEditorSettings::codeStyleFactory(Constants::CPP_SETTINGS_ID);
+ std::unique_ptr<TextEditor::Indenter> indenter(factory->createIndenter(textDocument));
+ indenter->setFileName(filePath);
+ return indenter;
+}
CppRefactoringChanges::CppRefactoringChanges(const Snapshot &snapshot)
: RefactoringChanges(new CppRefactoringChangesData(snapshot))
@@ -283,4 +233,43 @@ void CppRefactoringFile::fileChanged()
RefactoringFile::fileChanged();
}
+CppRefactoringChangesData::CppRefactoringChangesData(const Snapshot &snapshot)
+ : m_snapshot(snapshot)
+ , m_modelManager(CppModelManager::instance())
+ , m_workingCopy(m_modelManager->workingCopy())
+{}
+
+void CppRefactoringChangesData::indentSelection(const QTextCursor &selection,
+ const Utils::FilePath &filePath,
+ const TextEditor::TextDocument *textDocument) const
+{
+ if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
+ textDocument->indenter()->indent(selection, QChar::Null, textDocument->tabSettings());
+ } else {
+ const auto &tabSettings = ProjectExplorer::actualTabSettings(filePath.toString(),
+ textDocument);
+ auto indenter = createIndenter(filePath, selection.document());
+ indenter->indent(selection, QChar::Null, tabSettings);
+ }
+}
+
+void CppRefactoringChangesData::reindentSelection(const QTextCursor &selection,
+ const Utils::FilePath &filePath,
+ const TextEditor::TextDocument *textDocument) const
+{
+ if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
+ textDocument->indenter()->reindent(selection, textDocument->tabSettings());
+ } else {
+ const auto &tabSettings = ProjectExplorer::actualTabSettings(filePath.toString(),
+ textDocument);
+ auto indenter = createIndenter(filePath, selection.document());
+ indenter->reindent(selection, tabSettings);
+ }
+}
+
+void CppRefactoringChangesData::fileChanged(const Utils::FilePath &filePath)
+{
+ m_modelManager->updateSourceFiles({filePath.toString()});
+}
+
} // namespace CppEditor