https://github.com/HighCommander4 created https://github.com/llvm/llvm-project/pull/121178
Fixes https://github.com/clangd/clangd/issues/2232 >From 418a56b8e5bbdf479e427a1c3058022b5aacb74b Mon Sep 17 00:00:00 2001 From: Nathan Ridge <zeratul...@hotmail.com> Date: Thu, 26 Dec 2024 23:23:00 -0500 Subject: [PATCH] [clangd] Make EnableFunctionArgSnippets option string-typed Fixes https://github.com/clangd/clangd/issues/2232 --- clang-tools-extra/clangd/tool/ClangdMain.cpp | 27 +++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp index cc061e2d932314..d89b4d81d830d0 100644 --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -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{ @@ -635,6 +635,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; @@ -695,10 +711,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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits