Skip to content

Commit

Permalink
feat(javascript): Add Promise<T> as a return type when a function is …
Browse files Browse the repository at this point in the history
…async
  • Loading branch information
kkoomen committed May 22, 2020
1 parent 9553b5b commit 57712e9
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion autoload/doge.vim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function! doge#generate(arg) abort
if a:arg <= len(b:doge_supported_doc_standards)
let b:doge_doc_standard = b:doge_supported_doc_standards[a:arg - 1]
endif
elseif type(a:arg) ==# type('') && a:arg !=# ''
elseif type(a:arg) ==# type('') && !empty(a:arg)
if index(b:doge_supported_doc_standards, a:arg) >= 0
let b:doge_doc_standard = a:arg
endif
Expand Down
2 changes: 1 addition & 1 deletion autoload/doge/pattern.vim
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ endfunction
" Generates a template for a custom doc standard, and places it in
" after/ftplugin/{&ft}.vim
function! doge#pattern#custom(name) abort
if &filetype ==# ''
if empty(&filetype)
echo '[DoGe] A filetype is required in order to create a custom pattern.'
return 0
endif
Expand Down
8 changes: 7 additions & 1 deletion autoload/doge/preprocessors/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ function! doge#preprocessors#javascript#tokens(tokens) abort
if has_key(a:tokens, 'returnType')
if a:tokens['returnType'] ==# 'void'
let a:tokens['returnType'] = ''
elseif a:tokens['returnType'] ==# ''
elseif empty(a:tokens['returnType'])
let a:tokens['returnType'] = '!type'

" When we're dealing with an async function the return type is Promise<T>.
" Only wrap the return type in a Promise when the type is not specified.
if has_key(a:tokens, 'async') && !empty(a:tokens['async'])
let a:tokens['returnType'] = 'Promise<' . a:tokens['returnType'] . '>'
endif
endif
endif
endfunction
Expand Down
2 changes: 1 addition & 1 deletion autoload/doge/preprocessors/php.vim
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function! s:get_property_type_via_constructor(propertyName) abort

" Search for the constructor function in that class.
if match(l:class_content, '__construct(') != -1
let l:constructor_func_match = filter(matchlist(l:class_content, '\m\(__construct(.\{-})\s*{.\{-}}\)'), "v:val !=# ''")
let l:constructor_func_match = filter(matchlist(l:class_content, '\m\(__construct(.\{-})\s*{.\{-}}\)'), "!empty(v:val)")
let l:constructor_func_contents = l:constructor_func_match[1]
if l:constructor_func_contents != v:false
" Constructor exists, grab the type hint and if it exists then set it.
Expand Down
2 changes: 1 addition & 1 deletion autoload/doge/preprocessors/typescript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function! doge#preprocessors#typescript#tokens(tokens) abort
if has_key(a:tokens, 'returnType')
if a:tokens['returnType'] ==# 'void'
let a:tokens['returnType'] = ''
elseif a:tokens['returnType'] ==# ''
elseif empty(a:tokens['returnType'])
let a:tokens['returnType'] = '!type'
endif
endif
Expand Down
2 changes: 1 addition & 1 deletion test/filetypes/javascript/functions-inside-objects.vader
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Expect javascript (generated comment with @async, @function, @param and @return
* @param {array} [p2] - [TODO:description]
* @param {[TODO:type]} p3 - [TODO:description]
* @param {[TODO:type]} p4 - [TODO:description]
* @return {[TODO:type]} [TODO:description]
* @return {Promise<[TODO:type]>} [TODO:description]
*/
'my-func': async function test($p1: string = 'value', p2: array = [], p3, p4 /* inline comment */) {
//
Expand Down
4 changes: 2 additions & 2 deletions test/filetypes/javascript/functions.vader
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Expect javascript (generated comment with @async, @param and @return tags):
* @param {[TODO:type]} [p2] - [TODO:description]
* @param {[TODO:type]} p3 - [TODO:description]
* @param {[TODO:type]} p4 - [TODO:description]
* @return {[TODO:type]} [TODO:description]
* @return {Promise<[TODO:type]>} [TODO:description]
*/
async function myFunc($p1 = 'value', p2 = [], p3, p4) {}

Expand Down Expand Up @@ -221,7 +221,7 @@ Expect javascript (generated comment with @async, @param and @return tags):
* @param {[TODO:type]} [p2] - [TODO:description]
* @param {[TODO:type]} p3 - [TODO:description]
* @param {[TODO:type]} p4 - [TODO:description]
* @return {[TODO:type]} [TODO:description]
* @return {Promise<[TODO:type]>} [TODO:description]
*/
async function* myFunc($p1 = 'value', p2 = [], p3, p4) {}

Expand Down

0 comments on commit 57712e9

Please sign in to comment.