summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaCodeComplete.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-05-16 12:30:01 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-05-16 12:30:01 +0000
commita3f955bddb9102eb9813103f76fa76f1db9d1d9d (patch)
tree02c04ec0ca194b04423e6b287fe621ccf7ab84bb /clang/lib/Sema/SemaCodeComplete.cpp
parentd67ec24f3efdfb4e771ac4e3aa93c3377c5aa14f (diff)
downloadbcm5719-llvm-a3f955bddb9102eb9813103f76fa76f1db9d1d9d.tar.gz
bcm5719-llvm-a3f955bddb9102eb9813103f76fa76f1db9d1d9d.zip
[CodeComplete] Expose helpers to get RawComment of completion result.
Summary: Used in clangd, see D45999. Reviewers: sammccall, hokein, ioeric, arphaman Reviewed By: sammccall Subscribers: arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D46001 llvm-svn: 332457
Diffstat (limited to 'clang/lib/Sema/SemaCodeComplete.cpp')
-rw-r--r--clang/lib/Sema/SemaCodeComplete.cpp92
1 files changed, 62 insertions, 30 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 66b48e775b2..9d8ff7a4c85 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -2765,27 +2765,11 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx,
if (Declaration) {
Result.addParentContext(Declaration->getDeclContext());
Pattern->ParentName = Result.getParentName();
- // Provide code completion comment for self.GetterName where
- // GetterName is the getter method for a property with name
- // different from the property name (declared via a property
- // getter attribute.
- const NamedDecl *ND = Declaration;
- if (const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(ND))
- if (M->isPropertyAccessor())
- if (const ObjCPropertyDecl *PDecl = M->findPropertyDecl())
- if (PDecl->getGetterName() == M->getSelector() &&
- PDecl->getIdentifier() != M->getIdentifier()) {
- if (const RawComment *RC =
- Ctx.getRawCommentForAnyRedecl(M)) {
- Result.addBriefComment(RC->getBriefText(Ctx));
- Pattern->BriefComment = Result.getBriefComment();
- }
- else if (const RawComment *RC =
- Ctx.getRawCommentForAnyRedecl(PDecl)) {
- Result.addBriefComment(RC->getBriefText(Ctx));
- Pattern->BriefComment = Result.getBriefComment();
- }
- }
+ if (const RawComment *RC =
+ getPatternCompletionComment(Ctx, Declaration)) {
+ Result.addBriefComment(RC->getBriefText(Ctx));
+ Pattern->BriefComment = Result.getBriefComment();
+ }
}
return Pattern;
@@ -2845,14 +2829,9 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx,
if (IncludeBriefComments) {
// Add documentation comment, if it exists.
- if (const RawComment *RC = Ctx.getRawCommentForAnyRedecl(ND)) {
+ if (const RawComment *RC = getCompletionComment(Ctx, Declaration)) {
Result.addBriefComment(RC->getBriefText(Ctx));
}
- else if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND))
- if (OMD->isPropertyAccessor())
- if (const ObjCPropertyDecl *PDecl = OMD->findPropertyDecl())
- if (const RawComment *RC = Ctx.getRawCommentForAnyRedecl(PDecl))
- Result.addBriefComment(RC->getBriefText(Ctx));
}
if (StartsNestedNameSpecifier) {
@@ -3042,6 +3021,59 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx,
return Result.TakeString();
}
+const RawComment *clang::getCompletionComment(const ASTContext &Ctx,
+ const NamedDecl *ND) {
+ if (!ND)
+ return nullptr;
+ if (auto *RC = Ctx.getRawCommentForAnyRedecl(ND))
+ return RC;
+
+ // Try to find comment from a property for ObjC methods.
+ const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(ND);
+ if (!M)
+ return nullptr;
+ const ObjCPropertyDecl *PDecl = M->findPropertyDecl();
+ if (!PDecl)
+ return nullptr;
+
+ return Ctx.getRawCommentForAnyRedecl(PDecl);
+}
+
+const RawComment *clang::getPatternCompletionComment(const ASTContext &Ctx,
+ const NamedDecl *ND) {
+ const ObjCMethodDecl *M = dyn_cast_or_null<ObjCMethodDecl>(ND);
+ if (!M || !M->isPropertyAccessor())
+ return nullptr;
+
+ // Provide code completion comment for self.GetterName where
+ // GetterName is the getter method for a property with name
+ // different from the property name (declared via a property
+ // getter attribute.
+ const ObjCPropertyDecl *PDecl = M->findPropertyDecl();
+ if (!PDecl)
+ return nullptr;
+ if (PDecl->getGetterName() == M->getSelector() &&
+ PDecl->getIdentifier() != M->getIdentifier()) {
+ if (auto *RC = Ctx.getRawCommentForAnyRedecl(M))
+ return RC;
+ if (auto *RC = Ctx.getRawCommentForAnyRedecl(PDecl))
+ return RC;
+ }
+ return nullptr;
+}
+
+const RawComment *clang::getParameterComment(
+ const ASTContext &Ctx,
+ const CodeCompleteConsumer::OverloadCandidate &Result,
+ unsigned ArgIndex) {
+ auto FDecl = Result.getFunction();
+ if (!FDecl)
+ return nullptr;
+ if (ArgIndex < FDecl->getNumParams())
+ return Ctx.getRawCommentForAnyRedecl(FDecl->getParamDecl(ArgIndex));
+ return nullptr;
+}
+
/// Add function overload parameter chunks to the given code completion
/// string.
static void AddOverloadParameterChunks(ASTContext &Context,
@@ -3137,10 +3169,10 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString(
}
if (FDecl) {
- if (IncludeBriefComments && CurrentArg < FDecl->getNumParams())
- if (auto RC = S.getASTContext().getRawCommentForAnyRedecl(
- FDecl->getParamDecl(CurrentArg)))
+ if (IncludeBriefComments) {
+ if (auto RC = getParameterComment(S.getASTContext(), *this, CurrentArg))
Result.addBriefComment(RC->getBriefText(S.getASTContext()));
+ }
AddResultTypeChunk(S.Context, Policy, FDecl, QualType(), Result);
Result.AddTextChunk(
Result.getAllocator().CopyString(FDecl->getNameAsString()));
OpenPOWER on IntegriCloud