Revert "[clangd] Use ML Code completion ranking as default."
authorUtkarsh Saxena <usx@google.com>
Tue, 2 Mar 2021 13:57:26 +0000 (14:57 +0100)
committerUtkarsh Saxena <usx@google.com>
Tue, 2 Mar 2021 14:04:23 +0000 (15:04 +0100)
CodeCompletionContext::Kind has 36 Kinds. The completion model currently
only handles categorical features of 32 cardinality.
Changing the datatype to uint64_t will solve the problem.

This reverts commit 438b5bb05a429d697674088d400e4800c1108658.

clang-tools-extra/clangd/CodeComplete.h
clang-tools-extra/clangd/Quality.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

index 40a528c..debf71d 100644 (file)
@@ -133,7 +133,7 @@ struct CodeCompleteOptions {
   enum CodeCompletionRankingModel {
     Heuristics,
     DecisionForest,
-  } RankingModel = DecisionForest;
+  } RankingModel = Heuristics;
 
   /// Callback used to score a CompletionCandidate if DecisionForest ranking
   /// model is enabled.
index 9942100..b49392b 100644 (file)
@@ -580,16 +580,12 @@ evaluateDecisionForest(const SymbolQualitySignals &Quality,
   // multiplciative boost (like NameMatch). This allows us to weigh the
   // prediciton score and NameMatch appropriately.
   Scores.ExcludingName = pow(Base, Evaluate(E));
-  // Following cases are not part of the generated training dataset:
-  //  - Symbols with `NeedsFixIts`.
-  //  - Forbidden symbols.
-  //  - Keywords: Dataset contains only macros and decls.
+  // NeedsFixIts is not part of the DecisionForest as generating training
+  // data that needs fixits is not-feasible.
   if (Relevance.NeedsFixIts)
     Scores.ExcludingName *= 0.5;
   if (Relevance.Forbidden)
     Scores.ExcludingName *= 0;
-  if (Quality.Category == SymbolQualitySignals::Keyword)
-    Scores.ExcludingName *= 4;
 
   // NameMatch should be a multiplier on total score to support rescoring.
   Scores.Total = Relevance.NameMatch * Scores.ExcludingName;
index 0ff1e83..b7a4017 100644 (file)
@@ -647,13 +647,13 @@ TEST(CompletionTest, ScopedWithFilter) {
 }
 
 TEST(CompletionTest, ReferencesAffectRanking) {
-  EXPECT_THAT(completions("int main() { abs^ }", {func("absA"), func("absB")})
-                  .Completions,
-              HasSubsequence(Named("absA"), Named("absB")));
-  EXPECT_THAT(completions("int main() { abs^ }",
-                          {func("absA"), withReferences(1000, func("absB"))})
-                  .Completions,
-              HasSubsequence(Named("absB"), Named("absA")));
+  auto Results = completions("int main() { abs^ }", {ns("absl"), func("absb")});
+  EXPECT_THAT(Results.Completions,
+              HasSubsequence(Named("absb"), Named("absl")));
+  Results = completions("int main() { abs^ }",
+                        {withReferences(10000, ns("absl")), func("absb")});
+  EXPECT_THAT(Results.Completions,
+              HasSubsequence(Named("absl"), Named("absb")));
 }
 
 TEST(CompletionTest, ContextWords) {