LanguageClient: Make sure to run callback in all code paths

... when receiving a reply for textDocument/definition.

Change-Id: I08f3a22f7c39a33b7b84539125a76d0c0d625692
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-09-30 16:02:39 +02:00
parent ec7c60cd67
commit d52e7b9398
2 changed files with 7 additions and 6 deletions

View File

@@ -506,9 +506,6 @@ void ClangdTestLocalReferences::test()
client()->findLocalUsages(doc, cursor, std::move(handler)); client()->findLocalUsages(doc, cursor, std::move(handler));
timer.start(10000); timer.start(10000);
loop.exec(); loop.exec();
QEXPECT_FAIL("cursor not on identifier", "clangd bug: go to definition does not return", Abort);
QEXPECT_FAIL("template parameter member access",
"clangd bug: go to definition does not return", Abort);
QVERIFY(timer.isActive()); QVERIFY(timer.isActive());
timer.stop(); timer.stop();

View File

@@ -78,14 +78,18 @@ static void handleGotoDefinitionResponse(const GotoDefinitionRequest::Response &
{ {
if (Utils::optional<GotoResult> _result = response.result()) { if (Utils::optional<GotoResult> _result = response.result()) {
const GotoResult result = _result.value(); const GotoResult result = _result.value();
if (Utils::holds_alternative<std::nullptr_t>(result)) if (Utils::holds_alternative<std::nullptr_t>(result)) {
return; callback({});
if (auto ploc = Utils::get_if<Location>(&result)) { } else if (auto ploc = Utils::get_if<Location>(&result)) {
callback(linkUnderCursor.value_or(ploc->toLink())); 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()) if (!plloc->isEmpty())
callback(linkUnderCursor.value_or(plloc->value(0).toLink())); callback(linkUnderCursor.value_or(plloc->value(0).toLink()));
else
callback({});
} }
} else {
callback({});
} }
} }