<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br><div><div><br></div><div>On Jul 18, 2011, at 6:11 PM, Douglas Gregor wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi Connor,<br><br>On Jul 15, 2011, at 4:41 PM, Connor Wakamo wrote:<br><blockquote type="cite">I have another patch that I would like to submit for review.  This patch adds two new API functions to libclang to return the container type (for member accesses, Objective-C message sends, etc.) for the current code completion context.  Both functions take in a CXCodeCompleteResults to get the information that they return.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">The first function, clang_codeCompleteGetContainerTypeKind, returns a CXCursorKind for the container type.  Additionally, it returns via a parameter whether or not Clang sees the container type as incomplete.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">The second function, clang_codeCompleteGetContainerTypeUSR, returns a CXString with the USR for the container type.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Please let me know what changes I should make to my patch.<br></blockquote><br>Index: include/clang-c/Index.h<br>===================================================================<br>--- include/clang-c/Index.h<span class="Apple-tab-span" style="white-space:pre">   </span>(revision 134754)<br>+++ include/clang-c/Index.h<span class="Apple-tab-span" style="white-space:pre">      </span>(working copy)<br>@@ -3133,6 +3133,39 @@<br> CINDEX_LINKAGE<br> unsigned long long clang_codeCompleteGetContexts(<br>                                                 CXCodeCompleteResults *Results);<br>+<br>+/**<br>+ * \brief Returns the cursor kind for the container type for the current code<br>+ * completion context. The container type is only guaranteed to be set for<br>+ * contexts where a container type exists (i.e. member accesses or Objective-C<br>+ * message sends); if there is not a container type, this function will return<br>+ * CXCursor_InvalidCode.<br>+ *<br>+ * \param Results the code completion results to query<br>+ *<br>+ * \param IsIncomplete on return, this value will be false if Clang has complete<br>+ * type information about the container type. If Clang does not have complete<br>+ * type information, this value will be true.<br>+ *<br>+ * \returns the container type kind, or CXCursor_InvalidCode if there is not a<br>+ * container type<br>+ */<br>+CINDEX_LINKAGE<br>+enum CXCursorKind clang_codeCompleteGetContainerTypeKind(<br>+                                                 CXCodeCompleteResults *Results,<br>+                                                        unsigned *IsIncomplete);<br><br>Despite the internal representation (which is, basically, broken), the "container" of the code completion doesn't actually need a type, so I'd suggest removing references to "type" from the API and its documentation. The "container" could also be, for example, a C++ namespaces or the global scope, e.g.,<br><br><span class="Apple-tab-span" style="white-space:pre"> </span>namespace std {<br><span class="Apple-tab-span" style="white-space:pre">   </span><span class="Apple-tab-span" style="white-space:pre">    </span>template<typename T> class vector;<br><span class="Apple-tab-span" style="white-space:pre">  </span>}<br><br><span class="Apple-tab-span" style="white-space:pre">       </span>std::<complete here><br><br>the "container" here is the namespace "std". The code completion itself will go through Sema::CodeCompleteQualifiedId. It's okay not to update this particular completion point to support namespace containers, but the API should be general enough to support it.<br><br>+/**<br>+ * \brief Returns the USR for the container type for the current code completion<br>+ * context. If there is not a container type for the current context, this<br>+ * function will return the empty string.<br>+ *<br>+ * \param Results the code completion results to query<br>+ *<br>+ * \returns the USR for the container type<br>+ */<br>+CINDEX_LINKAGE<br>+CXString clang_codeCompleteGetContainerTypeUSR(CXCodeCompleteResults *Results);<br><br>Again, this isn't just about types.<br><br>Is there any way to write tests for this functionality? Perhaps some additional output in c-index-test giving the container and whether it's complete or not?<br><br><span class="Apple-tab-span" style="white-space:pre">     </span>- Doug</div></blockquote></div><br></div></body></html>