[libclang] Allow code-completion when pointing at the end-of-file.

llvm-svn: 220135
This commit is contained in:
Argyrios Kyrtzidis 2014-10-18 06:19:36 +00:00
parent 2b67fca033
commit e62d682a27
3 changed files with 20 additions and 13 deletions

View File

@ -384,21 +384,20 @@ bool Preprocessor::SetCodeCompletionPoint(const FileEntry *File,
}
Position += CompleteColumn - 1;
if (Position > Buffer->getBufferEnd())
Position = Buffer->getBufferEnd();
// Insert '\0' at the code-completion point.
if (Position < Buffer->getBufferEnd()) {
CodeCompletionFile = File;
CodeCompletionOffset = Position - Buffer->getBufferStart();
CodeCompletionFile = File;
CodeCompletionOffset = Position - Buffer->getBufferStart();
std::unique_ptr<MemoryBuffer> NewBuffer =
MemoryBuffer::getNewUninitMemBuffer(Buffer->getBufferSize() + 1,
Buffer->getBufferIdentifier());
char *NewBuf = const_cast<char*>(NewBuffer->getBufferStart());
char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf);
*NewPos = '\0';
std::copy(Position, Buffer->getBufferEnd(), NewPos+1);
SourceMgr.overrideFileContents(File, std::move(NewBuffer));
}
std::unique_ptr<MemoryBuffer> NewBuffer =
MemoryBuffer::getNewUninitMemBuffer(Buffer->getBufferSize() + 1,
Buffer->getBufferIdentifier());
char *NewBuf = const_cast<char*>(NewBuffer->getBufferStart());
char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf);
*NewPos = '\0';
std::copy(Position, Buffer->getBufferEnd(), NewPos+1);
SourceMgr.overrideFileContents(File, std::move(NewBuffer));
return false;
}

View File

@ -0,0 +1,3 @@
#define CAKE 1
typedef int foo;

View File

@ -0,0 +1,5 @@
// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test \
// 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}