usaxena95 created this revision. usaxena95 added a reviewer: hokein. Herald added subscribers: kadircet, arphaman. usaxena95 requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang.
Also treat Keywords separately as they are not recorded by the training set generator. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D96353 Files: clang-tools-extra/clangd/CodeComplete.h clang-tools-extra/clangd/Quality.cpp clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -647,13 +647,12 @@ } TEST(CompletionTest, ReferencesAffectRanking) { - auto Results = completions("int main() { abs^ }", {ns("absl"), func("absb")}); + auto Results = + completions("int main() { abs^ }", {func("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"))); + {withReferences(100, func("absl")), func("absb")}); } TEST(CompletionTest, ContextWords) { Index: clang-tools-extra/clangd/Quality.cpp =================================================================== --- clang-tools-extra/clangd/Quality.cpp +++ clang-tools-extra/clangd/Quality.cpp @@ -580,12 +580,16 @@ // multiplciative boost (like NameMatch). This allows us to weigh the // prediciton score and NameMatch appropriately. Scores.ExcludingName = pow(Base, Evaluate(E)); - // NeedsFixIts is not part of the DecisionForest as generating training - // data that needs fixits is not-feasible. + // Following cases are not part of the generated training dataset: + // - Symbols with `NeedsFixIts`. + // - Forbidden symbols. + // - Keywords: Dataset contains only macros and decls. 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: clang-tools-extra/clangd/CodeComplete.h =================================================================== --- clang-tools-extra/clangd/CodeComplete.h +++ clang-tools-extra/clangd/CodeComplete.h @@ -133,7 +133,7 @@ enum CodeCompletionRankingModel { Heuristics, DecisionForest, - } RankingModel = Heuristics; + } RankingModel = DecisionForest; /// Callback used to score a CompletionCandidate if DecisionForest ranking /// model is enabled.
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -647,13 +647,12 @@ } TEST(CompletionTest, ReferencesAffectRanking) { - auto Results = completions("int main() { abs^ }", {ns("absl"), func("absb")}); + auto Results = + completions("int main() { abs^ }", {func("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"))); + {withReferences(100, func("absl")), func("absb")}); } TEST(CompletionTest, ContextWords) { Index: clang-tools-extra/clangd/Quality.cpp =================================================================== --- clang-tools-extra/clangd/Quality.cpp +++ clang-tools-extra/clangd/Quality.cpp @@ -580,12 +580,16 @@ // multiplciative boost (like NameMatch). This allows us to weigh the // prediciton score and NameMatch appropriately. Scores.ExcludingName = pow(Base, Evaluate(E)); - // NeedsFixIts is not part of the DecisionForest as generating training - // data that needs fixits is not-feasible. + // Following cases are not part of the generated training dataset: + // - Symbols with `NeedsFixIts`. + // - Forbidden symbols. + // - Keywords: Dataset contains only macros and decls. 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: clang-tools-extra/clangd/CodeComplete.h =================================================================== --- clang-tools-extra/clangd/CodeComplete.h +++ clang-tools-extra/clangd/CodeComplete.h @@ -133,7 +133,7 @@ enum CodeCompletionRankingModel { Heuristics, DecisionForest, - } RankingModel = Heuristics; + } RankingModel = DecisionForest; /// Callback used to score a CompletionCandidate if DecisionForest ranking /// model is enabled.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits