forked from qt-creator/qt-creator
LanguageClient: avoid optional::value
Potentially throws std::bad_optional_access. Use operator* and operator-> instead. Change-Id: Idefa137da53f3663ea88961f1105b93402ec4777 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -29,12 +29,12 @@ namespace LanguageServerProtocol {
|
||||
|
||||
Utils::optional<QList<SymbolKind> > SymbolCapabilities::SymbolKindCapabilities::valueSet() const
|
||||
{
|
||||
Utils::optional<QList<int>> array = optionalArray<int>(valueSetKey);
|
||||
if (!array)
|
||||
return Utils::nullopt;
|
||||
return Utils::make_optional(Utils::transform(array.value(), [] (int value) {
|
||||
if (Utils::optional<QList<int>> array = optionalArray<int>(valueSetKey)) {
|
||||
return Utils::make_optional(Utils::transform(*array, [] (int value) {
|
||||
return static_cast<SymbolKind>(value);
|
||||
}));
|
||||
}
|
||||
return Utils::nullopt;
|
||||
}
|
||||
|
||||
void SymbolCapabilities::SymbolKindCapabilities::setValueSet(const QList<SymbolKind> &valueSet)
|
||||
|
@@ -44,14 +44,12 @@ Utils::optional<MarkupOrString> CompletionItem::documentation() const
|
||||
|
||||
Utils::optional<CompletionItem::InsertTextFormat> CompletionItem::insertTextFormat() const
|
||||
{
|
||||
Utils::optional<int> value = optionalValue<int>(insertTextFormatKey);
|
||||
return value.has_value()
|
||||
? Utils::make_optional(CompletionItem::InsertTextFormat(value.value()))
|
||||
: Utils::nullopt;
|
||||
if (Utils::optional<int> value = optionalValue<int>(insertTextFormatKey))
|
||||
return Utils::make_optional(CompletionItem::InsertTextFormat(*value));
|
||||
return Utils::nullopt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CompletionItemResolveRequest::CompletionItemResolveRequest(const CompletionItem ¶ms)
|
||||
: Request(methodName, params)
|
||||
{ }
|
||||
|
@@ -85,12 +85,12 @@ Utils::optional<QList<CompletionItemKind::Kind>>
|
||||
TextDocumentClientCapabilities::CompletionCapabilities::CompletionItemKindCapabilities::
|
||||
valueSet() const
|
||||
{
|
||||
Utils::optional<QList<int>> array = optionalArray<int>(valueSetKey);
|
||||
if (!array)
|
||||
return Utils::nullopt;
|
||||
return Utils::make_optional(Utils::transform(array.value(), [] (int value) {
|
||||
if (Utils::optional<QList<int>> array = optionalArray<int>(valueSetKey)) {
|
||||
return Utils::make_optional(Utils::transform(*array, [] (int value) {
|
||||
return static_cast<CompletionItemKind::Kind>(value);
|
||||
}));
|
||||
}
|
||||
return Utils::nullopt;
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -150,9 +150,8 @@ Utils::optional<LanguageClientValue<T>> JsonObject::optionalClientValue(const QS
|
||||
template<typename T>
|
||||
QList<T> JsonObject::array(const QString &key) const
|
||||
{
|
||||
const Utils::optional<QList<T>> &array = optionalArray<T>(key);
|
||||
if (array.has_value())
|
||||
return array.value();
|
||||
if (const Utils::optional<QList<T>> &array = optionalArray<T>(key))
|
||||
return *array;
|
||||
qCDebug(conversionLog) << QString("Expected array under %1 in:").arg(key) << *this;
|
||||
return {};
|
||||
}
|
||||
|
@@ -122,7 +122,7 @@ public:
|
||||
virtual bool parametersAreValid(QString *errorMessage) const
|
||||
{
|
||||
if (auto parameter = params())
|
||||
return parameter.value().isValid();
|
||||
return parameter->isValid();
|
||||
if (errorMessage)
|
||||
*errorMessage = QCoreApplication::translate("LanguageServerProtocol::Notification",
|
||||
"No parameters in \"%1\".").arg(method());
|
||||
|
@@ -204,10 +204,9 @@ RenameRequest::RenameRequest(const RenameParams ¶ms)
|
||||
|
||||
Utils::optional<DocumentUri> DocumentLink::target() const
|
||||
{
|
||||
Utils::optional<QString> optionalTarget = optionalValue<QString>(targetKey);
|
||||
return optionalTarget.has_value()
|
||||
? Utils::make_optional(DocumentUri::fromProtocol(optionalTarget.value()))
|
||||
: Utils::nullopt;
|
||||
if (Utils::optional<QString> optionalTarget = optionalValue<QString>(targetKey))
|
||||
return Utils::make_optional(DocumentUri::fromProtocol(*optionalTarget));
|
||||
return Utils::nullopt;
|
||||
}
|
||||
|
||||
Utils::optional<QJsonValue> DocumentLink::data() const
|
||||
|
@@ -43,7 +43,7 @@ namespace LanguageServerProtocol {
|
||||
Utils::optional<DiagnosticSeverity> Diagnostic::severity() const
|
||||
{
|
||||
if (auto val = optionalValue<int>(severityKey))
|
||||
return Utils::make_optional(static_cast<DiagnosticSeverity>(val.value()));
|
||||
return Utils::make_optional(static_cast<DiagnosticSeverity>(*val));
|
||||
return Utils::nullopt;
|
||||
}
|
||||
|
||||
@@ -352,13 +352,13 @@ bool DocumentFilter::applies(const Utils::FilePath &fileName, const Utils::MimeT
|
||||
QRegularExpression::PatternOption option = QRegularExpression::NoPatternOption;
|
||||
if (fileName.caseSensitivity() == Qt::CaseInsensitive)
|
||||
option = QRegularExpression::CaseInsensitiveOption;
|
||||
const QRegularExpression regexp(expressionForGlob(_pattern.value()), option);
|
||||
const QRegularExpression regexp(expressionForGlob(*_pattern), option);
|
||||
if (regexp.isValid() && regexp.match(fileName.toString()).hasMatch())
|
||||
return true;
|
||||
}
|
||||
if (Utils::optional<QString> _lang = language()) {
|
||||
auto match = [&_lang](const Utils::MimeType &mimeType){
|
||||
return _lang.value() == TextDocumentItem::mimeTypeToLanguageId(mimeType);
|
||||
return *_lang == TextDocumentItem::mimeTypeToLanguageId(mimeType);
|
||||
};
|
||||
if (mimeType.isValid() && match(mimeType))
|
||||
return true;
|
||||
|
@@ -43,13 +43,12 @@ void ServerCapabilities::setTextDocumentSync(const ServerCapabilities::TextDocum
|
||||
|
||||
TextDocumentSyncKind ServerCapabilities::textDocumentSyncKindHelper()
|
||||
{
|
||||
Utils::optional<TextDocumentSync> sync = textDocumentSync();
|
||||
if (sync.has_value()) {
|
||||
if (auto kind = Utils::get_if<int>(&sync.value()))
|
||||
if (Utils::optional<TextDocumentSync> sync = textDocumentSync()) {
|
||||
if (auto kind = Utils::get_if<int>(&*sync))
|
||||
return static_cast<TextDocumentSyncKind>(*kind);
|
||||
if (auto options = Utils::get_if<TextDocumentSyncOptions>(&sync.value())) {
|
||||
if (auto options = Utils::get_if<TextDocumentSyncOptions>(&*sync)) {
|
||||
if (const Utils::optional<int> &change = options->change())
|
||||
return static_cast<TextDocumentSyncKind>(change.value());
|
||||
return static_cast<TextDocumentSyncKind>(*change);
|
||||
}
|
||||
}
|
||||
return TextDocumentSyncKind::None;
|
||||
|
@@ -81,7 +81,7 @@ ExecuteCommandParams::ExecuteCommandParams(const Command &command)
|
||||
{
|
||||
setCommand(command.command());
|
||||
if (command.arguments().has_value())
|
||||
setArguments(command.arguments().value());
|
||||
setArguments(*command.arguments());
|
||||
}
|
||||
|
||||
LanguageServerProtocol::WorkSpaceFolderResult::operator const QJsonValue() const
|
||||
|
@@ -169,7 +169,7 @@ public:
|
||||
|
||||
bool detailIs(const QString &s) const
|
||||
{
|
||||
return detail() && detail().value() == s;
|
||||
return detail() && *detail() == s;
|
||||
}
|
||||
|
||||
bool isMemberFunctionCall() const
|
||||
|
@@ -380,7 +380,7 @@ void Client::openDocument(TextEditor::TextDocument *document)
|
||||
const FilePath &filePath = document->filePath();
|
||||
const QString method(DidOpenTextDocumentNotification::methodName);
|
||||
if (Utils::optional<bool> registered = m_dynamicCapabilities.isRegistered(method)) {
|
||||
if (!registered.value())
|
||||
if (!*registered)
|
||||
return;
|
||||
const TextDocumentRegistrationOptions option(
|
||||
m_dynamicCapabilities.option(method).toObject());
|
||||
@@ -390,7 +390,7 @@ void Client::openDocument(TextEditor::TextDocument *document)
|
||||
}
|
||||
} else if (Utils::optional<ServerCapabilities::TextDocumentSync> _sync
|
||||
= m_serverCapabilities.textDocumentSync()) {
|
||||
if (auto options = Utils::get_if<TextDocumentSyncOptions>(&_sync.value())) {
|
||||
if (auto options = Utils::get_if<TextDocumentSyncOptions>(&*_sync)) {
|
||||
if (!options->openClose().value_or(true))
|
||||
return;
|
||||
}
|
||||
@@ -570,7 +570,7 @@ void Client::requestDocumentHighlightsNow(TextEditor::TextEditorWidget *widget)
|
||||
const Id &id = TextEditor::TextEditorWidget::CodeSemanticsSelection;
|
||||
QList<QTextEdit::ExtraSelection> selections;
|
||||
const Utils::optional<DocumentHighlightsResult> &result = response.result();
|
||||
if (!result.has_value() || holds_alternative<std::nullptr_t>(result.value())) {
|
||||
if (!result.has_value() || holds_alternative<std::nullptr_t>(*result)) {
|
||||
widget->setExtraSelections(id, selections);
|
||||
return;
|
||||
}
|
||||
@@ -578,7 +578,7 @@ void Client::requestDocumentHighlightsNow(TextEditor::TextEditorWidget *widget)
|
||||
const QTextCharFormat &format =
|
||||
widget->textDocument()->fontSettings().toTextCharFormat(TextEditor::C_OCCURRENCES);
|
||||
QTextDocument *document = widget->document();
|
||||
for (const auto &highlight : get<QList<DocumentHighlight>>(result.value())) {
|
||||
for (const auto &highlight : get<QList<DocumentHighlight>>(*result)) {
|
||||
QTextEdit::ExtraSelection selection{widget->textCursor(), format};
|
||||
const int &start = highlight.range().start().toPositionInDocument(document);
|
||||
const int &end = highlight.range().end().toPositionInDocument(document);
|
||||
@@ -663,7 +663,7 @@ void Client::documentContentsSaved(TextEditor::TextDocument *document)
|
||||
bool includeText = false;
|
||||
const QString method(DidSaveTextDocumentNotification::methodName);
|
||||
if (Utils::optional<bool> registered = m_dynamicCapabilities.isRegistered(method)) {
|
||||
sendMessage = registered.value();
|
||||
sendMessage = *registered;
|
||||
if (sendMessage) {
|
||||
const TextDocumentSaveRegistrationOptions option(
|
||||
m_dynamicCapabilities.option(method).toObject());
|
||||
@@ -675,9 +675,9 @@ void Client::documentContentsSaved(TextEditor::TextDocument *document)
|
||||
}
|
||||
} else if (Utils::optional<ServerCapabilities::TextDocumentSync> _sync
|
||||
= m_serverCapabilities.textDocumentSync()) {
|
||||
if (auto options = Utils::get_if<TextDocumentSyncOptions>(&_sync.value())) {
|
||||
if (auto options = Utils::get_if<TextDocumentSyncOptions>(&*_sync)) {
|
||||
if (Utils::optional<SaveOptions> saveOptions = options->save())
|
||||
includeText = saveOptions.value().includeText().value_or(includeText);
|
||||
includeText = saveOptions->includeText().value_or(includeText);
|
||||
}
|
||||
}
|
||||
if (!sendMessage)
|
||||
@@ -698,7 +698,7 @@ void Client::documentWillSave(Core::IDocument *document)
|
||||
bool sendMessage = false;
|
||||
const QString method(WillSaveTextDocumentNotification::methodName);
|
||||
if (Utils::optional<bool> registered = m_dynamicCapabilities.isRegistered(method)) {
|
||||
sendMessage = registered.value();
|
||||
sendMessage = *registered;
|
||||
if (sendMessage) {
|
||||
const TextDocumentRegistrationOptions option(m_dynamicCapabilities.option(method));
|
||||
if (option.isValid()) {
|
||||
@@ -708,7 +708,7 @@ void Client::documentWillSave(Core::IDocument *document)
|
||||
}
|
||||
} else if (Utils::optional<ServerCapabilities::TextDocumentSync> _sync
|
||||
= m_serverCapabilities.textDocumentSync()) {
|
||||
if (auto options = Utils::get_if<TextDocumentSyncOptions>(&_sync.value()))
|
||||
if (auto options = Utils::get_if<TextDocumentSyncOptions>(&*_sync))
|
||||
sendMessage = options->willSave().value_or(sendMessage);
|
||||
}
|
||||
if (!sendMessage)
|
||||
@@ -728,7 +728,7 @@ void Client::documentContentsChanged(TextEditor::TextDocument *document,
|
||||
const QString method(DidChangeTextDocumentNotification::methodName);
|
||||
TextDocumentSyncKind syncKind = m_serverCapabilities.textDocumentSyncKindHelper();
|
||||
if (Utils::optional<bool> registered = m_dynamicCapabilities.isRegistered(method)) {
|
||||
syncKind = registered.value() ? TextDocumentSyncKind::Full : TextDocumentSyncKind::None;
|
||||
syncKind = *registered ? TextDocumentSyncKind::Full : TextDocumentSyncKind::None;
|
||||
if (syncKind != TextDocumentSyncKind::None) {
|
||||
const TextDocumentChangeRegistrationOptions option(
|
||||
m_dynamicCapabilities.option(method).toObject());
|
||||
@@ -920,7 +920,7 @@ void Client::requestCodeActions(const CodeActionRequest &request)
|
||||
|
||||
const QString method(CodeActionRequest::methodName);
|
||||
if (Utils::optional<bool> registered = m_dynamicCapabilities.isRegistered(method)) {
|
||||
if (!registered.value())
|
||||
if (!*registered)
|
||||
return;
|
||||
const TextDocumentRegistrationOptions option(
|
||||
m_dynamicCapabilities.option(method).toObject());
|
||||
@@ -941,9 +941,8 @@ void Client::handleCodeActionResponse(const CodeActionRequest::Response &respons
|
||||
{
|
||||
if (const Utils::optional<CodeActionRequest::Response::Error> &error = response.error())
|
||||
log(*error);
|
||||
if (const Utils::optional<CodeActionResult> &_result = response.result()) {
|
||||
const CodeActionResult &result = _result.value();
|
||||
if (auto list = Utils::get_if<QList<Utils::variant<Command, CodeAction>>>(&result)) {
|
||||
if (const Utils::optional<CodeActionResult> &result = response.result()) {
|
||||
if (auto list = Utils::get_if<QList<Utils::variant<Command, CodeAction>>>(&*result)) {
|
||||
for (const Utils::variant<Command, CodeAction> &item : *list) {
|
||||
if (auto action = Utils::get_if<CodeAction>(&item))
|
||||
updateCodeActionRefactoringMarker(this, *action, uri);
|
||||
@@ -1269,7 +1268,7 @@ LanguageClientValue<MessageActionItem> Client::showMessageBox(
|
||||
}
|
||||
QHash<QAbstractButton *, MessageActionItem> itemForButton;
|
||||
if (const Utils::optional<QList<MessageActionItem>> actions = message.actions()) {
|
||||
for (const MessageActionItem &action : actions.value())
|
||||
for (const MessageActionItem &action : *actions)
|
||||
itemForButton.insert(box->addButton(action.title(), QMessageBox::InvalidRole), action);
|
||||
}
|
||||
box->exec();
|
||||
@@ -1538,11 +1537,12 @@ void Client::initializeCallback(const InitializeRequest::Response &initResponse)
|
||||
{
|
||||
QTC_ASSERT(m_state == InitializeRequested, return);
|
||||
if (optional<ResponseError<InitializeError>> error = initResponse.error()) {
|
||||
if (error.value().data().has_value() && error.value().data().value().retry()) {
|
||||
if (Utils::optional<InitializeError> data = error->data()) {
|
||||
if (data->retry()) {
|
||||
const QString title(tr("Language Server \"%1\" Initialize Error").arg(m_displayName));
|
||||
auto result = QMessageBox::warning(Core::ICore::dialogParent(),
|
||||
title,
|
||||
error.value().message(),
|
||||
error->message(),
|
||||
QMessageBox::Retry | QMessageBox::Cancel,
|
||||
QMessageBox::Retry);
|
||||
if (result == QMessageBox::Retry) {
|
||||
@@ -1551,32 +1551,31 @@ void Client::initializeCallback(const InitializeRequest::Response &initResponse)
|
||||
return;
|
||||
}
|
||||
}
|
||||
setError(tr("Initialize error: ") + error.value().message());
|
||||
}
|
||||
setError(tr("Initialize error: ") + error->message());
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
const optional<InitializeResult> &_result = initResponse.result();
|
||||
if (!_result.has_value()) {// continue on ill formed result
|
||||
log(tr("No initialize result."));
|
||||
} else {
|
||||
const InitializeResult &result = _result.value();
|
||||
if (!result.isValid()) { // continue on ill formed result
|
||||
log(QJsonDocument(result).toJson(QJsonDocument::Indented) + '\n'
|
||||
if (const optional<InitializeResult> &result = initResponse.result()) {
|
||||
if (!result->isValid()) { // continue on ill formed result
|
||||
log(QJsonDocument(*result).toJson(QJsonDocument::Indented) + '\n'
|
||||
+ tr("Initialize result is not valid"));
|
||||
}
|
||||
const Utils::optional<ServerInfo> serverInfo = result.serverInfo();
|
||||
const Utils::optional<ServerInfo> serverInfo = result->serverInfo();
|
||||
if (serverInfo) {
|
||||
if (!serverInfo->isValid()) {
|
||||
log(QJsonDocument(result).toJson(QJsonDocument::Indented) + '\n'
|
||||
log(QJsonDocument(*result).toJson(QJsonDocument::Indented) + '\n'
|
||||
+ tr("Server Info is not valid"));
|
||||
} else {
|
||||
m_serverName = serverInfo->name();
|
||||
if (const Utils::optional<QString> version = serverInfo->version())
|
||||
m_serverVersion = version.value();
|
||||
m_serverVersion = *version;
|
||||
}
|
||||
}
|
||||
|
||||
m_serverCapabilities = result.capabilities();
|
||||
m_serverCapabilities = result->capabilities();
|
||||
} else {
|
||||
log(tr("No initialize result."));
|
||||
}
|
||||
|
||||
if (auto completionProvider = qobject_cast<LanguageClientCompletionAssistProvider *>(
|
||||
@@ -1646,10 +1645,10 @@ bool Client::sendWorkspceFolderChanges() const
|
||||
return true;
|
||||
}
|
||||
if (auto workspace = m_serverCapabilities.workspace()) {
|
||||
if (auto folder = workspace.value().workspaceFolders()) {
|
||||
if (folder.value().supported().value_or(false)) {
|
||||
if (auto folder = workspace->workspaceFolders()) {
|
||||
if (folder->supported().value_or(false)) {
|
||||
// holds either the Id for deregistration or whether it is registered
|
||||
auto notification = folder.value().changeNotifications().value_or(false);
|
||||
auto notification = folder->changeNotifications().value_or(false);
|
||||
return holds_alternative<QString>(notification)
|
||||
|| (holds_alternative<bool>(notification) && get<bool>(notification));
|
||||
}
|
||||
|
@@ -117,7 +117,7 @@ void DocumentSymbolCache::handleResponse(const DocumentUri &uri,
|
||||
m_runningRequests.remove(uri);
|
||||
if (Utils::optional<DocumentSymbolsRequest::Response::Error> error = response.error()) {
|
||||
if (m_client)
|
||||
m_client->log(error.value());
|
||||
m_client->log(*error);
|
||||
}
|
||||
const DocumentSymbolsResult &symbols = response.result().value_or(DocumentSymbolsResult());
|
||||
m_cache[uri] = symbols;
|
||||
|
@@ -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<QString> 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<CompletionResult> &result = response.result();
|
||||
if (!result || Utils::holds_alternative<std::nullptr_t>(*result)) {
|
||||
|
@@ -77,7 +77,7 @@ QFutureWatcher<ChangeSet> *LanguageClientFormatter::format(
|
||||
const DynamicCapabilities dynamicCapabilities = m_client->dynamicCapabilities();
|
||||
const QString method(DocumentRangeFormattingRequest::methodName);
|
||||
if (optional<bool> registered = dynamicCapabilities.isRegistered(method)) {
|
||||
if (!registered.value())
|
||||
if (!*registered)
|
||||
return nullptr;
|
||||
const TextDocumentRegistrationOptions option(dynamicCapabilities.option(method).toObject());
|
||||
if (option.isValid()
|
||||
|
@@ -103,7 +103,7 @@ IAssistProposal *FunctionHintProcessor::perform(const AssistInterface *interface
|
||||
void FunctionHintProcessor::cancel()
|
||||
{
|
||||
if (running()) {
|
||||
m_client->cancelRequest(m_currentRequest.value());
|
||||
m_client->cancelRequest(*m_currentRequest);
|
||||
m_client->removeAssistProcessor(this);
|
||||
m_currentRequest.reset();
|
||||
}
|
||||
@@ -113,7 +113,7 @@ void FunctionHintProcessor::handleSignatureResponse(const SignatureHelpRequest::
|
||||
{
|
||||
m_currentRequest.reset();
|
||||
if (auto error = response.error())
|
||||
m_client->log(error.value());
|
||||
m_client->log(*error);
|
||||
m_client->removeAssistProcessor(this);
|
||||
auto result = response.result().value_or(LanguageClientValue<SignatureHelp>());
|
||||
if (result.isNull()) {
|
||||
|
@@ -58,7 +58,8 @@ void HoverHandler::setHelpItem(const LanguageServerProtocol::MessageId &msgId,
|
||||
const Core::HelpItem &help)
|
||||
{
|
||||
if (msgId == m_response.id()) {
|
||||
setContent(m_response.result().value().content());
|
||||
if (Utils::optional<Hover> result = m_response.result())
|
||||
setContent(result->content());
|
||||
m_response = {};
|
||||
setLastHelpItemIdentified(help);
|
||||
m_report(priority());
|
||||
@@ -95,7 +96,7 @@ void HoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
||||
sendMessage = Utils::get<bool>(*provider);
|
||||
if (Utils::optional<bool> registered = m_client->dynamicCapabilities().isRegistered(
|
||||
HoverRequest::methodName)) {
|
||||
sendMessage = registered.value();
|
||||
sendMessage = *registered;
|
||||
if (sendMessage) {
|
||||
const TextDocumentRegistrationOptions option(
|
||||
m_client->dynamicCapabilities().option(HoverRequest::methodName).toObject());
|
||||
@@ -126,7 +127,7 @@ void HoverHandler::handleResponse(const HoverRequest::Response &response)
|
||||
m_currentRequest.reset();
|
||||
if (Utils::optional<HoverRequest::Response::Error> error = response.error()) {
|
||||
if (m_client)
|
||||
m_client->log(error.value());
|
||||
m_client->log(*error);
|
||||
}
|
||||
if (Utils::optional<Hover> result = response.result()) {
|
||||
if (m_helpItemProvider) {
|
||||
@@ -134,7 +135,7 @@ void HoverHandler::handleResponse(const HoverRequest::Response &response)
|
||||
m_helpItemProvider(response, m_uri);
|
||||
return;
|
||||
}
|
||||
setContent(result.value().content());
|
||||
setContent(result->content());
|
||||
}
|
||||
m_report(priority());
|
||||
}
|
||||
|
@@ -108,7 +108,7 @@ IAssistProposal *LanguageClientQuickFixAssistProcessor::perform(const AssistInte
|
||||
void LanguageClientQuickFixAssistProcessor::cancel()
|
||||
{
|
||||
if (running()) {
|
||||
m_client->cancelRequest(m_currentRequest.value());
|
||||
m_client->cancelRequest(*m_currentRequest);
|
||||
m_client->removeAssistProcessor(this);
|
||||
m_currentRequest.reset();
|
||||
}
|
||||
@@ -120,9 +120,8 @@ void LanguageClientQuickFixAssistProcessor::handleCodeActionResponse(const CodeA
|
||||
if (const Utils::optional<CodeActionRequest::Response::Error> &error = response.error())
|
||||
m_client->log(*error);
|
||||
QuickFixOperations ops;
|
||||
if (const Utils::optional<CodeActionResult> &_result = response.result()) {
|
||||
const CodeActionResult &result = _result.value();
|
||||
if (auto list = Utils::get_if<QList<Utils::variant<Command, CodeAction>>>(&result)) {
|
||||
if (const Utils::optional<CodeActionResult> &result = response.result()) {
|
||||
if (auto list = Utils::get_if<QList<Utils::variant<Command, CodeAction>>>(&*result)) {
|
||||
for (const Utils::variant<Command, CodeAction> &item : *list) {
|
||||
if (auto action = Utils::get_if<CodeAction>(&item))
|
||||
ops << new CodeActionQuickFixOperation(*action, m_client);
|
||||
|
@@ -76,13 +76,12 @@ static void handleGotoDefinitionResponse(const GotoDefinitionRequest::Response &
|
||||
Utils::ProcessLinkCallback callback,
|
||||
Utils::optional<Utils::Link> linkUnderCursor)
|
||||
{
|
||||
if (Utils::optional<GotoResult> _result = response.result()) {
|
||||
const GotoResult result = _result.value();
|
||||
if (Utils::holds_alternative<std::nullptr_t>(result)) {
|
||||
if (Utils::optional<GotoResult> result = response.result()) {
|
||||
if (Utils::holds_alternative<std::nullptr_t>(*result)) {
|
||||
callback({});
|
||||
} else if (auto ploc = Utils::get_if<Location>(&result)) {
|
||||
} else if (auto ploc = Utils::get_if<Location>(&*result)) {
|
||||
callback(linkUnderCursor.value_or(ploc->toLink()));
|
||||
} else if (auto plloc = Utils::get_if<QList<Location>>(&result)) {
|
||||
} else if (auto plloc = Utils::get_if<QList<Location>>(&*result)) {
|
||||
if (!plloc->isEmpty())
|
||||
callback(linkUnderCursor.value_or(plloc->value(0).toLink()));
|
||||
else
|
||||
@@ -206,8 +205,7 @@ void SymbolSupport::handleFindReferencesResponse(const FindReferencesRequest::Re
|
||||
if (result) {
|
||||
Core::SearchResult *search = Core::SearchResultWindow::instance()->startNewSearch(
|
||||
tr("Find References with %1 for:").arg(m_client->name()), "", wordUnderCursor);
|
||||
search->addResults(generateSearchResultItems(result.value()),
|
||||
Core::SearchResult::AddOrdered);
|
||||
search->addResults(generateSearchResultItems(*result), Core::SearchResult::AddOrdered);
|
||||
QObject::connect(search,
|
||||
&Core::SearchResult::activated,
|
||||
[](const Core::SearchResultItem &item) {
|
||||
|
@@ -166,22 +166,21 @@ void updateCodeActionRefactoringMarker(Client *client,
|
||||
marker.type = client->id();
|
||||
if (action.isValid())
|
||||
marker.tooltip = action.title();
|
||||
if (action.edit().has_value()) {
|
||||
WorkspaceEdit edit = action.edit().value();
|
||||
if (Utils::optional<WorkspaceEdit> edit = action.edit()) {
|
||||
marker.callback = [client, edit](const TextEditorWidget *) {
|
||||
applyWorkspaceEdit(client, edit);
|
||||
applyWorkspaceEdit(client, *edit);
|
||||
};
|
||||
if (diagnostics.isEmpty()) {
|
||||
QList<TextEdit> edits;
|
||||
if (optional<QList<TextDocumentEdit>> documentChanges = edit.documentChanges()) {
|
||||
if (optional<QList<TextDocumentEdit>> documentChanges = edit->documentChanges()) {
|
||||
QList<TextDocumentEdit> changesForUri = Utils::filtered(
|
||||
documentChanges.value(), [uri](const TextDocumentEdit &edit) {
|
||||
*documentChanges, [uri](const TextDocumentEdit &edit) {
|
||||
return edit.textDocument().uri() == uri;
|
||||
});
|
||||
for (const TextDocumentEdit &edit : changesForUri)
|
||||
edits << edit.edits();
|
||||
} else if (optional<WorkspaceEdit::Changes> localChanges = edit.changes()) {
|
||||
edits = localChanges.value()[uri];
|
||||
} else if (optional<WorkspaceEdit::Changes> localChanges = edit->changes()) {
|
||||
edits = (*localChanges)[uri];
|
||||
}
|
||||
for (const TextEdit &edit : qAsConst(edits)) {
|
||||
marker.cursor = endOfLineCursor(edit.range().start().toTextCursor(doc->document()));
|
||||
|
@@ -210,9 +210,9 @@ QList<Core::LocatorFilterEntry> DocumentLocatorFilter::matchesFor(
|
||||
|
||||
QTC_ASSERT(m_currentSymbols.has_value(), return {});
|
||||
|
||||
if (auto list = Utils::get_if<QList<DocumentSymbol>>(&m_currentSymbols.value()))
|
||||
if (auto list = Utils::get_if<QList<DocumentSymbol>>(&*m_currentSymbols))
|
||||
return generateEntries(*list, entry);
|
||||
else if (auto list = Utils::get_if<QList<SymbolInformation>>(&m_currentSymbols.value()))
|
||||
else if (auto list = Utils::get_if<QList<SymbolInformation>>(&*m_currentSymbols))
|
||||
return generateEntries(*list, entry);
|
||||
|
||||
return {};
|
||||
|
@@ -301,14 +301,15 @@ SemanticRequestTypes SemanticTokenSupport::supportedSemanticRequests(TextDocumen
|
||||
};
|
||||
const QString dynamicMethod = "textDocument/semanticTokens";
|
||||
const DynamicCapabilities &dynamicCapabilities = m_client->dynamicCapabilities();
|
||||
if (auto registered = dynamicCapabilities.isRegistered(dynamicMethod);
|
||||
registered.has_value()) {
|
||||
if (!registered.value())
|
||||
if (auto registered = dynamicCapabilities.isRegistered(dynamicMethod)) {
|
||||
if (!*registered)
|
||||
return SemanticRequestType::None;
|
||||
return supportedRequests(dynamicCapabilities.option(dynamicMethod).toObject());
|
||||
}
|
||||
if (m_client->capabilities().semanticTokensProvider().has_value())
|
||||
return supportedRequests(m_client->capabilities().semanticTokensProvider().value());
|
||||
if (Utils::optional<SemanticTokensOptions> provider = m_client->capabilities()
|
||||
.semanticTokensProvider()) {
|
||||
return supportedRequests(*provider);
|
||||
}
|
||||
return SemanticRequestType::None;
|
||||
}
|
||||
|
||||
@@ -359,10 +360,9 @@ void SemanticTokenSupport::handleSemanticTokensDelta(
|
||||
return;
|
||||
for (const auto start = data.begin() + edit.start(); it < start; ++it)
|
||||
newData.append(*it);
|
||||
const Utils::optional<QList<int>> editData = edit.data();
|
||||
if (editData.has_value()) {
|
||||
newData.append(editData.value());
|
||||
qCDebug(LOGLSPHIGHLIGHT) << edit.start() << edit.deleteCount() << editData.value();
|
||||
if (const Utils::optional<QList<int>> editData = edit.data()) {
|
||||
newData.append(*editData);
|
||||
qCDebug(LOGLSPHIGHLIGHT) << edit.start() << edit.deleteCount() << *editData;
|
||||
} else {
|
||||
qCDebug(LOGLSPHIGHLIGHT) << edit.start() << edit.deleteCount();
|
||||
}
|
||||
|
Reference in New Issue
Block a user