diff --git a/autoload/doge.vim b/autoload/doge.vim index 3077d312..8f0e3243 100644 --- a/autoload/doge.vim +++ b/autoload/doge.vim @@ -15,7 +15,7 @@ function! doge#generate(arg) abort " If the command is run with a count or a string as argument, the user is " requesting for a specific doc standard. " If no matching standards are found, or no arg (count or string) is given, - " just use whatever is currently set + " just use whatever is currently set. if exists('b:doge_supported_doc_standards') if type(a:arg) ==# type(0) && a:arg != 0 if a:arg <= len(b:doge_supported_doc_standards) @@ -29,7 +29,7 @@ function! doge#generate(arg) abort endif if exists('b:doge_patterns') - for l:pattern in get(b:, 'doge_patterns') + for l:pattern in get(b:doge_patterns, b:doge_doc_standard) if doge#generate#pattern(l:pattern) == v:false continue else diff --git a/autoload/doge/generate.vim b/autoload/doge/generate.vim index 282000ef..5370ac92 100644 --- a/autoload/doge/generate.vim +++ b/autoload/doge/generate.vim @@ -77,12 +77,9 @@ function! doge#generate#pattern(pattern) abort endtry for l:param_token in l:param_tokens - let l:format_doc_standard = has_key(l:params_dict['format'], b:doge_doc_standard) - \ ? l:params_dict['format'][b:doge_doc_standard] - \ : l:params_dict['format'][b:doge_supported_doc_standards[0]] let l:format = doge#token#replace( \ l:param_token, - \ l:format_doc_standard + \ l:params_dict['format'] \ ) if type(l:format) == v:t_list call add(l:formatted_params, join(l:format, "\n")) @@ -96,10 +93,7 @@ function! doge#generate#pattern(pattern) abort " Create the comment by replacing the tokens in the template with their " corresponding values. let l:comment = [] - let l:comment_template_doc_standard = has_key(a:pattern['comment']['template'], b:doge_doc_standard) - \ ? a:pattern['comment']['template'][b:doge_doc_standard] - \ : a:pattern['comment']['template'][b:doge_supported_doc_standards[0]] - for l:line in l:comment_template_doc_standard + for l:line in a:pattern['template'] " If empty lines are present, just append them to ensure a whiteline is " inserted rather then completely removed. This allows us to insert some " whitelines in the comment template. @@ -116,7 +110,7 @@ function! doge#generate#pattern(pattern) abort endfor endfor - if a:pattern['comment']['insert'] ==# 'below' + if a:pattern['insert'] ==# 'below' let l:comment_lnum_insert_position = line('.') let l:comment_lnum_inherited_indent = line('.') + 1 else @@ -132,7 +126,7 @@ function! doge#generate#pattern(pattern) abort " Update the inherited_indent variable based on the new insert position. " For now we only have to do this for languages like Python where we insert " below the declaration. - if a:pattern['comment']['insert'] ==# 'below' + if a:pattern['insert'] ==# 'below' let l:comment_lnum_inherited_indent = l:comment_lnum_insert_position + 1 endif catch /^Vim\%((\a\+)\)\=:E117/ @@ -149,7 +143,7 @@ function! doge#generate#pattern(pattern) abort " Enable interactive mode. if g:doge_comment_interactive == v:true - if a:pattern['comment']['insert'] ==# 'below' + if a:pattern['insert'] ==# 'below' let l:todo_match = search(s:comment_placeholder, 'nW', l:comment_lnum_insert_position + len(l:comment)) else let l:todo_match = search(s:comment_placeholder, 'bnW', l:comment_lnum_insert_position + 1) diff --git a/autoload/doge/helpers.vim b/autoload/doge/helpers.vim index e3706b89..f5fd70cf 100644 --- a/autoload/doge/helpers.vim +++ b/autoload/doge/helpers.vim @@ -95,6 +95,25 @@ function! doge#helpers#generator(generator) abort return 0 endfunction +"" @public +" Recursively merge nested dictionaries. +" a:1 is the base dictionary and every other parameter will be merged onto a:1. +function! doge#helpers#deepextend(...) abort + " Thanks to: https://vi.stackexchange.com/a/20843 + let l:new = deepcopy(a:1) + for l:arg in a:000 + let l:index = index(a:000, l:arg) + if l:index == 0 + continue + endif + for [l:k, l:v] in items(l:arg) + let l:new[l:k] = (type(l:v) is v:t_dict && type(get(l:new, l:k)) is v:t_dict) + \ ? doge#helpers#deepextend(l:new[l:k], l:v) + \ : l:v + endfor + endfor + return l:new +endfunction let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/autoload/doge/preprocessors/groovy.vim b/autoload/doge/preprocessors/groovy.vim index e56a0fdc..bdec4fb3 100644 --- a/autoload/doge/preprocessors/groovy.vim +++ b/autoload/doge/preprocessors/groovy.vim @@ -16,5 +16,13 @@ function! doge#preprocessors#groovy#insert_position(lnum_insert_pos) abort return a:lnum_insert_pos endfunction +" A callback function being called after the tokens have been extracted. This +" function will adjust the input if needed. +function! doge#preprocessors#groovy#tokens(tokens) abort + if has_key(a:tokens, 'returnType') && a:tokens['returnType'] ==# 'void' + let a:tokens['returnType'] = '' + endif +endfunction + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/c.vim b/ftplugin/c.vim index 8aad104d..f61bd431 100644 --- a/ftplugin/c.vim +++ b/ftplugin/c.vim @@ -7,6 +7,11 @@ let s:save_cpo = &cpoptions set cpoptions&vim +" The C filetype also gets triggerred for C++, so we want to ignore this. +if &filetype !=? 'c' + finish +endif + let b:doge_pattern_single_line_comment = '\m\(\/\*.\{-}\*\/\|\/\/.\{-}$\)' let b:doge_pattern_multi_line_comment = '\m\/\*.\{-}\*\/' @@ -27,166 +32,210 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} " ============================================================================== -" Functions and methods. +" Define our base for every pattern. " ============================================================================== -call add(b:doge_patterns, { +let s:pattern_base = { \ 'generator': { \ 'file': 'libclang.py', -\ 'args': [ -\ 'CONSTRUCTOR', -\ 'CXX_METHOD', -\ 'FUNCTION_DECL', -\ 'FUNCTION_TEMPLATE', -\ 'CLASS_TEMPLATE' -\ ], \ }, \ 'parameters': { -\ 'format': { -\ 'doxygen_javadoc': '@{param-type|param} {name} !description', -\ 'kernel_doc': '@{name}: !description', -\ }, +\ 'format': '@{param-type|param} {name} !description', \ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'doxygen_javadoc': [ -\ '/**', -\ ' * @brief !description', -\ ' *', -\ '%(parameters| * {parameters})%', -\ '%(returnType| * @return !description)%', -\ ' */', -\ ], -\ 'doxygen_javadoc_no_asterisk': [ -\ '/**', -\ '@brief !description', -\ '', -\ '%(parameters|{parameters})%', -\ '%(returnType|@return !description)%', -\ '*/', -\ ], -\ 'doxygen_javadoc_banner': [ -\ '/*******************************************************************************', -\ ' * @brief !description', -\ ' *', -\ '%(parameters| * {parameters})%', -\ '%(returnType| * @return !description)%', -\ ' ******************************************************************************/', -\ ], -\ 'doxygen_qt': [ -\ '/*!', -\ ' * @brief !description', -\ ' *', -\ '%(parameters| * {parameters})%', -\ '%(returnType| * @return !description)%', -\ ' */', -\ ], -\ 'doxygen_qt_no_asterisk': [ -\ '/*!', -\ '@brief !description', -\ '', -\ '%(parameters|{parameters})%', -\ '%(returnType|@return !description)%', -\ '*/', -\ ], -\ 'kernel_doc': [ -\ '/**', -\ ' * {name}(): !description', -\ '%(parameters| * {parameters})%', -\ ' *', -\ ' * !description', -\ '%(returnType| *)%', -\ '%(returnType| * Return: !description)%', -\ ' */', -\ ], -\ }, -\ }, -\}) +\ 'insert': 'above', +\} " ============================================================================== -" Struct declarations. +" Define the pattern types. " ============================================================================== -call add(b:doge_patterns, { + +" ------------------------------------------------------------------------------ +" Matches regular functions. +" ------------------------------------------------------------------------------ +" int add(int x, int y) {} +" template void h(int i = 0, T... args) {} +" ------------------------------------------------------------------------------ +let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'generator': { -\ 'file': 'libclang.py', -\ 'args': ['STRUCT_DECL'], -\ }, -\ 'parameters': { -\ 'format': { -\ 'doxygen_javadoc': '@{name}: !description', -\ }, +\ 'args': ['FUNCTION_DECL'], \ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'doxygen_javadoc': [ -\ '/**', -\ ' * struct {name} - !description', -\ '%(parameters| *)%', -\ '%(parameters| * {parameters})%', -\ ' */', -\ ], -\ 'doxygen_javadoc_no_asterisk': [ -\ '/**', -\ 'struct {name} - !description', -\ '%(parameters|)%', -\ '%(parameters|{parameters})%', -\ '*/', -\ ], -\ 'doxygen_javadoc_banner': [ -\ '/*******************************************************************************', -\ ' * struct {name} - !description', -\ '%(parameters| *)%', -\ '%(parameters| * {parameters})%', -\ ' ******************************************************************************/', -\ ], -\ 'doxygen_qt': [ -\ '/*!', -\ ' * struct {name} - !description', -\ '%(parameters| *)%', -\ '%(parameters| * {parameters})%', -\ ' */', -\ ], -\ 'doxygen_qt_no_asterisk': [ -\ '/*!', -\ 'struct {name} - !description', -\ '%(parameters|)%', -\ '%(parameters|{parameters})%', -\ '*/', -\ ], -\ 'kernel_doc': [ -\ '/**', -\ ' * struct {name} - !description', -\ '%(parameters|)%', -\ '%(parameters| * {parameters})%', -\ ' */', -\ ], -\ }, +\}) + +" ------------------------------------------------------------------------------ +" Matches structs. +" ------------------------------------------------------------------------------ +" struct foo { }; +" ------------------------------------------------------------------------------ +let s:struct_pattern = doge#helpers#deepextend(s:pattern_base, { +\ 'generator': { +\ 'args': ['STRUCT_DECL'], \ }, \}) -" ============================================================================== -" Field declarations. -" ============================================================================== -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" Matches field declarations inside structs. +" ------------------------------------------------------------------------------ +" struct foo { +" int bar; +" }; +" ------------------------------------------------------------------------------ +let s:field_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'generator': { -\ 'file': 'libclang.py', \ 'args': ['FIELD_DECL'], \ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'doxygen_javadoc': [ -\ '/**', -\ ' * @{name} !description', -\ ' */', -\ ], -\ }, -\ }, +\ 'parameters': v:false, +\ 'template': [ +\ '/**', +\ ' * @{name} !description', +\ ' */', +\ ], \}) +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.doxygen_javadoc = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/**', +\ ' * @brief !description', +\ ' *', +\ '%(parameters| * {parameters})%', +\ '%(returnType| * @return !description)%', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:struct_pattern, { +\ 'template': [ +\ '/**', +\ ' * struct {name} - !description', +\ '%(parameters| *)%', +\ '%(parameters| * {parameters})%', +\ ' */', +\ ], +\ }), +\ s:field_pattern, +\] + +let b:doge_patterns.doxygen_javadoc_no_asterisk = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/**', +\ '@brief !description', +\ '', +\ '%(parameters|{parameters})%', +\ '%(returnType|@return !description)%', +\ '*/', +\ ], +\ }), +\ doge#helpers#deepextend(s:struct_pattern, { +\ 'template': [ +\ '/**', +\ 'struct {name} - !description', +\ '%(parameters|)%', +\ '%(parameters|{parameters})%', +\ '*/', +\ ], +\ }), +\ s:field_pattern, +\] + +let b:doge_patterns.doxygen_javadoc_banner = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/*******************************************************************************', +\ ' * @brief !description', +\ ' *', +\ '%(parameters| * {parameters})%', +\ '%(returnType| * @return !description)%', +\ ' ******************************************************************************/', +\ ], +\ }), +\ doge#helpers#deepextend(s:struct_pattern, { +\ 'template': [ +\ '/*******************************************************************************', +\ ' * struct {name} - !description', +\ '%(parameters| *)%', +\ '%(parameters| * {parameters})%', +\ ' ******************************************************************************/', +\ ], +\ }), +\ s:field_pattern, +\] + +let b:doge_patterns.doxygen_qt = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/*!', +\ ' * @brief !description', +\ ' *', +\ '%(parameters| * {parameters})%', +\ '%(returnType| * @return !description)%', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:struct_pattern, { +\ 'template': [ +\ '/*!', +\ ' * struct {name} - !description', +\ '%(parameters| *)%', +\ '%(parameters| * {parameters})%', +\ ' */', +\ ], +\ }), +\ s:field_pattern, +\] + +let b:doge_patterns.doxygen_qt_no_asterisk = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/*!', +\ '@brief !description', +\ '', +\ '%(parameters|{parameters})%', +\ '%(returnType|@return !description)%', +\ '*/', +\ ], +\ }), +\ doge#helpers#deepextend(s:struct_pattern, { +\ 'template': [ +\ '/*!', +\ 'struct {name} - !description', +\ '%(parameters|)%', +\ '%(parameters|{parameters})%', +\ '*/', +\ ], +\ }), +\ s:field_pattern, +\] + +let s:kernel_doc_pattern_base = {'parameters': {'format': '@{name}: !description'}} +let b:doge_patterns.kernel_doc = [ +\ doge#helpers#deepextend(s:function_pattern, s:kernel_doc_pattern_base, { +\ 'template': [ +\ '/**', +\ ' * {name}(): !description', +\ '%(parameters| * {parameters})%', +\ ' *', +\ ' * !description', +\ '%(returnType| *)%', +\ '%(returnType| * Return: !description)%', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:struct_pattern, s:kernel_doc_pattern_base, { +\ 'template': [ +\ '/**', +\ ' * struct {name} - !description', +\ '%(parameters|)%', +\ '%(parameters| * {parameters})%', +\ ' */', +\ ], +\ }), +\ s:field_pattern, +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/coffee.vim b/ftplugin/coffee.vim index aed016a8..c51ba7a5 100644 --- a/ftplugin/coffee.vim +++ b/ftplugin/coffee.vim @@ -20,65 +20,59 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} " ============================================================================== -" Matches prototype functions. +" Define our base for every pattern. " ============================================================================== -" -" Matches the following scenarios: -" -" Person::greet = (name) -> -call add(b:doge_patterns, { -\ 'match': '\m^\([[:alnum:]_$]\+\)::\([[:alnum:]_$]\+\)\s*=\s*[-=]>', -\ 'match_group_names': ['className', 'funcName'], -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'jsdoc': [ -\ '###', -\ '!description', -\ '', -\ '@function {className}#{funcName}', -\ '###', -\ ], -\ } +let s:pattern_base = { +\ 'parameters': { +\ 'format': '@param {!type} {name} !description', \ }, -\}) +\ 'insert': 'above', +\} " ============================================================================== -" Matches regular functions. +" Define the pattern types. " ============================================================================== -" -" Matches the following scenarios: -" -" myFunc = (x) -> x * x -" -" myFunc = (p1, p2, p3) -> -call add(b:doge_patterns, { +let s:prototype_function_pattern = doge#helpers#deepextend(s:pattern_base, { +\ 'match': '\m^\([[:alnum:]_$]\+\)::\([[:alnum:]_$]\+\)\s*=\s*[-=]>', +\ 'match_group_names': ['className', 'funcName'], +\}) + +let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\([[:alnum:]_$]\+\)\s*=\s*(\(.\{-}\))\s*[-=]>', \ 'match_group_names': ['funcName', 'parameters'], \ 'parameters': { \ 'match': '\m\([^,]\+\)', \ 'match_group_names': ['name'], -\ 'format': { -\ 'jsdoc': '@param {!type} {name} !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'jsdoc': [ -\ '###', -\ '!description', -\ '', -\ '@function {funcName|}', -\ '%(parameters|{parameters})%', -\ '###', -\ ], -\ } \ }, \}) +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.jsdoc = [ +\ doge#helpers#deepextend(s:prototype_function_pattern, { +\ 'template': [ +\ '###', +\ '!description', +\ '', +\ '@function {className}#{funcName}', +\ '###', +\ ], +\ }), +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '###', +\ '!description', +\ '', +\ '@function {funcName|}', +\ '%(parameters|{parameters})%', +\ '###', +\ ], +\ }), +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/cpp.vim b/ftplugin/cpp.vim index a2b69f3e..196ce7b7 100644 --- a/ftplugin/cpp.vim +++ b/ftplugin/cpp.vim @@ -25,14 +25,32 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} " ============================================================================== -" Functions and methods. +" Define our base for every pattern. " ============================================================================== -call add(b:doge_patterns, { +let s:pattern_base = { \ 'generator': { \ 'file': 'libclang.py', +\ }, +\ 'parameters': { +\ 'format': '@{param-type|param} {name} !description', +\ }, +\ 'insert': 'above', +\} + +" ============================================================================== +" Define the pattern types. +" ============================================================================== + +" ------------------------------------------------------------------------------ +" Matches (template) function- and class method declarations. +" ------------------------------------------------------------------------------ +" int add(int x, int y) {} +" ------------------------------------------------------------------------------ +let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { +\ 'generator': { \ 'args': [ \ 'CONSTRUCTOR', \ 'CXX_METHOD', @@ -41,132 +59,155 @@ call add(b:doge_patterns, { \ 'CLASS_TEMPLATE' \ ], \ }, -\ 'parameters': { -\ 'format': { -\ 'doxygen_javadoc': '@{param-type|param} {name} !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'doxygen_javadoc': [ -\ '/**', -\ ' * @brief !description', -\ ' *', -\ '%(parameters| * {parameters})%', -\ '%(returnType| * @return !description)%', -\ ' */', -\ ], -\ 'doxygen_javadoc_no_asterisk': [ -\ '/**', -\ '@brief !description', -\ '', -\ '%(parameters|{parameters})%', -\ '%(returnType|@return !description)%', -\ '*/', -\ ], -\ 'doxygen_javadoc_banner': [ -\ '/*******************************************************************************', -\ ' * @brief !description', -\ ' *', -\ '%(parameters| * {parameters})%', -\ '%(returnType| * @return !description)%', -\ ' ******************************************************************************/', -\ ], -\ 'doxygen_qt': [ -\ '/*!', -\ ' * @brief !description', -\ ' *', -\ '%(parameters| * {parameters})%', -\ '%(returnType| * @return !description)%', -\ ' */', -\ ], -\ 'doxygen_qt_no_asterisk': [ -\ '/*!', -\ '@brief !description', -\ '', -\ '%(parameters|{parameters})%', -\ '%(returnType|@return !description)%', -\ '*/', -\ ], -\ }, -\ }, \}) -" ============================================================================== -" Struct declarations. -" ============================================================================== -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" Matches structs. +" ------------------------------------------------------------------------------ +" struct foo { }; +" ------------------------------------------------------------------------------ +let s:struct_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'generator': { -\ 'file': 'libclang.py', \ 'args': ['STRUCT_DECL'], \ }, -\ 'parameters': { -\ 'format': { -\ 'doxygen_javadoc': '@{name}: !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'doxygen_javadoc': [ -\ '/**', -\ ' * struct {name} - !description', -\ '%(parameters| *)%', -\ '%(parameters| * {parameters})%', -\ ' */', -\ ], -\ 'doxygen_javadoc_no_asterisk': [ -\ '/**', -\ 'struct {name} - !description', -\ '%(parameters|)%', -\ '%(parameters|{parameters})%', -\ '*/', -\ ], -\ 'doxygen_javadoc_banner': [ -\ '/*******************************************************************************', -\ ' * struct {name} - !description', -\ '%(parameters| *)%', -\ '%(parameters| * {parameters})%', -\ ' ******************************************************************************/', -\ ], -\ 'doxygen_qt': [ -\ '/*!', -\ ' * struct {name} - !description', -\ '%(parameters| *)%', -\ '%(parameters| * {parameters})%', -\ ' */', -\ ], -\ 'doxygen_qt_no_asterisk': [ -\ '/*!', -\ 'struct {name} - !description', -\ '%(parameters|)%', -\ '%(parameters|{parameters})%', -\ '*/', -\ ], -\ }, -\ }, \}) -" ============================================================================== -" Field declarations. -" ============================================================================== -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" Matches field declarations inside structs. +" ------------------------------------------------------------------------------ +" struct foo { +" int bar; +" }; +" ------------------------------------------------------------------------------ +let s:field_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'generator': { -\ 'file': 'libclang.py', \ 'args': ['FIELD_DECL'], \ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'doxygen_javadoc': [ -\ '/**', -\ ' * @{name} !description', -\ ' */', -\ ], -\ }, -\ }, +\ 'parameters': v:false, +\ 'template': [ +\ '/**', +\ ' * @{name} !description', +\ ' */', +\ ], \}) +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.doxygen_javadoc = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/**', +\ ' * @brief !description', +\ ' *', +\ '%(parameters| * {parameters})%', +\ '%(returnType| * @return !description)%', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:struct_pattern, { +\ 'template': [ +\ '/**', +\ ' * struct {name} - !description', +\ '%(parameters| *)%', +\ '%(parameters| * {parameters})%', +\ ' */', +\ ], +\ }), +\ s:field_pattern, +\] + +let b:doge_patterns.doxygen_javadoc_no_asterisk = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/**', +\ '@brief !description', +\ '', +\ '%(parameters|{parameters})%', +\ '%(returnType|@return !description)%', +\ '*/', +\ ], +\ }), +\ doge#helpers#deepextend(s:struct_pattern, { +\ 'template': [ +\ '/**', +\ 'struct {name} - !description', +\ '%(parameters|)%', +\ '%(parameters|{parameters})%', +\ '*/', +\ ], +\ }), +\ s:field_pattern, +\] + +let b:doge_patterns.doxygen_javadoc_banner = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/*******************************************************************************', +\ ' * @brief !description', +\ ' *', +\ '%(parameters| * {parameters})%', +\ '%(returnType| * @return !description)%', +\ ' ******************************************************************************/', +\ ], +\ }), +\ doge#helpers#deepextend(s:struct_pattern, { +\ 'template': [ +\ '/*******************************************************************************', +\ ' * struct {name} - !description', +\ '%(parameters| *)%', +\ '%(parameters| * {parameters})%', +\ ' ******************************************************************************/', +\ ], +\ }), +\ s:field_pattern, +\] + +let b:doge_patterns.doxygen_qt = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/*!', +\ ' * @brief !description', +\ ' *', +\ '%(parameters| * {parameters})%', +\ '%(returnType| * @return !description)%', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:struct_pattern, { +\ 'template': [ +\ '/*!', +\ ' * struct {name} - !description', +\ '%(parameters| *)%', +\ '%(parameters| * {parameters})%', +\ ' */', +\ ], +\ }), +\ s:field_pattern, +\] + +let b:doge_patterns.doxygen_qt_no_asterisk = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/*!', +\ '@brief !description', +\ '', +\ '%(parameters|{parameters})%', +\ '%(returnType|@return !description)%', +\ '*/', +\ ], +\ }), +\ doge#helpers#deepextend(s:struct_pattern, { +\ 'template': [ +\ '/*!', +\ 'struct {name} - !description', +\ '%(parameters|)%', +\ '%(parameters|{parameters})%', +\ '*/', +\ ], +\ }), +\ s:field_pattern, +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/groovy.vim b/ftplugin/groovy.vim index aed1213c..741ca85a 100644 --- a/ftplugin/groovy.vim +++ b/ftplugin/groovy.vim @@ -21,44 +21,45 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} " ============================================================================== -" Matches class methods. +" Define our base for every pattern. " ============================================================================== -" -" Matches the following scenarios: -" -" private void setChildrenRecursively(ElementDto childDto, int childId) {} -" -" private List createSortedList(Map map, int type) {} -" -" void foo(Map parameters) {} -" -" void MyParameterizedFunction(String p1, int p2, Boolean ...params) {} -call add(b:doge_patterns, { -\ 'match': '\m^\%(\%(public\|private\|protected\|static\|final\)\s*\)*\%(\%(\([[:alnum:]_]\+\)\?\s*\%(<[[:alnum:][:space:]_,]*>\)\?\)\?\s\+\)\?\%([[:alnum:]_]\+\)(\(.\{-}\))\s*{', +let s:pattern_base = { +\ 'parameters': { +\ 'format': '@param {name} !description', +\ }, +\ 'insert': 'above', +\} + +" ============================================================================== +" Define the pattern types. +" ============================================================================== +let s:class_method_pattern = doge#helpers#deepextend(s:pattern_base, { +\ 'match': '\m^\%(\%(public\|private\|protected\|static\|final\)\s*\)*\%(\%(\([[:alnum:]_]\+\)\?\s*\%(<[[:alnum:][:space:]_,]*>\)\?\)\?\s\+\)\?\%([[:alnum:]_]\+\)(\(.\{-}\))\s*[;{]', \ 'match_group_names': ['returnType', 'parameters'], \ 'parameters': { \ 'match': '\m\%(\([[:alnum:]_]\+\)\%(<[[:alnum:][:space:]_,]\+>\)\?\)\%(\s\+[.]\{3}\s\+\|\s\+[.]\{3}\|[.]\{3}\s\+\|\s\+\)\([[:alnum:]_]\+\)', \ 'match_group_names': ['type', 'name'], -\ 'format': { -\ 'javadoc': '@param {type} {name} !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'javadoc': [ -\ '/**', -\ ' * !description', -\ '%(parameters| * {parameters})%', -\ ' * @return {returnType|void} !description', -\ ' */', -\ ], -\ }, \ }, \}) +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.javadoc = [ +\ doge#helpers#deepextend(s:class_method_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ '%(parameters| *)%', +\ '%(parameters| * {parameters})%', +\ '%(returnType| * @return !description)%', +\ ' */', +\ ], +\ }), +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/java.vim b/ftplugin/java.vim index ee85c7f8..52db087a 100644 --- a/ftplugin/java.vim +++ b/ftplugin/java.vim @@ -19,44 +19,45 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] - -" ============================================================================== -" Matches class methods. -" ============================================================================== -" -" Matches the following scenarios: -" -" private void setChildrenRecursively(ElementDto childDto, int childId) {} -" -" private List createSortedList(Map map, int type) {} -" -" void foo(Map parameters) {} -" -" void MyParameterizedFunction(String p1, int p2, Boolean ...params) {} -call add(b:doge_patterns, { +let b:doge_patterns = {} + +" ============================================================================== +" Define our base for every pattern. +" ============================================================================== +let s:pattern_base = { +\ 'parameters': { +\ 'format': '@param {name} !description', +\ }, +\ 'insert': 'above', +\} + +" ============================================================================== +" Define the pattern types. +" ============================================================================== +let s:class_method_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(\%(public\|private\|protected\|static\|final\)\s*\)*\%(\%(\([[:alnum:]_]\+\)\?\s*\%(<[[:alnum:][:space:]_,]*>\)\?\)\?\s\+\)\?\%([[:alnum:]_]\+\)(\(.\{-}\))\s*[;{]', \ 'match_group_names': ['returnType', 'parameters'], \ 'parameters': { \ 'match': '\m\%(\([[:alnum:]_]\+\)\%(<[[:alnum:][:space:]_,]\+>\)\?\)\%(\s\+[.]\{3}\s\+\|\s\+[.]\{3}\|[.]\{3}\s\+\|\s\+\)\([[:alnum:]_]\+\)', \ 'match_group_names': ['type', 'name'], -\ 'format': { -\ 'javadoc': '@param {name} !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'javadoc': [ -\ '/**', -\ ' * !description', -\ '%(parameters| * {parameters})%', -\ '%(returnType| * @return !description)%', -\ ' */', -\ ], -\ }, \ }, \}) +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.javadoc = [ +\ doge#helpers#deepextend(s:class_method_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ '%(parameters| *)%', +\ '%(parameters| * {parameters})%', +\ '%(returnType| * @return !description)%', +\ ' */', +\ ], +\ }), +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/javascript.vim b/ftplugin/javascript.vim index 90bf7875..e77af587 100644 --- a/ftplugin/javascript.vim +++ b/ftplugin/javascript.vim @@ -19,217 +19,164 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} -" Matches the following pattern: +" ============================================================================== +" Define our base for every pattern. + +" The parameters.match describes the following pattern: " : = -let s:parameters_match_pattern = '\m\%(\%(public\|private\|protected\)\?\s*\)\?\([[:alnum:]_$]\+\)?\?\%(\s*:\s*\([[:alnum:]._| ]\+\%(\[[[:alnum:][:space:]_[\],]*\]\)\?\)\)\?\%(\s*=\s*\([[:alnum:]_.]\+(.\{-})\|[^,]\+\)\+\)\?' +" ============================================================================== +let s:pattern_base = { +\ 'parameters': { +\ 'match': '\m\%(\%(public\|private\|protected\)\?\s*\)\?\([[:alnum:]_$]\+\)?\?\%(\s*:\s*\([[:alnum:]._| ]\+\%(\[[[:alnum:][:space:]_[\],]*\]\)\?\)\)\?\%(\s*=\s*\([[:alnum:]_.]\+(.\{-})\|[^,]\+\)\+\)\?', +\ 'match_group_names': ['name', 'type'], +\ 'format': '@param {{type|!type}} {name} - !description', +\ }, +\ 'insert': 'above', +\} " ============================================================================== -" Matches fat-arrow / functions inside objects. +" Define the pattern types. " ============================================================================== -" -" Matches the following scenarios: -" -" myKey: function myRealFunction(p1, p2) {} -" -" myKey: async function myRealFunction(p1, p2) {} -" -" myKey: (p1, p2) => {} -" -" myKey: async (p1, p2) => {} -call add(b:doge_patterns, { + +" ------------------------------------------------------------------------------ +" Matches fat-arrow / functions inside objects. +" ------------------------------------------------------------------------------ +" myKey: function myRealFunction(p1, p2) {} +" myKey: async function myRealFunction(p1, p2) {} +" myKey: (p1, p2) => {} +" myKey: async (p1, p2) => {} +" ------------------------------------------------------------------------------ +let s:object_functions_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^[[:punct:]]\?\([[:alnum:]_-]\+\)[[:punct:]]\?\s*:\s*\(async\)\?\s*\%(function\)\?\s*\%([[:alnum:]_]\+\)\?(\(.\{-}\))\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\%(\s*=>\s*\)\?\s*[({]', \ 'match_group_names': ['funcName', 'async', 'parameters', 'returnType'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name', 'type'], -\ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} - !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'jsdoc': [ -\ '/**', -\ ' * !description', -\ ' *', -\ '%(async| * @{async})%', -\ ' * @function {funcName|}', -\ '%(parameters| * {parameters})%', -\ ' * @return {{returnType|!type}} !description', -\ ' */', -\ ], -\ }, -\ }, \}) -" ============================================================================== +" ------------------------------------------------------------------------------ " Matches class declarations. -" ============================================================================== -" -" Matches the following scenarios: -" -" export class Child {} -" -" class Child extends Parent {} -" -" class Child implements CustomInterfaceName {} -" -" export class Child extends Parent implements CustomInterfaceName {} -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" export class Child {} +" class Child extends Parent {} +" class Child implements CustomInterfaceName {} +" export class Child extends Parent implements CustomInterfaceName {} +" ------------------------------------------------------------------------------ +let s:class_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(export\s*\)\?class\s\+\%([[:alnum:]_$]\+\)\%(\s\+extends\s\+\([[:alnum:]_$.]\+\)\)\?\%(\s\+implements\s\+\([[:alnum:]_$.]\+\)\)\?\s*{', \ 'match_group_names': ['parentClassName', 'interfaceName'], -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'jsdoc': [ -\ '/**', -\ ' * !description', -\ '%(parentClassName| * @extends {parentClassName})%', -\ '%(interfaceName| * @implements {interfaceName})%', -\ ' */', -\ ], -\ }, -\ }, +\ 'parameters': v:false, \}) -"" -" ============================================================================== +" ------------------------------------------------------------------------------ " Matches regular and typed functions with default parameters. -" ============================================================================== -" -" Matches the following scenarios: -" -" function add(one: any, two: any = 'default'): number {} - -" export function configureStore(history: History, initialState: object): Store {} -" -" function configureStore(history: History, initialState: object): Store {} -" -" function rollDice(): 1 | 2 | 3 | 4 | 5 | 6 {} -" -" function pluck(o: T, names: K[]): T[K][] {} -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" function add(one: any, two: any = 'default'): number {} +" export function configureStore(history: History, initialState: object): Store {} +" function configureStore(history: History, initialState: object): Store {} +" function rollDice(): 1 | 2 | 3 | 4 | 5 | 6 {} +" function pluck(o: T, names: K[]): T[K][] {} +" ------------------------------------------------------------------------------ +let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(\%(export\|public\)\s\+\)*\(static\s\+\)\?\(async\s\+\)\?\%(function\*\?\s*\)\?\%([[:alnum:]_$]\+\)\?\s*\%(<[[:alnum:][:space:]_,]*>\)\?\s*(\([^>]\{-}\))\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\s*[{(]', \ 'match_group_names': ['static', 'async', 'parameters', 'returnType'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name', 'type'], -\ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} - !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'jsdoc': [ -\ '/**', -\ ' * !description', -\ ' *', -\ '%(static| * @static)%', -\ '%(async| * @async)%', -\ '%(parameters| * {parameters})%', -\ ' * @return {{returnType|!type}} !description', -\ ' */', -\ ], -\ }, -\ }, \}) -" ============================================================================== +" ------------------------------------------------------------------------------ " Matches prototype functions. -" ============================================================================== -" -" Matches the following scenarios: -" -" Person.prototype.greet = (p1: string = 'default', p2: Immutable.List = Immutable.List()) => {}; -" -" Person.prototype.greet = function (p1: string = 'default', p2: Immutable.List = Immutable.List()) {}; -" -" Person.prototype.greet = function*(p1: string = 'default', p2: Immutable.List = Immutable.List()) {}; -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" Person.prototype.greet = (p1: string = 'default', p2: Immutable.List = Immutable.List()) => {}; +" Person.prototype.greet = function (p1: string = 'default', p2: Immutable.List = Immutable.List()) {}; +" Person.prototype.greet = function*(p1: string = 'default', p2: Immutable.List = Immutable.List()) {}; +" ------------------------------------------------------------------------------ +let s:prototype_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\([[:alnum:]_$]\+\)\.prototype\.\([[:alnum:]_$]\+\)\s*=\s*\(async\s\+\)\?\%(function\*\?\s*\)\?({\?\([^>]\{-}\)}\?)\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\s*\(=>\s*\)\?[{(]', \ 'match_group_names': ['className', 'funcName', 'async', 'parameters', 'returnType'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name', 'type'], -\ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} - !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'jsdoc': [ -\ '/**', -\ ' * !description', -\ ' *', -\ '%(async| * @async)%', -\ ' * @function {className}#{funcName}', -\ '%(parameters| * {parameters})%', -\ ' * @return {{returnType|!type}} !description', -\ ' */', -\ ], -\ }, -\ }, \}) -" ============================================================================== +" ------------------------------------------------------------------------------ " Matches fat-arrow functions. -" ============================================================================== -" -" var myFunc = function($p1 = 'value', p2 = [], p3, p4) {} -" -" var myFunc = function*($p1 = 'value', p2 = [], p3, p4) {} -" -" var myFunc = async function*($p1 = 'value', p2 = [], p3, p4) {} -" -" var myFunc = async ($p1 = 'value', p2 = [], p3, p4) => {} -" -" (p1: array = []) => (p2: string) => { console.log(5); } -" -" (p1: array = []) => (p2: string) => { console.log(5); } -" -" static myMethod({ b: number }): number {} -" -" static async myMethod({ b: number }): number {} -" -" const user = (p1 = 'default') => (subp1, subp2 = 'default') => 5; -" -" const foo = bar => baz -" -" export const foo = bar => baz -" -" (p1: string = 'default', p2: int = 5, p3, p4: Immutable.List = [], p5: string[] = [], p6: float = 0.5): number[] => { }; -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" var myFunc = function($p1 = 'value', p2 = [], p3, p4) {} +" var myFunc = function*($p1 = 'value', p2 = [], p3, p4) {} +" var myFunc = async function*($p1 = 'value', p2 = [], p3, p4) {} +" var myFunc = async ($p1 = 'value', p2 = [], p3, p4) => {} +" (p1: array = []) => (p2: string) => { console.log(5); } +" (p1: array = []) => (p2: string) => { console.log(5); } +" static myMethod({ b: number }): number {} +" static async myMethod({ b: number }): number {} +" const user = (p1 = 'default') => (subp1, subp2 = 'default') => 5; +" const foo = bar => baz +" export const foo = bar => baz +" (p1: string = 'default', p2: int = 5, p3, p4: Immutable.List = [], p5: string[] = [], p6: float = 0.5): number[] => { }; +" ------------------------------------------------------------------------------ +let s:fat_arrow_function_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(export\s\+\)\?\%(\%(\%(var\|const\|let\)\s\+\)\?\%(\(static\)\s\+\)\?\([[:alnum:]_$]\+\)\)\?\s*=\s*\(static\s\+\)\?\(async\s\+\)\?\%(function\*\?\s*\)\?\(({\?[^>]\{-}}\?)\|[[:alnum:]_$]\+\)\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\s*\%(=>\s*\)\?[^ ]\{-}', \ 'match_group_names': ['static', 'funcName', 'static', 'async', 'parameters', 'returnType'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name', 'type'], -\ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} - !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'jsdoc': [ -\ '/**', -\ ' * !description', -\ ' *', -\ '%(static| * @static)%', -\ '%(async| * @async)%', -\ ' * @function {funcName|}', -\ '%(parameters| * {parameters})%', -\ ' * @return {{returnType|!type}} !description', -\ ' */', -\ ], -\ }, -\ }, \}) +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.jsdoc = [ +\ doge#helpers#deepextend(s:object_functions_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ ' *', +\ '%(async| * @{async})%', +\ ' * @function {funcName|}', +\ '%(parameters| * {parameters})%', +\ ' * @return {{returnType|!type}} !description', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:class_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ '%(parentClassName| * @extends {parentClassName})%', +\ '%(interfaceName| * @implements {interfaceName})%', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ ' *', +\ '%(static| * @static)%', +\ '%(async| * @async)%', +\ '%(parameters| * {parameters})%', +\ ' * @return {{returnType|!type}} !description', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:prototype_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ ' *', +\ '%(async| * @async)%', +\ ' * @function {className}#{funcName}', +\ '%(parameters| * {parameters})%', +\ ' * @return {{returnType|!type}} !description', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:fat_arrow_function_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ ' *', +\ '%(static| * @static)%', +\ '%(async| * @async)%', +\ ' * @function {funcName|}', +\ '%(parameters| * {parameters})%', +\ ' * @return {{returnType|!type}} !description', +\ ' */', +\ ], +\ }), +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/kotlin.vim b/ftplugin/kotlin.vim index 4c4f1d9e..3274b52d 100644 --- a/ftplugin/kotlin.vim +++ b/ftplugin/kotlin.vim @@ -19,12 +19,13 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} -" Matches the following pattern: -" : +" ============================================================================== +" Define our base for every pattern. " -" Matches the following scenarios: +" The parameters.match describes the following pattern: +" : " " (map: MutableMap, str: String.() -> Unit) " @@ -37,134 +38,101 @@ let b:doge_patterns = [] " (map: MutableMap, str: String) " " (onetime: Boolean = true, callback: () -> Unit) -let s:parameters_match_pattern = '\m\%(\%(var\|val\)\s\+\)\?\([[:alnum:]_]\+\)\%(\s*:\s*\%([[:alnum:]_]\+\)\?\%(<[[:alnum:][:space:]_,<>:?*]\{-1,}>\|[^,]\+\)\?\)\?' +let s:pattern_base = { +\ 'parameters': { +\ 'match': '\m\%(\%(var\|val\)\s\+\)\?\([[:alnum:]_]\+\)\%(\s*:\s*\%([[:alnum:]_]\+\)\?\%(<[[:alnum:][:space:]_,<>:?*]\{-1,}>\|[^,]\+\)\?\)\?', +\ 'match_group_names': ['name'], +\ 'format': '@param {name} !description' +\ }, +\ 'insert': 'above', +\} " ============================================================================== -" Matches regular functions, class methods and extension functions. +" Define the pattern types. " ============================================================================== -" -" Matches the following scenarios: -" -" fun MutableList.swap(index1: Int, index2: Int) { -" -" fun listenForPackageChanges(onetime: Boolean = true, callback: () -> Unit) = object : BroadcastReceiver() {} -" -" inline fun > printAllValues() {} -" -" fun id(x: T): T = x -" -" fun readOut(group: Group) {} -" -" fun readIn(group: Group) {} -" -" fun acceptAnyList(list: List) {} -" -" inline fun Gson.fromJson(json: JsonElement): T = this.fromJson(json, T::class.java) -" -" open fun f() { println("Foo.f()") } -call add(b:doge_patterns, { + +" ------------------------------------------------------------------------------ +" Matches regular functions, class methods and extension functions. +" ------------------------------------------------------------------------------ +" fun MutableList.swap(index1: Int, index2: Int) { +" fun listenForPackageChanges(onetime: Boolean = true, callback: () -> Unit) = object : BroadcastReceiver() {} +" inline fun > printAllValues() {} +" fun id(x: T): T = x +" fun readOut(group: Group) {} +" fun readIn(group: Group) {} +" fun acceptAnyList(list: List) {} +" inline fun Gson.fromJson(json: JsonElement): T = this.fromJson(json, T::class.java) +" open fun f() { println("Foo.f()") } +" ------------------------------------------------------------------------------ +let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(\%(public\|protected\|private\|final\|inline\|abstract\|override\|operator\|open\|data\)\s\+\)*fun\s\+\%([^(]\+\)\s*(\(.\{-}\))\%(\s*:\s*[[:alnum:]_:\.]\+\%(<[[:alnum:][:space:]_,<>:?*]\{-}>\)\??\?\)\?\s*[={]', \ 'match_group_names': ['parameters'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name'], -\ 'format': { -\ 'kdoc': '@param {name} !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'kdoc': [ -\ '/**', -\ ' * !description', -\ '%(parameters| * {parameters})%', -\ ' * @return !description', -\ ' */', -\ ], -\ }, -\ }, \}) -" ============================================================================== +" ------------------------------------------------------------------------------ " Matches classes. -" ============================================================================== -" -" Matches the following scenarios: -" -" class Outer() {} -" -" inner class Inner() {} -" -" data class User(val name: String, val age: Int) {} -" -" enum class Color(val rgb: Int) {} -" -" class Person constructor(firstName: String) {} -" -" class C private constructor(a: Int) {} -" -" class Person(firstName: String) {} -" -" class MyView() : View()) {} -" -" inline class Name(val s: String) {} -" -" abstract class Vehicle(val name: String, val color: String, val weight: Double) {} -" -" external class MyClass() {} -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" class Outer() {} +" inner class Inner() {} +" data class User(val name: String, val age: Int) {} +" enum class Color(val rgb: Int) {} +" class Person constructor(firstName: String) {} +" class C private constructor(a: Int) {} +" class Person(firstName: String) {} +" class MyView() : View()) {} +" inline class Name(val s: String) {} +" abstract class Vehicle(val name: String, val color: String, val weight: Double) {} +" external class MyClass() {} +" ------------------------------------------------------------------------------ +let s:class_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(\%(inner\|inline\|data\|enum\|external\|open\|abstract\|sealed\)\s\+\)*class\s\+\%([[:alnum:]_]\+\%(<[[:alnum:][:space:]_,<>:?*]\{-}>\)\?\)\s*\%(\%(public\|private\|protected\)\s*\)\?\%(constructor\s*\)\?(\(.\{-}\))', \ 'match_group_names': ['parameters'], \ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name'], -\ 'format': { -\ 'kdoc': '@property {name} !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'kdoc': [ -\ '/**', -\ ' * !description', -\ '%(parameters| * {parameters})%', -\ ' */', -\ ], -\ }, +\ 'format': '@property {name} !description', \ }, \}) -" ============================================================================== -" Matches constructors inside a class. -" ============================================================================== -" -" Matches the following scenarios: -" -" constructor(parent: Person, query: Query<*, >) {} -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" Matches class constructors. +" ------------------------------------------------------------------------------ +" constructor(parent: Person, query: Query<*, >) {} +" ------------------------------------------------------------------------------ +let s:class_constructor_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(\%(public\|private\|protected\)\s\+\)\?constructor\s*(\(.\{-}\))', \ 'match_group_names': ['parameters'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name'], -\ 'format': { -\ 'kdoc': '@param {name} !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'kdoc': [ -\ '/**', -\ ' * !description', -\ '%(parameters| * {parameters})%', -\ ' */', -\ ], -\ }, -\ }, \}) + +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.kdoc = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ '%(parameters| * {parameters})%', +\ ' * @return !description', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:class_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ '%(parameters| * {parameters})%', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:class_constructor_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ '%(parameters| * {parameters})%', +\ ' */', +\ ], +\ }), +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/lua.vim b/ftplugin/lua.vim index 0b41f509..b4ef5a53 100644 --- a/ftplugin/lua.vim +++ b/ftplugin/lua.vim @@ -19,78 +19,68 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] - -let s:parameters_match_pattern = '\m\([^,]\+\)' +let b:doge_patterns = {} " ============================================================================== -" Matches regular function expressions and class methods. +" Define our base for every pattern. " ============================================================================== -" -" Matches the following scenarios: -" -" function new_function(p1, p2, p3, p4) -" -" local function new_function(p1, p2, p3) -" -" function BotDetectionHandler:access(p1, p2, p3) -" -" function a.b:c (p1, p2) body end -" -" a.b.c = function (self, p1, p2) body end -call add(b:doge_patterns, { -\ 'match': '\m^\%(local\s*\)\?function\s*\%([[:alnum:]_:.]\+[:.]\)\?\%([[:alnum:]_]\+\)\s*(\(.\{-}\))', -\ 'match_group_names': ['parameters'], +let s:pattern_base = { \ 'parameters': { -\ 'match': s:parameters_match_pattern, +\ 'match': '\m\([^,]\+\)', \ 'match_group_names': ['name'], -\ 'format': { -\ 'ldoc': '@param {name} !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'ldoc': [ -\ '-- !summary', -\ '-- !description', -\ '%(parameters|-- {parameters})%', -\ ], -\ }, +\ 'format': '@param {name} !description', \ }, -\}) +\ 'insert': 'above', +\} -"" " ============================================================================== -" Matches regular function expressions as a variable value. +" Define the pattern types. " ============================================================================== -" -" Matches the following scenarios: -" -" myprint = function(p1, p2) -" -" local myprint = function(p1, p2, p3, p4, p5) -call add(b:doge_patterns, { + +" ------------------------------------------------------------------------------ +" Matches regular function expressions and class methods. +" ------------------------------------------------------------------------------ +" function new_function(p1, p2, p3, p4) +" local function new_function(p1, p2, p3) +" function BotDetectionHandler:access(p1, p2, p3) +" function a.b:c (p1, p2) body end +" a.b.c = function (self, p1, p2) body end +" ------------------------------------------------------------------------------ +let s:function_and_class_method_pattern = doge#helpers#deepextend(s:pattern_base, { +\ 'match': '\m^\%(local\s*\)\?function\s*\%([[:alnum:]_:.]\+[:.]\)\?\%([[:alnum:]_]\+\)\s*(\(.\{-}\))', +\ 'match_group_names': ['parameters'], +\}) + +" ------------------------------------------------------------------------------ +" Matches regular function expressions as a variable value. +" ------------------------------------------------------------------------------ +" myprint = function(p1, p2) +" local myprint = function(p1, p2, p3, p4, p5) +" ------------------------------------------------------------------------------ +let s:variable_function_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(local\s*\)\?\%([[:alnum:]_:.]\+[:.]\)\?\([[:alnum:]_]\+\)\s*=\s*\%(\s*function\s*\)\?(\(.\{-}\))', \ 'match_group_names': ['funcName', 'parameters'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name'], -\ 'format': { -\ 'ldoc': '@param {name} !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'ldoc': [ -\ '-- !summary', -\ '-- !description', -\ '%(parameters|-- {parameters})%', -\ ], -\ }, -\ }, \}) +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.ldoc = [ +\ doge#helpers#deepextend(s:function_and_class_method_pattern, { +\ 'template': [ +\ '-- !summary', +\ '-- !description', +\ '%(parameters|-- {parameters})%', +\ ], +\ }), +\ doge#helpers#deepextend(s:variable_function_pattern, { +\ 'template': [ +\ '-- !summary', +\ '-- !description', +\ '%(parameters|-- {parameters})%', +\ ], +\ }), +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/php.vim b/ftplugin/php.vim index ed3645ed..65d6d01d 100644 --- a/ftplugin/php.vim +++ b/ftplugin/php.vim @@ -19,113 +19,102 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} " ============================================================================== -" Matches class properties. +" Define our base for every pattern. " ============================================================================== -" -" Matches the following scenarios: -" -" protected $myProtectedVar; -" -" public $myPublicVar; -" -" public $myVarWithDefaultValue = 'string'; -" -" The {type} will be added by the doge#preprocess#php#tokens() function. -" See doge#preprocessors#php#tokens(). -call add(b:doge_patterns, { +let s:pattern_base = { +\ 'parameters': { +\ 'match': '\m\%(\([[:alnum:]_\\]\+\)\s\+\)\?&\?\(\$[[:alnum:]_]\+\)\%(\s*=\s*\([[:alnum:]_]\+(.\{-})\|[^,]\+\)\+\)\?', +\ 'match_group_names': ['type', 'name', 'default'], +\ 'format': '@param {type|!type} {name}%(default| (optional))% !description', +\ }, +\ 'insert': 'above', +\} + +" ============================================================================== +" Define the pattern types. +" ============================================================================== + +" ------------------------------------------------------------------------------ +" Matches class properties. +" ------------------------------------------------------------------------------ +" protected $myProtectedVar; +" public $myPublicVar; +" public $myVarWithDefaultValue = 'string'; +" ------------------------------------------------------------------------------ +let s:class_property_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(\%(public\|private\|protected\|static\|var\|const\)\s\+\)*\$\([[:alnum:]_]\+\)', \ 'match_group_names': ['propertyName'], -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'phpdoc': [ -\ '/**', -\ ' * @var {type|!type}', -\ ' */', -\ ], -\ }, -\ }, +\ 'parameters': v:false, \}) -" ============================================================================== +" ------------------------------------------------------------------------------ " Matches a constructor function. -" ============================================================================== -" -" Matches the following scenarios: -" -" public function __construct(...) {} -call add(b:doge_patterns, { -\ 'match': '\m^\%(\%(public\|private\|protected\|static\|final\)\s\+\)*function\s*__construct\s*(\(.\{-}\))\s*{', +" ------------------------------------------------------------------------------ +" public function __construct(...) {} +" ------------------------------------------------------------------------------ +let s:constructor_pattern = doge#helpers#deepextend(s:pattern_base, { +\ 'match': '\m^\%(\%(public\|private\|protected\|static\|final\)\s\+\)*function\s\+__construct\s*(\(.\{-}\))\s*{', \ 'match_group_names': ['parameters'], -\ 'parameters': { -\ 'match': '\m\%(\([[:alnum:]_\\]\+\)\s\+\)\?&\?\(\$[[:alnum:]_]\+\)\%(\s*=\s*\([[:alnum:]_]\+(.\{-})\|[^,]\+\)\+\)\?', -\ 'match_group_names': ['type', 'name', 'default'], -\ 'format': { -\ 'phpdoc': [ -\ '@param {type|!type} {name}%(default| (optional))% !description', -\ ], -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'phpdoc': [ -\ '/**', -\ ' * !description', -\ ' *', -\ '%(parameters| * {parameters})%', -\ ' */', -\ ], -\ }, -\ }, \}) -" ============================================================================== +" ------------------------------------------------------------------------------ " Matches regular function expressions and class methods. -" ============================================================================== -" -" Matches the following scenarios: -" -" function myFunction(array &$p1, string $p2, &$p3 = NULL, \Drupal\core\Entity\Node $p4) {} +" ------------------------------------------------------------------------------ +" function myFunction(array &$p1, string $p2, &$p3 = NULL, \Drupal\core\Entity\Node $p4) {} " -" function myFunction(QueryFactory $p4) {} +" function myFunction(QueryFactory $p4) {} " -" public function myPublicMethod( -" array &$p1, -" \Test\Namespacing\With\A\ClassInterface $p2, -" int $p3, -" $p4, -" $p5 = NULL -" ) {} -call add(b:doge_patterns, { +" public function myPublicMethod( +" array &$p1, +" \Test\Namespacing\With\A\ClassInterface $p2, +" int $p3, +" $p4, +" $p5 = NULL +" ) {} +" ------------------------------------------------------------------------------ +let s:function_and_class_method_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(\%(public\|private\|protected\|static\|final\)\s\+\)*function\s*\%([^(]\+\)\s*(\(.\{-}\))\s*{', \ 'match_group_names': ['parameters'], -\ 'parameters': { -\ 'match': '\m\%(\([[:alnum:]_\\]\+\)\s\+\)\?&\?\(\$[[:alnum:]_]\+\)\%(\s*=\s*\([[:alnum:]_]\+(.\{-})\|[^,]\+\)\+\)\?', -\ 'match_group_names': ['type', 'name', 'default'], -\ 'format': { -\ 'phpdoc': [ -\ '@param {type|!type} {name}%(default| (optional))% !description', -\ ], -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'phpdoc': [ -\ '/**', -\ ' * !description', -\ ' *', -\ '%(parameters| * {parameters})%', -\ ' * @return !type !description', -\ ' */', -\ ], -\ }, -\ }, \}) +" ============================================================================== +" Define the doc standards. +" +" s:class_property_pattern +" The {type} will be added by the doge#preprocess#php#tokens() function. +" See doge#preprocessors#php#tokens(). +" ============================================================================== +let b:doge_patterns.phpdoc = [ +\ doge#helpers#deepextend(s:class_property_pattern, { +\ 'template': [ +\ '/**', +\ ' * @var {type|!type}', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:constructor_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ ' *', +\ '%(parameters| * {parameters})%', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:function_and_class_method_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ ' *', +\ '%(parameters| * {parameters})%', +\ ' * @return !type !description', +\ ' */', +\ ], +\ }), +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/python.vim b/ftplugin/python.vim index 23442bba..49ac1fac 100644 --- a/ftplugin/python.vim +++ b/ftplugin/python.vim @@ -22,93 +22,121 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} " ============================================================================== -" Matches regular function expressions and class methods. +" Define our base for every pattern. " ============================================================================== -" -" Matches the following scenarios: -" -" def __init__(self: MyClass): -" -" def myMethod(self: MyClass, p1: Sequence[T]) -> Generator[int, float, str]: -" -" def call(self, *args: str, **kwargs: str) -> str: -" -" def myFunc(p1: Callable[[int], None] = False, p2: Callable[[int, Exception], None]) -> Sequence[T]: -call add(b:doge_patterns, { -\ 'match': '\m^def\s\+\%([^(]\+\)\s*(\(.\{-}\))\%(\s*->\s*\(.\{-}\)\)\?\s*:', -\ 'match_group_names': ['parameters', 'returnType'], +let s:pattern_base = { \ 'parameters': { \ 'match': '\m\([[:alnum:]_]\+\)\%(\s*:\s*\([[:alnum:]_.]\+\%(\[[[:alnum:]_[\],[:space:]]*\]\)\?\)\)\?\%(\s*=\s*\([^,]\+\)\)\?', \ 'match_group_names': ['name', 'type', 'default'], -\ 'format': { -\ 'reST': ':param {name} {type|!type}: !description', -\ 'sphinx': [ +\ }, +\ 'insert': 'below', +\} + +" ============================================================================== +" Define the pattern types. +" ============================================================================== + +" ------------------------------------------------------------------------------ +" Matches regular function expressions and class methods. +" ------------------------------------------------------------------------------ +" def __init__(self: MyClass): +" def myMethod(self: MyClass, p1: Sequence[T]) -> Generator[int, float, str]: +" def call(self, *args: str, **kwargs: str) -> str: +" def myFunc(p1: Callable[[int], None] = False, p2: Callable[[int, Exception], None]) -> Sequence[T]: +" ------------------------------------------------------------------------------ +let s:function_and_class_method_pattern = doge#helpers#deepextend(s:pattern_base, { +\ 'match': '\m^def\s\+\%([^(]\+\)\s*(\(.\{-}\))\%(\s*->\s*\(.\{-}\)\)\?\s*:', +\ 'match_group_names': ['parameters', 'returnType'], +\}) + +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.reST = [ +\ doge#helpers#deepextend(s:function_and_class_method_pattern, { +\ 'parameters': { +\ 'format': ':param {name} {type|!type}: !description', +\ }, +\ 'template': [ +\ '"""', +\ '!description', +\ '', +\ '%(parameters|{parameters})%', +\ '%(returnType|:rtype {returnType}: !description)%', +\ '"""', +\ ], +\ }), +\] + +let b:doge_patterns.sphinx = [ +\ doge#helpers#deepextend(s:function_and_class_method_pattern, { +\ 'parameters': { +\ 'format': [ \ ':param {name}: !description%(default|, defaults to {default})%', \ ':type {name}: {type|!type}%(default|, optional)%', \ ], -\ 'numpy': [ +\ }, +\ 'template': [ +\ '"""', +\ '!description', +\ '', +\ '%(parameters|{parameters})%', +\ '%(returnType|:return: !description)%', +\ '%(returnType|:rtype: {returnType})%', +\ '"""', +\ ], +\ }), +\] + +let b:doge_patterns.numpy = [ +\ doge#helpers#deepextend(s:function_and_class_method_pattern, { +\ 'parameters': { +\ 'format': [ \ '{name} : {type|!type}', \ '\t!description', \ ], -\ 'google': [ -\ '{name} ({type|!type}%(default|, optional)%): !description', -\ ], \ }, -\ }, -\ 'comment': { -\ 'insert': 'below', -\ 'template': { -\ 'reST': [ -\ '"""', -\ '!description', -\ '', -\ '%(parameters|{parameters})%', -\ '%(returnType|:rtype {returnType}: !description)%', -\ '"""', -\ ], -\ 'sphinx': [ -\ '"""', -\ '!description', -\ '', -\ '%(parameters|{parameters})%', -\ '%(returnType|:return: !description)%', -\ '%(returnType|:rtype: {returnType})%', -\ '"""', -\ ], -\ 'numpy': [ -\ '"""', -\ '!summary', -\ '', -\ '!description', -\ '%(parameters|)%', -\ '%(parameters|Parameters)%', -\ '%(parameters|----------)%', -\ '%(parameters|{parameters})%', -\ '%(returnType|)%', -\ '%(returnType|Returns)%', -\ '%(returnType|-------)%', -\ '%(returnType|{returnType}:)%', -\ '%(returnType|\t!description)%', -\ '"""', -\ ], -\ 'google': [ -\ '"""!summary', -\ '', -\ '!description', -\ '%(parameters|)%', -\ '%(parameters|Args:)%', -\ '%(parameters|\t{parameters})%', -\ '%(returnType|)%', -\ '%(returnType|Returns:)%', -\ '%(returnType|\t{returnType}: !description)%', -\ '"""', -\ ], +\ 'template': [ +\ '"""', +\ '!summary', +\ '', +\ '!description', +\ '%(parameters|)%', +\ '%(parameters|Parameters)%', +\ '%(parameters|----------)%', +\ '%(parameters|{parameters})%', +\ '%(returnType|)%', +\ '%(returnType|Returns)%', +\ '%(returnType|-------)%', +\ '%(returnType|{returnType}:)%', +\ '%(returnType|\t!description)%', +\ '"""', +\ ], +\ }), +\] + +let b:doge_patterns.google = [ +\ doge#helpers#deepextend(s:function_and_class_method_pattern, { +\ 'parameters': { +\ 'format': '{name} ({type|!type}%(default|, optional)%): !description', \ }, -\ }, -\}) +\ 'template': [ +\ '"""!summary', +\ '', +\ '!description', +\ '%(parameters|)%', +\ '%(parameters|Args:)%', +\ '%(parameters|\t{parameters})%', +\ '%(returnType|)%', +\ '%(returnType|Returns:)%', +\ '%(returnType|\t{returnType}: !description)%', +\ '"""', +\ ], +\ }), +\] let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/r.vim b/ftplugin/r.vim index e521a3d9..d823a4a6 100644 --- a/ftplugin/r.vim +++ b/ftplugin/r.vim @@ -19,46 +19,57 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} " ============================================================================== -" Matches regular functions. +" Define our base for every pattern. " ============================================================================== -" -" Matches the following scenarios: -" -" myFunc.default <- function( -" p1, -" p2.sub1 = FALSE, -" p3.sub1 = 20, -" p4.sub1 = 1/15, -" ... -" ) { -" # ... -" } - -" myFunc = function( -" p1 = TRUE, p2_sub1= TRUE, p3 = FALSE, -" p4 = 'libs', p5 = NULL, ..., p7 = 'default', -" p8 = c('lorem', 'ipsum+dor', 'sit', 'amet'), -" p9 = TRUE, p10 = list(), p11 = TRUE -" ) { -" # ... -" } -call add(b:doge_patterns, { -\ 'match': '\m^\%([[:alnum:]_.]\+\)\s*\%(=\|<-\)\s*function\s*(\(.\{-}\))\s*{', -\ 'match_group_names': ['parameters'], +let s:pattern_base = { \ 'parameters': { \ 'match': '\m\([[:alnum:]_]\+\%(.\%([[:alnum:]_]\+\)\)*\)\%(\s*=\s*\%([[:alnum:]_]\+(.\{-})\|[^,]\+\)\)\?', \ 'match_group_names': ['name'], -\ 'format': { -\ 'roxygen2': '@param {name} !description', -\ }, +\ 'format': '@param {name} !description', \ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'roxygen2': [ +\ 'insert': 'above', +\} + +" ============================================================================== +" Define the pattern types. +" ============================================================================== + +" ------------------------------------------------------------------------------ +" Matches regular functions. +" ------------------------------------------------------------------------------ +" myFunc.default <- function( +" p1, +" p2.sub1 = FALSE, +" p3.sub1 = 20, +" p4.sub1 = 1/15, +" ... +" ) { +" # ... +" } + +" myFunc = function( +" p1 = TRUE, p2_sub1= TRUE, p3 = FALSE, +" p4 = 'libs', p5 = NULL, ..., p7 = 'default', +" p8 = c('lorem', 'ipsum+dor', 'sit', 'amet'), +" p9 = TRUE, p10 = list(), p11 = TRUE +" ) { +" # ... +" } +" ------------------------------------------------------------------------------ +let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { +\ 'match': '\m^\%([[:alnum:]_.]\+\)\s*\%(=\|<-\)\s*function\s*(\(.\{-}\))\s*{', +\ 'match_group_names': ['parameters'], +\}) + +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.roxygen2 = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ \ "#' !description", \ "%(parameters|#')%", \ "%(parameters|#' {parameters})%", @@ -68,10 +79,9 @@ call add(b:doge_patterns, { \ "#'", \ "#' @examples", \ "#' !example", -\ ], -\ }, -\ }, -\}) +\ ], +\ }), +\] let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index 0396f40d..eb8273b4 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -19,41 +19,48 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} " ============================================================================== -" Matches regular function expressions and class methods. +" Define our base for every pattern. " ============================================================================== -" -" Matches the following scenarios: -" -" def myFunc(p1, p_2 = some_default_value) -" -" def def parameters (p1,p2=4, p3*) -" -" def where(attribute, type = nil, **options) -" -" def each(&block) -call add(b:doge_patterns, { -\ 'match': '\m^def\s\+\%([^=(!]\+\)[=!]\?\s*(\(.\{-}\))', -\ 'match_group_names': ['parameters'], +let s:pattern_base = { \ 'parameters': { \ 'match': '\m\([[:alnum:]_]\+\)\%(\s*=\s*[^,]\+\)\?', \ 'match_group_names': ['name'], -\ 'format': { -\ 'YARD': '@param {name} [!type] !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'YARD': [ -\ '# !description', -\ '%(parameters|# {parameters})%', -\ ], -\ }, +\ 'format': '@param {name} [!type] !description', \ }, +\ 'insert': 'above', +\} + +" ============================================================================== +" Define the pattern types. +" ============================================================================== + +" ------------------------------------------------------------------------------ +" Matches regular function expressions and class methods. +" ------------------------------------------------------------------------------ +" def myFunc(p1, p_2 = some_default_value) +" def def parameters (p1,p2=4, p3*) +" def where(attribute, type = nil, **options) +" def each(&block) +" ------------------------------------------------------------------------------ +let s:function_and_class_method_pattern = doge#helpers#deepextend(s:pattern_base, { +\ 'match': '\m^def\s\+\%([^=(!]\+\)[=!]\?\s*(\(.\{-}\))', +\ 'match_group_names': ['parameters'], \}) +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.YARD = [ +\ doge#helpers#deepextend(s:function_and_class_method_pattern, { +\ 'template': [ +\ '# !description', +\ '%(parameters|# {parameters})%', +\ ], +\ }), +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/scala.vim b/ftplugin/scala.vim index 33e6997e..905829da 100644 --- a/ftplugin/scala.vim +++ b/ftplugin/scala.vim @@ -19,114 +19,96 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} -" Matches the following pattern: -" : = -let s:parameters_match_pattern = '\m\%(\%(val\s\+\)\?\([[:alnum:]_]\+\)\)\%(\s*:\s*\([^,(\)=]\+\)\)\?\%(\s*=\s*[^,(\)]\+\)\?' - -" ============================================================================== -" Functions " ============================================================================== +" Define our base for every pattern. " -" Matches the following scenarios: -" -" (x: Int) => x + 1 -" -" val getTheAnswer = () => 42 -call add(b:doge_patterns, { -\ 'match': '\m^\%(val\s\+\%([[:alnum:]_]\+\)\s*=\s*\)\?(\(.\{-}\))\s*=>\s*', -\ 'match_group_names': ['parameters'], +" The parameters.match describes the following pattern: +" : = +" ============================================================================== +let s:pattern_base = { \ 'parameters': { -\ 'match': s:parameters_match_pattern, +\ 'match': '\m\%(\%(val\s\+\)\?\([[:alnum:]_]\+\)\)\%(\s*:\s*\([^,(\)=]\+\)\)\?\%(\s*=\s*[^,(\)]\+\)\?', \ 'match_group_names': ['name', 'type'], -\ 'format': { -\ 'scaladoc': '@param {name} {type} !description', -\ }, +\ 'format': '@param {name} {type} !description', \ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'scaladoc': [ -\ '/** !description', -\ ' *', -\ '%(parameters| * {parameters})%', -\ ' * @return !description', -\ ' */', -\ ], -\ }, -\ }, -\}) +\ 'insert': 'above', +\} " ============================================================================== -" Methods +" Define the pattern types. " ============================================================================== + +" ------------------------------------------------------------------------------ +" Matches regular functions. +" ------------------------------------------------------------------------------ +" (x: Int) => x + 1 +" val getTheAnswer = () => 42 +" ------------------------------------------------------------------------------ +let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { +\ 'match': '\m^\%(val\s\+\%([[:alnum:]_]\+\)\s*=\s*\)\?(\(.\{-}\))\s*=>\s*', +\ 'match_group_names': ['parameters'], +\}) + +" ------------------------------------------------------------------------------ +" Matches class methods. +" ------------------------------------------------------------------------------ +" def urlBuilder(ssl: Boolean = true, domainName: String = 'some domain value'): (String, String) => String = {} " -" Matches the following scenarios: -" -" def urlBuilder(ssl: Boolean = true, domainName: String = 'some domain value'): (String, String) => String = {} -" -" def main(args: Array[String]): Unit = -" println("Hello, Scala developer!") +" def main(args: Array[String]): Unit = +" println("Hello, Scala developer!") " -" def move(dx: Int, dy: Int): Unit = {} -call add(b:doge_patterns, { +" def move(dx: Int, dy: Int): Unit = {} +" ------------------------------------------------------------------------------ +let s:class_method_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(\%(public\|private\|protected\|override\)\s\+\)*def\s\+\%([[:alnum:]_]\+\)\%(\[.*\]\)\?\%(\s*=\s*\)\?(\(.\{-}\)):', \ 'match_group_names': ['parameters'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name', 'type'], -\ 'format': { -\ 'scaladoc': '@param {name} {type} !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'scaladoc': [ -\ '/** !description', -\ ' *', -\ '%(parameters| * {parameters})%', -\ ' * @return !description', -\ ' */', -\ ], -\ }, -\ }, \}) -" ============================================================================== -" Classes -" ============================================================================== -" -" Matches the following scenarios: -" -" class Cat(val name: String) extends Pet -" -" class IntIterator(to: Int) extends Iterator[Int] {} -" -" protected case class LoremIpsum(name: String, age: Int) extends B with C with D {} -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" Matches classes. +" ------------------------------------------------------------------------------ +" class Cat(val name: String) extends Pet +" class IntIterator(to: Int) extends Iterator[Int] {} +" protected case class LoremIpsum(name: String, age: Int) extends B with C with D {} +" ------------------------------------------------------------------------------ +let s:class_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(\%(public\|private\|protected\|package\|case\)\s\+\)*class\s\+\%([[:alnum:]_]\+\)\%(\[.*\]\)\?(\(.\{-}\))\([^{]\+{\)\?', \ 'match_group_names': ['parameters'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name', 'type'], -\ 'format': { -\ 'scaladoc': '@param {name} {type} !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'scaladoc': [ -\ '/** !description', -\ ' *', -\ '%(parameters| * {parameters})%', -\ ' */', -\ ], -\ }, -\ }, \}) +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.scaladoc = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/** !description', +\ ' *', +\ '%(parameters| * {parameters})%', +\ ' * @return !description', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:class_method_pattern, { +\ 'template': [ +\ '/** !description', +\ ' *', +\ '%(parameters| * {parameters})%', +\ ' * @return !description', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:class_pattern, { +\ 'template': [ +\ '/** !description', +\ ' *', +\ '%(parameters| * {parameters})%', +\ ' */', +\ ], +\ }), +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/sh.vim b/ftplugin/sh.vim index eef314d9..bbdc83b4 100644 --- a/ftplugin/sh.vim +++ b/ftplugin/sh.vim @@ -19,37 +19,48 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} " ============================================================================== -" Matches regular functions. +" Define our base for every pattern. +" ============================================================================== +let s:pattern_base = { +\ 'insert': 'above', +\} + " ============================================================================== -" -" Matches the following scenarios: -" -" function test {} -" -" test() {} -call add(b:doge_patterns, { +" Define the pattern types. +" ============================================================================== + +" ------------------------------------------------------------------------------ +" Matches regular functions. +" ------------------------------------------------------------------------------ +" function test {} +" test() {} +" ------------------------------------------------------------------------------ +let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\(function\s\+[[:alnum:]_-]\+\|[[:alnum:]_-]\+\s*(.\{-})\)\s*{', \ 'match_group_names': [], -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'google': [ -\ '################################################################################', -\ '# !description', -\ '# Globals:', -\ '# \t!var-name', -\ '# Arguments:', -\ '# \t$1: !description', -\ '# Returns:', -\ '# \t!description', -\ '################################################################################', -\ ], -\ }, -\ }, \}) +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.google = [ +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '################################################################################', +\ '# !description', +\ '# Globals:', +\ '# \t!var-name', +\ '# Arguments:', +\ '# \t$1: !description', +\ '# Returns:', +\ '# \t!description', +\ '################################################################################', +\ ], +\ }), +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/ftplugin/typescript.vim b/ftplugin/typescript.vim index b65daa1c..6bd54228 100644 --- a/ftplugin/typescript.vim +++ b/ftplugin/typescript.vim @@ -22,218 +22,164 @@ if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 \ ) endif -let b:doge_patterns = [] +let b:doge_patterns = {} -" Matches the following pattern: +" ============================================================================== +" Define our base for every pattern. + +" The parameters.match describes the following pattern: " : = -let s:parameters_match_pattern = '\m\%(\%(public\|private\|protected\)\?\s*\)\?\([[:alnum:]_$]\+\)?\?\%(\s*:\s*\([[:alnum:]._| ]\+\%(\[[[:alnum:][:space:]_[\],]*\]\)\?\)\)\?\%(\s*=\s*\([[:alnum:]_.]\+(.\{-})\|[^,]\+\)\+\)\?' +" ============================================================================== +let s:pattern_base = { +\ 'parameters': { +\ 'match': '\m\%(\%(public\|private\|protected\)\?\s*\)\?\([[:alnum:]_$]\+\)?\?\%(\s*:\s*\([[:alnum:]._| ]\+\%(\[[[:alnum:][:space:]_[\],]*\]\)\?\)\)\?\%(\s*=\s*\([[:alnum:]_.]\+(.\{-})\|[^,]\+\)\+\)\?', +\ 'match_group_names': ['name', 'type'], +\ 'format': '@param {{type|!type}} {name} - !description', +\ }, +\ 'insert': 'above', +\} " ============================================================================== -" Matches fat-arrow / functions inside objects. +" Define the pattern types. " ============================================================================== -" -" Matches the following scenarios: -" -" myKey: function myRealFunction(p1, p2) {} -" -" myKey: async function myRealFunction(p1, p2) {} -" -" myKey: (p1, p2) => {} -" -" myKey: async (p1, p2) => {} -call add(b:doge_patterns, { + +" ------------------------------------------------------------------------------ +" Matches fat-arrow / functions inside objects. +" ------------------------------------------------------------------------------ +" myKey: function myRealFunction(p1, p2) {} +" myKey: async function myRealFunction(p1, p2) {} +" myKey: (p1, p2) => {} +" myKey: async (p1, p2) => {} +" ------------------------------------------------------------------------------ +let s:object_functions_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^[[:punct:]]\?\([[:alnum:]_-]\+\)[[:punct:]]\?\s*:\s*\(async\)\?\s*\%(function\)\?\s*\%([[:alnum:]_]\+\)\?(\(.\{-}\))\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\%(\s*=>\s*\)\?\s*[({]', \ 'match_group_names': ['funcName', 'async', 'parameters', 'returnType'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name', 'type'], -\ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} - !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'jsdoc': [ -\ '/**', -\ ' * !description', -\ ' *', -\ '%(async| * @{async})%', -\ ' * @function {funcName|}', -\ '%(parameters| * {parameters})%', -\ ' * @return {{returnType|!type}} !description', -\ ' */', -\ ], -\ }, -\ }, \}) -" ============================================================================== +" ------------------------------------------------------------------------------ " Matches class declarations. -" ============================================================================== -" -" Matches the following scenarios: -" -" export class Child {} -" -" class Child extends Parent {} -" -" class Child implements CustomInterfaceName {} -" -" export class Child extends Parent implements CustomInterfaceName {} -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" export class Child {} +" class Child extends Parent {} +" class Child implements CustomInterfaceName {} +" export class Child extends Parent implements CustomInterfaceName {} +" ------------------------------------------------------------------------------ +let s:class_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(export\s*\)\?class\s\+\%([[:alnum:]_$]\+\)\%(\s\+extends\s\+\([[:alnum:]_$.]\+\)\)\?\%(\s\+implements\s\+\([[:alnum:]_$.]\+\)\)\?\s*{', \ 'match_group_names': ['parentClassName', 'interfaceName'], -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'jsdoc': [ -\ '/**', -\ ' * !description', -\ ' *', -\ '%(parentClassName| * @extends {parentClassName})%', -\ '%(interfaceName| * @implements {interfaceName})%', -\ ' */', -\ ], -\ }, -\ }, +\ 'parameters': v:false, \}) -"" -" ============================================================================== +" ------------------------------------------------------------------------------ " Matches regular and typed functions with default parameters. -" ============================================================================== -" -" Matches the following scenarios: -" -" function add(one: any, two: any = 'default'): number {} - -" export function configureStore(history: History, initialState: object): Store {} -" -" function configureStore(history: History, initialState: object): Store {} -" -" function rollDice(): 1 | 2 | 3 | 4 | 5 | 6 {} -" -" function pluck(o: T, names: K[]): T[K][] {} -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" function add(one: any, two: any = 'default'): number {} +" export function configureStore(history: History, initialState: object): Store {} +" function configureStore(history: History, initialState: object): Store {} +" function rollDice(): 1 | 2 | 3 | 4 | 5 | 6 {} +" function pluck(o: T, names: K[]): T[K][] {} +" ------------------------------------------------------------------------------ +let s:function_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(\%(export\|public\)\s\+\)*\(static\s\+\)\?\(async\s\+\)\?\%(function\*\?\s*\)\?\%([[:alnum:]_$]\+\)\?\s*\%(<[[:alnum:][:space:]_,]*>\)\?\s*(\([^>]\{-}\))\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\s*[{(]', \ 'match_group_names': ['static', 'async', 'parameters', 'returnType'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name', 'type'], -\ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} - !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'jsdoc': [ -\ '/**', -\ ' * !description', -\ ' *', -\ '%(static| * @static)%', -\ '%(async| * @async)%', -\ '%(parameters| * {parameters})%', -\ ' * @return {{returnType|!type}} !description', -\ ' */', -\ ], -\ }, -\ }, \}) -" ============================================================================== +" ------------------------------------------------------------------------------ " Matches prototype functions. -" ============================================================================== -" -" Matches the following scenarios: -" -" Person.prototype.greet = (p1: string = 'default', p2: Immutable.List = Immutable.List()) => {}; -" -" Person.prototype.greet = function (p1: string = 'default', p2: Immutable.List = Immutable.List()) {}; -" -" Person.prototype.greet = function*(p1: string = 'default', p2: Immutable.List = Immutable.List()) {}; -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" Person.prototype.greet = (p1: string = 'default', p2: Immutable.List = Immutable.List()) => {}; +" Person.prototype.greet = function (p1: string = 'default', p2: Immutable.List = Immutable.List()) {}; +" Person.prototype.greet = function*(p1: string = 'default', p2: Immutable.List = Immutable.List()) {}; +" ------------------------------------------------------------------------------ +let s:prototype_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\([[:alnum:]_$]\+\)\.prototype\.\([[:alnum:]_$]\+\)\s*=\s*\(async\s\+\)\?\%(function\*\?\s*\)\?({\?\([^>]\{-}\)}\?)\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\s*\(=>\s*\)\?[{(]', \ 'match_group_names': ['className', 'funcName', 'async', 'parameters', 'returnType'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name', 'type'], -\ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} - !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'jsdoc': [ -\ '/**', -\ ' * !description', -\ ' *', -\ '%(async| * @async)%', -\ ' * @function {className}#{funcName}', -\ '%(parameters| * {parameters})%', -\ ' * @return {{returnType|!type}} !description', -\ ' */', -\ ], -\ }, -\ }, \}) -" ============================================================================== +" ------------------------------------------------------------------------------ " Matches fat-arrow functions. -" ============================================================================== -" -" var myFunc = function($p1 = 'value', p2 = [], p3, p4) {} -" -" var myFunc = function*($p1 = 'value', p2 = [], p3, p4) {} -" -" var myFunc = async function*($p1 = 'value', p2 = [], p3, p4) {} -" -" var myFunc = async ($p1 = 'value', p2 = [], p3, p4) => {} -" -" (p1: array = []) => (p2: string) => { console.log(5); } -" -" (p1: array = []) => (p2: string) => { console.log(5); } -" -" static myMethod({ b: number }): number {} -" -" static async myMethod({ b: number }): number {} -" -" const user = (p1 = 'default') => (subp1, subp2 = 'default') => 5; -" -" const foo = bar => baz -" -" export const foo = bar => baz -" -" (p1: string = 'default', p2: int = 5, p3, p4: Immutable.List = [], p5: string[] = [], p6: float = 0.5): number[] => { }; -call add(b:doge_patterns, { +" ------------------------------------------------------------------------------ +" var myFunc = function($p1 = 'value', p2 = [], p3, p4) {} +" var myFunc = function*($p1 = 'value', p2 = [], p3, p4) {} +" var myFunc = async function*($p1 = 'value', p2 = [], p3, p4) {} +" var myFunc = async ($p1 = 'value', p2 = [], p3, p4) => {} +" (p1: array = []) => (p2: string) => { console.log(5); } +" (p1: array = []) => (p2: string) => { console.log(5); } +" static myMethod({ b: number }): number {} +" static async myMethod({ b: number }): number {} +" const user = (p1 = 'default') => (subp1, subp2 = 'default') => 5; +" const foo = bar => baz +" export const foo = bar => baz +" (p1: string = 'default', p2: int = 5, p3, p4: Immutable.List = [], p5: string[] = [], p6: float = 0.5): number[] => { }; +" ------------------------------------------------------------------------------ +let s:fat_arrow_function_pattern = doge#helpers#deepextend(s:pattern_base, { \ 'match': '\m^\%(export\s\+\)\?\%(\%(\%(var\|const\|let\)\s\+\)\?\%(\(static\)\s\+\)\?\([[:alnum:]_$]\+\)\)\?\s*=\s*\(static\s\+\)\?\(async\s\+\)\?\%(function\*\?\s*\)\?\(({\?[^>]\{-}}\?)\|[[:alnum:]_$]\+\)\%(\s*:\s*(\?\([[:alnum:][:space:]_[\].,|<>]\+\))\?\)\?\s*\%(=>\s*\)\?[^ ]\{-}', \ 'match_group_names': ['static', 'funcName', 'static', 'async', 'parameters', 'returnType'], -\ 'parameters': { -\ 'match': s:parameters_match_pattern, -\ 'match_group_names': ['name', 'type'], -\ 'format': { -\ 'jsdoc': '@param {{type|!type}} {name} - !description', -\ }, -\ }, -\ 'comment': { -\ 'insert': 'above', -\ 'template': { -\ 'jsdoc': [ -\ '/**', -\ ' * !description', -\ ' *', -\ '%(static| * @static)%', -\ '%(async| * @async)%', -\ ' * @function {funcName|}', -\ '%(parameters| * {parameters})%', -\ ' * @return {{returnType|!type}} !description', -\ ' */', -\ ], -\ }, -\ }, \}) +" ============================================================================== +" Define the doc standards. +" ============================================================================== +let b:doge_patterns.jsdoc = [ +\ doge#helpers#deepextend(s:object_functions_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ ' *', +\ '%(async| * @{async})%', +\ ' * @function {funcName|}', +\ '%(parameters| * {parameters})%', +\ ' * @return {{returnType|!type}} !description', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:class_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ '%(parentClassName| * @extends {parentClassName})%', +\ '%(interfaceName| * @implements {interfaceName})%', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:function_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ ' *', +\ '%(static| * @static)%', +\ '%(async| * @async)%', +\ '%(parameters| * {parameters})%', +\ ' * @return {{returnType|!type}} !description', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:prototype_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ ' *', +\ '%(async| * @async)%', +\ ' * @function {className}#{funcName}', +\ '%(parameters| * {parameters})%', +\ ' * @return {{returnType|!type}} !description', +\ ' */', +\ ], +\ }), +\ doge#helpers#deepextend(s:fat_arrow_function_pattern, { +\ 'template': [ +\ '/**', +\ ' * !description', +\ ' *', +\ '%(static| * @static)%', +\ '%(async| * @async)%', +\ ' * @function {funcName|}', +\ '%(parameters| * {parameters})%', +\ ' * @return {{returnType|!type}} !description', +\ ' */', +\ ], +\ }), +\] + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/test/filetypes/groovy/class-methods.vader b/test/filetypes/groovy/class-methods.vader index d53fb04e..7ce924b3 100644 --- a/test/filetypes/groovy/class-methods.vader +++ b/test/filetypes/groovy/class-methods.vader @@ -1,4 +1,4 @@ -# Groovy tests should be equal to Java tests. +# Groovy tests should be equal to groovy tests. # ============================================================================== # Method without parameters. @@ -6,19 +6,28 @@ Given groovy (method without parameters): class Test { List createSortedList() {} + + void foo(); } Do (trigger doge): :2\ \ + :8\ + \ Expect groovy (method with 'TODO' and a @return tag): class Test { /** * [TODO:description] - * @return List [TODO:description] + * @return [TODO:description] */ List createSortedList() {} + + /** + * [TODO:description] + */ + void foo(); } # ============================================================================== @@ -33,11 +42,10 @@ Do (trigger doge): :2\ \ -Expect groovy (method with 'TODO' and a @return tag containing 'void'): +Expect groovy (method with 'TODO' and a description): class Test { /** * [TODO:description] - * @return void [TODO:description] */ public createSortedList() {} } @@ -55,26 +63,28 @@ Given groovy (methods with parameters): Do (trigger doge): :2\ \ - :11\ + :12\ \ Expect groovy (generated comments with @param and @return tags): class Test { /** * [TODO:description] - * @param String p1 [TODO:description] - * @param int p2 [TODO:description] - * @param Boolean params [TODO:description] - * @return MstRelation [TODO:description] + * + * @param p1 [TODO:description] + * @param p2 [TODO:description] + * @param params [TODO:description] + * @return [TODO:description] */ private static MstRelation MyParameterizedMethod(String p1, int p2, Boolean ...params) {} /** * [TODO:description] - * @param String p1 [TODO:description] - * @param int p2 [TODO:description] - * @param Boolean params [TODO:description] - * @return ListResultBean [TODO:description] + * + * @param p1 [TODO:description] + * @param p2 [TODO:description] + * @param params [TODO:description] + * @return [TODO:description] */ ListResultBean MyParameterizedMethod(String p1, int p2, Boolean... params) {} } @@ -96,9 +106,9 @@ Expect groovy (generated comments with @param and @return tags inserted above th class Test { /** * [TODO:description] - * @param String p1 [TODO:description] - * @param int p2 [TODO:description] - * @return void [TODO:description] + * + * @param p1 [TODO:description] + * @param p2 [TODO:description] */ @Override protected void MyParameterizedMethod(String p1, int p2) {} diff --git a/test/filetypes/java/class-methods.vader b/test/filetypes/java/class-methods.vader index 23ec719c..d5267493 100644 --- a/test/filetypes/java/class-methods.vader +++ b/test/filetypes/java/class-methods.vader @@ -61,13 +61,14 @@ Given java (methods with parameters): Do (trigger doge): :2\ \ - :11\ + :12\ \ Expect java (generated comments with @param and @return tags): class Test { /** * [TODO:description] + * * @param p1 [TODO:description] * @param p2 [TODO:description] * @param params [TODO:description] @@ -77,6 +78,7 @@ Expect java (generated comments with @param and @return tags): /** * [TODO:description] + * * @param p1 [TODO:description] * @param p2 [TODO:description] * @param params [TODO:description] @@ -102,6 +104,7 @@ Expect java (generated comments with @param and @return tags inserted above the class Test { /** * [TODO:description] + * * @param p1 [TODO:description] * @param p2 [TODO:description] */