diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/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(); }