Skip to content

Commit 05199b0

Browse files
committed
✨ Enhance script with doc generation and edits
Added function doc generation, edit commitment, and normalization.
1 parent 7780dc1 commit 05199b0

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

packages/sample/genaisrc/ast-docs.genai.mts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ script({
1313
const { output } = env
1414
const { applyEdits } = env.vars
1515
const file = env.files[0]
16+
1617
// find all exported functions without comments
1718
const sg = await host.astGrep()
1819
const { matches, replace, commitEdits } = await sg.search("ts", file.filename, {
@@ -36,6 +37,7 @@ for (const match of matches) {
3637
(_) => {
3738
_.def("FILE", match.getRoot().root().text())
3839
_.def("FUNCTION", match.text())
40+
// this needs more eval-ing
3941
_.$`Generate a function documentation for <FUNCTION>.
4042
- Be concise. Use technical tone.
4143
- do NOT include types, this is for TypeScript.
@@ -53,6 +55,8 @@ for (const match of matches) {
5355
const updated = `${docs}\n${match.text()}`
5456
replace(match, updated)
5557
}
58+
59+
// apply all edits and write to the file
5660
const modified = await commitEdits()
5761
if (applyEdits) {
5862
await workspace.writeFiles(modified)
@@ -63,6 +67,7 @@ if (applyEdits) {
6367
)
6468
}
6569

70+
// normalizes the docstring in case the LLM decides not to generate proper comments
6671
function docify(docs: string) {
6772
if (!/^\/\*\*.*.*\*\/$/s.test(docs))
6873
docs = `/**\n* ${docs.split(/\r?\n/g).join("\n* ")}\n*/`

0 commit comments

Comments
 (0)