ClangFormat: Refactor indenter to allow ClangFormat unit-tests

We do not build texteditor files in unit-tests so some tricks
were required to make ClangFormatIndenter available.

First simple unit-test proofs it builds and runs.

Change-Id: I81d5ea099bd27fd1c1ed8b5b7877299dcc62a67f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Ivan Donchevskii
2019-01-16 09:37:54 +01:00
parent 8b5beeb952
commit d7058e1afe
71 changed files with 1200 additions and 818 deletions

View File

@@ -229,7 +229,7 @@ CMakeEditorFactory::CMakeEditorFactory()
setEditorCreator([]() { return new CMakeEditor; });
setEditorWidgetCreator([]() { return new CMakeEditorWidget; });
setDocumentCreator(createCMakeDocument);
setIndenterCreator([]() { return new CMakeIndenter; });
setIndenterCreator([](QTextDocument *doc) { return new CMakeIndenter(doc); });
setUseGenericHighlighter(true);
setCommentDefinition(Utils::CommentDefinition::HashStyle);
setCodeFoldingSupported(true);

View File

@@ -34,6 +34,10 @@
namespace CMakeProjectManager {
namespace Internal {
CMakeIndenter::CMakeIndenter(QTextDocument *doc)
: TextEditor::TextIndenter(doc)
{}
bool CMakeIndenter::isElectricCharacter(const QChar &ch) const
{
return ch == QLatin1Char('(') || ch == QLatin1Char(')');
@@ -98,7 +102,8 @@ static int paranthesesLevel(const QString &line)
return -1;
}
int CMakeIndenter::indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings)
int CMakeIndenter::indentFor(const QTextBlock &block,
const TextEditor::TabSettings &tabSettings)
{
QTextBlock previousBlock = block.previous();
// find the next previous block that is non-empty (contains non-whitespace characters)

View File

@@ -27,17 +27,19 @@
#include "cmake_global.h"
#include <texteditor/indenter.h>
#include <texteditor/textindenter.h>
namespace CMakeProjectManager {
namespace Internal {
class CMAKE_EXPORT CMakeIndenter : public TextEditor::Indenter
class CMAKE_EXPORT CMakeIndenter : public TextEditor::TextIndenter
{
public:
explicit CMakeIndenter(QTextDocument *doc);
bool isElectricCharacter(const QChar &ch) const override;
int indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings) override;
int indentFor(const QTextBlock &block,
const TextEditor::TabSettings &tabSettings) override;
};
} // namespace Internal