Skip to content

Commit 418a56b

Browse files
[clangd] Make EnableFunctionArgSnippets option string-typed
Fixes clangd/clangd#2232
1 parent d77cab8 commit 418a56b

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,13 @@ opt<std::string> FallbackStyle{
242242
init(clang::format::DefaultFallbackStyle),
243243
};
244244

245-
opt<int> EnableFunctionArgSnippets{
245+
opt<std::string> EnableFunctionArgSnippets{
246246
"function-arg-placeholders",
247247
cat(Features),
248248
desc("When disabled (0), completions contain only parentheses for "
249249
"function calls. When enabled (1), completions also contain "
250250
"placeholders for method parameters"),
251-
init(-1),
251+
init("-1"),
252252
};
253253

254254
opt<CodeCompleteOptions::IncludeInsertion> HeaderInsertion{
@@ -635,6 +635,22 @@ loadExternalIndex(const Config::ExternalIndexSpec &External,
635635
llvm_unreachable("Invalid ExternalIndexKind.");
636636
}
637637

638+
std::optional<bool> shouldEnableFunctionArgSnippets() {
639+
std::string Val = EnableFunctionArgSnippets;
640+
// Accept the same values that a bool option parser would, but also accept
641+
// -1 to indicate "unspecified", in which case the ArgumentListsPolicy
642+
// config option will be respected.
643+
if (Val == "1" || Val == "true" || Val == "True" || Val == "TRUE")
644+
return true;
645+
if (Val == "0" || Val == "false" || Val == "False" || Val == "FALSE")
646+
return false;
647+
if (Val != "-1")
648+
elog("Value specified by --function-arg-placeholders is invalid. Provide a "
649+
"boolean value or leave unspecified to use ArgumentListsPolicy from "
650+
"config instead.");
651+
return std::nullopt;
652+
}
653+
638654
class FlagsConfigProvider : public config::Provider {
639655
private:
640656
config::CompiledFragment Frag;
@@ -695,10 +711,9 @@ class FlagsConfigProvider : public config::Provider {
695711
BGPolicy = Config::BackgroundPolicy::Skip;
696712
}
697713

698-
if (EnableFunctionArgSnippets >= 0) {
699-
ArgumentLists = EnableFunctionArgSnippets
700-
? Config::ArgumentListsPolicy::FullPlaceholders
701-
: Config::ArgumentListsPolicy::Delimiters;
714+
if (std::optional<bool> Enable = shouldEnableFunctionArgSnippets()) {
715+
ArgumentLists = *Enable ? Config::ArgumentListsPolicy::FullPlaceholders
716+
: Config::ArgumentListsPolicy::Delimiters;
702717
}
703718

704719
Frag = [=](const config::Params &, Config &C) {

0 commit comments

Comments
 (0)