forked from qt-creator/qt-creator
LanguageClient: Avoid calling throwing functions
Similar to with std::optional we want to avoid calling throwing functions for std::variant, which includes std::get. In many cases this also avoids the chain of `std::holds_alternative` + `std::get` calls. And we never declare any `throws`. Change-Id: I14f62ddef921b6bee90226ea34d1ffa62629bdc3 Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -93,7 +93,8 @@ private:
|
|||||||
template<typename T, typename V>
|
template<typename T, typename V>
|
||||||
JsonObject::iterator JsonObject::insertVariant(const Key key, const V &variant)
|
JsonObject::iterator JsonObject::insertVariant(const Key key, const V &variant)
|
||||||
{
|
{
|
||||||
return std::holds_alternative<T>(variant) ? insert(key, std::get<T>(variant)) : end();
|
const auto v = std::get_if<T>(&variant);
|
||||||
|
return v ? insert(key, *v) : end();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T1, typename T2, typename... Args, typename V>
|
template<typename T1, typename T2, typename... Args, typename V>
|
||||||
|
@@ -68,19 +68,19 @@ public:
|
|||||||
private:
|
private:
|
||||||
friend size_t qHash(const MessageId &id)
|
friend size_t qHash(const MessageId &id)
|
||||||
{
|
{
|
||||||
if (std::holds_alternative<int>(id))
|
if (const int *iid = std::get_if<int>(&id))
|
||||||
return QT_PREPEND_NAMESPACE(qHash(std::get<int>(id)));
|
return QT_PREPEND_NAMESPACE(qHash(*iid));
|
||||||
if (std::holds_alternative<QString>(id))
|
if (const QString *sid = std::get_if<QString>(&id))
|
||||||
return QT_PREPEND_NAMESPACE(qHash(std::get<QString>(id)));
|
return QT_PREPEND_NAMESPACE(qHash(*sid));
|
||||||
return QT_PREPEND_NAMESPACE(qHash(0));
|
return QT_PREPEND_NAMESPACE(qHash(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
friend QDebug operator<<(QDebug stream, const MessageId &id)
|
friend QDebug operator<<(QDebug stream, const MessageId &id)
|
||||||
{
|
{
|
||||||
if (std::holds_alternative<int>(id))
|
if (const int *iid = std::get_if<int>(&id))
|
||||||
stream << std::get<int>(id);
|
stream << *iid;
|
||||||
else
|
else
|
||||||
stream << std::get<QString>(id);
|
stream << *std::get_if<QString>(&id);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -303,8 +303,8 @@ HoverContent::HoverContent(const QJsonValue &value)
|
|||||||
|
|
||||||
bool HoverContent::isValid() const
|
bool HoverContent::isValid() const
|
||||||
{
|
{
|
||||||
if (std::holds_alternative<MarkedString>(*this))
|
if (const auto s = std::get_if<MarkedString>(this))
|
||||||
return std::get<MarkedString>(*this).isValid();
|
return s->isValid();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -101,10 +101,10 @@ MarkupOrString::MarkupOrString(const QJsonValue &val)
|
|||||||
|
|
||||||
QJsonValue MarkupOrString::toJson() const
|
QJsonValue MarkupOrString::toJson() const
|
||||||
{
|
{
|
||||||
if (std::holds_alternative<QString>(*this))
|
if (const auto s = std::get_if<QString>(this))
|
||||||
return std::get<QString>(*this);
|
return *s;
|
||||||
if (std::holds_alternative<MarkupContent>(*this))
|
if (const auto c = std::get_if<MarkupContent>(this))
|
||||||
return QJsonValue(std::get<MarkupContent>(*this));
|
return QJsonValue(*c);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -89,15 +89,16 @@ public:
|
|||||||
|
|
||||||
QList<T> toListOrEmpty() const
|
QList<T> toListOrEmpty() const
|
||||||
{
|
{
|
||||||
if (std::holds_alternative<QList<T>>(*this))
|
if (const auto l = std::get_if<QList<T>>(this))
|
||||||
return std::get<QList<T>>(*this);
|
return *l;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<T> toList() const
|
QList<T> toList() const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(std::holds_alternative<QList<T>>(*this), return {});
|
const auto l = std::get_if<QList<T>>(this);
|
||||||
return std::get<QList<T>>(*this);
|
QTC_ASSERT(l, return {});
|
||||||
|
return *l;
|
||||||
}
|
}
|
||||||
bool isNull() const { return std::holds_alternative<std::nullptr_t>(*this); }
|
bool isNull() const { return std::holds_alternative<std::nullptr_t>(*this); }
|
||||||
};
|
};
|
||||||
@@ -127,15 +128,17 @@ public:
|
|||||||
|
|
||||||
T value(const T &defaultValue = T()) const
|
T value(const T &defaultValue = T()) const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(std::holds_alternative<T>(*this), return defaultValue);
|
const auto t = std::get_if<T>(this);
|
||||||
return std::get<T>(*this);
|
QTC_ASSERT(t, return defaultValue);
|
||||||
|
return *t;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
LanguageClientValue<Type> transform()
|
LanguageClientValue<Type> transform()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!std::holds_alternative<T>(*this), return LanguageClientValue<Type>());
|
const auto t = std::get_if<T>(this);
|
||||||
return Type(std::get<T>(*this));
|
QTC_ASSERT(t, return LanguageClientValue<Type>());
|
||||||
|
return Type(*t);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNull() const { return std::holds_alternative<std::nullptr_t>(*this); }
|
bool isNull() const { return std::holds_alternative<std::nullptr_t>(*this); }
|
||||||
|
@@ -21,9 +21,9 @@ ProgressToken::ProgressToken(const QJsonValue &value)
|
|||||||
|
|
||||||
ProgressToken::operator QJsonValue() const
|
ProgressToken::operator QJsonValue() const
|
||||||
{
|
{
|
||||||
if (std::holds_alternative<QString>(*this))
|
if (const auto s = std::get_if<QString>(this))
|
||||||
return QJsonValue(std::get<QString>(*this));
|
return QJsonValue(*s);
|
||||||
return QJsonValue(std::get<int>(*this));
|
return QJsonValue(*std::get_if<int>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgressParams::ProgressType ProgressParams::value() const
|
ProgressParams::ProgressType ProgressParams::value() const
|
||||||
|
@@ -189,10 +189,10 @@ void ServerCapabilities::setCallHierarchyProvider(
|
|||||||
const std::variant<bool, WorkDoneProgressOptions> &callHierarchyProvider)
|
const std::variant<bool, WorkDoneProgressOptions> &callHierarchyProvider)
|
||||||
{
|
{
|
||||||
QJsonValue val;
|
QJsonValue val;
|
||||||
if (std::holds_alternative<bool>(callHierarchyProvider))
|
if (const auto boolvalue = std::get_if<bool>(&callHierarchyProvider))
|
||||||
val = std::get<bool>(callHierarchyProvider);
|
val = *boolvalue;
|
||||||
else if (std::holds_alternative<WorkDoneProgressOptions>(callHierarchyProvider))
|
else if (const auto options = std::get_if<WorkDoneProgressOptions>(&callHierarchyProvider))
|
||||||
val = QJsonObject(std::get<WorkDoneProgressOptions>(callHierarchyProvider));
|
val = QJsonObject(*options);
|
||||||
insert(callHierarchyProviderKey, val);
|
insert(callHierarchyProviderKey, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,10 +211,10 @@ void ServerCapabilities::setTypeHierarchyProvider(
|
|||||||
const std::variant<bool, WorkDoneProgressOptions> &typeHierarchyProvider)
|
const std::variant<bool, WorkDoneProgressOptions> &typeHierarchyProvider)
|
||||||
{
|
{
|
||||||
QJsonValue val;
|
QJsonValue val;
|
||||||
if (std::holds_alternative<bool>(typeHierarchyProvider))
|
if (const auto boolvalue = std::get_if<bool>(&typeHierarchyProvider))
|
||||||
val = std::get<bool>(typeHierarchyProvider);
|
val = *boolvalue;
|
||||||
else if (std::holds_alternative<WorkDoneProgressOptions>(typeHierarchyProvider))
|
else if (const auto options = std::get_if<WorkDoneProgressOptions>(&typeHierarchyProvider))
|
||||||
val = QJsonObject(std::get<WorkDoneProgressOptions>(typeHierarchyProvider));
|
val = QJsonObject(*options);
|
||||||
insert(typeHierarchyProviderKey, val);
|
insert(typeHierarchyProviderKey, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -64,10 +64,11 @@ ExecuteCommandParams::ExecuteCommandParams(const Command &command)
|
|||||||
|
|
||||||
LanguageServerProtocol::WorkSpaceFolderResult::operator const QJsonValue() const
|
LanguageServerProtocol::WorkSpaceFolderResult::operator const QJsonValue() const
|
||||||
{
|
{
|
||||||
if (!std::holds_alternative<QList<WorkSpaceFolder>>(*this))
|
const auto folders = std::get_if<QList<WorkSpaceFolder>>(this);
|
||||||
|
if (!folders)
|
||||||
return QJsonValue::Null;
|
return QJsonValue::Null;
|
||||||
QJsonArray array;
|
QJsonArray array;
|
||||||
for (const auto &folder : std::get<QList<WorkSpaceFolder>>(*this))
|
for (const auto &folder : *folders)
|
||||||
array.append(QJsonValue(folder));
|
array.append(QJsonValue(folder));
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
@@ -903,7 +903,8 @@ void ClientPrivate::requestDocumentHighlightsNow(TextEditor::TextEditorWidget *w
|
|||||||
= m_serverCapabilities.documentHighlightProvider();
|
= m_serverCapabilities.documentHighlightProvider();
|
||||||
if (!provider.has_value())
|
if (!provider.has_value())
|
||||||
return;
|
return;
|
||||||
if (std::holds_alternative<bool>(*provider) && !std::get<bool>(*provider))
|
const auto boolvalue = std::get_if<bool>(&*provider);
|
||||||
|
if (boolvalue && !*boolvalue)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -935,7 +936,8 @@ void ClientPrivate::requestDocumentHighlightsNow(TextEditor::TextEditorWidget *w
|
|||||||
const QTextCharFormat &format =
|
const QTextCharFormat &format =
|
||||||
widget->textDocument()->fontSettings().toTextCharFormat(TextEditor::C_OCCURRENCES);
|
widget->textDocument()->fontSettings().toTextCharFormat(TextEditor::C_OCCURRENCES);
|
||||||
QTextDocument *document = widget->document();
|
QTextDocument *document = widget->document();
|
||||||
for (const auto &highlight : std::get<QList<DocumentHighlight>>(*result)) {
|
const auto highlights = std::get_if<QList<DocumentHighlight>>(&*result);
|
||||||
|
for (const auto &highlight : *highlights) {
|
||||||
QTextEdit::ExtraSelection selection{widget->textCursor(), format};
|
QTextEdit::ExtraSelection selection{widget->textCursor(), format};
|
||||||
const int &start = highlight.range().start().toPositionInDocument(document);
|
const int &start = highlight.range().start().toPositionInDocument(document);
|
||||||
const int &end = highlight.range().end().toPositionInDocument(document);
|
const int &end = highlight.range().end().toPositionInDocument(document);
|
||||||
@@ -1435,7 +1437,8 @@ void Client::requestCodeActions(const CodeActionRequest &request)
|
|||||||
} else {
|
} else {
|
||||||
std::variant<bool, CodeActionOptions> provider
|
std::variant<bool, CodeActionOptions> provider
|
||||||
= d->m_serverCapabilities.codeActionProvider().value_or(false);
|
= d->m_serverCapabilities.codeActionProvider().value_or(false);
|
||||||
if (!(std::holds_alternative<CodeActionOptions>(provider) || std::get<bool>(provider)))
|
const auto boolvalue = std::get_if<bool>(&provider);
|
||||||
|
if (boolvalue && !*boolvalue)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1661,8 +1664,8 @@ bool Client::supportsDocumentSymbols(const TextEditor::TextDocument *doc) const
|
|||||||
= capabilities().documentSymbolProvider();
|
= capabilities().documentSymbolProvider();
|
||||||
if (!provider.has_value())
|
if (!provider.has_value())
|
||||||
return false;
|
return false;
|
||||||
if (std::holds_alternative<bool>(*provider))
|
if (const auto boolvalue = std::get_if<bool>(&*provider))
|
||||||
return std::get<bool>(*provider);
|
return *boolvalue;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2233,10 +2236,10 @@ bool ClientPrivate::sendWorkspceFolderChanges() const
|
|||||||
if (auto folder = workspace->workspaceFolders()) {
|
if (auto folder = workspace->workspaceFolders()) {
|
||||||
if (folder->supported().value_or(false)) {
|
if (folder->supported().value_or(false)) {
|
||||||
// holds either the Id for deregistration or whether it is registered
|
// holds either the Id for deregistration or whether it is registered
|
||||||
auto notification = folder->changeNotifications().value_or(false);
|
const std::variant<QString, bool> notification
|
||||||
return std::holds_alternative<QString>(notification)
|
= folder->changeNotifications().value_or(false);
|
||||||
|| (std::holds_alternative<bool>(notification)
|
const auto boolvalue = std::get_if<bool>(¬ification);
|
||||||
&& std::get<bool>(notification));
|
return !boolvalue || *boolvalue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,8 @@ bool ClientWorkspaceSymbolRequest::preStartCheck()
|
|||||||
= client()->capabilities().workspaceSymbolProvider();
|
= client()->capabilities().workspaceSymbolProvider();
|
||||||
if (!capability.has_value())
|
if (!capability.has_value())
|
||||||
return false;
|
return false;
|
||||||
if (std::holds_alternative<bool>(*capability) && !std::get<bool>(*capability))
|
const auto boolvalue = std::get_if<bool>(&*capability);
|
||||||
|
if (boolvalue && !boolvalue)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -123,11 +123,11 @@ QString LanguageClientCompletionItem::detail() const
|
|||||||
if (auto _doc = m_item.documentation()) {
|
if (auto _doc = m_item.documentation()) {
|
||||||
auto doc = *_doc;
|
auto doc = *_doc;
|
||||||
QString detailDocText;
|
QString detailDocText;
|
||||||
if (std::holds_alternative<QString>(doc)) {
|
if (const auto s = std::get_if<QString>(&doc)) {
|
||||||
detailDocText = std::get<QString>(doc);
|
detailDocText = *s;
|
||||||
} else if (std::holds_alternative<MarkupContent>(doc)) {
|
} else if (const auto m = std::get_if<MarkupContent>(&doc)) {
|
||||||
// TODO markdown parser?
|
// TODO markdown parser?
|
||||||
detailDocText = std::get<MarkupContent>(doc).content();
|
detailDocText = m->content();
|
||||||
}
|
}
|
||||||
if (!detailDocText.isEmpty())
|
if (!detailDocText.isEmpty())
|
||||||
return detailDocText;
|
return detailDocText;
|
||||||
@@ -495,12 +495,10 @@ void LanguageClientCompletionAssistProcessor::handleCompletionResponse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
QList<CompletionItem> items;
|
QList<CompletionItem> items;
|
||||||
if (std::holds_alternative<CompletionList>(*result)) {
|
if (const auto list = std::get_if<CompletionList>(&*result))
|
||||||
const auto &list = std::get<CompletionList>(*result);
|
items = list->items().value_or(QList<CompletionItem>());
|
||||||
items = list.items().value_or(QList<CompletionItem>());
|
else if (const auto l = std::get_if<QList<CompletionItem>>(&*result))
|
||||||
} else if (std::holds_alternative<QList<CompletionItem>>(*result)) {
|
items = *l;
|
||||||
items = std::get<QList<CompletionItem>>(*result);
|
|
||||||
}
|
|
||||||
auto proposalItems = generateCompletionItems(items);
|
auto proposalItems = generateCompletionItems(items);
|
||||||
if (!m_snippetsGroup.isEmpty()) {
|
if (!m_snippetsGroup.isEmpty()) {
|
||||||
proposalItems << TextEditor::SnippetAssistCollector(m_snippetsGroup,
|
proposalItems << TextEditor::SnippetAssistCollector(m_snippetsGroup,
|
||||||
|
@@ -69,7 +69,8 @@ QFutureWatcher<ChangeSet> *LanguageClientFormatter::format(
|
|||||||
= m_client->capabilities().documentRangeFormattingProvider();
|
= m_client->capabilities().documentRangeFormattingProvider();
|
||||||
if (!provider.has_value())
|
if (!provider.has_value())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (std::holds_alternative<bool>(*provider) && !std::get<bool>(*provider))
|
const auto boolvalue = std::get_if<bool>(&*provider);
|
||||||
|
if (boolvalue && !*boolvalue)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
DocumentRangeFormattingParams params;
|
DocumentRangeFormattingParams params;
|
||||||
|
@@ -87,9 +87,8 @@ void HoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
|||||||
|
|
||||||
const std::optional<std::variant<bool, WorkDoneProgressOptions>> &provider
|
const std::optional<std::variant<bool, WorkDoneProgressOptions>> &provider
|
||||||
= m_client->capabilities().hoverProvider();
|
= m_client->capabilities().hoverProvider();
|
||||||
bool sendMessage = provider.has_value();
|
const bool *boolvalue = provider.has_value() ? std::get_if<bool>(&*provider) : nullptr;
|
||||||
if (sendMessage && std::holds_alternative<bool>(*provider))
|
bool sendMessage = provider.has_value() && (!boolvalue || *boolvalue);
|
||||||
sendMessage = std::get<bool>(*provider);
|
|
||||||
if (std::optional<bool> registered = m_client->dynamicCapabilities().isRegistered(
|
if (std::optional<bool> registered = m_client->dynamicCapabilities().isRegistered(
|
||||||
HoverRequest::methodName)) {
|
HoverRequest::methodName)) {
|
||||||
sendMessage = *registered;
|
sendMessage = *registered;
|
||||||
|
@@ -228,10 +228,10 @@ void LanguageClientOutlineWidget::handleResponse(const DocumentUri &uri,
|
|||||||
{
|
{
|
||||||
if (uri != m_uri)
|
if (uri != m_uri)
|
||||||
return;
|
return;
|
||||||
if (std::holds_alternative<QList<SymbolInformation>>(result))
|
if (const auto i = std::get_if<QList<SymbolInformation>>(&result))
|
||||||
m_model.setInfo(std::get<QList<SymbolInformation>>(result));
|
m_model.setInfo(*i);
|
||||||
else if (std::holds_alternative<QList<DocumentSymbol>>(result))
|
else if (const auto s = std::get_if<QList<DocumentSymbol>>(&result))
|
||||||
m_model.setInfo(std::get<QList<DocumentSymbol>>(result));
|
m_model.setInfo(*s);
|
||||||
else
|
else
|
||||||
m_model.clear();
|
m_model.clear();
|
||||||
|
|
||||||
@@ -369,10 +369,10 @@ void OutlineComboBox::updateModel(const DocumentUri &resultUri, const DocumentSy
|
|||||||
{
|
{
|
||||||
if (m_uri != resultUri)
|
if (m_uri != resultUri)
|
||||||
return;
|
return;
|
||||||
if (std::holds_alternative<QList<SymbolInformation>>(result))
|
if (const auto i = std::get_if<QList<SymbolInformation>>(&result))
|
||||||
m_model.setInfo(std::get<QList<SymbolInformation>>(result));
|
m_model.setInfo(*i);
|
||||||
else if (std::holds_alternative<QList<DocumentSymbol>>(result))
|
else if (const auto s = std::get_if<QList<DocumentSymbol>>(&result))
|
||||||
m_model.setInfo(std::get<QList<DocumentSymbol>>(result));
|
m_model.setInfo(*i);
|
||||||
else
|
else
|
||||||
m_model.clear();
|
m_model.clear();
|
||||||
|
|
||||||
|
@@ -100,9 +100,8 @@ static MessageId sendTextDocumentPositionParamsRequest(Client *client,
|
|||||||
sendMessage = supportedFile;
|
sendMessage = supportedFile;
|
||||||
} else {
|
} else {
|
||||||
const auto provider = std::mem_fn(member)(serverCapability);
|
const auto provider = std::mem_fn(member)(serverCapability);
|
||||||
sendMessage = provider.has_value();
|
const bool *boolvalue = provider.has_value() ? std::get_if<bool>(&*provider) : nullptr;
|
||||||
if (sendMessage && std::holds_alternative<bool>(*provider))
|
sendMessage = provider.has_value() && (!boolvalue || *boolvalue);
|
||||||
sendMessage = std::get<bool>(*provider);
|
|
||||||
}
|
}
|
||||||
if (sendMessage) {
|
if (sendMessage) {
|
||||||
client->sendMessage(request);
|
client->sendMessage(request);
|
||||||
@@ -191,9 +190,8 @@ bool SymbolSupport::supportsFindLink(TextEditor::TextDocument *document, LinkTar
|
|||||||
else
|
else
|
||||||
supported = m_client->isSupportedUri(uri);
|
supported = m_client->isSupportedUri(uri);
|
||||||
} else {
|
} else {
|
||||||
supported = provider.has_value();
|
const bool *boolvalue = provider.has_value() ? std::get_if<bool>(&*provider) : nullptr;
|
||||||
if (supported && std::holds_alternative<bool>(*provider))
|
supported = provider.has_value() && (!boolvalue || *boolvalue);
|
||||||
supported = std::get<bool>(*provider);
|
|
||||||
}
|
}
|
||||||
return supported;
|
return supported;
|
||||||
}
|
}
|
||||||
@@ -259,8 +257,8 @@ bool SymbolSupport::supportsFindUsages(TextEditor::TextDocument *document) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (auto referencesProvider = m_client->capabilities().referencesProvider()) {
|
} else if (auto referencesProvider = m_client->capabilities().referencesProvider()) {
|
||||||
if (std::holds_alternative<bool>(*referencesProvider)) {
|
if (const auto b = std::get_if<bool>(&*referencesProvider)) {
|
||||||
if (!std::get<bool>(*referencesProvider))
|
if (!*b)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -447,13 +445,11 @@ static bool supportsRename(Client *client,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (auto renameProvider = client->capabilities().renameProvider()) {
|
if (auto renameProvider = client->capabilities().renameProvider()) {
|
||||||
if (std::holds_alternative<bool>(*renameProvider)) {
|
if (const auto b = std::get_if<bool>(&*renameProvider)) {
|
||||||
if (!std::get<bool>(*renameProvider))
|
if (!*b)
|
||||||
return false;
|
return false;
|
||||||
} else if (std::holds_alternative<ServerCapabilities::RenameOptions>(*renameProvider)) {
|
} else if (const auto opt = std::get_if<ServerCapabilities::RenameOptions>(&*renameProvider)) {
|
||||||
prepareSupported = std::get<ServerCapabilities::RenameOptions>(*renameProvider)
|
prepareSupported = opt->prepareProvider().value_or(false);
|
||||||
.prepareProvider()
|
|
||||||
.value_or(false);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@@ -524,19 +520,17 @@ void SymbolSupport::requestPrepareRename(TextEditor::TextDocument *document,
|
|||||||
|
|
||||||
const std::optional<PrepareRenameResult> &result = response.result();
|
const std::optional<PrepareRenameResult> &result = response.result();
|
||||||
if (result.has_value()) {
|
if (result.has_value()) {
|
||||||
if (std::holds_alternative<PlaceHolderResult>(*result)) {
|
if (const auto placeHolderResult = std::get_if<PlaceHolderResult>(&*result)) {
|
||||||
auto placeHolderResult = std::get<PlaceHolderResult>(*result);
|
startRenameSymbol(
|
||||||
startRenameSymbol(params,
|
params,
|
||||||
placeholder.isEmpty() ? placeHolderResult.placeHolder()
|
placeholder.isEmpty() ? placeHolderResult->placeHolder() : placeholder,
|
||||||
: placeholder,
|
oldSymbolName,
|
||||||
oldSymbolName,
|
callback,
|
||||||
callback,
|
preferLowerCaseFileNames);
|
||||||
preferLowerCaseFileNames);
|
} else if (const auto range = std::get_if<Range>(&*result)) {
|
||||||
} else if (std::holds_alternative<Range>(*result)) {
|
|
||||||
auto range = std::get<Range>(*result);
|
|
||||||
if (document) {
|
if (document) {
|
||||||
const int start = range.start().toPositionInDocument(document->document());
|
const int start = range->start().toPositionInDocument(document->document());
|
||||||
const int end = range.end().toPositionInDocument(document->document());
|
const int end = range->end().toPositionInDocument(document->document());
|
||||||
const QString reportedSymbolName = document->textAt(start, end - start);
|
const QString reportedSymbolName = document->textAt(start, end - start);
|
||||||
startRenameSymbol(params,
|
startRenameSymbol(params,
|
||||||
derivePlaceholder(reportedSymbolName, placeholder),
|
derivePlaceholder(reportedSymbolName, placeholder),
|
||||||
@@ -586,28 +580,24 @@ Utils::SearchResultItems generateReplaceItems(const WorkspaceEdit &edits,
|
|||||||
const DocumentUri::PathMapper &pathMapper = client->hostPathMapper();
|
const DocumentUri::PathMapper &pathMapper = client->hostPathMapper();
|
||||||
if (!documentChanges.isEmpty()) {
|
if (!documentChanges.isEmpty()) {
|
||||||
for (const DocumentChange &documentChange : std::as_const(documentChanges)) {
|
for (const DocumentChange &documentChange : std::as_const(documentChanges)) {
|
||||||
if (std::holds_alternative<TextDocumentEdit>(documentChange)) {
|
if (const auto edit = std::get_if<TextDocumentEdit>(&documentChange)) {
|
||||||
const TextDocumentEdit edit = std::get<TextDocumentEdit>(documentChange);
|
rangesInDocument[edit->textDocument().uri().toFilePath(pathMapper)] = convertEdits(
|
||||||
rangesInDocument[edit.textDocument().uri().toFilePath(pathMapper)] = convertEdits(
|
edit->edits());
|
||||||
edit.edits());
|
|
||||||
} else {
|
} else {
|
||||||
Utils::SearchResultItem item;
|
Utils::SearchResultItem item;
|
||||||
|
|
||||||
if (std::holds_alternative<CreateFileOperation>(documentChange)) {
|
if (const auto op = std::get_if<CreateFileOperation>(&documentChange)) {
|
||||||
auto op = std::get<CreateFileOperation>(documentChange);
|
item.setLineText(op->message(pathMapper));
|
||||||
item.setLineText(op.message(pathMapper));
|
item.setFilePath(op->uri().toFilePath(pathMapper));
|
||||||
item.setFilePath(op.uri().toFilePath(pathMapper));
|
item.setUserData(QVariant(*op));
|
||||||
item.setUserData(QVariant(op));
|
} else if (const auto op = std::get_if<RenameFileOperation>(&documentChange)) {
|
||||||
} else if (std::holds_alternative<RenameFileOperation>(documentChange)) {
|
item.setLineText(op->message(pathMapper));
|
||||||
auto op = std::get<RenameFileOperation>(documentChange);
|
item.setFilePath(op->oldUri().toFilePath(pathMapper));
|
||||||
item.setLineText(op.message(pathMapper));
|
item.setUserData(QVariant(*op));
|
||||||
item.setFilePath(op.oldUri().toFilePath(pathMapper));
|
} else if (const auto op = std::get_if<DeleteFileOperation>(&documentChange)) {
|
||||||
item.setUserData(QVariant(op));
|
item.setLineText(op->message(pathMapper));
|
||||||
} else if (std::holds_alternative<DeleteFileOperation>(documentChange)) {
|
item.setFilePath(op->uri().toFilePath(pathMapper));
|
||||||
auto op = std::get<DeleteFileOperation>(documentChange);
|
item.setUserData(QVariant(*op));
|
||||||
item.setLineText(op.message(pathMapper));
|
|
||||||
item.setFilePath(op.uri().toFilePath(pathMapper));
|
|
||||||
item.setUserData(QVariant(op));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
items << item;
|
items << item;
|
||||||
|
@@ -349,13 +349,12 @@ bool applyDocumentChange(const Client *client, const DocumentChange &change)
|
|||||||
if (!client)
|
if (!client)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (std::holds_alternative<TextDocumentEdit>(change)) {
|
if (const auto e = std::get_if<TextDocumentEdit>(&change)) {
|
||||||
return applyTextDocumentEdit(client, std::get<TextDocumentEdit>(change));
|
return applyTextDocumentEdit(client, *e);
|
||||||
} else if (std::holds_alternative<CreateFileOperation>(change)) {
|
} else if (const auto createOperation = std::get_if<CreateFileOperation>(&change)) {
|
||||||
const auto createOperation = std::get<CreateFileOperation>(change);
|
const FilePath filePath = createOperation->uri().toFilePath(client->hostPathMapper());
|
||||||
const FilePath filePath = createOperation.uri().toFilePath(client->hostPathMapper());
|
|
||||||
if (filePath.exists()) {
|
if (filePath.exists()) {
|
||||||
if (const std::optional<CreateFileOptions> options = createOperation.options()) {
|
if (const std::optional<CreateFileOptions> options = createOperation->options()) {
|
||||||
if (options->overwrite().value_or(false)) {
|
if (options->overwrite().value_or(false)) {
|
||||||
if (!filePath.removeFile())
|
if (!filePath.removeFile())
|
||||||
return false;
|
return false;
|
||||||
@@ -365,16 +364,15 @@ bool applyDocumentChange(const Client *client, const DocumentChange &change)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filePath.ensureExistingFile();
|
return filePath.ensureExistingFile();
|
||||||
} else if (std::holds_alternative<RenameFileOperation>(change)) {
|
} else if (const auto renameOperation = std::get_if<RenameFileOperation>(&change)) {
|
||||||
const RenameFileOperation renameOperation = std::get<RenameFileOperation>(change);
|
const FilePath oldPath = renameOperation->oldUri().toFilePath(client->hostPathMapper());
|
||||||
const FilePath oldPath = renameOperation.oldUri().toFilePath(client->hostPathMapper());
|
|
||||||
if (!oldPath.exists())
|
if (!oldPath.exists())
|
||||||
return false;
|
return false;
|
||||||
const FilePath newPath = renameOperation.newUri().toFilePath(client->hostPathMapper());
|
const FilePath newPath = renameOperation->newUri().toFilePath(client->hostPathMapper());
|
||||||
if (oldPath == newPath)
|
if (oldPath == newPath)
|
||||||
return true;
|
return true;
|
||||||
if (newPath.exists()) {
|
if (newPath.exists()) {
|
||||||
if (const std::optional<CreateFileOptions> options = renameOperation.options()) {
|
if (const std::optional<CreateFileOptions> options = renameOperation->options()) {
|
||||||
if (options->overwrite().value_or(false)) {
|
if (options->overwrite().value_or(false)) {
|
||||||
if (!newPath.removeFile())
|
if (!newPath.removeFile())
|
||||||
return false;
|
return false;
|
||||||
@@ -384,10 +382,9 @@ bool applyDocumentChange(const Client *client, const DocumentChange &change)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return oldPath.renameFile(newPath);
|
return oldPath.renameFile(newPath);
|
||||||
} else if (std::holds_alternative<DeleteFileOperation>(change)) {
|
} else if (const auto deleteOperation = std::get_if<DeleteFileOperation>(&change)) {
|
||||||
const auto deleteOperation = std::get<DeleteFileOperation>(change);
|
const FilePath filePath = deleteOperation->uri().toFilePath(client->hostPathMapper());
|
||||||
const FilePath filePath = deleteOperation.uri().toFilePath(client->hostPathMapper());
|
if (const std::optional<DeleteFileOptions> options = deleteOperation->options()) {
|
||||||
if (const std::optional<DeleteFileOptions> options = deleteOperation.options()) {
|
|
||||||
if (!filePath.exists())
|
if (!filePath.exists())
|
||||||
return options->ignoreIfNotExists().value_or(false);
|
return options->ignoreIfNotExists().value_or(false);
|
||||||
if (filePath.isDir() && options->recursive().value_or(false))
|
if (filePath.isDir() && options->recursive().value_or(false))
|
||||||
|
@@ -69,10 +69,10 @@ bool ProgressManager::isProgressEndMessage(const LanguageServerProtocol::Progres
|
|||||||
Utils::Id languageClientProgressId(const ProgressToken &token)
|
Utils::Id languageClientProgressId(const ProgressToken &token)
|
||||||
{
|
{
|
||||||
constexpr char k_LanguageClientProgressId[] = "LanguageClient.ProgressId.";
|
constexpr char k_LanguageClientProgressId[] = "LanguageClient.ProgressId.";
|
||||||
auto toString = [](const ProgressToken &token){
|
auto toString = [](const ProgressToken &token) {
|
||||||
if (std::holds_alternative<int>(token))
|
if (const auto i = std::get_if<int>(&token))
|
||||||
return QString::number(std::get<int>(token));
|
return QString::number(*i);
|
||||||
return std::get<QString>(token);
|
return *std::get_if<QString>(&token);
|
||||||
};
|
};
|
||||||
return Utils::Id(k_LanguageClientProgressId).withSuffix(toString(token));
|
return Utils::Id(k_LanguageClientProgressId).withSuffix(toString(token));
|
||||||
}
|
}
|
||||||
|
@@ -251,11 +251,11 @@ void SnippetParsingTest::testSnippetParsing()
|
|||||||
QFETCH(Parts, parts);
|
QFETCH(Parts, parts);
|
||||||
|
|
||||||
SnippetParseResult result = LanguageClient::parseSnippet(input);
|
SnippetParseResult result = LanguageClient::parseSnippet(input);
|
||||||
QCOMPARE(std::holds_alternative<ParsedSnippet>(result), success);
|
const auto snippet = std::get_if<ParsedSnippet>(&result);
|
||||||
|
QCOMPARE(snippet != nullptr, success);
|
||||||
if (!success)
|
if (!success)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ParsedSnippet snippet = std::get<ParsedSnippet>(result);
|
|
||||||
|
|
||||||
auto rangesCompare = [&](const ParsedSnippet::Part &actual, const SnippetPart &expected) {
|
auto rangesCompare = [&](const ParsedSnippet::Part &actual, const SnippetPart &expected) {
|
||||||
QCOMPARE(actual.text, expected.text);
|
QCOMPARE(actual.text, expected.text);
|
||||||
@@ -264,10 +264,10 @@ void SnippetParsingTest::testSnippetParsing()
|
|||||||
QCOMPARE(manglerId, expected.manglerId);
|
QCOMPARE(manglerId, expected.manglerId);
|
||||||
};
|
};
|
||||||
|
|
||||||
QCOMPARE(snippet.parts.count(), parts.count());
|
QCOMPARE(snippet->parts.count(), parts.count());
|
||||||
|
|
||||||
for (int i = 0; i < parts.count(); ++i)
|
for (int i = 0; i < parts.count(); ++i)
|
||||||
rangesCompare(snippet.parts.at(i), parts.at(i));
|
rangesCompare(snippet->parts.at(i), parts.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *createSnippetParsingTest()
|
QObject *createSnippetParsingTest()
|
||||||
|
Reference in New Issue
Block a user