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

Shaurya Gupta via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 1 09:55:44 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL364809: Summary: [Clangd] Added hidden command line option -tweaks to specify which… (authored by SureYeaah, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63989?vs=207358&id=207363#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63989/new/

https://reviews.llvm.org/D63989

Files:
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/clangd/test/fixits-duplication.test
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/trunk/clangd/test/fixits-duplication.test
===================================================================
--- clang-tools-extra/trunk/clangd/test/fixits-duplication.test
+++ clang-tools-extra/trunk/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; }"}}}
Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -278,6 +278,12 @@
         "/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 @@
   }
   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;
Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/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<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()});
     }
Index: clang-tools-extra/trunk/clangd/ClangdServer.h
===================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.h
+++ clang-tools-extra/trunk/clangd/ClangdServer.h
@@ -140,6 +140,9 @@
 
     /// 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 @@
   // 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63989.207363.patch
Type: text/x-patch
Size: 4132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190701/c69597eb/attachment.bin>


More information about the llvm-commits mailing list