Skip to content

[clangd] --header-insertion CLI fix #146235

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

Conversation

MythreyaK
Copy link
Contributor

In PR #128503, CLI option overwrites only if it was set to never. This commit ensures that CLI options always overwrite any config option.

Thanks to the fix from @HighCommander4 here!

In PR llvm#128503, CLI option overwrites only if it
was set to `never`. This commit ensures that CLI
options always overwrite any config option.
@llvmbot
Copy link
Member

llvmbot commented Jun 28, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Mythreya (MythreyaK)

Changes

In PR #128503, CLI option overwrites only if it was set to never. This commit ensures that CLI options always overwrite any config option.

Thanks to the fix from @HighCommander4 here!


Full diff: https://github.com/llvm/llvm-project/pull/146235.diff

1 Files Affected:

  • (modified) clang-tools-extra/clangd/tool/ClangdMain.cpp (+2-8)
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index b11d194da04db..f287439f10cab 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -668,7 +668,6 @@ class FlagsConfigProvider : public config::Provider {
     std::optional<Config::ExternalIndexSpec> IndexSpec;
     std::optional<Config::BackgroundPolicy> BGPolicy;
     std::optional<Config::ArgumentListsPolicy> ArgumentLists;
-    std::optional<Config::HeaderInsertionPolicy> HeaderInsertionPolicy;
 
     // If --compile-commands-dir arg was invoked, check value and override
     // default path.
@@ -713,11 +712,6 @@ class FlagsConfigProvider : public config::Provider {
       BGPolicy = Config::BackgroundPolicy::Skip;
     }
 
-    // If CLI has set never, use that regardless of what the config files have
-    if (HeaderInsertion == Config::HeaderInsertionPolicy::NeverInsert) {
-      HeaderInsertionPolicy = Config::HeaderInsertionPolicy::NeverInsert;
-    }
-
     if (std::optional<bool> Enable = shouldEnableFunctionArgSnippets()) {
       ArgumentLists = *Enable ? Config::ArgumentListsPolicy::FullPlaceholders
                               : Config::ArgumentListsPolicy::Delimiters;
@@ -732,8 +726,8 @@ class FlagsConfigProvider : public config::Provider {
         C.Index.Background = *BGPolicy;
       if (ArgumentLists)
         C.Completion.ArgumentLists = *ArgumentLists;
-      if (HeaderInsertionPolicy)
-        C.Completion.HeaderInsertion = *HeaderInsertionPolicy;
+      if (HeaderInsertion.getNumOccurrences())
+        C.Completion.HeaderInsertion = HeaderInsertion;
       if (AllScopesCompletion.getNumOccurrences())
         C.Completion.AllScopes = AllScopesCompletion;
 

@llvmbot
Copy link
Member

llvmbot commented Jun 28, 2025

@llvm/pr-subscribers-clangd

Author: Mythreya (MythreyaK)

Changes

In PR #128503, CLI option overwrites only if it was set to never. This commit ensures that CLI options always overwrite any config option.

Thanks to the fix from @HighCommander4 here!


Full diff: https://github.com/llvm/llvm-project/pull/146235.diff

1 Files Affected:

  • (modified) clang-tools-extra/clangd/tool/ClangdMain.cpp (+2-8)
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index b11d194da04db..f287439f10cab 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -668,7 +668,6 @@ class FlagsConfigProvider : public config::Provider {
     std::optional<Config::ExternalIndexSpec> IndexSpec;
     std::optional<Config::BackgroundPolicy> BGPolicy;
     std::optional<Config::ArgumentListsPolicy> ArgumentLists;
-    std::optional<Config::HeaderInsertionPolicy> HeaderInsertionPolicy;
 
     // If --compile-commands-dir arg was invoked, check value and override
     // default path.
@@ -713,11 +712,6 @@ class FlagsConfigProvider : public config::Provider {
       BGPolicy = Config::BackgroundPolicy::Skip;
     }
 
-    // If CLI has set never, use that regardless of what the config files have
-    if (HeaderInsertion == Config::HeaderInsertionPolicy::NeverInsert) {
-      HeaderInsertionPolicy = Config::HeaderInsertionPolicy::NeverInsert;
-    }
-
     if (std::optional<bool> Enable = shouldEnableFunctionArgSnippets()) {
       ArgumentLists = *Enable ? Config::ArgumentListsPolicy::FullPlaceholders
                               : Config::ArgumentListsPolicy::Delimiters;
@@ -732,8 +726,8 @@ class FlagsConfigProvider : public config::Provider {
         C.Index.Background = *BGPolicy;
       if (ArgumentLists)
         C.Completion.ArgumentLists = *ArgumentLists;
-      if (HeaderInsertionPolicy)
-        C.Completion.HeaderInsertion = *HeaderInsertionPolicy;
+      if (HeaderInsertion.getNumOccurrences())
+        C.Completion.HeaderInsertion = HeaderInsertion;
       if (AllScopesCompletion.getNumOccurrences())
         C.Completion.AllScopes = AllScopesCompletion;
 

@MythreyaK
Copy link
Contributor Author

I tested these locally and seems to work as expected. Please do double-check, just in case I missed something!

config cli outcome
IWYU iwyu inserted
IWYU never not inserted
Never iwyu inserted
Never never not inserted
Never [no opt] not inserted
IWYU [no opt] inserted
[no opt] iwyu inserted
[no opt] never not inserted
[no opt] [no opt] inserted

Copy link
Collaborator

@HighCommander4 HighCommander4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@HighCommander4 HighCommander4 merged commit d2d5203 into llvm:main Jun 29, 2025
10 checks passed
@MythreyaK MythreyaK deleted the mythreyak/clangd-header-insert-cli-fix branch June 29, 2025 14:48
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 30, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-darwin running on doug-worker-3 while building clang-tools-extra at step 2 "checkout".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/23/builds/11723

Here is the relevant piece of the build log for the reference
Step 2 (checkout) failure: update (failure)
...
remote: Counting objects:  76% (65/85)        
remote: Counting objects:  77% (66/85)        
remote: Counting objects:  78% (67/85)        
remote: Counting objects:  80% (68/85)        
remote: Counting objects:  81% (69/85)        
remote: Counting objects:  82% (70/85)        
remote: Counting objects:  83% (71/85)        
remote: Counting objects:  84% (72/85)        
remote: Counting objects:  85% (73/85)        
remote: Counting objects:  87% (74/85)        
remote: Counting objects:  88% (75/85)        
remote: Counting objects:  89% (76/85)        
remote: Counting objects:  90% (77/85)        
remote: Counting objects:  91% (78/85)        
remote: Counting objects:  92% (79/85)        
remote: Counting objects:  94% (80/85)        
remote: Counting objects:  95% (81/85)        
remote: Counting objects:  96% (82/85)        
remote: Counting objects:  97% (83/85)        
remote: Counting objects:  98% (84/85)        
remote: Counting objects: 100% (85/85)        
remote: Counting objects: 100% (85/85), done.        
remote: Compressing objects:   4% (1/23)        
remote: Compressing objects:   8% (2/23)        
remote: Compressing objects:  13% (3/23)        
remote: Compressing objects:  17% (4/23)        
remote: Compressing objects:  21% (5/23)        
remote: Compressing objects:  26% (6/23)        
remote: Compressing objects:  30% (7/23)        
remote: Compressing objects:  34% (8/23)        
remote: Compressing objects:  39% (9/23)        
remote: Compressing objects:  43% (10/23)        
remote: Compressing objects:  47% (11/23)        
remote: Compressing objects:  52% (12/23)        
remote: Compressing objects:  56% (13/23)        
remote: Compressing objects:  60% (14/23)        
remote: Compressing objects:  65% (15/23)        
remote: Compressing objects:  69% (16/23)        
remote: Compressing objects:  73% (17/23)        
remote: Compressing objects:  78% (18/23)        
remote: Compressing objects:  82% (19/23)        
remote: Compressing objects:  86% (20/23)        
remote: Compressing objects:  91% (21/23)        
remote: Compressing objects:  95% (22/23)        
remote: Compressing objects: 100% (23/23)        
remote: Compressing objects: 100% (23/23), done.        
remote: Total 25 (delta 20), reused 4 (delta 2), pack-reused 0 (from 0)        
From https://github.com/llvm/llvm-project
 * branch                      main       -> FETCH_HEAD
fatal: reference is not a tree: d2d5203bf48af9b55b8e379c1c152fec97349340

@MythreyaK MythreyaK restored the mythreyak/clangd-header-insert-cli-fix branch June 30, 2025 02:28
@MythreyaK MythreyaK deleted the mythreyak/clangd-header-insert-cli-fix branch June 30, 2025 02:29
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
…erInsertion` (llvm#146235)

In PR llvm#128503, the CLI option would take precedence over the config option
only if it was set to `never`. This commit ensures the CLI option always takes
precedence over the config option.
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
…erInsertion` (llvm#146235)

In PR llvm#128503, the CLI option would take precedence over the config option
only if it was set to `never`. This commit ensures the CLI option always takes
precedence over the config option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants