Skip to content

Commit a1432e3

Browse files
committed
fixup! [clangd] Add CodePatterns config option under Completion
Fix the #include preprocessor not autocompleting when CodePatterns is set to None
1 parent 7e71544 commit a1432e3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,8 @@ struct CompletionRecorder : public CodeCompleteConsumer {
926926
// FIXME: in case there is no future sema completion callback after the
927927
// recovery mode, we might still want to provide some results (e.g. trivial
928928
// identifier-based completion).
929-
if (Context.getKind() == CodeCompletionContext::CCC_Recovery) {
929+
CodeCompletionContext::Kind ContextKind = Context.getKind();
930+
if (ContextKind == CodeCompletionContext::CCC_Recovery) {
930931
log("Code complete: Ignoring sema code complete callback with Recovery "
931932
"context.");
932933
return;
@@ -952,7 +953,8 @@ struct CompletionRecorder : public CodeCompleteConsumer {
952953
auto &Result = InResults[I];
953954
if (Config::current().Completion.CodePatterns ==
954955
Config::CodePatternsPolicy::None &&
955-
Result.Kind == CodeCompletionResult::RK_Pattern)
956+
Result.Kind == CodeCompletionResult::RK_Pattern &&
957+
ContextKind != CodeCompletionContext::CCC_IncludedFile)
956958
continue;
957959
// Class members that are shadowed by subclasses are usually noise.
958960
if (Result.Hidden && Result.Declaration &&

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,6 +3344,22 @@ TEST(CompletionTest, NoCodePatternsIfDisabled) {
33443344
Not(Contains(kind(CompletionItemKind::Snippet))));
33453345
}
33463346

3347+
TEST(CompletionTest, CompleteIncludeIfCodePatternsNone) {
3348+
clangd::CodeCompleteOptions Opts = {};
3349+
Opts.EnableSnippets = true;
3350+
Opts.CodePatterns = Config::CodePatternsPolicy::None;
3351+
3352+
Annotations Test(R"cpp(#include "^)cpp");
3353+
auto TU = TestTU::withCode(Test.code());
3354+
TU.AdditionalFiles["foo/bar.h"] = "";
3355+
TU.ExtraArgs.push_back("-I" + testPath("foo"));
3356+
3357+
auto Results = completions(TU, Test.point(), {}, Opts);
3358+
EXPECT_THAT(Results.Completions,
3359+
AllOf(has("foo/", CompletionItemKind::Folder),
3360+
has("bar.h\"", CompletionItemKind::File)));
3361+
}
3362+
33473363
TEST(CompletionTest, NoQualifierIfShadowed) {
33483364
clangd::CodeCompleteOptions Opts = {};
33493365
Opts.AllScopes = true;

0 commit comments

Comments
 (0)