Documentation ¶
Index ¶
- type Finding
- type JotBot
- func (bot *JotBot) ConfigureLanguage(name string, lang Language)
- func (bot *JotBot) Extensions() []string
- func (bot *JotBot) Find(ctx context.Context, opts ...find.Option) ([]Finding, error)
- func (bot *JotBot) Generate(ctx context.Context, findings []Finding, svc generate.Service, ...) (*Patch, error)
- type Language
- type Option
- type Patch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Finding ¶ added in v0.0.4
Finding represents a single code identifier found within a file with its associated language.
type JotBot ¶ added in v0.0.4
type JotBot struct {
// contains filtered or unexported fields
}
JotBot is a utility for finding and generating code snippets in various programming languages within a project. It supports configurable languages, filters, and file systems, and offers patching capabilities for applying generated changes.
func New ¶
New creates a new JotBot instance with the given root directory and options. The returned JotBot is configured with the provided languages, filters, and logger.
func (*JotBot) ConfigureLanguage ¶ added in v0.0.4
ConfigureLanguage configures a Language for the given name, associating it with the provided extensions. The Language is used by JotBot to find and generate code for identifiers in files with the associated extensions.
func (*JotBot) Extensions ¶ added in v0.0.4
Extensions returns a slice of file extensions that are associated with configured languages in the JotBot instance.
func (*JotBot) Find ¶ added in v0.0.4
Find searches the JotBot's root directory for files matching the provided options, extracts identifiers from those files using the configured languages, and returns a slice of Findings containing the extracted identifiers, file paths, and language names. It filters the extracted identifiers based on the JotBot's configured filters. If any error occurs during the process, it returns the error.
func (*JotBot) Generate ¶ added in v0.0.4
func (bot *JotBot) Generate(ctx context.Context, findings []Finding, svc generate.Service, opts ...generate.Option) (*Patch, error)
Generate creates a Patch by generating code snippets for the given Findings using the provided generate.Service and options. It returns a Patch that can be applied to the project or used in a dry run.
type Language ¶ added in v0.0.4
type Language interface { patch.Language generate.Language // Extensions returns a slice of file extensions that are supported by the // Language. Each extension is associated with a specific language // implementation for code generation and patching purposes. Extensions() []string // Find searches the provided byte slice for identifiers in the language and // returns a slice of found identifiers along with any error encountered during // the search. Find([]byte) ([]string, error) }
Language is an interface that combines the patch.Language and generate.Language interfaces, adding methods to retrieve supported file extensions and find identifiers within source code. It is used by JotBot to work with different programming languages, allowing for language-specific operations such as finding identifiers and generating patches.
type Option ¶
type Option func(*JotBot)
Option is a function that takes a pointer to a JotBot and modifies its configuration. It can be used to set custom languages, loggers, or filters for the JotBot instance.
func Match ¶ added in v0.0.4
Match appends the provided regular expression filters to the JotBot's filters. These filters are used to determine which findings should be included in the final result when searching for identifiers in files.
func WithLanguage ¶ added in v0.0.4
WithLanguage configures a JotBot instance to use the specified language for processing files with the given name. It associates the language with its supported file extensions.
func WithLogger ¶
WithLogger configures a JotBot to use the provided slog.Handler for logging.
type Patch ¶ added in v0.0.4
Patch is a wrapper around a patch.Patch that provides additional functionality for applying and dry-running patches using Language implementations. It is used to generate, apply, and preview changes to source code based on the provided findings.
func (*Patch) Apply ¶ added in v0.0.4
Apply applies the patch to the filesystem rooted at the given root path, using the configured languages for applying changes. The operation can be canceled through the provided context. It returns an error if any issues are encountered during the application process.