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 @@ -140,6 +140,10 @@ /// Enable semantic highlighting features. bool SemanticHighlighting = false; + + /// Returns true if the StringRef is a tweak that should be enabled + std::function TweakFilter; + }; // Sensible default options for use in tests. // Features like indexing must be enabled if desired. @@ -313,7 +317,8 @@ // can be caused by missing includes (e.g. member access in incomplete type). bool SuggestMissingIncludes = false; bool EnableHiddenFeatures = false; - + + std::function TweakFilter; // GUARDED_BY(CachedCompletionFuzzyFindRequestMutex) llvm::StringMap> CachedCompletionFuzzyFindRequestByFile; 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 @@ -102,6 +102,7 @@ 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 // parsed file and rebuild the file index synchronously each time an AST @@ -333,7 +334,7 @@ return CB(Selection.takeError()); std::vector Res; for (auto &T : prepareTweaks(*Selection)) { - if (T->hidden() && !EnableHiddenFeatures) + if (!TweakFilter(T->id()) || (T->hidden() && !EnableHiddenFeatures)) continue; Res.push_back({T->id(), T->title(), T->intent()}); } diff --git a/clang-tools-extra/clangd/test/fixits-duplication.test b/clang-tools-extra/clangd/test/fixits-duplication.test --- a/clang-tools-extra/clangd/test/fixits-duplication.test +++ b/clang-tools-extra/clangd/test/fixits-duplication.test @@ -1,4 +1,4 @@ -# RUN: clangd -lit-test -clang-tidy-checks=modernize-use-nullptr,hicpp-use-nullptr < %s | FileCheck -strict-whitespace %s +# RUN: clangd -lit-test -clang-tidy-checks=modernize-use-nullptr,hicpp-use-nullptr -tweaks="" < %s | FileCheck -strict-whitespace %s {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{}}}},"trace":"off"}} --- {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.cpp","languageId":"cpp","version":1,"text":"void foo() { char* p = 0; }"}}} 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 @@ -278,6 +278,12 @@ "/usr/bin/**/clang-*,/path/to/repo/**/g++-*"), llvm::cl::CommaSeparated); +static llvm::cl::list TweakList( + "tweaks", + llvm::cl::desc( + "Specify a list of Tweaks to enable (only for clangd developers)."), + llvm::cl::Hidden, llvm::cl::CommaSeparated); + namespace { /// \brief Supports a test URI scheme with relaxed constraints for lit tests. @@ -476,7 +482,6 @@ Opts.StaticIndex = StaticIdx.get(); Opts.AsyncThreadsCount = WorkerThreadsCount; Opts.HiddenFeatures = HiddenFeatures; - clangd::CodeCompleteOptions CCOpts; CCOpts.IncludeIneligibleResults = IncludeIneligibleResults; CCOpts.Limit = LimitResults; @@ -533,6 +538,15 @@ } Opts.SuggestMissingIncludes = SuggestMissingIncludes; Opts.QueryDriverGlobs = std::move(QueryDriverGlobs); + Opts.TweakFilter = [&](llvm::StringRef TweakToSearch) { + // return true if any tweak matches the TweakToSearch + for (auto Tweak : TweakList) { + if (TweakToSearch == Tweak) + return true; + } + // return true if TweakList is not provided i.e. allow all tweaks + return !TweakList.getNumOccurrences(); + }; llvm::Optional OffsetEncodingFromFlag; if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding) OffsetEncodingFromFlag = ForceOffsetEncoding;