This revision was automatically updated to reflect the committed changes. Closed by commit rG8aa84ad37db7: [clangd] Store Index in Tweak::Selection (authored by kadircet).
Changed prior to commit: https://reviews.llvm.org/D69165?vs=225871&id=226399#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D69165/new/ https://reviews.llvm.org/D69165 Files: clang-tools-extra/clangd/ClangdServer.cpp clang-tools-extra/clangd/refactor/Tweak.cpp clang-tools-extra/clangd/refactor/Tweak.h clang-tools-extra/clangd/unittests/TweakTesting.cpp clang-tools-extra/clangd/unittests/TweakTesting.h
Index: clang-tools-extra/clangd/unittests/TweakTesting.h =================================================================== --- clang-tools-extra/clangd/unittests/TweakTesting.h +++ clang-tools-extra/clangd/unittests/TweakTesting.h @@ -10,9 +10,11 @@ #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TWEAKTESTING_H #include "TestTU.h" +#include "index/Index.h" #include "llvm/ADT/StringMap.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include <memory> #include <string> namespace clang { @@ -66,6 +68,9 @@ // Context in which snippets of code should be placed to run tweaks. CodeContext Context = File; + // Index to be passed into Tweak::Selection. + std::unique_ptr<const SymbolIndex> Index = nullptr; + // Apply the current tweak to the range (or point) in MarkedCode. // MarkedCode will be wrapped according to the Context. // - if the tweak produces edits, returns the edited code (without markings) Index: clang-tools-extra/clangd/unittests/TweakTesting.cpp =================================================================== --- clang-tools-extra/clangd/unittests/TweakTesting.cpp +++ clang-tools-extra/clangd/unittests/TweakTesting.cpp @@ -14,6 +14,7 @@ #include "refactor/Tweak.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/Support/Error.h" +#include "gmock/gmock.h" #include "gtest/gtest.h" #include <string> @@ -62,7 +63,7 @@ cantFail(positionToOffset(A.code(), SelectionRng.end))}; } -MATCHER_P4(TweakIsAvailable, TweakID, Ctx, Header, ExtraFiles, +MATCHER_P5(TweakIsAvailable, TweakID, Ctx, Header, ExtraFiles, Index, (TweakID + (negation ? " is unavailable" : " is available")).str()) { std::string WrappedCode = wrap(Ctx, arg); Annotations Input(WrappedCode); @@ -72,7 +73,7 @@ TU.Code = Input.code(); TU.AdditionalFiles = std::move(ExtraFiles); ParsedAST AST = TU.build(); - Tweak::Selection S(AST, Selection.first, Selection.second); + Tweak::Selection S(Index, AST, Selection.first, Selection.second); auto PrepareResult = prepareTweak(TweakID, S); if (PrepareResult) return true; @@ -94,7 +95,7 @@ TU.Code = Input.code(); TU.ExtraArgs = ExtraArgs; ParsedAST AST = TU.build(); - Tweak::Selection S(AST, Selection.first, Selection.second); + Tweak::Selection S(Index.get(), AST, Selection.first, Selection.second); auto T = prepareTweak(TweakID, S); if (!T) { @@ -129,8 +130,8 @@ } ::testing::Matcher<llvm::StringRef> TweakTest::isAvailable() const { - return TweakIsAvailable(llvm::StringRef(TweakID), Context, Header, - ExtraFiles); + return TweakIsAvailable(llvm::StringRef(TweakID), Context, Header, ExtraFiles, + Index.get()); } std::vector<std::string> TweakTest::expandCases(llvm::StringRef MarkedCode) { Index: clang-tools-extra/clangd/refactor/Tweak.h =================================================================== --- clang-tools-extra/clangd/refactor/Tweak.h +++ clang-tools-extra/clangd/refactor/Tweak.h @@ -24,6 +24,7 @@ #include "Protocol.h" #include "Selection.h" #include "SourceCode.h" +#include "index/Index.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringMap.h" @@ -46,9 +47,12 @@ public: /// Input to prepare and apply tweaks. struct Selection { - Selection(ParsedAST &AST, unsigned RangeBegin, unsigned RangeEnd); + Selection(const SymbolIndex *Index, ParsedAST &AST, unsigned RangeBegin, + unsigned RangeEnd); /// The text of the active document. llvm::StringRef Code; + /// The Index for handling codebase related queries. + const SymbolIndex *Index = nullptr; /// Parsed AST of the active file. ParsedAST &AST; /// A location of the cursor in the editor. Index: clang-tools-extra/clangd/refactor/Tweak.cpp =================================================================== --- clang-tools-extra/clangd/refactor/Tweak.cpp +++ clang-tools-extra/clangd/refactor/Tweak.cpp @@ -9,6 +9,7 @@ #include "Logger.h" #include "Path.h" #include "SourceCode.h" +#include "index/Index.h" #include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" @@ -44,9 +45,10 @@ } } // namespace -Tweak::Selection::Selection(ParsedAST &AST, unsigned RangeBegin, - unsigned RangeEnd) - : AST(AST), SelectionBegin(RangeBegin), SelectionEnd(RangeEnd), +Tweak::Selection::Selection(const SymbolIndex *Index, ParsedAST &AST, + unsigned RangeBegin, unsigned RangeEnd) + : Index(Index), AST(AST), SelectionBegin(RangeBegin), + SelectionEnd(RangeEnd), ASTSelection(AST.getASTContext(), AST.getTokens(), RangeBegin, RangeEnd) { auto &SM = AST.getSourceManager(); Code = SM.getBufferData(SM.getMainFileID()); Index: clang-tools-extra/clangd/ClangdServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdServer.cpp +++ clang-tools-extra/clangd/ClangdServer.cpp @@ -367,7 +367,7 @@ auto End = positionToOffset(AST.Inputs.Contents, Sel.end); if (!End) return End.takeError(); - return Tweak::Selection(AST.AST, *Begin, *End); + return Tweak::Selection(AST.Inputs.Index, AST.AST, *Begin, *End); } void ClangdServer::enumerateTweaks(PathRef File, Range Sel,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits