From 6d101cd8120a88a5e6f5ec0487d3cd70c0882b0b Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 4 Dec 2023 10:53:32 +0100 Subject: [PATCH] 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 --- src/plugins/clangcodemodel/clangdfollowsymbol.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugins/clangcodemodel/clangdfollowsymbol.cpp b/src/plugins/clangcodemodel/clangdfollowsymbol.cpp index a975c787368..ed74dac0d9d 100644 --- a/src/plugins/clangcodemodel/clangdfollowsymbol.cpp +++ b/src/plugins/clangcodemodel/clangdfollowsymbol.cpp @@ -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);