[PATCH] D62298: [CodeComplete] Filter override completions by function name
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 23 04:08:49 PDT 2019
ilya-biryukov updated this revision to Diff 200927.
ilya-biryukov added a comment.
- Simplify negative tests a bit
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62298/new/
https://reviews.llvm.org/D62298
Files:
clang/lib/Sema/SemaCodeComplete.cpp
clang/test/CodeCompletion/overrides.cpp
Index: clang/test/CodeCompletion/overrides.cpp
===================================================================
--- clang/test/CodeCompletion/overrides.cpp
+++ clang/test/CodeCompletion/overrides.cpp
@@ -20,14 +20,16 @@
// CHECK-CC1: COMPLETION: Pattern : void vfunc(bool param, int p) override{{$}}
// CHECK-CC1-NOT: COMPLETION: Pattern : void vfunc(bool param) override{{$}}
//
-// Runs completion at vo^id.
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:14:5 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
-// CHECK-CC2: COMPLETION: Pattern : void vfunc(bool param, int p) override{{$}}
+// Runs completion at v^oid.
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:14:4 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
// CHECK-CC2-NOT: COMPLETION: Pattern : int ttt(bool param, int x = 3) const override{{$}}
+// CHECK-CC2: COMPLETION: Pattern : void vfunc(bool param, int p) override{{$}}
// CHECK-CC2-NOT: COMPLETION: Pattern : void vfunc(bool param) override{{$}}
//
+// Runs completion at vo^id.
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:14:5 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+// CHECK-CC3-NOT: override
+//
// Runs completion at void ^.
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:14:8 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
-// CHECK-CC3-NOT: COMPLETION: Pattern : int ttt(bool param, int x = 3) const override{{$}}
-// CHECK-CC3-NOT: COMPLETION: Pattern : void vfunc(bool param, int p) override{{$}}
-// CHECK-CC3-NOT: COMPLETION: Pattern : void vfunc(bool param) override{{$}}
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:14:8 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+// CHECK-CC4-NOT: override
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.
+static void PrintOverrideString(const CodeCompletionString &CCS,
+ CodeCompletionBuilder &Result) {
+ for (auto &Chunk : CCS) {
+ if (Chunk.Kind == CodeCompletionString::CK_Optional) {
+ PrintOverrideString(*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.
+ PrintOverrideString(*CCS, Result);
+ Result.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+ Result.AddTextChunk("override");
return Result.TakeString();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62298.200927.patch
Type: text/x-patch
Size: 4382 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190523/6dae2291/attachment.bin>
More information about the cfe-commits
mailing list