Index: clang-tools-extra/trunk/clangd/Quality.h =================================================================== --- clang-tools-extra/trunk/clangd/Quality.h +++ clang-tools-extra/trunk/clangd/Quality.h @@ -87,6 +87,7 @@ bool Forbidden = false; // Unavailable (e.g const) or inaccessible (private). /// Whether fixits needs to be applied for that completion or not. bool NeedsFixIts = false; + bool InBaseClass = false; // A member from base class of the accessed class. URIDistance *FileProximityMatch = nullptr; /// These are used to calculate proximity between the index symbol and the Index: clang-tools-extra/trunk/clangd/Quality.cpp =================================================================== --- clang-tools-extra/trunk/clangd/Quality.cpp +++ clang-tools-extra/trunk/clangd/Quality.cpp @@ -299,6 +299,7 @@ : 0.6; SemaFileProximityScore = std::max(DeclProximity, SemaFileProximityScore); IsInstanceMember |= isInstanceMember(SemaCCResult.Declaration); + InBaseClass |= SemaCCResult.InBaseClass; } // Declarations are scoped, others (like macros) are assumed global. @@ -372,9 +373,12 @@ if (!IsInstanceMember && (Context == CodeCompletionContext::CCC_DotMemberAccess || Context == CodeCompletionContext::CCC_ArrowMemberAccess)) { - Score *= 0.5; + Score *= 0.2; } + if (InBaseClass) + Score *= 0.5; + // Penalize for FixIts. if (NeedsFixIts) Score *= 0.5; Index: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp +++ clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp @@ -185,6 +185,13 @@ Relevance = {}; Relevance.merge(CodeCompletionResult(&findDecl(AST, "S::S"), 42)); EXPECT_EQ(Relevance.Scope, SymbolRelevanceSignals::GlobalScope); + + Relevance = {}; + EXPECT_FALSE(Relevance.InBaseClass); + auto BaseMember = CodeCompletionResult(&findAnyDecl(AST, "y"), 42); + BaseMember.InBaseClass = true; + Relevance.merge(BaseMember); + EXPECT_TRUE(Relevance.InBaseClass); } // Do the signals move the scores in the direction we expect? @@ -276,6 +283,10 @@ EXPECT_LT(Instance.evaluate(), Default.evaluate()); Instance.IsInstanceMember = true; EXPECT_EQ(Instance.evaluate(), Default.evaluate()); + + SymbolRelevanceSignals InBaseClass; + InBaseClass.InBaseClass = true; + EXPECT_LT(InBaseClass.evaluate(), Default.evaluate()); } TEST(QualityTests, ScopeProximity) {