r220135 - [libclang] Allow code-completion when pointing at the end-of-file.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Oct 17 23:19:36 PDT 2014
Author: akirtzidis
Date: Sat Oct 18 01:19:36 2014
New Revision: 220135
URL: http://llvm.org/viewvc/llvm-project?rev=220135&view=rev
Log:
[libclang] Allow code-completion when pointing at the end-of-file.
Added:
cfe/trunk/test/Index/Inputs/complete-at-EOF.c
cfe/trunk/test/Index/complete-at-EOF.c
Modified:
cfe/trunk/lib/Lex/Preprocessor.cpp
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=220135&r1=220134&r2=220135&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Sat Oct 18 01:19:36 2014
@@ -384,21 +384,20 @@ bool Preprocessor::SetCodeCompletionPoin
}
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;
}
Added: cfe/trunk/test/Index/Inputs/complete-at-EOF.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Inputs/complete-at-EOF.c?rev=220135&view=auto
==============================================================================
--- cfe/trunk/test/Index/Inputs/complete-at-EOF.c (added)
+++ cfe/trunk/test/Index/Inputs/complete-at-EOF.c Sat Oct 18 01:19:36 2014
@@ -0,0 +1,3 @@
+#define CAKE 1
+
+typedef int foo;
Added: cfe/trunk/test/Index/complete-at-EOF.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-at-EOF.c?rev=220135&view=auto
==============================================================================
--- cfe/trunk/test/Index/complete-at-EOF.c (added)
+++ cfe/trunk/test/Index/complete-at-EOF.c Sat Oct 18 01:19:36 2014
@@ -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}
More information about the cfe-commits
mailing list