/docs/editors/README.md
Editor Support
This doc file contains tips on how to handle the bulk of boilerplate needed for asyncmachine-go.
Agent Skills
Using LLMs to generate boilerplate is often faster than using am-gen or using live
templates. Dirs with SKILL.md files are auto-generated from documentation using the command below. Each skill being a
single file can easily be copy-pasted and guarantees the highest compatibility.
# in repo root
./scripts/dep-taskfile.sh
task gen-docs-skills
cp ./docs/editors/skills/* $DEST
Token Usage
Skills are divided based on token usage, each fully contained within a single SKILL.md file.
/am-mini~1.3k tokens - compacted version/am~2.9k tokens - basic boilerplate/am-cook~11k tokens - also includes /docs/cookbook.md/am-full~18k tokens - also includes /docs/manual.md
Live Templates
Live templates expand semantically inside Goland IDE for fast tab-completion.
Handler
am
var _ = $SS$.$STATE$
func ($N$ *$HANDLERS$) $STATE$$TYPE$(e *am.Event) $RET$ {
$END$
}
| Name | Expression | Default value | Skip if defined |
|---|---|---|---|
SS |
completeSmart() |
ss | |
STATE |
completeSmart() |
"Foo" |
|
TYPE |
enum("State","Enter","Exit","End") |
"State" |
|
RET |
enum("","bool") |
||
HANDLERS |
completeSmart() |
||
N |
goSuggestVariableName() |
"h" |
Handler With Boilerplate
am2
var _ = $SS$.$STATE$
func ($N$ *$HANDLERS$) $STATE$$TYPE$(e *am.Event) $RET$ {
ctx := $N$.Mach.NewStateCtx($STATE$)
mach := $N$.Mach
mach.Fork(ctx, e, func() {
$END$
})
}
| Name | Expression | Default value | Skip if defined |
|---|---|---|---|
SS |
completeSmart() |
ss | |
STATE |
completeSmart() |
"Foo" |
|
TYPE |
enum("State","Enter","Exit","End") |
"State" |
|
RET |
enum("","bool") |
||
HANDLERS |
completeSmart() |
||
N |
goSuggestVariableName() |
"h" |
Error Setter
amerr
var Err$NAME$ = errors.New("$NAME2$ error")
// AddErr$NAME$ adds [Err$NAME$].
func AddErr$NAME$(
event *am.Event, mach *am.Machine, err error, args ...am.A,
) am.Result {
if err == nil {
return am.Executed
}
err = fmt.Errorf("%w: %w", Err$NAME$, err)
return mach.EvAddErrState(event, ss.Err$NAME$, err, am.OptArgs(args))
}
| Name | Expression | Default value | Skip if defined |
|---|---|---|---|
NAME |
capitalize(String) |
||
NAME2 |
camelCase(String) |
$NAME$ |
Context Expiration Check
ctxexp
if ctx.Err() != nil {
return // expired
}$END$
