Skip to content
Snippets Groups Projects
Commit 767b614f authored by Argyrios Kyrtzidis's avatar Argyrios Kyrtzidis
Browse files

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220135 91177308-0d34-0410-b5e6-96231b3b80d8
parent df77101c
No related branches found
No related tags found
No related merge requests found
......@@ -384,21 +384,20 @@ bool Preprocessor::SetCodeCompletionPoint(const FileEntry *File,
}
Position += CompleteColumn - 1;
// Insert '\0' at the code-completion point.
if (Position < Buffer->getBufferEnd()) {
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));
}
if (Position > Buffer->getBufferEnd())
Position = Buffer->getBufferEnd();
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));
return false;
}
......
#define CAKE 1
typedef int foo;
// 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}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment