Documentation ¶
Index ¶
- Variables
- func Prompt(input generate.PromptInput) string
- func Target(identifier string) string
- type Finder
- type FinderOption
- type Option
- type Service
- func (svc *Service) Extensions() []string
- func (svc *Service) Find(code []byte) ([]string, error)
- func (svc *Service) Minify(code []byte) ([]byte, error)
- func (svc *Service) Patch(ctx context.Context, identifier, doc string, code []byte) ([]byte, error)
- func (svc *Service) Prompt(input generate.PromptInput) string
Constants ¶
This section is empty.
Variables ¶
var ( // FileExtensions is a slice of strings representing the file extensions // supported by the package, such as ".go" for Go source files. FileExtensions = []string{".go"} // DefaultMinification is a predefined set of minification options used by the // Service to minify Go source code. The options include minifying unexported // elements, exporting functions with their bodies, and minifying all elements. DefaultMinification = []nodes.MinifyOptions{ nodes.MinifyUnexported, { FuncBody: true, Exported: true, }, nodes.MinifyExported, nodes.MinifyAll, } )
Functions ¶
func Prompt ¶
func Prompt(input generate.PromptInput) string
Prompt takes an input of type generate.Input and generates a string that forms a GoDoc-style comment for the input. It first creates a target description of the identifier contained in the input using the Target function, and obtains a simplified identifier with the simpleIdentifier function. The resulting string is formatted to provide instructions on how to write a GoDoc comment for the targeted identifier.
Types ¶
type Finder ¶
type Finder struct {
// contains filtered or unexported fields
}
Finder is a utility that searches for exported identifiers in Go code, with options to include or exclude test functions and documented identifiers. It can be configured using FinderOption functions like FindTests and IncludeDocumented. The Find method takes a byte slice of Go code and returns a sorted slice of strings representing the found exported identifiers.
func NewFinder ¶
func NewFinder(opts ...FinderOption) *Finder
NewFinder creates a new Finder with the provided options. The Finder can be used to find exported identifiers in Go code, optionally including test functions and documented identifiers.
func (*Finder) Find ¶
Find searches the provided code for exported identifiers, such as functions, types, and variables. It returns a sorted slice of strings containing the found identifiers. The search can be configured to include or exclude test functions and documented identifiers with FinderOptions.
type FinderOption ¶
type FinderOption func(*Finder)
FinderOption is a function type that modifies the behavior of a Finder, which searches for exported identifiers in Go code. Common options include FindTests and IncludeDocumented.
func FindTests ¶
func FindTests(find bool) FinderOption
FindTests is a function that returns a FinderOption which sets the findTests field of a Finder. The findTests field determines whether or not test functions should be included in the search results.
func IncludeDocumented ¶
func IncludeDocumented(include bool) FinderOption
IncludeDocumented modifies a Finder to include documented declarations if the passed boolean is true. If false, only undocumented declarations will be considered by the Finder.
type Option ¶
type Option func(*Service)
Option is a function that modifies a Service instance. It is used to provide optional configurations for the Service during its creation, such as setting the finder, model, or minification steps.
func ClearComments ¶ added in v0.0.10
ClearComments is an Option that sets whether or not to remove comments from the code when generating a prompt for the Service. If clear is true, comments will be removed; otherwise, they will be preserved.
func Minify ¶
func Minify(steps []nodes.MinifyOptions) Option
Minify is an Option that sets the minification steps for a Service, specifying how the source code should be minified in each step.
func Model ¶
Model sets the model name for a Service. The provided model name is used to create a tokenizer.Codec and determine the maximum number of tokens allowed for code minification.
func WithFinder ¶
WithFinder sets the Finder for a Service, which is used to search for specific elements in the source code.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is a type that provides functionality for parsing, minifying, and patching Go source code. It can find identifiers, minify source code based on configured steps, generate prompts, and apply documentation patches to specified identifiers. The Service can be customized with various options, such as setting a Finder for searching elements in the source code, specifying a model for the tokenizer, and configuring minification steps.
func Must ¶
Must creates a new Service with the provided options and panics if an error occurs. It is useful for creating a Service when it is known that the provided options are valid and an error will not occur.
func New ¶
New creates a new Service with the provided options, initializes its tokenizer based on the model, and sets the maximum tokens allowed. If no finder is provided, it creates a new Finder. Returns an error if there's an issue creating the tokenizer.
func (*Service) Extensions ¶
Extensions returns a copy of the slice containing file extensions supported by the Service.
func (*Service) Find ¶
Find returns a slice of strings representing the identifiers found in the provided code byte slice. An error is returned if the search for identifiers fails.
func (*Service) Minify ¶
Minify takes a byte slice of code and returns a minified version of the code, removing unnecessary elements based on the minification steps configured for the Service. If the minified code's token count is within the limit, it returns the minified code; otherwise, it returns an error.
func (*Service) Patch ¶
Patch applies a given documentation string to the specified identifier in the provided code, and returns the updated code. It updates the documentation for functions, general declarations, type specifications, value specifications, and fields. If the specified identifier is not found in the code, an error is returned.
func (*Service) Prompt ¶
func (svc *Service) Prompt(input generate.PromptInput) string
Prompt takes an input of type generate.Input and returns a string. If the Service is configured to clear comments, it clears the comments from the input code before generating the prompt.