[PATCH] D88553: [clangd] Stash a patch piece
Kirill Bobyrev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 30 04:10:18 PDT 2020
kbobyrev created this revision.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D88553
Files:
clang-tools-extra/clangd/SemanticSelection.cpp
Index: clang-tools-extra/clangd/SemanticSelection.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticSelection.cpp
+++ clang-tools-extra/clangd/SemanticSelection.cpp
@@ -13,6 +13,8 @@
#include "SourceCode.h"
#include "clang/AST/DeclBase.h"
#include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Tree.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/Error.h"
@@ -28,19 +30,6 @@
}
}
-// Recursively collects FoldingRange from a symbol and its children.
-void collectFoldingRanges(DocumentSymbol Symbol,
- std::vector<FoldingRange> &Result) {
- FoldingRange Range;
- Range.startLine = Symbol.range.start.line;
- Range.startCharacter = Symbol.range.start.character;
- Range.endLine = Symbol.range.end.line;
- Range.endCharacter = Symbol.range.end.character;
- Result.push_back(Range);
- for (const auto &Child : Symbol.children)
- collectFoldingRanges(Child, Result);
-}
-
} // namespace
llvm::Expected<SelectionRange> getSemanticRanges(ParsedAST &AST, Position Pos) {
@@ -100,19 +89,12 @@
// FIXME(kirillbobyrev): Collect comments, PP conditional regions, includes and
// other code regions (e.g. public/private/protected sections of classes,
// control flow statement bodies).
-// Related issue:
-// https://github.com/clangd/clangd/issues/310
+// Related issue: https://github.com/clangd/clangd/issues/310
llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST) {
- // FIXME(kirillbobyrev): getDocumentSymbols() is conveniently available but
- // limited (e.g. doesn't yield blocks inside functions and provides ranges for
- // nodes themselves instead of their contents which is less useful). Replace
- // this with a more general RecursiveASTVisitor implementation instead.
- auto DocumentSymbols = getDocumentSymbols(AST);
- if (!DocumentSymbols)
- return DocumentSymbols.takeError();
+ syntax::Arena A(AST.getSourceManager(), AST.getLangOpts(), AST.getTokens());
+ auto *SyntaxTree =
+ syntax::buildSyntaxTree(A, *AST.getASTContext().getTranslationUnitDecl());
std::vector<FoldingRange> Result;
- for (const auto &Symbol : *DocumentSymbols)
- collectFoldingRanges(Symbol, Result);
return Result;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88553.295233.patch
Type: text/x-patch
Size: 2333 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200930/123540d1/attachment-0001.bin>
More information about the cfe-commits
mailing list