[PATCH] D88553: [clangd] Start using SyntaxTrees for folding ranges feature

Eduardo Caldas via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 20 04:58:33 PDT 2020


eduucaldas added inline comments.


================
Comment at: clang-tools-extra/clangd/SemanticSelection.cpp:49-51
+  if (Node->getKind() == syntax::NodeKind::CompoundStatement) {
+    const auto *Tree = dyn_cast<syntax::Tree>(Node);
+    assert(Tree);
----------------



================
Comment at: clang-tools-extra/clangd/SemanticSelection.cpp:52-55
+    const syntax::Token *FirstToken = Tree->findFirstLeaf()->getToken(),
+                        *LastToken = Tree->findLastLeaf()->getToken();
+    assert(FirstToken->kind() == tok::TokenKind::l_brace);
+    assert(LastToken->kind() == tok::TokenKind::r_brace);
----------------
Take a look at `clang/include/clang/Tooling/Syntax/Nodes.h`, syntax constructs usually have nice classes with accessors.

For instance `CompoundStatement` has the accessors `getLbrace` and `getRbrace` that seem to be exactly what you want.

However these might not give exactly the first leaf and last leaf in the case of syntactically incorrect code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88553/new/

https://reviews.llvm.org/D88553



More information about the cfe-commits mailing list