Skip to content

Commit

Permalink
[clangd] Make EnableFunctionArgSnippets option string-typed (llvm#121178
Browse files Browse the repository at this point in the history
  • Loading branch information
HighCommander4 authored Dec 31, 2024
1 parent 07e13b7 commit fe1f64e
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions clang-tools-extra/clangd/tool/ClangdMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ opt<std::string> FallbackStyle{
init(clang::format::DefaultFallbackStyle),
};

opt<int> EnableFunctionArgSnippets{
opt<std::string> EnableFunctionArgSnippets{
"function-arg-placeholders",
cat(Features),
desc("When disabled (0), completions contain only parentheses for "
"function calls. When enabled (1), completions also contain "
"placeholders for method parameters"),
init(-1),
init("-1"),
};

opt<CodeCompleteOptions::IncludeInsertion> HeaderInsertion{
Expand Down Expand Up @@ -636,6 +636,22 @@ loadExternalIndex(const Config::ExternalIndexSpec &External,
llvm_unreachable("Invalid ExternalIndexKind.");
}

std::optional<bool> shouldEnableFunctionArgSnippets() {
std::string Val = EnableFunctionArgSnippets;
// Accept the same values that a bool option parser would, but also accept
// -1 to indicate "unspecified", in which case the ArgumentListsPolicy
// config option will be respected.
if (Val == "1" || Val == "true" || Val == "True" || Val == "TRUE")
return true;
if (Val == "0" || Val == "false" || Val == "False" || Val == "FALSE")
return false;
if (Val != "-1")
elog("Value specified by --function-arg-placeholders is invalid. Provide a "
"boolean value or leave unspecified to use ArgumentListsPolicy from "
"config instead.");
return std::nullopt;
}

class FlagsConfigProvider : public config::Provider {
private:
config::CompiledFragment Frag;
Expand Down Expand Up @@ -696,10 +712,9 @@ class FlagsConfigProvider : public config::Provider {
BGPolicy = Config::BackgroundPolicy::Skip;
}

if (EnableFunctionArgSnippets >= 0) {
ArgumentLists = EnableFunctionArgSnippets
? Config::ArgumentListsPolicy::FullPlaceholders
: Config::ArgumentListsPolicy::Delimiters;
if (std::optional<bool> Enable = shouldEnableFunctionArgSnippets()) {
ArgumentLists = *Enable ? Config::ArgumentListsPolicy::FullPlaceholders
: Config::ArgumentListsPolicy::Delimiters;
}

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

0 comments on commit fe1f64e

Please sign in to comment.