From 29f1aca1c8e39f6edeaa27cc546eaa49e6459819 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 2 Feb 2021 07:36:21 +0100 Subject: [PATCH] LanguageClient: remove unused formatting functions The formatting functionality was moved into languageclientformatter.cpp Change-Id: Ieeafd49c297a854e478a11d4fcb81062b9cfcf19 Reviewed-by: Christian Stenger --- src/plugins/languageclient/client.cpp | 95 --------------------------- src/plugins/languageclient/client.h | 3 - 2 files changed, 98 deletions(-) diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index aaa213e8f98..fbabc51a1cf 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -755,101 +755,6 @@ void Client::executeCommand(const Command &command) sendContent(ExecuteCommandRequest(ExecuteCommandParams(command))); } -static const FormattingOptions formattingOptions(const TextEditor::TabSettings &settings) -{ - FormattingOptions options; - options.setTabSize(settings.m_tabSize); - options.setInsertSpace(settings.m_tabPolicy == TextEditor::TabSettings::SpacesOnlyTabPolicy); - return options; -} - -template -static void handleFormattingResponse(const DocumentUri &uri, - const QPointer client, - const FormattingResponse &response) -{ - if (client) { - if (const Utils::optional &error = response.error()) - client->log(*error); - } - if (Utils::optional> result = response.result()) { - if (!result->isNull()) { - applyTextEdits(uri, result->toList()); - } - } - -} - -void Client::formatFile(const TextEditor::TextDocument *document) -{ - if (!isSupportedDocument(document)) - return; - - const FilePath &filePath = document->filePath(); - const QString method(DocumentFormattingRequest::methodName); - if (Utils::optional registered = m_dynamicCapabilities.isRegistered(method)) { - if (!registered.value()) - return; - const TextDocumentRegistrationOptions option( - m_dynamicCapabilities.option(method).toObject()); - if (option.isValid(nullptr) - && !option.filterApplies(filePath, Utils::mimeTypeForName(document->mimeType()))) { - return; - } - } else if (!m_serverCapabilities.documentFormattingProvider().value_or(false)) { - return; - } - - DocumentFormattingParams params; - const DocumentUri uri = DocumentUri::fromFilePath(filePath); - params.setTextDocument(TextDocumentIdentifier(uri)); - params.setOptions(formattingOptions(document->tabSettings())); - DocumentFormattingRequest request(params); - request.setResponseCallback( - [uri, self = QPointer(this)](const DocumentFormattingRequest::Response &response) { - handleFormattingResponse(uri, self, response); - }); - sendContent(request); -} - -void Client::formatRange(const TextEditor::TextDocument *document, const QTextCursor &cursor) -{ - if (!isSupportedDocument(document)) - return; - - const FilePath &filePath = document->filePath(); - const QString method(DocumentRangeFormattingRequest::methodName); - if (Utils::optional registered = m_dynamicCapabilities.isRegistered(method)) { - if (!registered.value()) - return; - const TextDocumentRegistrationOptions option( - m_dynamicCapabilities.option(method).toObject()); - if (option.isValid(nullptr) - && !option.filterApplies(filePath, Utils::mimeTypeForName(document->mimeType()))) { - return; - } - } else if (!m_serverCapabilities.documentRangeFormattingProvider().value_or(false)) { - return; - } - DocumentRangeFormattingParams params; - const DocumentUri uri = DocumentUri::fromFilePath(filePath); - params.setTextDocument(TextDocumentIdentifier(uri)); - params.setOptions(formattingOptions(document->tabSettings())); - if (!cursor.hasSelection()) { - QTextCursor c = cursor; - c.select(QTextCursor::LineUnderCursor); - params.setRange(Range(c)); - } else { - params.setRange(Range(cursor)); - } - DocumentRangeFormattingRequest request(params); - request.setResponseCallback([uri, self = QPointer(this)]( - const DocumentRangeFormattingRequest::Response &response) { - handleFormattingResponse(uri, self, response); - }); - sendContent(request); -} - const ProjectExplorer::Project *Client::project() const { return m_project; diff --git a/src/plugins/languageclient/client.h b/src/plugins/languageclient/client.h index b52eded2a72..2eac8ee2c03 100644 --- a/src/plugins/languageclient/client.h +++ b/src/plugins/languageclient/client.h @@ -123,9 +123,6 @@ public: const LanguageServerProtocol::DocumentUri &uri); void executeCommand(const LanguageServerProtocol::Command &command); - void formatFile(const TextEditor::TextDocument *document); - void formatRange(const TextEditor::TextDocument *document, const QTextCursor &cursor); - // workspace control void setCurrentProject(ProjectExplorer::Project *project); const ProjectExplorer::Project *project() const;