sammccall created this revision. sammccall added a reviewer: hokein. Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov. Herald added a project: clang.
Restricting the categories prevents extra unwanted options from creeping into help (D60663 <https://reviews.llvm.org/D60663>), and removes a bunch of noise from --help-hidden. While here, remove `static` from the opts in favor of an anon namespace, to reduce the noise level. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D65200 Files: clang-tools-extra/clangd/tool/ClangdMain.cpp
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp =================================================================== --- clang-tools-extra/clangd/tool/ClangdMain.cpp +++ clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -35,6 +35,7 @@ namespace clang { namespace clangd { +namespace { using llvm::cl::cat; using llvm::cl::CommaSeparated; @@ -43,25 +44,38 @@ using llvm::cl::init; using llvm::cl::list; using llvm::cl::opt; +using llvm::cl::OptionCategory; using llvm::cl::values; -static opt<Path> CompileCommandsDir{ +// All flags must be placed in a category, or they will be shown neither in +// --help, nor --help-hidden! +OptionCategory Features("clangd feature options"); +OptionCategory Protocol("clangd protocol and logging options"); +OptionCategory CompileCommands("clangd compilation flags options"); +OptionCategory Misc("clangd miscellaneous options"); +const OptionCategory *ClangdCategories[] = {&Features, &Protocol, + &CompileCommands, &Misc}; + +opt<Path> CompileCommandsDir{ "compile-commands-dir", + cat(CompileCommands), desc("Specify a path to look for compile_commands.json. If path " "is invalid, clangd will look in the current directory and " "parent paths of each source file"), }; -static opt<unsigned> WorkerThreadsCount{ +opt<unsigned> WorkerThreadsCount{ "j", + cat(Misc), desc("Number of async workers used by clangd"), init(getDefaultAsyncThreadsCount()), }; // FIXME: also support "plain" style where signatures are always omitted. enum CompletionStyleFlag { Detailed, Bundled }; -static opt<CompletionStyleFlag> CompletionStyle{ +opt<CompletionStyleFlag> CompletionStyle{ "completion-style", + cat(Features), desc("Granularity of code completion suggestions"), values(clEnumValN(Detailed, "detailed", "One completion item for each semantically distinct " @@ -73,15 +87,17 @@ // FIXME: Flags are the wrong mechanism for user preferences. // We should probably read a dotfile or similar. -static opt<bool> IncludeIneligibleResults{ +opt<bool> IncludeIneligibleResults{ "include-ineligible-results", + cat(Features), desc("Include ineligible completion results (e.g. private members)"), init(CodeCompleteOptions().IncludeIneligibleResults), Hidden, }; -static opt<JSONStreamStyle> InputStyle{ +opt<JSONStreamStyle> InputStyle{ "input-style", + cat(Protocol), desc("Input JSON stream encoding"), values( clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP protocol"), @@ -91,14 +107,16 @@ Hidden, }; -static opt<bool> PrettyPrint{ +opt<bool> PrettyPrint{ "pretty", + cat(Protocol), desc("Pretty-print JSON output"), init(false), }; -static opt<Logger::Level> LogLevel{ +opt<Logger::Level> LogLevel{ "log", + cat(Protocol), desc("Verbosity of log messages written to stderr"), values(clEnumValN(Logger::Error, "error", "Error messages only"), clEnumValN(Logger::Info, "info", "High level execution tracing"), @@ -106,25 +124,28 @@ init(Logger::Info), }; -static opt<bool> Test{ +opt<bool> Test{ "lit-test", + cat(Misc), desc("Abbreviation for -input-style=delimited -pretty -sync " - "-enable-test-scheme -log=verbose." + "-enable-test-scheme -log=verbose. " "Intended to simplify lit tests"), init(false), Hidden, }; -static opt<bool> EnableTestScheme{ +opt<bool> EnableTestScheme{ "enable-test-uri-scheme", + cat(Protocol), desc("Enable 'test:' URI scheme. Only use in lit tests"), init(false), Hidden, }; enum PCHStorageFlag { Disk, Memory }; -static opt<PCHStorageFlag> PCHStorage{ +opt<PCHStorageFlag> PCHStorage{ "pch-storage", + cat(Misc), desc("Storing PCHs in memory increases memory usages, but may " "improve performance"), values( @@ -133,36 +154,41 @@ init(PCHStorageFlag::Disk), }; -static opt<int> LimitResults{ +opt<int> LimitResults{ "limit-results", + cat(Features), desc("Limit the number of results returned by clangd. " "0 means no limit (default=100)"), init(100), }; -static opt<bool> Sync{ +opt<bool> Sync{ "sync", + cat(Misc), desc("Parse on main thread. If set, -j is ignored"), init(false), Hidden, }; -static opt<Path> ResourceDir{ +opt<Path> ResourceDir{ "resource-dir", + cat(CompileCommands), desc("Directory for system clang headers"), init(""), Hidden, }; -static opt<Path> InputMirrorFile{ +opt<Path> InputMirrorFile{ "input-mirror-file", + cat(Protocol), desc("Mirror all LSP input to the specified file. Useful for debugging"), init(""), Hidden, }; -static opt<bool> EnableIndex{ +opt<bool> EnableIndex{ "index", + cat(Features), desc("Enable index-based features. By default, clangd maintains an index " "built from symbols in opened files. Global index support needs to " "enabled separatedly"), @@ -170,8 +196,9 @@ Hidden, }; -static opt<bool> AllScopesCompletion{ +opt<bool> AllScopesCompletion{ "all-scopes-completion", + cat(Features), desc("If set to true, code completion will include index symbols that are " "not defined in the scopes (e.g. " "namespaces) visible from the code completion point. Such completions " @@ -179,15 +206,17 @@ init(true), }; -static opt<bool> ShowOrigins{ +opt<bool> ShowOrigins{ "debug-origin", + cat(Features), desc("Show origins of completion items"), init(CodeCompleteOptions().ShowOrigins), Hidden, }; -static opt<CodeCompleteOptions::IncludeInsertion> HeaderInsertion{ +opt<CodeCompleteOptions::IncludeInsertion> HeaderInsertion{ "header-insertion", + cat(Features), desc("Add #include directives when accepting code completions"), init(CodeCompleteOptions().InsertIncludes), values( @@ -201,16 +230,18 @@ "Never insert #include directives as part of code completion")), }; -static opt<bool> HeaderInsertionDecorators{ +opt<bool> HeaderInsertionDecorators{ "header-insertion-decorators", + cat(Features), desc("Prepend a circular dot or space before the completion " "label, depending on whether " "an include line will be inserted or not"), init(true), }; -static opt<Path> IndexFile{ +opt<Path> IndexFile{ "index-file", + cat(Misc), desc( "Index file to build the static index. The file must have been created " "by a compatible clangd-indexer\n" @@ -220,16 +251,18 @@ Hidden, }; -static opt<bool> EnableBackgroundIndex{ +opt<bool> EnableBackgroundIndex{ "background-index", + cat(Features), desc("Index project code in the background and persist index on disk. " "Experimental"), init(true), }; enum CompileArgsFrom { LSPCompileArgs, FilesystemCompileArgs }; -static opt<CompileArgsFrom> CompileArgsFrom{ +opt<CompileArgsFrom> CompileArgsFrom{ "compile_args_from", + cat(CompileCommands), desc("The source of compile commands"), values(clEnumValN(LSPCompileArgs, "lsp", "All compile commands come from LSP and " @@ -241,8 +274,9 @@ Hidden, }; -static opt<bool> EnableFunctionArgSnippets{ +opt<bool> EnableFunctionArgSnippets{ "function-arg-placeholders", + cat(Features), desc("When disabled, completions contain only parentheses for " "function calls. When enabled, completions also contain " "placeholders for method parameters"), @@ -250,35 +284,40 @@ Hidden, }; -static opt<std::string> ClangTidyChecks{ +opt<std::string> ClangTidyChecks{ "clang-tidy-checks", + cat(Features), desc("List of clang-tidy checks to run (this will override " ".clang-tidy files). Only meaningful when -clang-tidy flag is on"), init(""), }; -static opt<bool> EnableClangTidy{ +opt<bool> EnableClangTidy{ "clang-tidy", + cat(Features), desc("Enable clang-tidy diagnostics"), init(true), }; -static opt<std::string> FallbackStyle{ +opt<std::string> FallbackStyle{ "fallback-style", + cat(Features), desc("clang-format style to apply by default when " "no .clang-format file is found"), init(clang::format::DefaultFallbackStyle), }; -static opt<bool> SuggestMissingIncludes{ +opt<bool> SuggestMissingIncludes{ "suggest-missing-includes", + cat(Features), desc("Attempts to fix diagnostic errors caused by missing " "includes using index"), init(true), }; -static opt<OffsetEncoding> ForceOffsetEncoding{ +opt<OffsetEncoding> ForceOffsetEncoding{ "offset-encoding", + cat(Protocol), desc("Force the offsetEncoding used for character positions. " "This bypasses negotiation via client capabilities"), values( @@ -288,8 +327,9 @@ init(OffsetEncoding::UnsupportedEncoding), }; -static opt<CodeCompleteOptions::CodeCompletionParse> CodeCompletionParse{ +opt<CodeCompleteOptions::CodeCompletionParse> CodeCompletionParse{ "completion-parse", + cat(Features), desc("Whether the clang-parser is used for code-completion"), values(clEnumValN(CodeCompleteOptions::AlwaysParse, "always", "Block until the parser can be used"), @@ -302,15 +342,17 @@ Hidden, }; -static opt<bool> HiddenFeatures{ +opt<bool> HiddenFeatures{ "hidden-features", + cat(Features), desc("Enable hidden features mostly useful to clangd developers"), init(false), Hidden, }; -static list<std::string> QueryDriverGlobs{ +list<std::string> QueryDriverGlobs{ "query-driver", + cat(CompileCommands), desc( "Comma separated list of globs for white-listing gcc-compatible " "drivers that are safe to execute. Drivers matching any of these globs " @@ -319,15 +361,14 @@ CommaSeparated, }; -static list<std::string> TweakList{ +list<std::string> TweakList{ "tweaks", + cat(Features), desc("Specify a list of Tweaks to enable (only for clangd developers)."), Hidden, CommaSeparated, }; -namespace { - /// \brief Supports a test URI scheme with relaxed constraints for lit tests. /// The path in a test URI will be combined with a platform-specific fake /// directory to form an absolute path. For example, test:///a.cpp is resolved @@ -392,6 +433,7 @@ llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) { OS << clang::getClangToolFullVersion("clangd") << "\n"; }); + llvm::cl::HideUnrelatedOptions(ClangdCategories); llvm::cl::ParseCommandLineOptions( argc, argv, "clangd is a language server that provides IDE-like features to editors. "
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits