diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/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 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 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 WorkerThreadsCount{ +opt 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 CompletionStyle{ +opt 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 IncludeIneligibleResults{ +opt IncludeIneligibleResults{ "include-ineligible-results", + cat(Features), desc("Include ineligible completion results (e.g. private members)"), init(CodeCompleteOptions().IncludeIneligibleResults), Hidden, }; -static opt InputStyle{ +opt 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 PrettyPrint{ +opt PrettyPrint{ "pretty", + cat(Protocol), desc("Pretty-print JSON output"), init(false), }; -static opt LogLevel{ +opt 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 Test{ +opt 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 EnableTestScheme{ +opt 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 PCHStorage{ +opt 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 LimitResults{ +opt LimitResults{ "limit-results", + cat(Features), desc("Limit the number of results returned by clangd. " "0 means no limit (default=100)"), init(100), }; -static opt Sync{ +opt Sync{ "sync", + cat(Misc), desc("Parse on main thread. If set, -j is ignored"), init(false), Hidden, }; -static opt ResourceDir{ +opt ResourceDir{ "resource-dir", + cat(CompileCommands), desc("Directory for system clang headers"), init(""), Hidden, }; -static opt InputMirrorFile{ +opt InputMirrorFile{ "input-mirror-file", + cat(Protocol), desc("Mirror all LSP input to the specified file. Useful for debugging"), init(""), Hidden, }; -static opt EnableIndex{ +opt 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 AllScopesCompletion{ +opt 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 ShowOrigins{ +opt ShowOrigins{ "debug-origin", + cat(Features), desc("Show origins of completion items"), init(CodeCompleteOptions().ShowOrigins), Hidden, }; -static opt HeaderInsertion{ +opt 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 HeaderInsertionDecorators{ +opt 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 IndexFile{ +opt 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 EnableBackgroundIndex{ +opt 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{ +opt 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 EnableFunctionArgSnippets{ +opt 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 ClangTidyChecks{ +opt 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 EnableClangTidy{ +opt EnableClangTidy{ "clang-tidy", + cat(Features), desc("Enable clang-tidy diagnostics"), init(true), }; -static opt FallbackStyle{ +opt 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 SuggestMissingIncludes{ +opt SuggestMissingIncludes{ "suggest-missing-includes", + cat(Features), desc("Attempts to fix diagnostic errors caused by missing " "includes using index"), init(true), }; -static opt ForceOffsetEncoding{ +opt 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 CodeCompletionParse{ +opt 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 HiddenFeatures{ +opt HiddenFeatures{ "hidden-features", + cat(Features), desc("Enable hidden features mostly useful to clangd developers"), init(false), Hidden, }; -static list QueryDriverGlobs{ +list 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 TweakList{ +list 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. "