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

@@ -111,7 +111,7 @@ CppEditorDocument::CppEditorDocument()
ICodeStylePreferencesFactory *factory
= TextEditorSettings::codeStyleFactory(CppTools::Constants::CPP_SETTINGS_ID);
setIndenter(factory->createIndenter());
setIndenter(factory->createIndenter(document()));
connect(this, &TextEditor::TextDocument::tabSettingsChanged,
this, &CppEditorDocument::invalidateFormatterCache);
@@ -243,6 +243,7 @@ void CppEditorDocument::onFilePathChanged(const Utils::FileName &oldPath,
Q_UNUSED(oldPath);
if (!newPath.isEmpty()) {
indenter()->setFileName(newPath);
setMimeType(Utils::mimeTypeForFile(newPath.toFileInfo()).name());
connect(this, &Core::IDocument::contentsChanged,
@@ -443,9 +444,7 @@ CppTools::BaseEditorDocumentProcessor *CppEditorDocument::processor()
TextEditor::TabSettings CppEditorDocument::tabSettings() const
{
return indenter()->hasTabSettings()
? indenter()->tabSettings()
: TextEditor::TextDocument::tabSettings();
return indenter()->tabSettings().value_or(TextEditor::TextDocument::tabSettings());
}
} // namespace Internal