Summary: [Clangd] Added hidden command line option -tweaks to specify which tweaks to enable

- Only for development purposes
- Disabled tweaks in fixits-duplications test
Reviewers: sammccall, kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63989

llvm-svn: 364809
This commit is contained in:
Shaurya Gupta 2019-07-01 16:55:29 +00:00
parent 265059eaf6
commit 8cae7d79b5
4 changed files with 20 additions and 3 deletions

View File

@ -102,6 +102,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
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 @@ void ClangdServer::enumerateTweaks(PathRef File, Range Sel,
return CB(Selection.takeError());
std::vector<TweakRef> 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()});
}

View File

@ -140,6 +140,9 @@ public:
/// Enable semantic highlighting features.
bool SemanticHighlighting = false;
/// Returns true if the StringRef is a tweak that should be enabled
std::function<bool(llvm::StringRef)> TweakFilter = [](llvm::StringRef TweakToSearch) {return true;};
};
// Sensible default options for use in tests.
// Features like indexing must be enabled if desired.
@ -313,7 +316,9 @@ private:
// can be caused by missing includes (e.g. member access in incomplete type).
bool SuggestMissingIncludes = false;
bool EnableHiddenFeatures = false;
std::function<bool(llvm::StringRef)> TweakFilter;
// GUARDED_BY(CachedCompletionFuzzyFindRequestMutex)
llvm::StringMap<llvm::Optional<FuzzyFindRequest>>
CachedCompletionFuzzyFindRequestByFile;

View File

@ -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; }"}}}

View File

@ -278,6 +278,12 @@ static llvm::cl::list<std::string> QueryDriverGlobs(
"/usr/bin/**/clang-*,/path/to/repo/**/g++-*"),
llvm::cl::CommaSeparated);
static llvm::cl::list<std::string> 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.
@ -533,6 +539,11 @@ int main(int argc, char *argv[]) {
}
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();
};
llvm::Optional<OffsetEncoding> OffsetEncodingFromFlag;
if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding)
OffsetEncodingFromFlag = ForceOffsetEncoding;