Skip to content

Commit 64cdba6

Browse files
committed
[clangd] Fix filename completion at the end of file
Fixes clangd/clangd#433 Differential Revision: https://reviews.llvm.org/D95419
1 parent 9338f3a commit 64cdba6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,9 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
11231123
// skip all includes in this case; these completions are really simple.
11241124
PreambleBounds PreambleRegion =
11251125
ComputePreambleBounds(*CI->getLangOpts(), *ContentsBuffer, 0);
1126-
bool CompletingInPreamble = PreambleRegion.Size > Input.Offset;
1126+
bool CompletingInPreamble = Input.Offset < PreambleRegion.Size ||
1127+
(!PreambleRegion.PreambleEndsAtStartOfLine &&
1128+
Input.Offset == PreambleRegion.Size);
11271129
if (Input.Patch)
11281130
Input.Patch->apply(*CI);
11291131
// NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2573,7 +2573,7 @@ TEST(SignatureHelpTest, ConstructorInitializeFields) {
25732573
}
25742574

25752575
TEST(CompletionTest, IncludedCompletionKinds) {
2576-
Annotations Test(R"cpp(#include "^")cpp");
2576+
Annotations Test(R"cpp(#include "^)cpp");
25772577
auto TU = TestTU::withCode(Test.code());
25782578
TU.AdditionalFiles["sub/bar.h"] = "";
25792579
TU.ExtraArgs.push_back("-I" + testPath("sub"));

0 commit comments

Comments
 (0)