Author: Christian Kandeler Date: 2021-09-23T16:09:13+02:00 New Revision: eb209c13cce99b1ad8d8e619bf2006f4376ed1ef
URL: https://github.com/llvm/llvm-project/commit/eb209c13cce99b1ad8d8e619bf2006f4376ed1ef DIFF: https://github.com/llvm/llvm-project/commit/eb209c13cce99b1ad8d8e619bf2006f4376ed1ef.diff LOG: clangd: Do not report inline overrides twice ... in textDocument/references. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D110324 Added: Modified: clang-tools-extra/clangd/XRefs.cpp clang-tools-extra/clangd/unittests/XRefsTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp index 4cec85e20ad6..ea61cba460ef 100644 --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -1431,17 +1431,20 @@ ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit, !OverriddenBy.Subjects.empty()) Index->relations( OverriddenBy, [&](const SymbolID &Subject, const Symbol &Object) { - if (auto LSPLoc = - toLSPLocation(Object.CanonicalDeclaration, *MainFilePath)) { + const auto LSPLocDecl = + toLSPLocation(Object.CanonicalDeclaration, *MainFilePath); + const auto LSPLocDef = + toLSPLocation(Object.Definition, *MainFilePath); + if (LSPLocDecl && LSPLocDecl != LSPLocDef) { ReferencesResult::Reference Result; - Result.Loc = std::move(*LSPLoc); + Result.Loc = std::move(*LSPLocDecl); Result.Attributes = ReferencesResult::Declaration | ReferencesResult::Override; Results.References.push_back(std::move(Result)); } - if (auto LSPLoc = toLSPLocation(Object.Definition, *MainFilePath)) { + if (LSPLocDef) { ReferencesResult::Reference Result; - Result.Loc = std::move(*LSPLoc); + Result.Loc = std::move(*LSPLocDef); Result.Attributes = ReferencesResult::Declaration | ReferencesResult::Definition | ReferencesResult::Override; diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp index 166e0674afea..6a9d355792a6 100644 --- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -1947,6 +1947,9 @@ TEST(FindReferences, IncludeOverrides) { void $overridedecl[[func]]() override; }; void Derived::$overridedef[[func]]() {} + class Derived2 : public Base { + void $overridedef[[func]]() override {} + }; void test(Derived* D) { D->func(); // No references to the overrides. })cpp"; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits