Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[clangd] Add CodePatterns config option under Completion #137613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! [clangd] Add CodePatterns config option under Completion
Fix the #include preprocessor not autocompleting when CodePatterns is
set to None
  • Loading branch information
Noustaa committed May 5, 2025
commit a1432e369b6db61615114553085bd7b2d8b95f8c
6 changes: 4 additions & 2 deletions 6 clang-tools-extra/clangd/CodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,8 @@ struct CompletionRecorder : public CodeCompleteConsumer {
// FIXME: in case there is no future sema completion callback after the
// recovery mode, we might still want to provide some results (e.g. trivial
// identifier-based completion).
if (Context.getKind() == CodeCompletionContext::CCC_Recovery) {
CodeCompletionContext::Kind ContextKind = Context.getKind();
if (ContextKind == CodeCompletionContext::CCC_Recovery) {
log("Code complete: Ignoring sema code complete callback with Recovery "
"context.");
return;
Expand All @@ -952,7 +953,8 @@ struct CompletionRecorder : public CodeCompleteConsumer {
auto &Result = InResults[I];
if (Config::current().Completion.CodePatterns ==
Config::CodePatternsPolicy::None &&
Result.Kind == CodeCompletionResult::RK_Pattern)
Result.Kind == CodeCompletionResult::RK_Pattern &&
ContextKind != CodeCompletionContext::CCC_IncludedFile)
Noustaa marked this conversation as resolved.
Show resolved Hide resolved
continue;
// Class members that are shadowed by subclasses are usually noise.
if (Result.Hidden && Result.Declaration &&
Expand Down
16 changes: 16 additions & 0 deletions 16 clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3344,6 +3344,22 @@ TEST(CompletionTest, NoCodePatternsIfDisabled) {
Not(Contains(kind(CompletionItemKind::Snippet))));
}

TEST(CompletionTest, CompleteIncludeIfCodePatternsNone) {
clangd::CodeCompleteOptions Opts = {};
Opts.EnableSnippets = true;
Opts.CodePatterns = Config::CodePatternsPolicy::None;

Annotations Test(R"cpp(#include "^)cpp");
auto TU = TestTU::withCode(Test.code());
TU.AdditionalFiles["foo/bar.h"] = "";
TU.ExtraArgs.push_back("-I" + testPath("foo"));

auto Results = completions(TU, Test.point(), {}, Opts);
EXPECT_THAT(Results.Completions,
AllOf(has("foo/", CompletionItemKind::Folder),
has("bar.h\"", CompletionItemKind::File)));
}

TEST(CompletionTest, NoQualifierIfShadowed) {
clangd::CodeCompleteOptions Opts = {};
Opts.AllScopes = true;
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.