kadircet created this revision. kadircet added reviewers: hokein, kbobyrev. Herald added subscribers: usaxena95, arphaman. kadircet requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang.
Fixes https://github.com/clangd/clangd/issues/433 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D95419 Files: clang-tools-extra/clangd/CodeComplete.cpp clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -2573,7 +2573,7 @@ } TEST(CompletionTest, IncludedCompletionKinds) { - Annotations Test(R"cpp(#include "^")cpp"); + Annotations Test(R"cpp(#include "^)cpp"); auto TU = TestTU::withCode(Test.code()); TU.AdditionalFiles["sub/bar.h"] = ""; TU.ExtraArgs.push_back("-I" + testPath("sub")); Index: clang-tools-extra/clangd/CodeComplete.cpp =================================================================== --- clang-tools-extra/clangd/CodeComplete.cpp +++ clang-tools-extra/clangd/CodeComplete.cpp @@ -1123,7 +1123,11 @@ // skip all includes in this case; these completions are really simple. PreambleBounds PreambleRegion = ComputePreambleBounds(*CI->getLangOpts(), *ContentsBuffer, 0); - bool CompletingInPreamble = PreambleRegion.Size > Input.Offset; + // If preamble doesn't end on a new line, include the following byte in + // preamble to enable include completion on a new file. e.g: #include "^ + bool CompletingInPreamble = + PreambleRegion.Size + !PreambleRegion.PreambleEndsAtStartOfLine > + Input.Offset; if (Input.Patch) Input.Patch->apply(*CI); // NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -2573,7 +2573,7 @@ } TEST(CompletionTest, IncludedCompletionKinds) { - Annotations Test(R"cpp(#include "^")cpp"); + Annotations Test(R"cpp(#include "^)cpp"); auto TU = TestTU::withCode(Test.code()); TU.AdditionalFiles["sub/bar.h"] = ""; TU.ExtraArgs.push_back("-I" + testPath("sub")); Index: clang-tools-extra/clangd/CodeComplete.cpp =================================================================== --- clang-tools-extra/clangd/CodeComplete.cpp +++ clang-tools-extra/clangd/CodeComplete.cpp @@ -1123,7 +1123,11 @@ // skip all includes in this case; these completions are really simple. PreambleBounds PreambleRegion = ComputePreambleBounds(*CI->getLangOpts(), *ContentsBuffer, 0); - bool CompletingInPreamble = PreambleRegion.Size > Input.Offset; + // If preamble doesn't end on a new line, include the following byte in + // preamble to enable include completion on a new file. e.g: #include "^ + bool CompletingInPreamble = + PreambleRegion.Size + !PreambleRegion.PreambleEndsAtStartOfLine > + Input.Offset; if (Input.Patch) Input.Patch->apply(*CI); // NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits