-
Notifications
You must be signed in to change notification settings - Fork 15.2k
issue-63565: community requested small QoL fix for more configurabili… #108005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
4e9cbd6
ae6e02e
9e67e06
6e31a07
49ca6dd
e222a84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,11 +126,29 @@ struct Config { | |
| std::vector<std::string> FullyQualifiedNamespaces; | ||
| } Style; | ||
|
|
||
| /// controls the completion options for argument lists. | ||
| enum class ArgumentListsOption { | ||
|
||
| /// the default value. This will imply FullPlaceholders unless overridden by | ||
| /// --function-arg-placeholders=0, in which case Delimiters is used. | ||
| /// any other use-case of --function-arg-placeholders is ignored | ||
| UnsetDefault = 0, | ||
|
||
| /// nothing, no argument list and also NO Delimiters "()" or "<>" | ||
| None, | ||
| /// open, only opening delimiter "(" or "<" | ||
| OpenDelimiter, | ||
| /// empty pair of delimiters "()" or "<>" (or [legacy] alias 0) | ||
|
||
| Delimiters, | ||
| /// full name of both type and variable (or [legacy] alias 1) | ||
| FullPlaceholders, | ||
| }; | ||
|
|
||
| /// Configures code completion feature. | ||
| struct { | ||
| /// Whether code completion includes results that are not visible in current | ||
| /// scopes. | ||
| bool AllScopes = true; | ||
| /// controls the completion options for argument lists. | ||
| ArgumentListsOption ArgumentLists = ArgumentListsOption::UnsetDefault; | ||
| } Completion; | ||
|
|
||
| /// Configures hover feature. | ||
|
|
@@ -150,6 +168,7 @@ struct Config { | |
| bool BlockEnd = false; | ||
| // Limit the length of type names in inlay hints. (0 means no limit) | ||
| uint32_t TypeNameLimit = 32; | ||
|
|
||
| } InlayHints; | ||
|
|
||
| struct { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -504,10 +504,10 @@ struct FragmentCompiler { | |
| auto Fast = isFastTidyCheck(Str); | ||
| if (!Fast.has_value()) { | ||
| diag(Warning, | ||
| llvm::formatv( | ||
| "Latency of clang-tidy check '{0}' is not known. " | ||
| "It will only run if ClangTidy.FastCheckFilter is Loose or None", | ||
| Str) | ||
| llvm::formatv("Latency of clang-tidy check '{0}' is not known. " | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I'm seeing some diff hunks containing unrelated formatting changes. If would be great to remove this as they pollute the blame
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use |
||
| "It will only run if ClangTidy.FastCheckFilter is " | ||
| "Loose or None", | ||
| Str) | ||
| .str(), | ||
| Arg.Range); | ||
| } else if (!*Fast) { | ||
|
|
@@ -622,6 +622,31 @@ struct FragmentCompiler { | |
| C.Completion.AllScopes = AllScopes; | ||
| }); | ||
| } | ||
| if (F.ArgumentLists) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a |
||
| if (**F.ArgumentLists == "None") { | ||
| Out.Apply.push_back( | ||
| [ArgumentLists(**F.ArgumentLists)](const Params &, Config &C) { | ||
| C.Completion.ArgumentLists = Config::ArgumentListsOption::None; | ||
| }); | ||
| } else if (**F.ArgumentLists == "OpenDelimiter") { | ||
| Out.Apply.push_back( | ||
| [ArgumentLists(**F.ArgumentLists)](const Params &, Config &C) { | ||
| C.Completion.ArgumentLists = | ||
| Config::ArgumentListsOption::OpenDelimiter; | ||
| }); | ||
| } else if (**F.ArgumentLists == "Delimiters") { | ||
| Out.Apply.push_back([ArgumentLists(**F.ArgumentLists)](const Params &, | ||
| Config &C) { | ||
| C.Completion.ArgumentLists = Config::ArgumentListsOption::Delimiters; | ||
| }); | ||
| } else if (**F.ArgumentLists == "FullPlaceholders") { | ||
| Out.Apply.push_back( | ||
| [ArgumentLists(**F.ArgumentLists)](const Params &, Config &C) { | ||
| C.Completion.ArgumentLists = | ||
| Config::ArgumentListsOption::FullPlaceholders; | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void compile(Fragment::HoverBlock &&F) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CONFIGFRAGMENT_H | ||
| #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CONFIGFRAGMENT_H | ||
|
|
||
| #include "Config.h" | ||
| #include "ConfigProvider.h" | ||
| #include "llvm/Support/SMLoc.h" | ||
| #include "llvm/Support/SourceMgr.h" | ||
|
|
@@ -308,6 +309,13 @@ struct Fragment { | |
| /// Whether code completion should include suggestions from scopes that are | ||
| /// not visible. The required scope prefix will be inserted. | ||
| std::optional<Located<bool>> AllScopes; | ||
| /// How to present the argument list between '()' and '<>': | ||
| /// valid values are enum Config::ArgumentListsOption values: | ||
| /// None: Nothing at all | ||
| /// OpenDelimiter: only opening delimiter "(" or "<" | ||
| /// Delimiters: empty pair of delimiters "()" or "<>" | ||
| /// FullPlaceholders: full name of both type and variable | ||
|
||
| std::optional<Located<std::string>> ArgumentLists; | ||
| }; | ||
| CompletionBlock Completion; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,6 +230,10 @@ class Parser { | |
| if (auto AllScopes = boolValue(N, "AllScopes")) | ||
| F.AllScopes = *AllScopes; | ||
| }); | ||
| Dict.handle("ArgumentLists", [&](Node &N) { | ||
| if (auto ArgumentLists = scalarValue(N, "ArgumentLists")) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (this comment remains to be addressed) |
||
| F.ArgumentLists = *ArgumentLists; | ||
| }); | ||
| Dict.parse(N); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -242,13 +242,16 @@ opt<std::string> FallbackStyle{ | |
| init(clang::format::DefaultFallbackStyle), | ||
| }; | ||
|
|
||
| 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"), | ||
| init(CodeCompleteOptions().EnableFunctionArgSnippets), | ||
| opt<Config::ArgumentListsOption> PlaceholderOption{ | ||
|
||
| "function-arg-placeholders", cat(Features), | ||
| desc("Set the way placeholders and delimiters are implemented."), | ||
| init(CodeCompleteOptions().ArgumentLists), | ||
| values(clEnumValN(Config::ArgumentListsOption::Delimiters, "0", | ||
| "Empty pair of delimiters inserted"), | ||
| clEnumValN( | ||
| Config::ArgumentListsOption::FullPlaceholders, "1", | ||
| "[default] Delimiters and placeholder arguments are inserted.")) | ||
|
|
||
| }; | ||
|
|
||
| opt<CodeCompleteOptions::IncludeInsertion> HeaderInsertion{ | ||
|
|
@@ -650,6 +653,7 @@ class FlagsConfigProvider : public config::Provider { | |
| std::optional<Config::CDBSearchSpec> CDBSearch; | ||
| std::optional<Config::ExternalIndexSpec> IndexSpec; | ||
| std::optional<Config::BackgroundPolicy> BGPolicy; | ||
| std::optional<Config::ArgumentListsOption> ArgumentLists; | ||
|
|
||
| // If --compile-commands-dir arg was invoked, check value and override | ||
| // default path. | ||
|
|
@@ -694,13 +698,20 @@ class FlagsConfigProvider : public config::Provider { | |
| BGPolicy = Config::BackgroundPolicy::Skip; | ||
| } | ||
|
|
||
| if (PlaceholderOption == Config::ArgumentListsOption::Delimiters) { | ||
| ArgumentLists = PlaceholderOption; | ||
| } | ||
|
|
||
| Frag = [=](const config::Params &, Config &C) { | ||
| if (CDBSearch) | ||
| C.CompileFlags.CDBSearch = *CDBSearch; | ||
| if (IndexSpec) | ||
| C.Index.External = *IndexSpec; | ||
| if (BGPolicy) | ||
| C.Index.Background = *BGPolicy; | ||
| if (ArgumentLists && C.Completion.ArgumentLists == | ||
|
||
| Config::ArgumentListsOption::UnsetDefault) | ||
| C.Completion.ArgumentLists = *ArgumentLists; | ||
| if (AllScopesCompletion.getNumOccurrences()) | ||
| C.Completion.AllScopes = AllScopesCompletion; | ||
|
|
||
|
|
@@ -916,7 +927,6 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var | |
| Opts.CodeComplete.IncludeIndicator.Insert.clear(); | ||
| Opts.CodeComplete.IncludeIndicator.NoInsert.clear(); | ||
| } | ||
| Opts.CodeComplete.EnableFunctionArgSnippets = EnableFunctionArgSnippets; | ||
| Opts.CodeComplete.RunParser = CodeCompletionParse; | ||
| Opts.CodeComplete.RankingModel = RankingModel; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with our existing
Completionoption (AllScopes), let's do theConfiglookup here and propagate it intoCodeCompleteOpts.That then gets propagated to
CodeCompletionBuilder::ArgumentListsin theCodeCompletionBuilderconstructor, and here we can just use theArgumentListsmember without doing anything further.