forked from OSchip/llvm-project
[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 llvm-svn: 345140
This commit is contained in:
parent
6e763a36c6
commit
52a11b5662
|
@ -299,6 +299,7 @@ void SymbolRelevanceSignals::merge(const CodeCompletionResult &SemaCCResult) {
|
|||
: 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() const {
|
|||
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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -185,6 +185,13 @@ TEST(QualityTests, SymbolRelevanceSignalExtraction) {
|
|||
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, SymbolRelevanceSignalsSanity) {
|
|||
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) {
|
||||
|
|
Loading…
Reference in New Issue