[clang-tools-extra] r345140 - [clangd] Downrank members from base class
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 24 06:45:17 PDT 2018
Author: ioeric
Date: Wed Oct 24 06:45:17 2018
New Revision: 345140
URL: http://llvm.org/viewvc/llvm-project?rev=345140&view=rev
Log:
[clangd] Downrank members from base class
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D53638
Modified:
clang-tools-extra/trunk/clangd/Quality.cpp
clang-tools-extra/trunk/clangd/Quality.h
clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=345140&r1=345139&r2=345140&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Wed Oct 24 06:45:17 2018
@@ -299,6 +299,7 @@ void SymbolRelevanceSignals::merge(const
: 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 @@ float SymbolRelevanceSignals::evaluate()
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;
Modified: clang-tools-extra/trunk/clangd/Quality.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.h?rev=345140&r1=345139&r2=345140&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Quality.h (original)
+++ clang-tools-extra/trunk/clangd/Quality.h Wed Oct 24 06:45:17 2018
@@ -87,6 +87,7 @@ struct SymbolRelevanceSignals {
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
Modified: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp?rev=345140&r1=345139&r2=345140&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Wed Oct 24 06:45:17 2018
@@ -185,6 +185,13 @@ TEST(QualityTests, SymbolRelevanceSignal
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 @@ TEST(QualityTests, SymbolRelevanceSignal
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) {
More information about the cfe-commits
mailing list