From 0c010cddb32775721fcc5dce9ae815d0510578e0 Mon Sep 17 00:00:00 2001 From: Francisco Lopes da Silva Date: Wed, 28 Jan 2015 14:17:22 +0000 Subject: Improves overload completion result chunks. The code building the code completion string for overloads was providing less detail compared to the one building completion strings for function declarations. There was no information about optionals and no information about what's a parameter and what's a function identifier, everything besides ResultType, CurrentParameter and special characters was classified as Text. This makes code completion strings for overload candidates to follow a pattern very similar, but not identical, to the one in use for function declarations: - return type chunk: ResultType - function identifier chunk: Text - parameter chunks: Placeholder - optional parameter chunks: Optional - current parameter chunk: CurrentParameter llvm-svn: 227309 --- clang/lib/Sema/CodeCompleteConsumer.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'clang/lib/Sema/CodeCompleteConsumer.cpp') diff --git a/clang/lib/Sema/CodeCompleteConsumer.cpp b/clang/lib/Sema/CodeCompleteConsumer.cpp index b2dc2d79616..92d2aeb9189 100644 --- a/clang/lib/Sema/CodeCompleteConsumer.cpp +++ b/clang/lib/Sema/CodeCompleteConsumer.cpp @@ -483,6 +483,31 @@ PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef, } } +// This function is used solely to preserve the former presentation of overloads +// by "clang -cc1 -code-completion-at", since CodeCompletionString::getAsString +// needs to be improved for printing the newer and more detailed overload +// chunks. +static std::string getOverloadAsString(const CodeCompletionString &CCS) { + std::string Result; + llvm::raw_string_ostream OS(Result); + + for (auto &C : CCS) { + switch (C.Kind) { + case CodeCompletionString::CK_Informative: + case CodeCompletionString::CK_ResultType: + OS << "[#" << C.Text << "#]"; + break; + + case CodeCompletionString::CK_CurrentParameter: + OS << "<#" << C.Text << "#>"; + break; + + default: OS << C.Text; break; + } + } + return OS.str(); +} + void PrintingCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef, unsigned CurrentArg, @@ -491,8 +516,9 @@ PrintingCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef, for (unsigned I = 0; I != NumCandidates; ++I) { if (CodeCompletionString *CCS = Candidates[I].CreateSignatureString(CurrentArg, SemaRef, - getAllocator(), CCTUInfo)) { - OS << "OVERLOAD: " << CCS->getAsString() << "\n"; + getAllocator(), CCTUInfo, + includeBriefComments())) { + OS << "OVERLOAD: " << getOverloadAsString(*CCS) << "\n"; } } } -- cgit v1.2.3