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 an identifier found within a file and its associated language.
type JotBot ¶ added in v0.0.4
type JotBot struct {
// contains filtered or unexported fields
}
JotBot is a tool for finding, generating, and patching code snippets in multiple programming languages. It supports customizable language configurations and can be extended with additional languages. JotBot can filter findings based on regular expressions, generate new code snippets using a provided generate.Service, and apply or dry-run patches to modify the source code.
func New ¶
New creates a new JotBot instance with the specified root directory and optional configurations. The returned JotBot can be used to find and generate code snippets based on configured languages and filters.
func (*JotBot) ConfigureLanguage ¶ added in v0.0.4
ConfigureLanguage configures a Language for the given name and adds the language's file extensions to the mapping of extensions to languages.
func (*JotBot) Extensions ¶ added in v0.0.4
Extensions returns a slice of file extensions for which a language is configured in the JotBot instance.
func (*JotBot) Find ¶ added in v0.0.4
Find searches for files in the root directory of a JotBot instance, filters them by configured languages, and returns a slice of findings. Each finding includes the identifier, file path, and language name associated with the matched file. The search can be further customized using context and find options.
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 for the given Findings using the provided generate.Service and options. It returns an error if there is any issue during code generation.
type Language ¶ added in v0.0.4
type Language interface { patch.Language generate.Language // Extensions returns a slice of file extensions supported by the configured // languages in the Language interface. Extensions() []string // Find searches the provided byte slice for language-specific identifiers and // returns a slice of found identifiers and an error if any occurs. Find([]byte) ([]string, error) }
Language is an interface that combines the functionality of patch.Language and generate.Language, providing methods for file extension handling and finding identifiers in source code. It extends the capabilities of patching and generating code by allowing customization for different programming languages.
type Option ¶
type Option func(*JotBot)
Option is a function that configures a JotBot instance. It takes a JotBot pointer as an argument and modifies its properties according to the desired configuration. Common options include WithLanguage, which associates a language with JotBot, and WithLogger, which sets up a logger for the JotBot instance.
func Match ¶ added in v0.0.4
Match adds the provided regular expression filters to the JotBot instance, which are then used to filter identifiers found in files during the Find operation.
func WithLanguage ¶ added in v0.0.4
WithLanguage configures a JotBot instance to use the specified Language implementation with the given name. The Language implementation is used for finding identifiers, generating code, and patching files with the corresponding file extension.
func WithLogger ¶
WithLogger configures a JotBot to use the provided slog.Handler for logging.
type Patch ¶ added in v0.0.4
Patch represents a set of changes to be applied to source code files. It provides methods for applying the changes directly or performing a dry run to preview the resulting files without modifying them. A Patch is created by generating code from a list of findings using a generate.Service and various generate.Option values.
func (*Patch) Apply ¶ added in v0.0.4
Apply applies the patch to the files in the provided root directory. It returns an error if there is an issue applying the patch or accessing the file system.
func (*Patch) DryRun ¶ added in v0.0.4
DryRun applies the patch in a simulated environment without making actual changes to the files in the specified root directory, returning a map of filenames to their updated contents after applying the patch. It is useful for previewing changes before applying them.