14#include "clang/AST/ASTTypeTraits.h"
15#include "clang/AST/Type.h"
16#include "llvm/Support/FormatVariadic.h"
17#include "llvm/Support/ScopedPrinter.h"
18#include "llvm/Support/raw_ostream.h"
33class DumpAST :
public Tweak {
35 const char *id() const final;
37 bool prepare(const Selection &Inputs)
override {
38 for (
auto *N = Inputs.ASTSelection.commonAncestor(); N && !Node;
40 if (dumpable(N->ASTNode))
42 return Node.has_value();
44 Expected<Effect> apply(
const Selection &Inputs)
override;
45 std::string title()
const override {
47 llvm::formatv(
"Dump {0} AST",
Node->getNodeKind().asStringRef()));
50 bool hidden()
const override {
return true; }
53 static bool dumpable(
const DynTypedNode &N) {
56 return N.get<
Decl>() || N.get<Stmt>() || N.get<
Type>();
59 std::optional<DynTypedNode>
Node;
63llvm::Expected<Tweak::Effect> DumpAST::apply(
const Selection &Inputs) {
65 llvm::raw_string_ostream
OS(Str);
66 Node->dump(
OS, Inputs.AST->getASTContext());
67 return Effect::showMessage(std::move(
OS.str()));
86class ShowSelectionTree :
public Tweak {
88 const char *id() const final;
90 bool prepare(const Selection &Inputs)
override {
return true; }
91 Expected<Effect> apply(
const Selection &Inputs)
override {
92 return Effect::showMessage(llvm::to_string(Inputs.ASTSelection));
94 std::string title()
const override {
return "Show selection tree"; }
96 bool hidden()
const override {
return true; }
107class DumpSymbol :
public Tweak {
108 const char *id() const final;
109 bool prepare(const Selection &Inputs)
override {
return true; }
110 Expected<Effect> apply(
const Selection &Inputs)
override {
112 llvm::raw_string_ostream
Out(Storage);
118 return Effect::showMessage(
Out.str());
120 std::string title()
const override {
return "Dump symbol under the cursor"; }
122 bool hidden()
const override {
return true; }
135class DumpRecordLayout :
public Tweak {
137 const char *id() const final;
139 bool prepare(const Selection &Inputs)
override {
140 if (
auto *Node = Inputs.ASTSelection.commonAncestor())
141 if (
auto *D =
Node->ASTNode.get<
Decl>())
142 Record = dyn_cast<RecordDecl>(D);
143 return Record &&
Record->isThisDeclarationADefinition() &&
144 !
Record->isDependentType();
146 Expected<Effect> apply(
const Selection &Inputs)
override {
148 llvm::raw_string_ostream
OS(Str);
149 Inputs.AST->getASTContext().DumpRecordLayout(Record,
OS);
150 return Effect::showMessage(std::move(
OS.str()));
152 std::string title()
const override {
153 return std::string(llvm::formatv(
155 TypeWithKeyword::getTagTypeKindName(
Record->getTagKind())));
162 bool hidden()
const override {
return true; }
165 const RecordDecl *
Record =
nullptr;
const FunctionDecl * Decl
CompiledFragmentImpl & Out
::clang::DynTypedNode Node
#define REGISTER_TWEAK(Subclass)
std::vector< SymbolDetails > getSymbolInfo(ParsedAST &AST, Position Pos)
Get info about symbols at Pos.
Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc)
Turn a SourceLocation into a [line, column] pair.
@ Type
An inlay hint that for a type annotation.
llvm::SmallVector< uint64_t, 1024 > Record
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static const llvm::StringLiteral INFO_KIND