19 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_ACTIONS_TWEAK_H 20 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_ACTIONS_TWEAK_H 25 #include "clang/Tooling/Core/Replacement.h" 26 #include "llvm/ADT/Optional.h" 27 #include "llvm/ADT/StringRef.h" 85 virtual ~Tweak() =
default;
89 virtual const char *
id()
const = 0;
104 virtual std::string
title()
const = 0;
109 virtual bool hidden()
const {
return false; }
113 #define REGISTER_TWEAK(Subclass) \ 114 ::llvm::Registry<::clang::clangd::Tweak>::Add<Subclass> \ 115 TweakRegistrationFor##Subclass(#Subclass, ""); \ 116 const char *Subclass::id() const { return #Subclass; } 120 std::vector<std::unique_ptr<Tweak>>
122 llvm::function_ref<
bool(
const Tweak &)> Filter);
127 llvm::Expected<std::unique_ptr<Tweak>>
prepareTweak(StringRef TweakID,
128 const Tweak::Selection &S);
virtual std::string title() const =0
A one-line title of the action that should be shown to the users in the UI.
virtual bool prepare(const Selection &Sel)=0
Run the first stage of the action.
llvm::Expected< std::unique_ptr< Tweak > > prepareTweak(StringRef ID, const Tweak::Selection &S)
Apply changes that preserve the behavior of the code.
llvm::Optional< tooling::Replacements > ApplyEdit
An edit to apply to the input file.
Provide information to the user.
llvm::StringRef Code
The text of the active document.
Selection(ParsedAST &AST, unsigned RangeBegin, unsigned RangeEnd)
SelectionTree ASTSelection
The AST nodes that were selected.
virtual Expected< Effect > apply(const Selection &Sel)=0
Run the second stage of the action that would produce the actual effect.
SourceLocation Cursor
A location of the cursor in the editor.
Input to prepare and apply tweaks.
virtual bool hidden() const
Is this a 'hidden' tweak, which are off by default.
Stores and provides access to parsed AST.
virtual const char * id() const =0
A unique id of the action, it is always equal to the name of the class defining the Tweak...
unsigned SelectionBegin
The begin offset of the selection.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
virtual Intent intent() const =0
Describes what kind of action this is.
static Effect applyEdit(tooling::Replacements R)
An interface base for small context-sensitive refactoring actions.
unsigned SelectionEnd
The end offset of the selection.
llvm::Optional< std::string > ShowMessage
A message to be displayed to the user.
std::vector< std::unique_ptr< Tweak > > prepareTweaks(const Tweak::Selection &S, llvm::function_ref< bool(const Tweak &)> Filter)
Calls prepare() on all tweaks that satisfy the filter, returning those that can run on the selection...
ParsedAST & AST
Parsed AST of the active file.
static Effect showMessage(StringRef S)