forked from qt-creator/qt-creator
Clang: Use clang-format for indentation
This is the new experimental plugin based on LibFormat. It replaces the default indenter for CppEditorDocument and applies clang-format after the CR or the set of 'electric' characters. Uses the global .clang-format kept in QtC settings or the one for current project. Both can be configured. For indentation some style modifications and code manipulations are done to prevent line shrinking when it's not expected. Manual indentation uses unmodified style from .clang-format file. Change-Id: I6279b805e418e1804b553efa615f5c843f395a58 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
#include "cpplocatordata.h"
|
||||
#include "cpplocatorfilter.h"
|
||||
#include "cppmodelmanagersupportinternal.h"
|
||||
#include "cppqtstyleindenter.h"
|
||||
#include "cpprefactoringchanges.h"
|
||||
#include "cpprefactoringengine.h"
|
||||
#include "cppsourceprocessor.h"
|
||||
@@ -61,6 +62,7 @@
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectmacro.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <texteditor/indenter.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -507,7 +509,9 @@ void CppModelManager::initializeBuiltinModelManagerSupport()
|
||||
}
|
||||
|
||||
CppModelManager::CppModelManager()
|
||||
: CppModelManagerBase(nullptr), d(new CppModelManagerPrivate)
|
||||
: CppModelManagerBase(nullptr)
|
||||
, createCppIndenter([]() { return new CppQtStyleIndenter; })
|
||||
, d(new CppModelManagerPrivate)
|
||||
{
|
||||
d->m_indexingSupporter = 0;
|
||||
d->m_enableGC = true;
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace CPlusPlus { class LookupContext; }
|
||||
namespace ProjectExplorer { class Project; }
|
||||
namespace TextEditor {
|
||||
class BaseHoverHandler;
|
||||
class Indenter;
|
||||
class TextDocument;
|
||||
} // namespace TextEditor
|
||||
|
||||
@@ -212,6 +213,13 @@ public:
|
||||
RefactoringEngineInterface *refactoringEngine);
|
||||
static void removeRefactoringEngine(RefactoringEngineType type);
|
||||
|
||||
using CppIndenterCreator = std::function<TextEditor::Indenter *()>;
|
||||
void setCppIndenterCreator(CppIndenterCreator indenterCreator)
|
||||
{
|
||||
createCppIndenter = std::move(indenterCreator);
|
||||
}
|
||||
CppIndenterCreator createCppIndenter;
|
||||
|
||||
void setLocatorFilter(std::unique_ptr<Core::ILocatorFilter> &&filter);
|
||||
void setClassesFilter(std::unique_ptr<Core::ILocatorFilter> &&filter);
|
||||
void setIncludesFilter(std::unique_ptr<Core::ILocatorFilter> &&filter);
|
||||
|
||||
@@ -129,7 +129,8 @@ void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
|
||||
void CppQtStyleIndenter::indent(QTextDocument *doc,
|
||||
const QTextCursor &cursor,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
bool /*autoTriggered*/)
|
||||
{
|
||||
if (cursor.hasSelection()) {
|
||||
QTextBlock block = doc->findBlock(cursor.selectionStart());
|
||||
|
||||
@@ -53,7 +53,8 @@ public:
|
||||
void indent(QTextDocument *doc,
|
||||
const QTextCursor &cursor,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings) override;
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
bool autoTriggered = true) override;
|
||||
|
||||
void setCodeStylePreferences(TextEditor::ICodeStylePreferences *preferences) override;
|
||||
void invalidateCache(QTextDocument *doc) override;
|
||||
|
||||
Reference in New Issue
Block a user