[clang-tools-extra] [clangd] `--header-insertion` CLI fix (PR #146235)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 28 12:42:52 PDT 2025
https://github.com/MythreyaK created https://github.com/llvm/llvm-project/pull/146235
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](https://github.com/llvm/llvm-project/pull/128503#issuecomment-2823259618)!
>From 41987cabfbbc951f46d62b17cbd6ddb4118e62e5 Mon Sep 17 00:00:00 2001
From: Mythreya Kuricheti <git at mythreya.dev>
Date: Sat, 28 Jun 2025 12:27:36 -0700
Subject: [PATCH] [clangd] `--header-insertion` CLI fix
In PR #128503, CLI option overwrites only if it
was set to `never`. This commit ensures that CLI
options always overwrite any config option.
---
clang-tools-extra/clangd/tool/ClangdMain.cpp | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
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;
More information about the cfe-commits
mailing list