aboutsummaryrefslogtreecommitdiff
path: root/clang/tools
diff options
context:
space:
mode:
authorEgor Zhdan <e_zhdan@apple.com>2022-10-31 15:46:43 -0700
committerEgor Zhdan <e_zhdan@apple.com>2022-11-10 16:16:36 -0800
commit97105e5bf70fae5d9902081e917fd178b57f1717 (patch)
tree69abfc900d49fe1402fc69aeb0769e7e96fc0ffc /clang/tools
parent48321eea9679e1d8c5a30f4027e1aa49738aebf3 (diff)
downloadllvm-97105e5bf70fae5d9902081e917fd178b57f1717.zip
llvm-97105e5bf70fae5d9902081e917fd178b57f1717.tar.gz
llvm-97105e5bf70fae5d9902081e917fd178b57f1717.tar.bz2
[libclang] Expose completion result kind in `CXCompletionResult`
This allows clients of libclang to check whether a completion result is a keyword. Previously, keywords had `CursorKind == CXCursor_NotImplemented` and it wasn't trivial to distinguish a keyword from a pattern. This change moves `CodeCompletionResult::ResultKind` to `clang-c` under a new name `CXCompletionResultKind`. It also tweaks `c-index-test` to print the result kind instead of `NotImplemented`, and adjusts the tests for the new output. rdar://91852088 Differential Revision: https://reviews.llvm.org/D136844
Diffstat (limited to 'clang/tools')
-rw-r--r--clang/tools/c-index-test/c-index-test.c5
-rw-r--r--clang/tools/libclang/CIndex.cpp16
-rw-r--r--clang/tools/libclang/CIndexCodeCompletion.cpp15
-rw-r--r--clang/tools/libclang/libclang.map5
4 files changed, 40 insertions, 1 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 108b445..4d49dfa 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -2512,7 +2512,10 @@ static void print_completion_result(CXTranslationUnit translation_unit,
unsigned index,
FILE *file) {
CXCompletionResult *completion_result = completion_results->Results + index;
- CXString ks = clang_getCursorKindSpelling(completion_result->CursorKind);
+ CXString ks =
+ completion_result->CursorKind == CXCursor_NotImplemented
+ ? clang_getCompletionResultKindSpelling(completion_result->ResultKind)
+ : clang_getCursorKindSpelling(completion_result->CursorKind);
unsigned annotationCount;
enum CXCursorKind ParentKind;
CXString ParentName;
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index ee67735..0f47a6c 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -5403,6 +5403,22 @@ CXString clang_getCursorDisplayName(CXCursor C) {
return clang_getCursorSpelling(C);
}
+CXString
+clang_getCompletionResultKindSpelling(enum CXCompletionResultKind Kind) {
+ switch (Kind) {
+ case CXCompletionResult_Declaration:
+ return cxstring::createRef("Declaration");
+ case CXCompletionResult_Keyword:
+ return cxstring::createRef("Keyword");
+ case CXCompletionResult_Macro:
+ return cxstring::createRef("Macro");
+ case CXCompletionResult_Pattern:
+ return cxstring::createRef("Pattern");
+ }
+
+ llvm_unreachable("Unhandled CXCompletionResultKind");
+}
+
CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
switch (Kind) {
case CXCursor_FunctionDecl:
diff --git a/clang/tools/libclang/CIndexCodeCompletion.cpp b/clang/tools/libclang/CIndexCodeCompletion.cpp
index 0d75970..9cfa710 100644
--- a/clang/tools/libclang/CIndexCodeCompletion.cpp
+++ b/clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -586,6 +586,20 @@ namespace {
includeBriefComments());
CXCompletionResult R;
+ switch (Results[I].Kind) {
+ case CodeCompletionResult::RK_Declaration:
+ R.ResultKind = CXCompletionResult_Declaration;
+ break;
+ case CodeCompletionResult::RK_Keyword:
+ R.ResultKind = CXCompletionResult_Keyword;
+ break;
+ case CodeCompletionResult::RK_Macro:
+ R.ResultKind = CXCompletionResult_Macro;
+ break;
+ case CodeCompletionResult::RK_Pattern:
+ R.ResultKind = CXCompletionResult_Pattern;
+ break;
+ }
R.CursorKind = Results[I].CursorKind;
R.CompletionString = StoredCompletion;
StoredResults.push_back(R);
@@ -666,6 +680,7 @@ namespace {
includeBriefComments(), Braced);
CXCompletionResult R;
+ R.ResultKind = CXCompletionResult_Declaration;
R.CursorKind = CXCursor_OverloadCandidate;
R.CompletionString = StoredCompletion;
StoredResults.push_back(R);
diff --git a/clang/tools/libclang/libclang.map b/clang/tools/libclang/libclang.map
index 331ad57..41603b4 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -4,6 +4,11 @@
# On platforms where versions scripts are not used, this file will be used to
# generate a list of exports for libclang.so
+LLVM_15 {
+ global:
+ clang_getCompletionResultKindSpelling;
+};
+
LLVM_13 {
global:
clang_BlockCommandComment_getArgText;