ClangFormat: Format more code while typing

With the extra option "Format while typing" checked try to format
text before the current position without breaking the current input.
To accomplish that we make proper choices which replacements to apply.

The advantage of this change is to decrease the need to manually
format code which is just written.

Some minor bugs are fixed during the testing of this change.

Change-Id: Ibed569042e6c46a881e7a83b1882cf2bb23b3626
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2019-01-28 08:13:33 +01:00
parent 68bce815ac
commit 536b733f29
11 changed files with 340 additions and 65 deletions

View File

@@ -28,6 +28,7 @@
#include "clangformatutils.h"
#include <texteditor/tabsettings.h>
#include <texteditor/textdocumentlayout.h>
using namespace clang;
using namespace format;
@@ -49,6 +50,11 @@ bool ClangFormatIndenter::formatCodeInsteadOfIndent() const
return ClangFormatSettings::instance().formatCodeInsteadOfIndent();
}
bool ClangFormatIndenter::formatWhileTyping() const
{
return ClangFormatSettings::instance().formatWhileTyping();
}
Utils::optional<TabSettings> ClangFormatIndenter::tabSettings() const
{
FormatStyle style = currentProjectStyle();
@@ -76,4 +82,9 @@ Utils::optional<TabSettings> ClangFormatIndenter::tabSettings() const
return tabSettings;
}
int ClangFormatIndenter::lastSaveRevision() const
{
return qobject_cast<TextEditor::TextDocumentLayout *>(m_doc->documentLayout())->lastSaveRevision;
}
} // namespace ClangFormat