[clangd] Prefer definitions for gototype and implementation
authorKadir Cetinkaya <kadircet@google.com>
Wed, 14 Sep 2022 08:07:15 +0000 (10:07 +0200)
committerKadir Cetinkaya <kadircet@google.com>
Fri, 21 Jul 2023 12:38:51 +0000 (14:38 +0200)
Differential Revision: https://reviews.llvm.org/D133843

clang-tools-extra/clangd/ClangdLSPServer.cpp

index 65ee603..a87da25 100644 (file)
@@ -1451,7 +1451,7 @@ void ClangdLSPServer::onGoToType(const TextDocumentPositionParams &Params,
           return Reply(Types.takeError());
         std::vector<Location> Response;
         for (const LocatedSymbol &Sym : *Types)
-          Response.push_back(Sym.PreferredDeclaration);
+          Response.push_back(Sym.Definition.value_or(Sym.PreferredDeclaration));
         return Reply(std::move(Response));
       });
 }
@@ -1467,7 +1467,7 @@ void ClangdLSPServer::onGoToImplementation(
           return Reply(Overrides.takeError());
         std::vector<Location> Impls;
         for (const LocatedSymbol &Sym : *Overrides)
-          Impls.push_back(Sym.PreferredDeclaration);
+          Impls.push_back(Sym.Definition.value_or(Sym.PreferredDeclaration));
         return Reply(std::move(Impls));
       });
 }