[PATCH] D53638: [clangd] Downrank members from base class

Eric Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 24 06:47:35 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL345140: [clangd] Downrank members from base class (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D53638

Files:
  clang-tools-extra/trunk/clangd/Quality.cpp
  clang-tools-extra/trunk/clangd/Quality.h
  clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp


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) {
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/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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53638.170873.patch
Type: text/x-patch
Size: 2572 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181024/7e860dcb/attachment.bin>


More information about the cfe-commits mailing list