[clangd] Improve SelectionTree string representation
authorSam McCall <sam.mccall@gmail.com>
Mon, 24 Jun 2019 13:01:28 +0000 (13:01 +0000)
committerSam McCall <sam.mccall@gmail.com>
Mon, 24 Jun 2019 13:01:28 +0000 (13:01 +0000)
llvm-svn: 364180

clang-tools-extra/clangd/Selection.cpp

index 2eef06031e1efcea0d85808c0b01125aac9477f7..e0fb4423737291e2773f7e77ad038f2cdef60d62 100644 (file)
@@ -246,7 +246,17 @@ void SelectionTree::print(llvm::raw_ostream &OS, const SelectionTree::Node &N,
                                                                     : '.');
   else
     OS.indent(Indent);
-  OS << N.ASTNode.getNodeKind().asStringRef() << " ";
+  if (const TypeLoc *TL = N.ASTNode.get<TypeLoc>()) {
+    // TypeLoc is a hierarchy, but has only a single ASTNodeKind.
+    // Synthesize the name from the Type subclass (except for QualifiedTypeLoc).
+    if (TL->getTypeLocClass() == TypeLoc::Qualified)
+      OS << "QualifiedTypeLoc";
+    else
+      OS << TL->getType()->getTypeClassName() << "TypeLoc";
+  } else {
+    OS << N.ASTNode.getNodeKind().asStringRef();
+  }
+  OS << " ";
   N.ASTNode.print(OS, PrintPolicy);
   OS << "\n";
   for (const Node *Child : N.Children)
@@ -280,6 +290,7 @@ SelectionTree::SelectionTree(ASTContext &AST, unsigned Begin, unsigned End)
   if (Begin == End)
     std::tie(Begin, End) = pointBounds(Begin, FID, AST);
   PrintPolicy.TerseOutput = true;
+  PrintPolicy.IncludeNewlines = false;
 
   Nodes = SelectionVisitor::collect(AST, Begin, End, FID);
   Root = Nodes.empty() ? nullptr : &Nodes.front();