From 4452f71201e44552c36527c0aeffb1fb9ad025c4 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 24 Feb 2022 09:38:59 +0100 Subject: LanguageClient: avoid optional::value Potentially throws std::bad_optional_access. Use operator* and operator-> instead. Change-Id: Idefa137da53f3663ea88961f1105b93402ec4777 Reviewed-by: Eike Ziller Reviewed-by: --- .../languageclient/languageclientcompletionassist.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/plugins/languageclient/languageclientcompletionassist.cpp') diff --git a/src/plugins/languageclient/languageclientcompletionassist.cpp b/src/plugins/languageclient/languageclientcompletionassist.cpp index 3cec5a2e49..7024445aa0 100644 --- a/src/plugins/languageclient/languageclientcompletionassist.cpp +++ b/src/plugins/languageclient/languageclientcompletionassist.cpp @@ -66,7 +66,7 @@ bool LanguageClientCompletionItem::implicitlyApplies() const bool LanguageClientCompletionItem::prematurelyApplies(const QChar &typedCharacter) const { - if (m_item.commitCharacters().has_value() && m_item.commitCharacters().value().contains(typedCharacter)) { + if (m_item.commitCharacters() && m_item.commitCharacters()->contains(typedCharacter)) { m_triggeredCommitCharacter = typedCharacter; return true; } @@ -194,10 +194,8 @@ bool LanguageClientCompletionItem::hasSortText() const QString LanguageClientCompletionItem::filterText() const { - if (m_filterText.isEmpty()) { - const Utils::optional filterText = m_item.filterText(); - m_filterText = filterText.has_value() ? filterText.value() : m_item.label(); - } + if (m_filterText.isEmpty()) + m_filterText = m_item.filterText().value_or(m_item.label()); return m_filterText; } @@ -211,7 +209,7 @@ bool LanguageClientCompletionItem::isPerfectMatch(int pos, QTextDocument *doc) c QTC_ASSERT(doc, return false); using namespace Utils::Text; if (auto additionalEdits = m_item.additionalTextEdits()) { - if (!additionalEdits.value().isEmpty()) + if (!additionalEdits->isEmpty()) return false; } if (isSnippet()) @@ -393,7 +391,7 @@ void LanguageClientCompletionAssistProcessor::cancel() { if (m_currentRequest.has_value()) { if (m_client) { - m_client->cancelRequest(m_currentRequest.value()); + m_client->cancelRequest(*m_currentRequest); m_client->removeAssistProcessor(this); } m_currentRequest.reset(); @@ -410,7 +408,7 @@ void LanguageClientCompletionAssistProcessor::handleCompletionResponse( m_currentRequest.reset(); QTC_ASSERT(m_client, setAsyncProposalAvailable(nullptr); return); if (auto error = response.error()) - m_client->log(error.value()); + m_client->log(*error); const Utils::optional &result = response.result(); if (!result || Utils::holds_alternative(*result)) { -- cgit v1.2.1