Author: Nathan Ridge Date: 2024-12-30T20:49:26-05:00 New Revision: fe1f64e7e935c9905a115842183ea29dd1312dfe
URL: https://github.com/llvm/llvm-project/commit/fe1f64e7e935c9905a115842183ea29dd1312dfe DIFF: https://github.com/llvm/llvm-project/commit/fe1f64e7e935c9905a115842183ea29dd1312dfe.diff LOG: [clangd] Make EnableFunctionArgSnippets option string-typed (#121178) Fixes https://github.com/clangd/clangd/issues/2232 Added: Modified: clang-tools-extra/clangd/tool/ClangdMain.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp index 80a0653f8f7404..714891703b6f31 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{ @@ -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; @@ -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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits