19#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_TWEAK_H
20#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_REFACTOR_TWEAK_H
27#include "clang/Tooling/Core/Replacement.h"
28#include "llvm/ADT/StringRef.h"
29#include "llvm/Support/Error.h"
36class FeatureModuleSet;
52 llvm::vfs::FileSystem *VFS);
70 llvm::vfs::FileSystem *
FS =
nullptr;
84 E.ShowMessage = std::string(S);
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);
105 virtual const char *
id()
const = 0;
120 virtual std::string
title()
const = 0;
123 virtual llvm::StringLiteral
kind()
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; }
136std::vector<std::unique_ptr<Tweak>>
138 llvm::function_ref<
bool(
const Tweak &)> Filter,
139 const FeatureModuleSet *Modules);
144llvm::Expected<std::unique_ptr<Tweak>>
146 const FeatureModuleSet *Modules);
Stores and provides access to parsed AST.
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
An interface base for small context-sensitive refactoring actions.
virtual bool prepare(const Selection &Sel)=0
Run the first stage of the action.
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 hidden() const
Is this a 'hidden' tweak, which are off by 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.
virtual Expected< Effect > apply(const Selection &Sel)=0
Run the second stage of the action that would produce the actual effect.
virtual llvm::StringLiteral kind() const =0
Describes what kind of action this is.
llvm::Expected< std::unique_ptr< Tweak > > prepareTweak(StringRef ID, const Tweak::Selection &S, const FeatureModuleSet *Modules)
llvm::StringMap< Edit > FileEdits
A mapping from absolute file path (the one used for accessing the underlying VFS) to edits.
std::vector< std::unique_ptr< Tweak > > prepareTweaks(const Tweak::Selection &S, llvm::function_ref< bool(const Tweak &)> Filter, const FeatureModuleSet *Modules)
Calls prepare() on all tweaks that satisfy the filter, returning those that can run on the selection.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static llvm::Expected< Tweak::Effect > mainFileEdit(const SourceManager &SM, tooling::Replacements Replacements)
Creates an effect with an Edit for the main file.
static Effect showMessage(StringRef S)
std::optional< std::string > ShowMessage
A message to be displayed to the user.
bool FormatEdits
Whether the edits should be formatted before presenting to the client.
static llvm::Expected< std::pair< Path, Edit > > fileEdit(const SourceManager &SM, FileID FID, tooling::Replacements Replacements)
Path is the absolute, symlink-resolved path for the file pointed by FID in SM.
Input to prepare and apply tweaks.
SourceLocation Cursor
A location of the cursor in the editor.
unsigned SelectionBegin
The begin offset of the selection.
llvm::vfs::FileSystem * FS
File system used to access source code (for cross-file tweaks).
unsigned SelectionEnd
The end offset of the selection.
ParsedAST * AST
The parsed active file. Never null. (Pointer so Selection is movable).
const SymbolIndex * Index
The Index for handling codebase related queries.
SelectionTree ASTSelection
The AST nodes that were selected.
llvm::StringRef Code
The text of the active document.