summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp')
-rw-r--r--clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp b/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
index 9baa8fa4ad6..ed3725bf7ea 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
@@ -9,6 +9,7 @@
// Some of these are fairly clang-specific and hidden (e.g. textual AST dumps).
// Others are more generally useful (class layout) and are exposed by default.
//===----------------------------------------------------------------------===//
+#include "XRefs.h"
#include "refactor/Tweak.h"
#include "clang/AST/ASTTypeTraits.h"
#include "clang/AST/Type.h"
@@ -94,6 +95,32 @@ public:
};
REGISTER_TWEAK(ShowSelectionTree)
+/// Dumps the symbol under the cursor.
+/// Inputs:
+/// void foo();
+/// ^^^
+/// Message:
+/// foo -
+/// {"containerName":null,"id":"CA2EBE44A1D76D2A","name":"foo","usr":"c:@F@foo#"}
+class DumpSymbol : public Tweak {
+ const char *id() const override final;
+ bool prepare(const Selection &Inputs) override { return true; }
+ Expected<Effect> apply(const Selection &Inputs) override {
+ std::string Storage;
+ llvm::raw_string_ostream Out(Storage);
+
+ for (auto &Sym : getSymbolInfo(
+ Inputs.AST,
+ sourceLocToPosition(Inputs.AST.getSourceManager(), Inputs.Cursor)))
+ Out << Sym;
+ return Effect::showMessage(Out.str());
+ }
+ std::string title() const override { return "Dump symbol under the cursor"; }
+ Intent intent() const override { return Info; }
+ bool hidden() const override { return true; }
+};
+REGISTER_TWEAK(DumpSymbol)
+
/// Shows the layout of the RecordDecl under the cursor.
/// Input:
/// struct X { int foo; };
OpenPOWER on IntegriCloud