Skip to content

Commit b9710d1

Browse files
committed
Address review comments
1 parent 60ffbf0 commit b9710d1

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
455455
CodeCompleteOpts.MainFileSignals = IP->Signals;
456456
CodeCompleteOpts.AllScopes = Config::current().Completion.AllScopes;
457457
CodeCompleteOpts.ArgumentLists = Config::current().Completion.ArgumentLists;
458-
CodeCompleteOpts.InsertIncludes = Config::current().HeaderInsertion.Policy;
458+
CodeCompleteOpts.InsertIncludes =
459+
Config::current().Completion.HeaderInsertion;
459460
// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
460461
// both the old and the new version in case only one of them matches.
461462
CodeCompleteResult Result = clangd::codeComplete(

clang-tools-extra/clangd/Config.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,22 @@ struct Config {
147147
FullPlaceholders,
148148
};
149149

150+
enum class HeaderInsertionPolicy {
151+
IWYU, // Include what you use
152+
NeverInsert // Never insert headers as part of code completion
153+
};
154+
150155
/// Configures code completion feature.
151156
struct {
152157
/// Whether code completion includes results that are not visible in current
153158
/// scopes.
154159
bool AllScopes = true;
155160
/// controls the completion options for argument lists.
156161
ArgumentListsPolicy ArgumentLists = ArgumentListsPolicy::FullPlaceholders;
162+
/// Controls if headers should be inserted when completions are accepted
163+
HeaderInsertionPolicy HeaderInsertion = HeaderInsertionPolicy::IWYU;
157164
} Completion;
158165

159-
enum class HeaderInsertionPolicy {
160-
IWYU, // Include what you use
161-
NeverInsert // Never insert headers as part of code completion
162-
};
163-
164-
struct {
165-
HeaderInsertionPolicy Policy = HeaderInsertionPolicy::IWYU;
166-
} HeaderInsertion;
167-
168166
/// Configures hover feature.
169167
struct {
170168
/// Whether hover show a.k.a type.

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ struct FragmentCompiler {
705705
.map("Never", Config::HeaderInsertionPolicy::NeverInsert)
706706
.value())
707707
Out.Apply.push_back([Val](const Params &, Config &C) {
708-
C.HeaderInsertion.Policy = *Val;
708+
C.Completion.HeaderInsertion = *Val;
709709
});
710710
}
711711
}

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ class FlagsConfigProvider : public config::Provider {
668668
std::optional<Config::ExternalIndexSpec> IndexSpec;
669669
std::optional<Config::BackgroundPolicy> BGPolicy;
670670
std::optional<Config::ArgumentListsPolicy> ArgumentLists;
671+
std::optional<Config::HeaderInsertionPolicy> _HeaderInsertion;
671672

672673
// If --compile-commands-dir arg was invoked, check value and override
673674
// default path.
@@ -712,6 +713,11 @@ class FlagsConfigProvider : public config::Provider {
712713
BGPolicy = Config::BackgroundPolicy::Skip;
713714
}
714715

716+
// If CLI has set never, use that regardless of what the config files have
717+
if (HeaderInsertion == CodeCompleteOptions::IncludeInsertion::NeverInsert) {
718+
_HeaderInsertion = CodeCompleteOptions::IncludeInsertion::NeverInsert;
719+
}
720+
715721
if (std::optional<bool> Enable = shouldEnableFunctionArgSnippets()) {
716722
ArgumentLists = *Enable ? Config::ArgumentListsPolicy::FullPlaceholders
717723
: Config::ArgumentListsPolicy::Delimiters;
@@ -726,6 +732,8 @@ class FlagsConfigProvider : public config::Provider {
726732
C.Index.Background = *BGPolicy;
727733
if (ArgumentLists)
728734
C.Completion.ArgumentLists = *ArgumentLists;
735+
if (_HeaderInsertion)
736+
C.Completion.HeaderInsertion = *_HeaderInsertion;
729737
if (AllScopesCompletion.getNumOccurrences())
730738
C.Completion.AllScopes = AllScopesCompletion;
731739

0 commit comments

Comments
 (0)