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

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


Author: sureyeaah
Date: Mon Jul  1 09:55:29 2019
New Revision: 364809

URL: http://llvm.org/viewvc/llvm-project?rev=364809&view=rev
Log:
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

Modified:
    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

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=364809&r1=364808&r2=364809&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Jul  1 09:55:29 2019
@@ -102,6 +102,7 @@ ClangdServer::ClangdServer(const GlobalC
       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(PathR
       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()});
     }

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=364809&r1=364808&r2=364809&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Mon Jul  1 09:55:29 2019
@@ -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;

Modified: clang-tools-extra/trunk/clangd/test/fixits-duplication.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/fixits-duplication.test?rev=364809&r1=364808&r2=364809&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/test/fixits-duplication.test (original)
+++ clang-tools-extra/trunk/clangd/test/fixits-duplication.test Mon Jul  1 09:55:29 2019
@@ -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; }"}}}

Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=364809&r1=364808&r2=364809&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Mon Jul  1 09:55:29 2019
@@ -278,6 +278,12 @@ static llvm::cl::list<std::string> Query
         "/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;




More information about the cfe-commits mailing list