@@ -2765,27 +2765,11 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx,
27652765 if (Declaration) {
27662766 Result.addParentContext (Declaration->getDeclContext ());
27672767 Pattern->ParentName = Result.getParentName ();
2768- // Provide code completion comment for self.GetterName where
2769- // GetterName is the getter method for a property with name
2770- // different from the property name (declared via a property
2771- // getter attribute.
2772- const NamedDecl *ND = Declaration;
2773- if (const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(ND))
2774- if (M->isPropertyAccessor ())
2775- if (const ObjCPropertyDecl *PDecl = M->findPropertyDecl ())
2776- if (PDecl->getGetterName () == M->getSelector () &&
2777- PDecl->getIdentifier () != M->getIdentifier ()) {
2778- if (const RawComment *RC =
2779- Ctx.getRawCommentForAnyRedecl (M)) {
2780- Result.addBriefComment (RC->getBriefText (Ctx));
2781- Pattern->BriefComment = Result.getBriefComment ();
2782- }
2783- else if (const RawComment *RC =
2784- Ctx.getRawCommentForAnyRedecl (PDecl)) {
2785- Result.addBriefComment (RC->getBriefText (Ctx));
2786- Pattern->BriefComment = Result.getBriefComment ();
2787- }
2788- }
2768+ if (const RawComment *RC =
2769+ getPatternCompletionComment (Ctx, Declaration)) {
2770+ Result.addBriefComment (RC->getBriefText (Ctx));
2771+ Pattern->BriefComment = Result.getBriefComment ();
2772+ }
27892773 }
27902774
27912775 return Pattern;
@@ -2845,14 +2829,9 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx,
28452829
28462830 if (IncludeBriefComments) {
28472831 // Add documentation comment, if it exists.
2848- if (const RawComment *RC = Ctx. getRawCommentForAnyRedecl (ND )) {
2832+ if (const RawComment *RC = getCompletionComment (Ctx, Declaration )) {
28492833 Result.addBriefComment (RC->getBriefText (Ctx));
28502834 }
2851- else if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND))
2852- if (OMD->isPropertyAccessor ())
2853- if (const ObjCPropertyDecl *PDecl = OMD->findPropertyDecl ())
2854- if (const RawComment *RC = Ctx.getRawCommentForAnyRedecl (PDecl))
2855- Result.addBriefComment (RC->getBriefText (Ctx));
28562835 }
28572836
28582837 if (StartsNestedNameSpecifier) {
@@ -3042,6 +3021,59 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx,
30423021 return Result.TakeString ();
30433022}
30443023
3024+ const RawComment *clang::getCompletionComment (const ASTContext &Ctx,
3025+ const NamedDecl *ND) {
3026+ if (!ND)
3027+ return nullptr ;
3028+ if (auto *RC = Ctx.getRawCommentForAnyRedecl (ND))
3029+ return RC;
3030+
3031+ // Try to find comment from a property for ObjC methods.
3032+ const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(ND);
3033+ if (!M)
3034+ return nullptr ;
3035+ const ObjCPropertyDecl *PDecl = M->findPropertyDecl ();
3036+ if (!PDecl)
3037+ return nullptr ;
3038+
3039+ return Ctx.getRawCommentForAnyRedecl (PDecl);
3040+ }
3041+
3042+ const RawComment *clang::getPatternCompletionComment (const ASTContext &Ctx,
3043+ const NamedDecl *ND) {
3044+ const ObjCMethodDecl *M = dyn_cast_or_null<ObjCMethodDecl>(ND);
3045+ if (!M || !M->isPropertyAccessor ())
3046+ return nullptr ;
3047+
3048+ // Provide code completion comment for self.GetterName where
3049+ // GetterName is the getter method for a property with name
3050+ // different from the property name (declared via a property
3051+ // getter attribute.
3052+ const ObjCPropertyDecl *PDecl = M->findPropertyDecl ();
3053+ if (!PDecl)
3054+ return nullptr ;
3055+ if (PDecl->getGetterName () == M->getSelector () &&
3056+ PDecl->getIdentifier () != M->getIdentifier ()) {
3057+ if (auto *RC = Ctx.getRawCommentForAnyRedecl (M))
3058+ return RC;
3059+ if (auto *RC = Ctx.getRawCommentForAnyRedecl (PDecl))
3060+ return RC;
3061+ }
3062+ return nullptr ;
3063+ }
3064+
3065+ const RawComment *clang::getParameterComment (
3066+ const ASTContext &Ctx,
3067+ const CodeCompleteConsumer::OverloadCandidate &Result,
3068+ unsigned ArgIndex) {
3069+ auto FDecl = Result.getFunction ();
3070+ if (!FDecl)
3071+ return nullptr ;
3072+ if (ArgIndex < FDecl->getNumParams ())
3073+ return Ctx.getRawCommentForAnyRedecl (FDecl->getParamDecl (ArgIndex));
3074+ return nullptr ;
3075+ }
3076+
30453077// / Add function overload parameter chunks to the given code completion
30463078// / string.
30473079static void AddOverloadParameterChunks (ASTContext &Context,
@@ -3137,10 +3169,10 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString(
31373169 }
31383170
31393171 if (FDecl) {
3140- if (IncludeBriefComments && CurrentArg < FDecl->getNumParams ())
3141- if (auto RC = S.getASTContext ().getRawCommentForAnyRedecl (
3142- FDecl->getParamDecl (CurrentArg)))
3172+ if (IncludeBriefComments) {
3173+ if (auto RC = getParameterComment (S.getASTContext (), *this , CurrentArg))
31433174 Result.addBriefComment (RC->getBriefText (S.getASTContext ()));
3175+ }
31443176 AddResultTypeChunk (S.Context , Policy, FDecl, QualType (), Result);
31453177 Result.AddTextChunk (
31463178 Result.getAllocator ().CopyString (FDecl->getNameAsString ()));
0 commit comments