forked from qt-creator/qt-creator
LanguageClient: remove unused formatting functions
The formatting functionality was moved into languageclientformatter.cpp Change-Id: Ieeafd49c297a854e478a11d4fcb81062b9cfcf19 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -755,101 +755,6 @@ void Client::executeCommand(const Command &command)
|
|||||||
sendContent(ExecuteCommandRequest(ExecuteCommandParams(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<typename FormattingResponse>
|
|
||||||
static void handleFormattingResponse(const DocumentUri &uri,
|
|
||||||
const QPointer<Client> client,
|
|
||||||
const FormattingResponse &response)
|
|
||||||
{
|
|
||||||
if (client) {
|
|
||||||
if (const Utils::optional<typename FormattingResponse::Error> &error = response.error())
|
|
||||||
client->log(*error);
|
|
||||||
}
|
|
||||||
if (Utils::optional<LanguageClientArray<TextEdit>> 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<bool> 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<Client>(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<bool> 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<Client>(this)](
|
|
||||||
const DocumentRangeFormattingRequest::Response &response) {
|
|
||||||
handleFormattingResponse(uri, self, response);
|
|
||||||
});
|
|
||||||
sendContent(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
const ProjectExplorer::Project *Client::project() const
|
const ProjectExplorer::Project *Client::project() const
|
||||||
{
|
{
|
||||||
return m_project;
|
return m_project;
|
||||||
|
@@ -123,9 +123,6 @@ public:
|
|||||||
const LanguageServerProtocol::DocumentUri &uri);
|
const LanguageServerProtocol::DocumentUri &uri);
|
||||||
void executeCommand(const LanguageServerProtocol::Command &command);
|
void executeCommand(const LanguageServerProtocol::Command &command);
|
||||||
|
|
||||||
void formatFile(const TextEditor::TextDocument *document);
|
|
||||||
void formatRange(const TextEditor::TextDocument *document, const QTextCursor &cursor);
|
|
||||||
|
|
||||||
// workspace control
|
// workspace control
|
||||||
void setCurrentProject(ProjectExplorer::Project *project);
|
void setCurrentProject(ProjectExplorer::Project *project);
|
||||||
const ProjectExplorer::Project *project() const;
|
const ProjectExplorer::Project *project() const;
|
||||||
|
Reference in New Issue
Block a user