Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ jsdoc.vim

jsdoc.vim generates JSDoc block comments based on a function signature.

![image](images/vim-jsdoc-screencast-preview.gif)

This plugin based on https://gist.github.com/3903772#file-jsdoc-vim written by [NAKAMURA, Hisashi](https://gist.github.com/sunvisor)

Depending on your confuguration, jsdoc.vim will prompt for description, `@return` type and description. It will also prompt you for types and descriptions for each function `@param`.

Data type tab completion supported for parameter and return types
* currently: `boolean`, `null`, `undefined`, `number`, `string`, `symbol`, `object`

## Usage
1. Move cursor on `function` keyword line.
2. Type `:JsDoc` or `<C-l>` which is default key mapping to insert JsDoc.
3. Insert JsDoc above the `function` keyword line.

## Configuration
**g:jsdoc_allow_input_prompt** *default: 0*
Allow prompt for intaractive input.
Allow prompt for interactive input.

**g:jsdoc_input_description** *default: 1*
Prompt for a function description
Expand Down
10 changes: 8 additions & 2 deletions autoload/jsdoc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ if !exists('g:jsdoc_allow_shorthand')
let g:jsdoc_allow_shorthand = 0
endif

" Return data types for argument type auto completion :)
function! jsdoc#listDataTypes(A,L,P)
let l:types = ['boolean', 'null', 'undefined', 'number', 'string', 'symbol', 'object']
return join(l:types, "\n")
endfunction

function! jsdoc#insert()
let l:jsDocregex = '^.\{-}\s*\([a-zA-Z_$][a-zA-Z0-9_$]*\)\s*[:=]\s*function\s*(\s*\([^)]*\)\s*).*$'
let l:jsDocregex2 = '^.\{-}\s*function\s\+\([a-zA-Z_$][a-zA-Z0-9_$]*\)\s*(\s*\([^)]*\)\s*).*$'
Expand Down Expand Up @@ -131,7 +137,7 @@ function! jsdoc#insert()

for l:arg in l:args
if g:jsdoc_allow_input_prompt == 1
let l:argType = input('Argument "' . l:arg . '" type: ')
let l:argType = input('Argument "' . l:arg . '" type: ', '', 'custom,jsdoc#listDataTypes')
let l:argDescription = input('Argument "' . l:arg . '" description: ')
" Prepend space to start of description only if it was provided
if l:argDescription != ''
Expand All @@ -145,7 +151,7 @@ function! jsdoc#insert()
endif
if g:jsdoc_return == 1
if g:jsdoc_allow_input_prompt == 1
let l:returnType = input('Return type (blank for no @return): ')
let l:returnType = input('Return type (blank for no @return): ', '', 'custom,jsdoc#listDataTypes')
let l:returnDescription = ''
if l:returnType != ''
if g:jsdoc_return_description == 1
Expand Down
Binary file added images/vim-jsdoc-screencast-preview.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.