forked from qt-creator/qt-creator
LanguageClient: Indent code coming from the server
... if the client implementation requests it. The server is not necessarily aware of our indentation style, so we might have to apply it to the newly inserted code. Change-Id: I43518575c7124568da42be3b04a28d7f352f6dc2 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -88,17 +88,22 @@ bool applyTextDocumentEdit(const Client *client, const TextDocumentEdit &edit)
|
||||
LanguageClientValue<int> version = edit.textDocument().version();
|
||||
if (!version.isNull() && version.value(0) < client->documentVersion(filePath))
|
||||
return false;
|
||||
return applyTextEdits(uri, edits);
|
||||
return applyTextEdits(client, uri, edits);
|
||||
}
|
||||
|
||||
bool applyTextEdits(const DocumentUri &uri, const QList<TextEdit> &edits)
|
||||
bool applyTextEdits(const Client *client, const DocumentUri &uri, const QList<TextEdit> &edits)
|
||||
{
|
||||
if (edits.isEmpty())
|
||||
return true;
|
||||
RefactoringChanges changes;
|
||||
RefactoringChangesData * const backend = client->createRefactoringChangesBackend();
|
||||
RefactoringChanges changes(backend);
|
||||
RefactoringFilePtr file;
|
||||
file = changes.file(uri.toFilePath());
|
||||
file->setChangeSet(editsToChangeSet(edits, file->document()));
|
||||
if (backend) {
|
||||
for (const TextEdit &edit : edits)
|
||||
file->appendIndentRange(convertRange(file->document(), edit.range()));
|
||||
}
|
||||
return file->apply();
|
||||
}
|
||||
|
||||
@@ -130,7 +135,7 @@ bool applyWorkspaceEdit(const Client *client, const WorkspaceEdit &edit)
|
||||
} else {
|
||||
const WorkspaceEdit::Changes &changes = edit.changes().value_or(WorkspaceEdit::Changes());
|
||||
for (auto it = changes.cbegin(); it != changes.cend(); ++it)
|
||||
result |= applyTextEdits(it.key(), it.value());
|
||||
result |= applyTextEdits(client, it.key(), it.value());
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user