forked from qt-creator/qt-creator
LanguageClient: Improve formatting
Use Utils::ChangeSet and TextEditor::RefactoringChanges to apply the text edits that are reported from language server to format the current file. Change-Id: Id2f490b6e2791f676ebc751219bfbbf9e178f120 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -518,15 +518,25 @@ void TextDocument::autoFormat(const QTextCursor &cursor)
|
||||
using namespace Utils::Text;
|
||||
if (!d->m_formatter)
|
||||
return;
|
||||
if (QFutureWatcher<Replacements> *watcher = d->m_formatter->format(cursor, tabSettings())) {
|
||||
connect(watcher, &QFutureWatcher<Replacements>::finished, this, [this, watcher]() {
|
||||
if (QFutureWatcher<ChangeSet> *watcher = d->m_formatter->format(cursor, tabSettings())) {
|
||||
connect(watcher, &QFutureWatcher<ChangeSet>::finished, this, [this, watcher]() {
|
||||
if (!watcher->isCanceled())
|
||||
Utils::Text::applyReplacements(document(), watcher->result());
|
||||
applyChangeSet(watcher->result());
|
||||
delete watcher;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool TextDocument::applyChangeSet(const ChangeSet &changeSet)
|
||||
{
|
||||
if (changeSet.isEmpty())
|
||||
return true;
|
||||
RefactoringChanges changes;
|
||||
const RefactoringFilePtr file = changes.file(filePath().toString());
|
||||
file->setChangeSet(changeSet);
|
||||
return file->apply();
|
||||
}
|
||||
|
||||
const ExtraEncodingSettings &TextDocument::extraEncodingSettings() const
|
||||
{
|
||||
return d->m_extraEncodingSettings;
|
||||
|
||||
Reference in New Issue
Block a user