diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h --- a/clang-tools-extra/clangd/ClangdServer.h +++ b/clang-tools-extra/clangd/ClangdServer.h @@ -126,10 +126,6 @@ bool SuggestMissingIncludes = false; - /// Enable hidden features mostly useful to clangd developers. - /// e.g. tweaks to dump the AST. - bool HiddenFeatures = false; - /// Clangd will execute compiler drivers matching one of these globs to /// fetch system include path. std::vector QueryDriverGlobs; @@ -137,8 +133,10 @@ /// Enable semantic highlighting features. bool SemanticHighlighting = false; - /// Returns true if the StringRef is a tweak that should be enabled - std::function TweakFilter = [](llvm::StringRef TweakToSearch) {return true;}; + /// Returns true if the StringRef is a tweak ID that should be enabled. + std::function TweakFilter = [](const Tweak &T) { + return true; // always enabled all tweaks. + }; }; // Sensible default options for use in tests. // Features like indexing must be enabled if desired. @@ -315,8 +313,8 @@ // can be caused by missing includes (e.g. member access in incomplete type). bool SuggestMissingIncludes = false; bool EnableHiddenFeatures = false; - - std::function TweakFilter; + + std::function TweakFilter; // GUARDED_BY(CachedCompletionFuzzyFindRequestMutex) llvm::StringMap> diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -101,7 +101,6 @@ : nullptr), GetClangTidyOptions(Opts.GetClangTidyOptions), SuggestMissingIncludes(Opts.SuggestMissingIncludes), - EnableHiddenFeatures(Opts.HiddenFeatures), TweakFilter(Opts.TweakFilter), WorkspaceRoot(Opts.WorkspaceRoot), // Pass a callback into `WorkScheduler` to extract symbols from a newly @@ -334,11 +333,9 @@ if (!Selection) return CB(Selection.takeError()); std::vector Res; - for (auto &T : prepareTweaks(*Selection)) { - if (!TweakFilter(T->id()) || (T->hidden() && !EnableHiddenFeatures)) - continue; + for (auto &T : prepareTweaks(*Selection, TweakFilter)) Res.push_back({T->id(), T->title(), T->intent()}); - } + CB(std::move(Res)); }; diff --git a/clang-tools-extra/clangd/index/Background.h b/clang-tools-extra/clangd/index/Background.h --- a/clang-tools-extra/clangd/index/Background.h +++ b/clang-tools-extra/clangd/index/Background.h @@ -66,7 +66,7 @@ /// A work item on the thread pool's queue. struct Task { template - explicit Task(Func &&F) : Run(std::forward(F)){}; + explicit Task(Func &&F) : Run(std::forward(F)){} std::function Run; llvm::ThreadPriority ThreadPri = llvm::ThreadPriority::Background; diff --git a/clang-tools-extra/clangd/refactor/Tweak.h b/clang-tools-extra/clangd/refactor/Tweak.h --- a/clang-tools-extra/clangd/refactor/Tweak.h +++ b/clang-tools-extra/clangd/refactor/Tweak.h @@ -110,9 +110,11 @@ TweakRegistrationFor##Subclass(#Subclass, /*Description=*/""); \ const char *Subclass::id() const { return #Subclass; } -/// Calls prepare() on all tweaks, returning those that can run on the -/// selection. -std::vector> prepareTweaks(const Tweak::Selection &S); +/// Calls prepare() on all tweaks that satisfy the filter, returning those that +/// can run on the selection. +std::vector> +prepareTweaks(const Tweak::Selection &S, + std::function Filter); // Calls prepare() on the tweak with a given ID. // If prepare() returns false, returns an error. diff --git a/clang-tools-extra/clangd/refactor/Tweak.cpp b/clang-tools-extra/clangd/refactor/Tweak.cpp --- a/clang-tools-extra/clangd/refactor/Tweak.cpp +++ b/clang-tools-extra/clangd/refactor/Tweak.cpp @@ -46,13 +46,15 @@ Cursor = SM.getComposedLoc(SM.getMainFileID(), RangeBegin); } -std::vector> prepareTweaks(const Tweak::Selection &S) { +std::vector> +prepareTweaks(const Tweak::Selection &S, + std::function Filter) { validateRegistry(); std::vector> Available; for (const auto &E : TweakRegistry::entries()) { std::unique_ptr T = E.instantiate(); - if (!T->prepare(S)) + if (!Filter(*T) || !T->prepare(S)) continue; Available.push_back(std::move(T)); } 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 @@ -472,7 +472,6 @@ } Opts.StaticIndex = StaticIdx.get(); Opts.AsyncThreadsCount = WorkerThreadsCount; - Opts.HiddenFeatures = HiddenFeatures; clangd::CodeCompleteOptions CCOpts; CCOpts.IncludeIneligibleResults = IncludeIneligibleResults; @@ -531,11 +530,14 @@ } Opts.SuggestMissingIncludes = SuggestMissingIncludes; Opts.QueryDriverGlobs = std::move(QueryDriverGlobs); - if (TweakList.getNumOccurrences()) - Opts.TweakFilter = [&](llvm::StringRef TweakToSearch) { - // return true if any tweak matches the TweakToSearch - return llvm::find(TweakList, TweakToSearch) != TweakList.end(); - }; + + Opts.TweakFilter = [&](const Tweak &T) { + // Enable non-hidden tweaks and hidden tweaks if -hiden-features flag is on. + bool DefaultEnable = !T.hidden() || HiddenFeatures; + if (TweakList.getNumOccurrences()) + return llvm::is_contained(TweakList, T.id()) && DefaultEnable; + return DefaultEnable; + }; llvm::Optional OffsetEncodingFromFlag; if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding) OffsetEncodingFromFlag = ForceOffsetEncoding;