Is there a plugin for vim, somewhat like Jsbeautify, which automatically generates JavaDoc like comments in the script files.
For example it will take this
function(a , b , c){
}
and return
/**
* Description.
*
* @param a Description.
* @param b Description.
* @param c Description.
*/
function(a , b , c){
}
Here's a little something to get you started - tweak as required!-)
" generate doc comment template
map <LocalLeader>/ :call GenerateDOCComment()<cr>
function! GenerateDOCComment()
let l = line('.')
let i = indent(l)
let pre = repeat(' ',i)
let text = getline(l)
let params = matchstr(text,'([^)]*)')
let paramPat = '\([$a-zA-Z_0-9]\+\)[, ]*\(.*\)'
echomsg params
let vars = []
let m = ' '
let ml = matchlist(params,paramPat)
while ml!=[]
let [_,var;rest]= ml
let vars += [pre.' * @param '.var]
let ml = matchlist(rest,paramPat,0)
endwhile
let comment = [pre.'/**',pre.' * '] + vars + [pre.' */']
call append(l-1,comment)
call cursor(l+1,i+3)
endfunction
Assuming the parameter list is on one line, it tries to match out the parameters, builds up a comment string, and appends that comment string to the line before the function header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With