]> granicus.if.org Git - clang/commitdiff
[libclang] If the code-completion point is inside the preamble, adjust the position...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 18 Oct 2014 06:23:50 +0000 (06:23 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 18 Oct 2014 06:23:50 +0000 (06:23 +0000)
Otherwise we will not hit the code-completion point.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220136 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/Preprocessor.cpp
test/Index/complete-at-EOF.c

index c15a6ab956a792b9be97a8e519f142c4d98091b7..5da54aea30f730063e83aaf1d0f1ab2b99b4a3d7 100644 (file)
@@ -384,6 +384,15 @@ bool Preprocessor::SetCodeCompletionPoint(const FileEntry *File,
   }
 
   Position += CompleteColumn - 1;
+
+  // If pointing inside the preamble, adjust the position at the beginning of
+  // the file after the preamble.
+  if (SkipMainFilePreamble.first &&
+      SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()) == File) {
+    if (Position - Buffer->getBufferStart() < SkipMainFilePreamble.first)
+      Position = Buffer->getBufferStart() + SkipMainFilePreamble.first;
+  }
+
   if (Position > Buffer->getBufferEnd())
     Position = Buffer->getBufferEnd();
 
index ff39233f0a6fb8c190303dce518f24ef37180907..d039aaa1af18911575c9d5d3303b0afcfa2552fa 100644 (file)
@@ -3,3 +3,7 @@
 // RUN:            -code-completion-at=%S/Inputs/complete-at-EOF.c:4:1 %S/Inputs/complete-at-EOF.c | FileCheck -check-prefix=CHECK-EOF %s
 // CHECK-EOF: macro definition:{TypedText CAKE}
 // CHECK-EOF: TypedefDecl:{TypedText foo}
+
+// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test \
+// RUN:     -code-completion-at=%S/Inputs/complete-at-EOF.c:2:1 %S/Inputs/complete-at-EOF.c | FileCheck -check-prefix=CHECK-AFTER-PREAMBLE %s
+// CHECK-AFTER-PREAMBLE: macro definition:{TypedText CAKE}