forked from OSchip/llvm-project
[libclang] Allow code-completion when pointing at the end-of-file.
llvm-svn: 220135
This commit is contained in:
parent
2b67fca033
commit
e62d682a27
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#define CAKE 1
|
||||
|
||||
typedef int foo;
|
|
@ -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}
|
Loading…
Reference in New Issue