r220136 - [libclang] If the code-completion point is inside the preamble, adjust the position at the beginning of the file after the preamble.

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Oct 17 23:23:50 PDT 2014


Author: akirtzidis
Date: Sat Oct 18 01:23:50 2014
New Revision: 220136

URL: http://llvm.org/viewvc/llvm-project?rev=220136&view=rev
Log:
[libclang] If the code-completion point is inside the preamble, adjust the position at the beginning of the file after the preamble.
    
Otherwise we will not hit the code-completion point.

Modified:
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/test/Index/complete-at-EOF.c

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=220136&r1=220135&r2=220136&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Sat Oct 18 01:23:50 2014
@@ -384,6 +384,15 @@ bool Preprocessor::SetCodeCompletionPoin
   }
 
   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();
 

Modified: cfe/trunk/test/Index/complete-at-EOF.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-at-EOF.c?rev=220136&r1=220135&r2=220136&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-at-EOF.c (original)
+++ cfe/trunk/test/Index/complete-at-EOF.c Sat Oct 18 01:23:50 2014
@@ -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}





More information about the cfe-commits mailing list