CINDEX_LINKAGE
CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
+
+/**
+ * \brief Returns the currently-entered selector for an Objective-C message
+ * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
+ * non-empty string for CXCompletionContext_ObjCInstanceMessage and
+ * CXCompletionContext_ObjCClassMessage.
+ *
+ * \param Results the code completion results to query
+ *
+ * \returns the selector (or partial selector) that has been entered thus far
+ * for an Objective-C message send.
+ */
+CINDEX_LINKAGE
+CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
+
/**
* @}
*/
/// \brief The type of the base object in a member access expression.
QualType BaseType;
+ /// \brief The identifiers for Objective-C selector parts.
+ IdentifierInfo **SelIdents;
+
+ /// \brief The number of Objective-C selector parts.
+ unsigned NumSelIdents;
+
public:
/// \brief Construct a new code-completion context of the given kind.
- CodeCompletionContext(enum Kind Kind) : Kind(Kind) { }
+ CodeCompletionContext(enum Kind Kind) : Kind(Kind), SelIdents(NULL),
+ NumSelIdents(0) { }
/// \brief Construct a new code-completion context of the given kind.
- CodeCompletionContext(enum Kind Kind, QualType T) : Kind(Kind) {
+ CodeCompletionContext(enum Kind Kind, QualType T,
+ IdentifierInfo **SelIdents = NULL,
+ unsigned NumSelIdents = 0) : Kind(Kind),
+ SelIdents(SelIdents),
+ NumSelIdents(NumSelIdents) {
if (Kind == CCC_DotMemberAccess || Kind == CCC_ArrowMemberAccess ||
Kind == CCC_ObjCPropertyAccess || Kind == CCC_ObjCClassMessage ||
Kind == CCC_ObjCInstanceMessage)
/// \brief Retrieve the type of the base object in a member-access
/// expression.
QualType getBaseType() const { return BaseType; }
+
+ /// \brief Retrieve the Objective-C selector identifiers.
+ IdentifierInfo **getSelIdents() const { return SelIdents; }
+
+ /// \brief Retrieve the number of Objective-C selector identifiers.
+ unsigned getNumSelIdents() const { return NumSelIdents; }
/// \brief Determines whether we want C++ constructors as results within this
/// context.
ResultBuilder Results(*this, CodeCompleter->getAllocator(),
CodeCompletionContext(CodeCompletionContext::CCC_ObjCClassMessage,
- T));
+ T, SelIdents, NumSelIdents));
AddClassMessageCompletions(*this, S, Receiver, SelIdents, NumSelIdents,
AtArgumentExpression, IsSuper, Results);
// Build the set of methods we can see.
ResultBuilder Results(*this, CodeCompleter->getAllocator(),
CodeCompletionContext(CodeCompletionContext::CCC_ObjCInstanceMessage,
- ReceiverType));
+ ReceiverType, SelIdents, NumSelIdents));
Results.EnterNewScope();
// RUN: c-index-test -code-completion-at=%s:95:24 %s | FileCheck -check-prefix=CHECK-CC9 %s
// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText Arg2:}{Placeholder (int)}
// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText OtherArg:}{Placeholder (id)}
+// CHECK-CC9: Objective-C selector: Method:Arg1:
// RUN: c-index-test -code-completion-at=%s:61:11 %s | FileCheck -check-prefix=CHECK-CCA %s
// CHECK-CCA: TypedefDecl:{TypedText Class}
// CHECK-CCA-NEXT: ObjCInterfaceDecl:{TypedText Foo}
// CHECK-CCD: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)}
// CHECK-CCD: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{TypedText SomeArg:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)}
// CHECK-CCD-NOT: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{TypedText }
+// CHECK-CCD: Objective-C selector: Method:
// RUN: c-index-test -code-completion-at=%s:116:30 %s | FileCheck -check-prefix=CHECK-CCE %s
// CHECK-CCE: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText Arg2:}{Placeholder (int)}
// CHECK-CCE: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText OtherArg:}{Placeholder (id)}
unsigned i, n = results->NumResults, containerIsIncomplete = 0;
unsigned long long contexts;
enum CXCursorKind containerKind;
+ CXString objCSelector;
+ const char *selectorString;
if (!timing_only) {
/* Sort the code-completion results based on the typed text. */
clang_sortCodeCompletionResults(results->Results, results->NumResults);
contexts = clang_codeCompleteGetContexts(results);
print_completion_contexts(contexts, stdout);
- containerKind = clang_codeCompleteGetContainerKind(results, &containerIsIncomplete);
+ containerKind = clang_codeCompleteGetContainerKind(results,
+ &containerIsIncomplete);
if (containerKind != CXCursor_InvalidCode) {
/* We have found a container */
clang_disposeString(containerUSR);
}
+ objCSelector = clang_codeCompleteGetObjCSelector(results);
+ selectorString = clang_getCString(objCSelector);
+ if (selectorString && strlen(selectorString) > 0) {
+ printf("Objective-C selector: %s\n", selectorString);
+ }
+ clang_disposeString(objCSelector);
+
clang_disposeCodeCompleteResults(results);
}
clang_disposeTranslationUnit(TU);
/// current context.
unsigned long long Contexts;
+ /// \brief The kind of the container for the current context for completions.
enum CXCursorKind ContainerKind;
+ /// \brief The USR of the container for the current context for completions.
CXString ContainerUSR;
-
+ /// \brief a boolean value indicating whether there is complete information
+ /// about the container
unsigned ContainerIsIncomplete;
+
+ /// \brief A string containing the Objective-C selector entered thus far for a
+ /// message send.
+ std::string Selector;
};
/// \brief Tracks the number of code-completion result objects that are
AllocatedResults.ContextKind = contextKind;
AllocatedResults.Contexts = getContextsForContextKind(contextKind, S);
+ AllocatedResults.Selector = "";
+ if (Context.getNumSelIdents() > 0) {
+ for (unsigned i = 0; i < Context.getNumSelIdents(); i++) {
+ IdentifierInfo *selIdent = Context.getSelIdents()[i];
+ if (selIdent != NULL) {
+ StringRef selectorString = Context.getSelIdents()[i]->getName();
+ AllocatedResults.Selector += selectorString.str();
+ }
+ AllocatedResults.Selector += ":";
+ }
+ }
+
QualType baseType = Context.getBaseType();
NamedDecl *D = NULL;
}
pchName.push_back('\0');
struct stat stat_results;
- if (stat(pchName.data(), &stat_results) == 0)
+ if (stat(pchName.str().c_str(), &stat_results) == 0)
usesPCH = true;
continue;
}
return createCXString(clang_getCString(Results->ContainerUSR));
}
+
+
+CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *ResultsIn) {
+ AllocatedCXCodeCompleteResults *Results =
+ static_cast<AllocatedCXCodeCompleteResults *>(ResultsIn);
+ if (!Results)
+ return createCXString("");
+
+ return createCXString(Results->Selector);
+}
} // end extern "C"
_clang_codeCompleteGetContainerKind
_clang_codeCompleteGetContainerUSR
_clang_codeCompleteGetContexts
+_clang_codeCompleteGetObjCSelector
_clang_constructUSR_ObjCCategory
_clang_constructUSR_ObjCClass
_clang_constructUSR_ObjCIvar
clang_codeCompleteGetContainerKind
clang_codeCompleteGetContainerUSR
clang_codeCompleteGetContexts
+clang_codeCompleteGetObjCSelector
clang_constructUSR_ObjCCategory
clang_constructUSR_ObjCClass
clang_constructUSR_ObjCIvar