[PATCH] D63989: [Clangd] Added hidden command line option -tweaks to specify which tweaks to enable
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=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 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 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 Res; for (auto : 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 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 TweakFilter; + // GUARDED_BY(CachedCompletionFuzzyFindRequestMutex) llvm::StringMap> CachedCompletionFuzzyFindRequestByFile; Index: clang-tools-extra/trunk/clangd/test/fixits-duplication.test === --- clang-tools-extra/trunk/clangd/test/fixits-duplication.test +++
[PATCH] D63989: [Clangd] Added hidden command line option -tweaks to specify which tweaks to enable
SureYeaah updated this revision to Diff 207358. SureYeaah marked 3 inline comments as done. SureYeaah added a comment. Refactored code 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 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 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,9 @@ /// Enable semantic highlighting features. bool SemanticHighlighting = false; + +/// Returns true if the StringRef is a tweak that should be enabled +std::function 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 TweakFilter; + // GUARDED_BY(CachedCompletionFuzzyFindRequestMutex) llvm::StringMap> 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 Res; for (auto : 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/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 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
[PATCH] D63989: [Clangd] Added hidden command line option -tweaks to specify which tweaks to enable
sammccall accepted this revision. sammccall added inline comments. This revision is now accepted and ready to land. Comment at: clang-tools-extra/clangd/ClangdServer.h:145 +/// Returns true if the StringRef is a tweak that should be enabled +std::function TweakFilter; + ClangdServer::Options needs to be default-constructible with sensible default options. Can you either inline-initialize this `= [](llvm::StringRef) { return true; }` (if possible), or have the code handle TweakFilter==nullptr as accepting anything? Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:542 Opts.QueryDriverGlobs = std::move(QueryDriverGlobs); + Opts.TweakFilter = [&](llvm::StringRef TweakToSearch) { +// return true if any tweak matches the TweakToSearch it would be clearer to set this only `if TweakList.getNumOccurrences()`, rather than using it inside the lambda, I think Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:544 +// return true if any tweak matches the TweakToSearch +for (auto Tweak : TweakList) { + if (TweakToSearch == Tweak) return llvm::find(TweakList, TweakToSearch) != TweakList.end() ? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D63989/new/ https://reviews.llvm.org/D63989 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D63989: [Clangd] Added hidden command line option -tweaks to specify which tweaks to enable
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 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 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 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; 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 Res; for (auto : 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/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 TweakList( +"tweaks", +llvm::cl::desc( +"Specify a list of Tweaks to enable (only for clangd developers)."), +llvm::cl::Hidden, llvm::cl::CommaSeparated); + namespace { /// \brief
[PATCH] D63989: [Clangd] Added hidden command line option -tweaks to specify which tweaks to enable
SureYeaah updated this revision to Diff 207321. SureYeaah added a comment. Removed extra comment 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 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; 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 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; 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 Res; for (auto : 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/clangd/tool/ClangdMain.cpp === --- clang-tools-extra/clangd/tool/ClangdMain.cpp +++ clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -278,6 +278,12 @@