Skip to content

Commit

Permalink
Merge branch 'feature_default_message'
Browse files Browse the repository at this point in the history
  • Loading branch information
heavenshell committed Sep 3, 2015
2 parents c88dafd + 57af941 commit a0c8603
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -33,6 +33,7 @@ Option | Default | Description
**g:jsdoc_allow_shorthand** | 0 | Set value to 1 to allow ECMAScript6 shorthand syntax.
**g:jsdoc_param_description_separator** | ' ' | Characters used to separate `@param` name and description.
**g:jsdoc_custom_args_hook** | {} | Override default type and description. See help more detail.
**g:jsdoc_type_hook** | {} | Allow to insert default description depending on the type.

## Keymap
Since version `0.3`, `g:jsdoc_default_mapping` was removed.
Expand Down
34 changes: 31 additions & 3 deletions autoload/jsdoc.vim
@@ -1,7 +1,7 @@
" File: jsdoc.vim
" Author: NAKAMURA, Hisashi <https://github.com/sunvisor>
" Modifyed: Shinya Ohyanagi <sohyanagi@gmail.com>
" Version: 0.3.1
" Version: 0.4.0
" WebPage: http://github.com/heavenshell/vim-jsdoc/
" Description: Generate JSDoc to your JavaScript file.
" License: BSD, see LICENSE for more details.
Expand Down Expand Up @@ -60,12 +60,41 @@ if !exists('g:jsdoc_custom_args_hook')
let g:jsdoc_custom_args_hook = {}
endif

if !exists('g:jsdoc_type_hook')
let g:jsdoc_type_hook = {}
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', 'function', 'array']
return join(l:types, "\n")
endfunction

function! s:build_description(argType, arg)
let description = ''
let override = 0
if has_key(g:jsdoc_type_hook, a:argType)
if type(g:jsdoc_type_hook[a:argType]) == 1
let description = g:jsdoc_type_hook[a:argType]
elseif type(g:jsdoc_type_hook[a:argType]) == 4
if has_key(g:jsdoc_type_hook[a:argType], 'force_override')
let override = g:jsdoc_type_hook[a:argType]['force_override']
endif
if has_key(g:jsdoc_type_hook[a:argType], 'description')
let description = g:jsdoc_type_hook[a:argType]['description']
endif
endif
endif
if override == 0
let inputDescription = input('Argument "' . a:arg . '" description: ')
if inputDescription != ''
let description = inputDescription
endif
endif

return description
endfunction

function! s:hookArgs(lines, space, arg, hook, argType, argDescription)
" Hook function signature's args for insert as default value.
if g:jsdoc_custom_args_hook == {}
Expand Down Expand Up @@ -185,8 +214,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: ', '', 'custom,jsdoc#listDataTypes')
let l:argDescription = input('Argument "' . l:arg . '" description: ')

let l:argDescription = s:build_description(l:argType, l:arg)
if g:jsdoc_custom_args_hook == {}
" Prepend separator to start of description only if it was provided
if l:argDescription != ''
Expand Down
26 changes: 26 additions & 0 deletions doc/jsdoc.txt
Expand Up @@ -168,8 +168,34 @@ g:jsdoc_custom_args_hook *g:jsdoc_custom_args_hook*
function foo(bar, callback, cb) {
}
g:jsdoc_type_hook *g:jsdoc_type_hook*
Allow to insert default description depending on the type.

Default value is '{}'
>
If you set following setting to .vimrc or _vimrc.
let g:jsdoc_type_hook = {
\ 'object': {
\ 'description':'An object containing the following fields',
\ 'force_override': 1,
\ },
\ 'function': 'Callback function'
\ }
The key of g:jsdoc_type_hook is a variable type.
If type is an {object} and force_override is 1,
insert g:jsdoc_type_hook['object']['description'] automagically.
If forece_override is 0 or not set, JSDoc.vim ask to
input description. If you did not enter description,
g:jsdoc_type_hook['object']['description'] would insert
automagically.
==============================================================================
CHANGELOG *jsdoc-changelog*
2015-08-29
- Add g:jsdoc_type_hook.
See https://github.com/heavenshell/vim-jsdoc/issues/36 details.

2015-08-28
- Add function and array to tab completion
(thx @jacoborus)
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/javascript/jsdoc.vim
@@ -1,7 +1,7 @@
" File: jsdoc.vim
" Author: NAKAMURA, Hisashi <https://github.com/sunvisor>
" Modifyed: Shinya Ohyanagi <sohyanagi@gmail.com>
" Version: 0.3.1
" Version: 0.4.0
" WebPage: http://github.com/heavenshell/vim-jsdoc/
" Description: Generate JSDoc to your JavaScript file.
" License: BSD, see LICENSE for more details.
Expand Down

0 comments on commit a0c8603

Please sign in to comment.