[PATCH] D90588: [clangd] NFC: Only pass ASTContext and TokenBuffer in getFoldingRanges API
Kirill Bobyrev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 1 23:55:33 PST 2020
kbobyrev created this revision.
kbobyrev added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman.
Herald added a project: clang.
kbobyrev requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Follow-up on https://reviews.llvm.org/D88553#inline-837013
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D90588
Files:
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/SemanticSelection.cpp
clang-tools-extra/clangd/SemanticSelection.h
clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
Index: clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
@@ -263,7 +263,8 @@
for (const char *Test : Tests) {
auto T = Annotations(Test);
auto AST = TestTU::withCode(T.code()).build();
- EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(AST))),
+ EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(
+ getFoldingRanges(AST.getASTContext(), AST.getTokens()))),
UnorderedElementsAreArray(T.ranges()))
<< Test;
}
Index: clang-tools-extra/clangd/SemanticSelection.h
===================================================================
--- clang-tools-extra/clangd/SemanticSelection.h
+++ clang-tools-extra/clangd/SemanticSelection.h
@@ -14,6 +14,7 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICSELECTION_H
#include "ParsedAST.h"
#include "Protocol.h"
+#include "clang/Tooling/Syntax/Tokens.h"
#include "llvm/Support/Error.h"
#include <vector>
namespace clang {
@@ -27,7 +28,8 @@
/// Returns a list of ranges whose contents might be collapsible in an editor.
/// This should include large scopes, preprocessor blocks etc.
-llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST);
+llvm::Expected<std::vector<FoldingRange>>
+getFoldingRanges(ASTContext &Context, const syntax::TokenBuffer &Tokens);
} // namespace clangd
} // namespace clang
Index: clang-tools-extra/clangd/SemanticSelection.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticSelection.cpp
+++ clang-tools-extra/clangd/SemanticSelection.cpp
@@ -12,6 +12,7 @@
#include "Protocol.h"
#include "Selection.h"
#include "SourceCode.h"
+#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclBase.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
@@ -158,11 +159,12 @@
// other code regions (e.g. public/private/protected sections of classes,
// control flow statement bodies).
// Related issue: https://github.com/clangd/clangd/issues/310
-llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST) {
- syntax::Arena A(AST.getSourceManager(), AST.getLangOpts(), AST.getTokens());
+llvm::Expected<std::vector<FoldingRange>>
+getFoldingRanges(ASTContext &Context, const syntax::TokenBuffer &Tokens) {
+ syntax::Arena A(Context.getSourceManager(), Context.getLangOpts(), Tokens);
const auto *SyntaxTree =
- syntax::buildSyntaxTree(A, *AST.getASTContext().getTranslationUnitDecl());
- return collectFoldingRanges(SyntaxTree, AST.getSourceManager());
+ syntax::buildSyntaxTree(A, *Context.getTranslationUnitDecl());
+ return collectFoldingRanges(SyntaxTree, Context.getSourceManager());
}
} // namespace clangd
Index: clang-tools-extra/clangd/ClangdServer.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -711,7 +711,8 @@
[CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
if (!InpAST)
return CB(InpAST.takeError());
- CB(clangd::getFoldingRanges(InpAST->AST));
+ CB(clangd::getFoldingRanges(InpAST->AST.getASTContext(),
+ InpAST->AST.getTokens()));
};
WorkScheduler.runWithAST("foldingRanges", File, std::move(Action),
TUScheduler::InvalidateOnUpdate);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90588.302217.patch
Type: text/x-patch
Size: 3614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201102/f3b28d4a/attachment.bin>
More information about the cfe-commits
mailing list