clang-tools  12.0.0git
Classes | Public Types | Public Member Functions | List of all members
clang::clangd::Tweak Class Referenceabstract

An interface base for small context-sensitive refactoring actions. More...

#include <Tweak.h>

Classes

struct  Effect
 
struct  Selection
 Input to prepare and apply tweaks. More...
 

Public Types

enum  Intent { Refactor, Info }
 Output of a tweak. More...
 

Public Member Functions

virtual ~Tweak ()=default
 
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. More...
 
virtual bool prepare (const Selection &Sel)=0
 Run the first stage of the action. More...
 
virtual Expected< Effectapply (const Selection &Sel)=0
 Run the second stage of the action that would produce the actual effect. More...
 
virtual std::string title () const =0
 A one-line title of the action that should be shown to the users in the UI. More...
 
virtual Intent intent () const =0
 Describes what kind of action this is. More...
 
virtual bool hidden () const
 Is this a 'hidden' tweak, which are off by default. More...
 

Detailed Description

An interface base for small context-sensitive refactoring actions.

To implement a new tweak use the following pattern in a .cpp file: class MyTweak : public Tweak { public: const char* id() const override final; // defined by REGISTER_TWEAK. // implement other methods here. }; REGISTER_TWEAK(MyTweak);

Definition at line 46 of file Tweak.h.

Member Enumeration Documentation

◆ Intent

Output of a tweak.

Enumerator
Refactor 

Apply changes that preserve the behavior of the code.

Info 

Provide information to the user.

Definition at line 71 of file Tweak.h.

Constructor & Destructor Documentation

◆ ~Tweak()

virtual clang::clangd::Tweak::~Tweak ( )
virtualdefault

Member Function Documentation

◆ apply()

virtual Expected<Effect> clang::clangd::Tweak::apply ( const Selection Sel)
pure virtual

Run the second stage of the action that would produce the actual effect.

EXPECTS: prepare() was called and returned true.

◆ hidden()

virtual bool clang::clangd::Tweak::hidden ( ) const
inlinevirtual

Is this a 'hidden' tweak, which are off by default.

Definition at line 125 of file Tweak.h.

◆ id()

virtual const char* clang::clangd::Tweak::id ( ) const
pure virtual

A unique id of the action, it is always equal to the name of the class defining the Tweak.

Definition is provided automatically by REGISTER_TWEAK.

◆ intent()

virtual Intent clang::clangd::Tweak::intent ( ) const
pure virtual

Describes what kind of action this is.

EXPECTS: prepare() was called and returned true.

◆ prepare()

virtual bool clang::clangd::Tweak::prepare ( const Selection Sel)
pure virtual

Run the first stage of the action.

Returns true indicating that the action is available and should be shown to the user. Returns false if the action is not available. This function should be fast, if the action requires non-trivial work it should be moved into 'apply'. Returns true iff the action is available and apply() can be called on it.

◆ title()

virtual std::string clang::clangd::Tweak::title ( ) const
pure virtual

A one-line title of the action that should be shown to the users in the UI.

EXPECTS: prepare() was called and returned true.


The documentation for this class was generated from the following file: