summaryrefslogtreecommitdiffstats
path: root/clang/tools/c-index-test
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2018-06-13 12:37:08 +0000
committerIvan Donchevskii <ivan.donchevskii@qt.io>2018-06-13 12:37:08 +0000
commit3957e48a68d163ed08d3105803feb5e836bc4822 (patch)
treeb1210de954c5e1177b6c77f13a2480c11caa88e9 /clang/tools/c-index-test
parentb983ac6fe1d90b8d117c5e08054bf5a0b160c3a7 (diff)
downloadbcm5719-llvm-3957e48a68d163ed08d3105803feb5e836bc4822.tar.gz
bcm5719-llvm-3957e48a68d163ed08d3105803feb5e836bc4822.zip
[libclang] Optionally add code completion results for arrow instead of dot
Follow up for D41537 - libclang part. Differential Revision: https://reviews.llvm.org/D46862 llvm-svn: 334593
Diffstat (limited to 'clang/tools/c-index-test')
-rw-r--r--clang/tools/c-index-test/c-index-test.c50
1 files changed, 45 insertions, 5 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index e86a20b55b6..50fea5ba8ba 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -2270,8 +2270,33 @@ static void print_completion_string(CXCompletionString completion_string,
}
-static void print_completion_result(CXCompletionResult *completion_result,
+static void print_line_column(CXSourceLocation location, FILE *file) {
+ unsigned line, column;
+ clang_getExpansionLocation(location, NULL, &line, &column, NULL);
+ fprintf(file, "%d:%d", line, column);
+}
+
+static void print_token_range(CXTranslationUnit translation_unit,
+ CXSourceLocation start, FILE *file) {
+ CXToken *token = clang_getToken(translation_unit, start);
+
+ fprintf(file, "{");
+ if (token != NULL) {
+ CXSourceRange token_range = clang_getTokenExtent(translation_unit, *token);
+ print_line_column(clang_getRangeStart(token_range), file);
+ fprintf(file, "-");
+ print_line_column(clang_getRangeEnd(token_range), file);
+ clang_disposeTokens(translation_unit, token, 1);
+ }
+
+ fprintf(file, "}");
+}
+
+static void print_completion_result(CXTranslationUnit translation_unit,
+ CXCodeCompleteResults *completion_results,
+ unsigned index,
FILE *file) {
+ CXCompletionResult *completion_result = completion_results->Results + index;
CXString ks = clang_getCursorKindSpelling(completion_result->CursorKind);
unsigned annotationCount;
enum CXCursorKind ParentKind;
@@ -2339,7 +2364,20 @@ static void print_completion_result(CXCompletionResult *completion_result,
fprintf(file, "(brief comment: %s)", BriefCommentCString);
}
clang_disposeString(BriefComment);
-
+
+ unsigned i;
+ for (i = 0; i < clang_getCompletionNumFixIts(completion_results, index);
+ ++i) {
+ CXSourceRange correction_range;
+ CXString FixIt = clang_getCompletionFixIt(completion_results, index, i,
+ &correction_range);
+ fprintf(file, " (requires fix-it: ");
+ print_token_range(translation_unit, clang_getRangeStart(correction_range),
+ file);
+ fprintf(file, " to \"%s\")", clang_getCString(FixIt));
+ clang_disposeString(FixIt);
+ }
+
fprintf(file, "\n");
}
@@ -2438,6 +2476,8 @@ int perform_code_completion(int argc, const char **argv, int timing_only) {
completionOptions |= CXCodeComplete_IncludeBriefComments;
if (getenv("CINDEXTEST_COMPLETION_SKIP_PREAMBLE"))
completionOptions |= CXCodeComplete_SkipPreamble;
+ if (getenv("CINDEXTEST_COMPLETION_INCLUDE_FIXITS"))
+ completionOptions |= CXCodeComplete_IncludeCompletionsWithFixIts;
if (timing_only)
input += strlen("-code-completion-timing=");
@@ -2502,7 +2542,7 @@ int perform_code_completion(int argc, const char **argv, int timing_only) {
clang_sortCodeCompletionResults(results->Results, results->NumResults);
for (i = 0; i != n; ++i)
- print_completion_result(results->Results + i, stdout);
+ print_completion_result(TU, results, i, stdout);
}
n = clang_codeCompleteGetNumDiagnostics(results);
for (i = 0; i != n; ++i) {
@@ -4402,10 +4442,10 @@ static void printLocation(CXSourceLocation L) {
CXFile File;
CXString FileName;
unsigned line, column, offset;
-
+
clang_getExpansionLocation(L, &File, &line, &column, &offset);
FileName = clang_getFileName(File);
-
+
fprintf(stderr, "%s:%d:%d", clang_getCString(FileName), line, column);
clang_disposeString(FileName);
}
OpenPOWER on IntegriCloud