[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.

llvm-svn: 220136
This commit is contained in:
Argyrios Kyrtzidis 2014-10-18 06:23:50 +00:00
parent e62d682a27
commit ee301f941c
2 changed files with 13 additions and 0 deletions

View 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();

View 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}