@@ -13,6 +13,7 @@ script({
1313const { output } = env
1414const { applyEdits } = env . vars
1515const file = env . files [ 0 ]
16+
1617// find all exported functions without comments
1718const sg = await host . astGrep ( )
1819const { 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
5660const modified = await commitEdits ( )
5761if ( 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
6671function docify ( docs : string ) {
6772 if ( ! / ^ \/ \* \* .* .* \* \/ $ / s. test ( docs ) )
6873 docs = `/**\n* ${ docs . split ( / \r ? \n / g) . join ( "\n* " ) } \n*/`
0 commit comments