19 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_ACTIONS_TWEAK_H 20 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_ACTIONS_TWEAK_H 28 #include "clang/Tooling/Core/Replacement.h" 29 #include "llvm/ADT/Optional.h" 30 #include "llvm/ADT/StringMap.h" 31 #include "llvm/ADT/StringRef.h" 32 #include "llvm/Support/Error.h" 91 static llvm::Expected<std::pair<Path, Edit>>
92 fileEdit(
const SourceManager &SM, FileID FID,
93 tooling::Replacements Replacements);
97 static llvm::Expected<Tweak::Effect>
98 mainFileEdit(
const SourceManager &SM, tooling::Replacements Replacements);
101 virtual ~Tweak() =
default;
105 virtual const char *
id()
const = 0;
120 virtual std::string
title()
const = 0;
125 virtual bool hidden()
const {
return false; }
129 #define REGISTER_TWEAK(Subclass) \ 130 ::llvm::Registry<::clang::clangd::Tweak>::Add<Subclass> \ 131 TweakRegistrationFor##Subclass(#Subclass, ""); \ 132 const char *Subclass::id() const { return #Subclass; } 136 std::vector<std::unique_ptr<Tweak>>
138 llvm::function_ref<
bool(
const Tweak &)> Filter);
143 llvm::Expected<std::unique_ptr<Tweak>>
prepareTweak(StringRef TweakID,
144 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.
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Provide information to the user.
llvm::StringRef Code
The text of the active document.
SelectionTree ASTSelection
The AST nodes that were selected.
const SymbolIndex * Index
The Index for handling codebase related queries.
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...
llvm::StringMap< Edit > FileEdits
A mapping from absolute file path (the one used for accessing the underlying VFS) to edits...
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.
ParsedAST * AST
The parsed active file. Never null. (Pointer so Selection is movable).
An interface base for small context-sensitive refactoring actions.
Selection(const SymbolIndex *Index, ParsedAST &AST, unsigned RangeBegin, unsigned RangeEnd)
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...
static Effect showMessage(StringRef S)