diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-03-27 23:34:16 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-03-27 23:34:16 +0000 |
commit | ba1030698dbc276db86b11c5329a1edee8a1805e (patch) | |
tree | 05795b249632407ea75e576411c56c9078255b80 /tools | |
parent | 2259286fc5c1514089b17ec93e26ca56ba8ac2b6 (diff) |
Introduce a new libclang API to determine the parent context of a code
completion item. For example, if the code completion itself represents
a declaration in a namespace (say, std::vector), then this API
retrieves the cursor kind and name of the namespace (std). Implements
<rdar://problem/11121951>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153545 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/c-index-test/c-index-test.c | 17 | ||||
-rw-r--r-- | tools/libclang/CIndexCodeCompletion.cpp | 16 | ||||
-rw-r--r-- | tools/libclang/libclang.exports | 1 |
3 files changed, 32 insertions, 2 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 67de8508cd..39bb8ebed0 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -1082,7 +1082,9 @@ void print_completion_result(CXCompletionResult *completion_result, FILE *file = (FILE *)client_data; CXString ks = clang_getCursorKindSpelling(completion_result->CursorKind); unsigned annotationCount; - + enum CXCursorKind ParentKind; + CXString ParentName; + fprintf(file, "%s:", clang_getCString(ks)); clang_disposeString(ks); @@ -1121,6 +1123,19 @@ void print_completion_result(CXCompletionResult *completion_result, fprintf(file, ")"); } + if (!getenv("CINDEXTEST_NO_COMPLETION_PARENTS")) { + ParentName = clang_getCompletionParent(completion_result->CompletionString, + &ParentKind); + if (ParentKind != CXCursor_NotImplemented) { + CXString KindSpelling = clang_getCursorKindSpelling(ParentKind); + fprintf(file, " (parent: %s '%s')", + clang_getCString(KindSpelling), + clang_getCString(ParentName)); + clang_disposeString(KindSpelling); + } + clang_disposeString(ParentName); + } + fprintf(file, "\n"); } diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp index 10f2411320..1b4a7e4800 100644 --- a/tools/libclang/CIndexCodeCompletion.cpp +++ b/tools/libclang/CIndexCodeCompletion.cpp @@ -213,7 +213,21 @@ CXString clang_getCompletionAnnotation(CXCompletionString completion_string, : createCXString((const char *) 0); } - +CXString +clang_getCompletionParent(CXCompletionString completion_string, + CXCursorKind *kind) { + if (kind) + *kind = CXCursor_NotImplemented; + + CodeCompletionString *CCStr = (CodeCompletionString *)completion_string; + if (!CCStr) + return createCXString((const char *)0); + + if (kind) + *kind = CCStr->getParentContextKind(); + return createCXString(CCStr->getParentContextName(), /*DupString=*/false); +} + /// \brief The CXCodeCompleteResults structure we allocate internally; /// the client only sees the initial CXCodeCompleteResults structure. struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults { diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index 1900ac86c0..afdb0c90bc 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -65,6 +65,7 @@ clang_getCompletionChunkCompletionString clang_getCompletionChunkKind clang_getCompletionChunkText clang_getCompletionNumAnnotations +clang_getCompletionParent clang_getCompletionPriority clang_getCursor clang_getCursorAvailability |