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

Shaurya Gupta via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 1 08:15:41 PDT 2019


SureYeaah updated this revision to Diff 207323.
SureYeaah added a comment.

Whitespace formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63989

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


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===================================================================
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ 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<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,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<OffsetEncoding> OffsetEncodingFromFlag;
   if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding)
     OffsetEncodingFromFlag = ForceOffsetEncoding;
Index: clang-tools-extra/clangd/test/fixits-duplication.test
===================================================================
--- clang-tools-extra/clangd/test/fixits-duplication.test
+++ 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; }"}}}
Index: clang-tools-extra/clangd/ClangdServer.h
===================================================================
--- clang-tools-extra/clangd/ClangdServer.h
+++ 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<bool(llvm::StringRef)> 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<bool(llvm::StringRef)> TweakFilter;
   // GUARDED_BY(CachedCompletionFuzzyFindRequestMutex)
   llvm::StringMap<llvm::Optional<FuzzyFindRequest>>
       CachedCompletionFuzzyFindRequestByFile;
Index: clang-tools-extra/clangd/ClangdServer.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ 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<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()});
     }


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


More information about the cfe-commits mailing list