@@ -895,14 +895,9 @@ struct ScoredSignature {
895895// part of it.
896896int paramIndexForArg (const CodeCompleteConsumer::OverloadCandidate &Candidate,
897897 int Arg) {
898- int NumParams = 0 ;
899- if (const auto *F = Candidate.getFunction ()) {
900- NumParams = F->getNumParams ();
901- if (F->isVariadic ())
902- ++NumParams;
903- } else if (auto *T = Candidate.getFunctionType ()) {
898+ int NumParams = Candidate.getNumParams ();
899+ if (auto *T = Candidate.getFunctionType ()) {
904900 if (auto *Proto = T->getAs <FunctionProtoType>()) {
905- NumParams = Proto->getNumParams ();
906901 if (Proto->isVariadic ())
907902 ++NumParams;
908903 }
@@ -923,7 +918,8 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
923918 void ProcessOverloadCandidates (Sema &S, unsigned CurrentArg,
924919 OverloadCandidate *Candidates,
925920 unsigned NumCandidates,
926- SourceLocation OpenParLoc) override {
921+ SourceLocation OpenParLoc,
922+ bool Braced) override {
927923 assert (!OpenParLoc.isInvalid ());
928924 SourceManager &SrcMgr = S.getSourceManager ();
929925 OpenParLoc = SrcMgr.getFileLoc (OpenParLoc);
@@ -963,8 +959,9 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
963959 paramIndexForArg (Candidate, SigHelp.activeParameter );
964960 }
965961
966- const auto *CCS = Candidate.CreateSignatureString (
967- CurrentArg, S, *Allocator, CCTUInfo, true );
962+ const auto *CCS =
963+ Candidate.CreateSignatureString (CurrentArg, S, *Allocator, CCTUInfo,
964+ /* IncludeBriefComment=*/ true , Braced);
968965 assert (CCS && " Expected the CodeCompletionString to be non-null" );
969966 ScoredSignatures.push_back (processOverloadCandidate (
970967 Candidate, *CCS,
@@ -996,8 +993,7 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
996993 const ScoredSignature &R) {
997994 // Ordering follows:
998995 // - Less number of parameters is better.
999- // - Function is better than FunctionType which is better than
1000- // Function Template.
996+ // - Aggregate > Function > FunctionType > FunctionTemplate
1001997 // - High score is better.
1002998 // - Shorter signature is better.
1003999 // - Alphabetically smaller is better.
@@ -1009,15 +1005,22 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
10091005 R.Quality .NumberOfOptionalParameters ;
10101006 if (L.Quality .Kind != R.Quality .Kind ) {
10111007 using OC = CodeCompleteConsumer::OverloadCandidate;
1012- switch (L.Quality .Kind ) {
1013- case OC::CK_Function:
1014- return true ;
1015- case OC::CK_FunctionType:
1016- return R.Quality .Kind != OC::CK_Function;
1017- case OC::CK_FunctionTemplate:
1018- return false ;
1019- }
1020- llvm_unreachable (" Unknown overload candidate type." );
1008+ auto KindPriority = [&](OC::CandidateKind K) {
1009+ switch (K) {
1010+ case OC::CK_Aggregate:
1011+ return 1 ;
1012+ case OC::CK_Function:
1013+ return 2 ;
1014+ case OC::CK_FunctionType:
1015+ return 3 ;
1016+ case OC::CK_FunctionTemplate:
1017+ return 4 ;
1018+ case OC::CK_Template:
1019+ return 5 ;
1020+ }
1021+ llvm_unreachable (" Unknown overload candidate type." );
1022+ };
1023+ return KindPriority (L.Quality .Kind ) < KindPriority (R.Quality .Kind );
10211024 }
10221025 if (L.Signature .label .size () != R.Signature .label .size ())
10231026 return L.Signature .label .size () < R.Signature .label .size ();
@@ -1162,24 +1165,15 @@ class ParamNameCollector final : public CodeCompleteConsumer {
11621165 void ProcessOverloadCandidates (Sema &S, unsigned CurrentArg,
11631166 OverloadCandidate *Candidates,
11641167 unsigned NumCandidates,
1165- SourceLocation OpenParLoc) override {
1168+ SourceLocation OpenParLoc,
1169+ bool Braced) override {
11661170 assert (CurrentArg <= (unsigned )std::numeric_limits<int >::max () &&
11671171 " too many arguments" );
11681172
11691173 for (unsigned I = 0 ; I < NumCandidates; ++I) {
1170- OverloadCandidate Candidate = Candidates[I];
1171- auto *Func = Candidate.getFunction ();
1172- if (!Func || Func->getNumParams () <= CurrentArg)
1173- continue ;
1174- auto *PVD = Func->getParamDecl (CurrentArg);
1175- if (!PVD)
1176- continue ;
1177- auto *Ident = PVD->getIdentifier ();
1178- if (!Ident)
1179- continue ;
1180- auto Name = Ident->getName ();
1181- if (!Name.empty ())
1182- ParamNames.insert (Name.str ());
1174+ if (const NamedDecl *ND = Candidates[I].getParamDecl (CurrentArg))
1175+ if (const auto *II = ND->getIdentifier ())
1176+ ParamNames.emplace (II->getName ());
11831177 }
11841178 }
11851179
0 commit comments