[PATCH] D62298: [CodeComplete] Override completion items are filtered by funciton names

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 23 03:19:18 PDT 2019


ilya-biryukov created this revision.
ilya-biryukov added a reviewer: kadircet.
Herald added a project: clang.

We put only the function name into "typed text" chunks now, previously
the whole signature was "typed text".

This leads to meaningful fuzzy match scores, giving better signals to
compare with other completion items.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62298

Files:
  clang/lib/Sema/SemaCodeComplete.cpp


Index: clang/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1828,19 +1828,6 @@
   Results.AddResult(CodeCompletionResult(Builder.TakeString()));
 }
 
-static void printOverrideString(llvm::raw_ostream &OS,
-                                CodeCompletionString *CCS) {
-  for (const auto &C : *CCS) {
-    if (C.Kind == CodeCompletionString::CK_Optional)
-      printOverrideString(OS, C.Optional);
-    else
-      OS << C.Text;
-    // Add a space after return type.
-    if (C.Kind == CodeCompletionString::CK_ResultType)
-      OS << ' ';
-  }
-}
-
 static void AddOverrideResults(ResultBuilder &Results,
                                const CodeCompletionContext &CCContext,
                                CodeCompletionBuilder &Builder) {
@@ -3162,19 +3149,37 @@
       PP, Ctx, Result, IncludeBriefComments, CCContext, Policy);
 }
 
+/// Turns a completion string for a declaration into a textual representation.
+/// The result contains only 'typed text' and 'text' chunks.
+void TurnDeclarationToText(const CodeCompletionString &CCS,
+                           CodeCompletionBuilder &Result) {
+  for (auto &Chunk : CCS) {
+    if (Chunk.Kind == CodeCompletionString::CK_Optional) {
+      TurnDeclarationToText(*Chunk.Optional, Result);
+      continue;
+    }
+    if (Chunk.Kind == CodeCompletionString::CK_TypedText)
+      Result.AddTypedTextChunk(Chunk.Text);
+    else
+      Result.AddTextChunk(Chunk.Text);
+    // Add a space after return type.
+    if (Chunk.Kind == CodeCompletionString::CK_ResultType)
+      Result.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+  }
+}
+
 CodeCompletionString *
 CodeCompletionResult::createCodeCompletionStringForOverride(
     Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
     bool IncludeBriefComments, const CodeCompletionContext &CCContext,
     PrintingPolicy &Policy) {
-  std::string OverrideSignature;
-  llvm::raw_string_ostream OS(OverrideSignature);
   auto *CCS = createCodeCompletionStringForDecl(PP, Ctx, Result,
                                                 /*IncludeBriefComments=*/false,
                                                 CCContext, Policy);
-  printOverrideString(OS, CCS);
-  OS << " override";
-  Result.AddTypedTextChunk(Result.getAllocator().CopyString(OS.str()));
+  // For overrides all chunks go into the result, none are informative.
+  TurnDeclarationToText(*CCS, Result);
+  Result.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+  Result.AddTextChunk("override");
   return Result.TakeString();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62298.200919.patch
Type: text/x-patch
Size: 2673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190523/44e2fb18/attachment.bin>


More information about the cfe-commits mailing list