ClangCodeModel: Fix following virtual functions

We used to follow a Goto Implementation request with a Goto Definition
request, because the latter gave us the declaration instead of the
definition. This has changed in clangd 17, which means we now called Goto
Definition on a definition, which clangd interprets as switching to the
declaration.
We now do the right thing for all supported clangd versions.

Change-Id: I1c0acd2c8d5c942f7e25dedb1da953bb4f8d8d13
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2023-12-04 10:53:32 +01:00
parent 5c1b8dee32
commit 6d101cd812

View File

@@ -464,7 +464,7 @@ void ClangdFollowSymbol::Private::handleGotoImplementationResult(
// Also get the AST for the base declaration, so we can find out whether it's
// pure virtual and mark it accordingly.
// In addition, we need to follow all override links, because for these, clangd
// gives us the declaration instead of the definition.
// gives us the declaration instead of the definition (until clangd 16).
for (const Link &link : std::as_const(allLinks)) {
if (!client->documentForFilePath(link.targetFilePath) && addOpenFile(link.targetFilePath))
client->openExtraFile(link.targetFilePath);
@@ -492,6 +492,9 @@ void ClangdFollowSymbol::Private::handleGotoImplementationResult(
if (link == defLink)
continue;
if (client->versionNumber().majorVersion() >= 17)
continue;
const TextDocumentIdentifier doc(client->hostPathToServerUri(link.targetFilePath));
const TextDocumentPositionParams params(doc, pos);
GotoDefinitionRequest defReq(params);