From ca67b5039c0fae122df9a6c324e60dc36df48c2d Mon Sep 17 00:00:00 2001 From: Kim K Date: Thu, 27 Jun 2019 15:47:42 +0200 Subject: [PATCH] feat: Support multiple doc standard (feature issue #3) --- .github/ISSUE_TEMPLATE/doc_standard.md | 19 ++++ CONTRIBUTING.md | 41 ++++----- README.md | 72 ++++++++++++--- autoload/doge/generate.vim | 44 ++++++--- autoload/doge/indent.vim | 13 ++- autoload/doge/token.vim | 122 ++++++++++++++----------- ftplugin/coffee.vim | 47 ++++++---- ftplugin/groovy.vim | 31 +++++-- ftplugin/java.vim | 31 +++++-- ftplugin/javascript.vim | 97 ++++++++++++-------- ftplugin/kotlin.vim | 67 +++++++++----- ftplugin/lua.vim | 39 ++++++-- ftplugin/php.vim | 43 ++++++--- ftplugin/python.vim | 55 ++++++++--- ftplugin/r.vim | 33 +++++-- ftplugin/ruby.vim | 25 ++++- ftplugin/scala.vim | 69 +++++++++----- ftplugin/typescript.vim | 97 ++++++++++++-------- playground/test.js | 6 +- test/filetypes/php/class-methods.vader | 1 - test/filetypes/php/functions.vader | 1 - test/filetypes/python/functions.vader | 72 +++++++++++++++ test/filetypes/r/functions.vader | 4 +- 23 files changed, 722 insertions(+), 307 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/doc_standard.md diff --git a/.github/ISSUE_TEMPLATE/doc_standard.md b/.github/ISSUE_TEMPLATE/doc_standard.md new file mode 100644 index 00000000..32c4445f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/doc_standard.md @@ -0,0 +1,19 @@ +--- +name: Doc standard +about: Suggest a new doc standard for a specific language +title: 'Add doc standard for ' +labels: 'enhancement' +assignees: '' + +--- + +**Documentation standard** +Specify a link to the documentation standard section containing the tags. + +**How popular is the doc standard?** +- [ ] Not popular at all +- [ ] Some people use it +- [ ] Quite a lot of people use it +- [ ] It's not the most popular one, but a good alternative +- [ ] Everyone within the community is using it +- [ ] Everyone is using it diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f8a82aed..95b48354 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,7 +24,7 @@ When contributing make sure you: * [Writing your first pattern](#writing-your-first-pattern) + [Additional token formatting](#additional-token-formatting) - [Default value](#default-value) - - [Prevent rendering when captured group failed to capture](#prevent-rendering-when-captured-group-failed-to-capture) + - [Conditional rendering](#conditional-rendering) * [Writing proper regex](#writing-proper-regex) # How does DoGe work? @@ -217,35 +217,34 @@ You can also leave the default value empty to just remove the token when it fails to capture a value. Example: `{type|}`. This will result in: `* @param $p1 TODO` instead of `* @param {type} $p1 TODO`. -#### Prevent rendering when captured group failed to capture +#### Conditional rendering -When groups fail to capture a value there are scenarios where you do not want -the token to render. You can use the exclamation mark `!` at the beginning of a -sentence in the `template` or `parameters.format` keys to accomplish this. +The syntax for a conditional render is `#(|)` where `` is +the name of the token and `` the value you want to render when `` +is _not empty_. Example: -Javascript uses JSDoc where a function should use the `@async` tag when a -function is declared using the `async` keyword. We want to render the tag -_only_ when the `async` keyword is used in the function declaration. This is how it's done: ```vim +" Example taken from ftplugin/python.vim + call add(b:doge_patterns, { -\ 'match': '...\(async\)\?...', -\ 'match_group_names': ['async'], -\ 'parameters': {}, +\ " ... \ 'comment': { -\ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * @description TODO', - " The '{async}' token renders the word 'async' which ends up in '@async'. - " The whole line is removed when `{async}` fails to be captured. -\ '! * @{async}', -\ ' * {parameters}', -\ ' */', -\ ], +\ 'insert': 'below', +\ 'template': { +\ 'numpy': [ +\ '"""', +\ 'TODO', +\ '#(parameters|)', " Render an empty line if '{parameters}' is not empty +\ '#(parameters|Parameters)', " Renders 'Parameters' if '{parameters}' is not empty +\ '#(parameters|----------)', " Renders '----------' if '{parameters}' is not empty +\ '#(parameters|{parameters})', " Renders '{parameters}' if '{parameters}' is not empty +\ '"""', +\ ], +\ } \ }, \}) ``` diff --git a/README.md b/README.md index be07ff19..05b023b1 100644 --- a/README.md +++ b/README.md @@ -61,20 +61,20 @@ Every language that has a documentation standard should be supported by DoGe. Is your favorite language not supported? [Make a feature request](https://github.com/kkoomen/vim-doge/issues/new?labels=enhancement&template=feature_request.md&title=Add+support+for+) :tada: -| | Language | Doc standard | -| --- | --- | --- | -| :white_check_mark: | Python | ([Sphinx reST](http://daouzli.com/blog/docstring.html#restructuredtext)) | -| :white_check_mark: | PHP | ([phpdoc](https://www.phpdoc.org)) | -| :white_check_mark: | JavaScript (Including: ES6, FlowJS and NodeJS) | ([JSDoc](https://jsdoc.app)) | -| :white_check_mark: | TypeScript | ([JSDoc](https://jsdoc.app)) | -| :white_check_mark: | CoffeeScript | ([JSDoc](https://jsdoc.app)) | -| :white_check_mark: | Lua | ([LDoc](https://github.com/stevedonovan/LDoc)) | -| :white_check_mark: | Java | ([JavaDoc](https://www.oracle.com/technetwork/articles/javase/index-137868.html)) | -| :white_check_mark: | Groovy | ([JavaDoc](https://www.oracle.com/technetwork/articles/javase/index-137868.html)) | -| :white_check_mark: | Ruby | ([YARD](https://www.rubydoc.info/gems/yard/file/docs/Tags.md)) | -| :white_check_mark: | Scala | ([ScalaDoc](https://docs.scala-lang.org/style/scaladoc.html)) | -| :white_check_mark: | Kotlin | ([KDoc](https://kotlinlang.org/docs/reference/kotlin-doc.html)) | -| :white_check_mark: | R | ([Roxygen2](https://github.com/klutometis/roxygen)) | +| | Language | Doc standard | +| --- | --- | --- | +| :white_check_mark: | Python | [reST](http://daouzli.com/blog/docstring.html#restructuredtext), [Numpy](http://daouzli.com/blog/docstring.html#numpydoc) | +| :white_check_mark: | PHP | [phpdoc](https://www.phpdoc.org) | +| :white_check_mark: | JavaScript (Including: ES6, FlowJS and NodeJS) | [JSDoc](https://jsdoc.app) | +| :white_check_mark: | TypeScript | [JSDoc](https://jsdoc.app) | +| :white_check_mark: | CoffeeScript | [JSDoc](https://jsdoc.app) | +| :white_check_mark: | Lua | [LDoc](https://github.com/stevedonovan/LDoc) | +| :white_check_mark: | Java | [JavaDoc](https://www.oracle.com/technetwork/articles/javase/index-137868.html) | +| :white_check_mark: | Groovy | [JavaDoc](https://www.oracle.com/technetwork/articles/javase/index-137868.html) | +| :white_check_mark: | Ruby | [YARD](https://www.rubydoc.info/gems/yard/file/docs/Tags.md) | +| :white_check_mark: | Scala | [ScalaDoc](https://docs.scala-lang.org/style/scaladoc.html) | +| :white_check_mark: | Kotlin | [KDoc](https://kotlinlang.org/docs/reference/kotlin-doc.html) | +| :white_check_mark: | R | [Roxygen2](https://github.com/klutometis/roxygen) | # Getting started @@ -128,6 +128,50 @@ Adds the `TODO` suffix after every generated parameter. Jumps interactively through all `TODO` items in the generated comment. +## Choose different doc standard + +DoGe supports multiple doc standard and you can overwrite them per filetype in +your vimrc. Does DoGe not support your preferred dog standard? +[Make a feature request](https://github.com/kkoomen/vim-doge/issues/new?labels=enhancement&template=doc_standard.md)! + +Here is the full list of available doc standards per filetype: +- `let g:doge_doc_standard_python` + - Default: `reST` + - Available: `['reST', 'numpy']` +- `let g:doge_doc_standard_php` + - Default: `phpdoc` + - Available: `['phpdoc']` +- `let g:doge_doc_standard_javascript` + - Default: `jsdoc` + - Available: `['jsdoc']` +- `let g:doge_doc_standard_typescript` + - Default: `jsdoc` + - Available: `['jsdoc']` +- `let g:doge_doc_standard_coffeescript` + - Default: `jsdoc` + - Available: `['jsdoc']` +- `let g:doge_doc_standard_lua` + - Default: `ldoc` + - Available: `['ldoc']` +- `let g:doge_doc_standard_java` + - Default: `javadoc` + - Available: `['javadoc']` +- `let g:doge_doc_standard_groovy` + - Default: `javadoc` + - Available: `['javadoc']` +- `let g:doge_doc_standard_ruby` + - Default: `YARD` + - Available: `['YARD']` +- `let g:doge_doc_standard_scala` + - Default: `scaladoc` + - Available: `['scaladoc']` +- `let g:doge_doc_standard_kotlin` + - Default: `kdoc` + - Available: `['kdoc']` +- `let g:doge_doc_standard_r` + - Default: `roxygen2` + - Available: `['roxygen2']` + # Help To open all the help pages, run `:help doge`. diff --git a/autoload/doge/generate.vim b/autoload/doge/generate.vim index 7d6cfdd9..e08582c4 100644 --- a/autoload/doge/generate.vim +++ b/autoload/doge/generate.vim @@ -7,8 +7,8 @@ set cpoptions&vim function! doge#generate#pattern(pattern) abort " Assuming multiline function expressions won't be longer than 15 lines. let l:lines_raw = getline('.', line('.') + 15) - let l:lines = map(l:lines_raw, {key, line -> - \ substitute(line, b:doge_pattern_single_line_comment, '' ,'g')}) + let l:lines = map(l:lines_raw, { key, line -> + \ substitute(line, b:doge_pattern_single_line_comment, '' ,'g') }) " Skip if the cursor doesn't start with text. if empty(trim(l:lines[0])) @@ -48,7 +48,11 @@ function! doge#generate#pattern(pattern) abort " Go through each parameter, match the regex, extract the token values and " replace the 'parameters' key with the formatted version. let l:formatted_params = [] - let l:param_tokens = doge#token#extract(l:params, l:params_dict['match'], l:params_dict['match_group_names']) + let l:param_tokens = doge#token#extract( + \ l:params, + \ l:params_dict['match'], + \ l:params_dict['match_group_names'] + \ ) " Preprocess the extracted parameter tokens. try @@ -58,12 +62,22 @@ function! doge#generate#pattern(pattern) abort endtry for l:param_token in l:param_tokens - let l:format = doge#token#replace(l:param_token, l:params_dict['format']) - let l:format = join(filter(l:format, "v:val !=# ''"), ' ') - if g:doge_comment_todo_suffix == v:false - let l:format = substitute(l:format, '\m\s*TODO\s*$', '', 'g') + let l:format = doge#token#replace( + \ l:param_token, + \ l:params_dict['format'][b:doge_doc_standard] + \ ) + if type(l:format) == v:t_list + if g:doge_comment_todo_suffix == v:false + let l:format = map(l:format, { key, line -> + \ substitute(line, '\m\s*TODO\s*$', '', 'g') }) + endif + call add(l:formatted_params, join(l:format, "\n")) + else + if g:doge_comment_todo_suffix == v:false + let l:format = substitute(l:format, '\m\s*TODO\s*$', '', 'g') + endif + call add(l:formatted_params, l:format) endif - call add(l:formatted_params, l:format) endfor let l:tokens['parameters'] = l:formatted_params endif @@ -71,18 +85,20 @@ function! doge#generate#pattern(pattern) abort " Create the comment by replacing the tokens in the template with their " corresponding values. let l:comment = [] - for l:line in a:pattern['comment']['template'] + for l:line in a:pattern['comment']['template'][b:doge_doc_standard] " 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. - if empty(l:line) - call add(l:comment, l:line) + let l:line_replaced = doge#token#replace(l:tokens, l:line) + if empty(l:line) || empty(l:line_replaced) + call add(l:comment, '') + continue + elseif l:line_replaced ==# '-' continue endif - let l:line_replaced = split(doge#token#replace(l:tokens, l:line), "\n") - for l:replaced in l:line_replaced - call add(l:comment, l:replaced) + for l:replaced in split(l:line_replaced, "\n") + call add(l:comment, doge#indent#convert(l:replaced)) endfor endfor diff --git a/autoload/doge/indent.vim b/autoload/doge/indent.vim index b439c2cd..e9b9c574 100644 --- a/autoload/doge/indent.vim +++ b/autoload/doge/indent.vim @@ -3,7 +3,7 @@ set cpoptions&vim "" " @public -" Indent a string based on a given line its indent. +" Indent a string based on a given line its indent, based on the user setting. function! doge#indent#add(lnum, text) abort if &expandtab return repeat(' ', indent(a:lnum)) . a:text @@ -12,5 +12,16 @@ function! doge#indent#add(lnum, text) abort endif endfunction +"" +" @public +" Convert spaces to tabs and tabs to spaces based on the user setting. +function! doge#indent#convert(text) abort + if &expandtab + return substitute(a:text, "\t", repeat(' ', shiftwidth()), 'g') + else + return substitute(a:text, repeat(' ', shiftwidth()), "\t", 'g') + endif +endfunction + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/autoload/doge/token.vim b/autoload/doge/token.vim index 4df84fe8..e44e9154 100644 --- a/autoload/doge/token.vim +++ b/autoload/doge/token.vim @@ -12,35 +12,44 @@ function! s:token_replace(tokens, text) abort endif let l:text = deepcopy(a:text) + let l:empty_conditional_pattern_value = 0 + + for [l:token, l:token_value] in items(a:tokens) + let l:formatted_token = printf('{%s}', l:token) + + " Tokens can be in the following 2 formats: + " - {name} + " - {name|default} + " so if the line contains a pipe character with a default value then we + " grab that value and remove it from the text. + let l:stripped_token = matchlist(l:text, '\m{\([^|{}]\+\)\(|[^}]*\)\?}') + let l:token_default_value = trim(get(l:stripped_token, 2, '|'))[1:] + let l:has_token_default_value = !empty(trim(get(l:stripped_token, 2, ''))) + if l:has_token_default_value + let l:text = substitute( + \ l:text, + \ '{' . l:token . '|' . fnameescape(l:token_default_value) . '}', + \ '{' . l:token . '}', + \ 'g' + \ ) + endif - " When the text starts with '!' it indicates that we should empty the string - " the token did not got replaced to ensure no additional markup is left. - let l:return_empty_on_fail = l:text =~# '\m^!' - if l:return_empty_on_fail - " Remove the '!' character - let l:text = l:text[1:] - endif - - " Tokens can be in the following 2 formats: - " - {name} - " - {name|default} - " so if the line contains a pipe character with a default value then we - " grab that value and remove it from the text. - let l:stripped_line = matchlist(l:text, '\m{\([^|{}]\+\)\%(\(|[^}]*\)\)\?}') - let l:default_token_value = trim(get(l:stripped_line, 2, '|'))[1:] - let l:has_default_token_value = !empty(trim(get(l:stripped_line, 2, ''))) - if l:has_default_token_value - let l:text = substitute( - \ l:text, - \ '{' . trim(get(l:stripped_line, 1, '')) . '|' . fnameescape(get(l:stripped_line, 2, '|')[1:]) . '}', - \ '{' . trim(get(l:stripped_line, 1, '')) . '}', - \ 'g' - \ ) - endif - let l:has_replaced_tokens = 0 - for [l:token, l:value] in items(a:tokens) - let l:formatted_token = '{' . l:token . '}' + let l:conditional_pattern = printf('\m#(%s|\(.*\))', l:token) + if l:text =~# l:conditional_pattern + let l:conditional_pattern_replacement_value = '\1' + if (type(l:token_value) == v:t_string && empty(l:token_value)) + \ || (type(l:token_value) == v:t_list && len(l:token_value) < 1) + let l:conditional_pattern_replacement_value = '' + let l:empty_conditional_pattern_value = 1 + endif + let l:text = substitute( + \ l:text, + \ l:conditional_pattern, + \ l:conditional_pattern_replacement_value, + \ 'g' + \) + endif " Skip if the token does not exists in the text. if l:text !~# l:formatted_token @@ -48,44 +57,49 @@ function! s:token_replace(tokens, text) abort endif " The value of a token might be a list, for example: - " { 'format': ['someRandomText', '{token|default}'] } + " { 'parameters': ['@param $p1 string TODO', '@param $p2 int TODO'] } " and if this is the case then do a replacement for each item. - if type(l:value) == v:t_list + if type(l:token_value) == v:t_list let l:multiline_replacement = [] - for l:item in l:value - if empty(l:item) && l:has_default_token_value - call add(l:multiline_replacement, substitute(l:text, l:formatted_token, l:default_token_value, 'g')) - elseif !empty(l:item) - call add(l:multiline_replacement, substitute(l:text, l:formatted_token, escape(l:item, '\'), 'g')) + for l:multi_line_value in l:token_value + if empty(l:multi_line_value) && l:has_token_default_value + call add(l:multiline_replacement, + \ substitute(l:text, l:formatted_token, l:token_default_value, 'g')) + elseif !empty(l:multi_line_value) + call add(l:multiline_replacement, + \ substitute(l:text, l:formatted_token, escape(l:multi_line_value, '\'), 'g')) endif endfor let l:text = join(l:multiline_replacement, "\n") else - if empty(l:value) && l:has_default_token_value - let l:text = substitute(l:text, l:formatted_token, l:default_token_value, 'g') - elseif !empty(l:value) - let l:text = substitute(l:text, l:formatted_token, l:value, 'g') + if empty(l:token_value) && l:has_token_default_value + let l:text = substitute(l:text, l:formatted_token, l:token_default_value, 'g') + elseif !empty(l:token_value) + let l:text = substitute(l:text, l:formatted_token, l:token_value, 'g') endif endif - - if l:text !~# l:formatted_token - let l:has_replaced_tokens = 1 - " break - endif endfor - if l:has_replaced_tokens == v:false && l:return_empty_on_fail == v:true - return '' - endif + " Replace 2 or more white-spaces with 1 single white-space, except for leading + " white-spaces and/or newlines. Those should be preserved. + let l:text = substitute(l:text, '\m\(^\|\s\|\n\)\@ s:token_replace(a:tokens, line)}) + return map(l:text, { key, line -> s:token_replace(a:tokens, line) }) elseif type(l:text) == v:t_string return s:token_replace(a:tokens, l:text) endif @@ -113,7 +127,7 @@ function! doge#token#extract(text, regex, regex_group_names) abort let l:submatches = [] call substitute(a:text, a:regex, '\=add(l:submatches, submatch(0))', 'g') - let l:matches = map(l:submatches, {key, val -> trim(val)}) + let l:matches = map(l:submatches, { key, val -> trim(val) }) let l:tokens = [] " We can expect a list of matches like: diff --git a/ftplugin/coffee.vim b/ftplugin/coffee.vim index d8929cc3..ea8b3e52 100644 --- a/ftplugin/coffee.vim +++ b/ftplugin/coffee.vim @@ -9,6 +9,17 @@ set cpoptions&vim let b:doge_pattern_single_line_comment = '\m#\@\)\?\)\%(\s\+[.]\{3}\s\+\|\s\+[.]\{3}\|[.]\{3}\s\+\|\s\+\)\([[:alnum:]_]\+\)', \ 'match_group_names': ['type', 'name'], -\ 'format': ['@param', '{type}', '{name}', 'TODO'], +\ 'format': { +\ 'javadoc': '@param {type} {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * TODO', -\ '! * {parameters}', -\ '! * @return {returnType|void} TODO', -\ ' */', -\ ], +\ 'template': { +\ 'javadoc': [ +\ '/**', +\ ' * TODO', +\ '#(parameters| * {parameters})', +\ ' * @return {returnType|void} TODO', +\ ' */', +\ ], +\ }, \ }, \}) diff --git a/ftplugin/java.vim b/ftplugin/java.vim index f9f71617..765875f1 100644 --- a/ftplugin/java.vim +++ b/ftplugin/java.vim @@ -8,6 +8,17 @@ set cpoptions&vim let b:doge_pattern_single_line_comment = '\m\(\/\*.\{-}\*\/\|\/\/.\{-}$\)' let b:doge_pattern_multi_line_comment = '\m\/\*.\{-}\*\/' + +let b:doge_supported_doc_standards = ['javadoc'] +let b:doge_doc_standard = get(g:, 'doge_doc_standard_java', b:doge_supported_doc_standards[0]) +if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 + echoerr printf( + \ '[DoGe] %s is not a valid Java doc standard, available doc standard are: %s', + \ b:doge_doc_standard, + \ join(b:doge_supported_doc_standards, ', ') + \ ) +endif + let b:doge_patterns = [] " ============================================================================== @@ -29,17 +40,21 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': '\m\%(\([[:alnum:]_]\+\)\%(<[[:alnum:][:space:]_,]\+>\)\?\)\%(\s\+[.]\{3}\s\+\|\s\+[.]\{3}\|[.]\{3}\s\+\|\s\+\)\([[:alnum:]_]\+\)', \ 'match_group_names': ['type', 'name'], -\ 'format': ['@param', '{type}', '{name}', 'TODO'], +\ 'format': { +\ 'javadoc': '@param {type} {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * TODO', -\ '! * {parameters}', -\ '! * @return {returnType|void} TODO', -\ ' */', -\ ], +\ 'template': { +\ 'javadoc': [ +\ '/**', +\ ' * TODO', +\ '#(parameters| * {parameters})', +\ ' * @return {returnType|void} TODO', +\ ' */', +\ ], +\ }, \ }, \}) diff --git a/ftplugin/javascript.vim b/ftplugin/javascript.vim index 90c694ba..79895703 100644 --- a/ftplugin/javascript.vim +++ b/ftplugin/javascript.vim @@ -8,6 +8,17 @@ set cpoptions&vim let b:doge_pattern_single_line_comment = '\m\(\/\*.\{-}\*\/\|\/\/.\{-}$\)' let b:doge_pattern_multi_line_comment = '\m\/\*.\{-}\*\/' + +let b:doge_supported_doc_standards = ['jsdoc'] +let b:doge_doc_standard = get(g:, 'doge_doc_standard_javascript', b:doge_supported_doc_standards[0]) +if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 + echoerr printf( + \ '[DoGe] %s is not a valid JavaScript doc standard, available doc standard are: %s', + \ b:doge_doc_standard, + \ join(b:doge_supported_doc_standards, ', ') + \ ) +endif + let b:doge_patterns = [] " Matches the following pattern: @@ -32,13 +43,15 @@ call add(b:doge_patterns, { \ 'match_group_names': ['parentClassName', 'interfaceName'], \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * @description TODO', -\ '! * @extends {parentClassName}', -\ '! * @implements {interfaceName}', -\ ' */', -\ ], +\ 'template': { +\ 'jsdoc': [ +\ '/**', +\ ' * @description TODO', +\ '#(parentClassName| * @extends {parentClassName})', +\ '#(interfaceName| * @implements {interfaceName})', +\ ' */', +\ ], +\ }, \ }, \}) @@ -64,18 +77,22 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], -\ 'format': ['@param', '{{type|*}}', '{name}', 'TODO'], +\ 'format': { +\ 'jsdoc': '@param {{type|*}} {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * @description TODO', -\ '! * @{async}', -\ '! * {parameters}', -\ '! * @return {{returnType}} TODO', -\ ' */', -\ ], +\ 'template': { +\ 'jsdoc': [ +\ '/**', +\ ' * @description TODO', +\ '#(async| * @{async})', +\ '#(parameters| * {parameters})', +\ '#(returnType| * @return {{returnType}} TODO)', +\ ' */', +\ ], +\ }, \ }, \}) @@ -96,19 +113,23 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], -\ 'format': ['@param', '{{type|*}}', '{name}', 'TODO'], +\ 'format': { +\ 'jsdoc': '@param {{type|*}} {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * @description TODO', -\ '! * @{async}', -\ ' * @function {className}#{funcName}', -\ '! * {parameters}', -\ '! * @return {{returnType}} TODO', -\ ' */', -\ ], +\ 'template': { +\ 'jsdoc': [ +\ '/**', +\ ' * @description TODO', +\ '#(async| * @{async})', +\ ' * @function {className}#{funcName}', +\ '#(parameters| * {parameters})', +\ '#(returnType| * @return {{returnType}} TODO)', +\ ' */', +\ ], +\ }, \ }, \}) @@ -141,19 +162,23 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], -\ 'format': ['@param', '{{type|*}}', '{name}', 'TODO'], +\ 'format': { +\ 'jsdoc': '@param {{type|*}} {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * @description TODO', -\ '! * @{async}', -\ ' * @function {funcName|}', -\ '! * {parameters}', -\ '! * @return {{returnType}} TODO', -\ ' */', -\ ], +\ 'template': { +\ 'jsdoc': [ +\ '/**', +\ ' * @description TODO', +\ '#(async| * @{async})', +\ ' * @function {funcName|}', +\ '#(parameters| * {parameters})', +\ '#(returnType| * @return {{returnType}} TODO)', +\ ' */', +\ ], +\ }, \ }, \}) diff --git a/ftplugin/kotlin.vim b/ftplugin/kotlin.vim index a71cbd76..7a15b292 100644 --- a/ftplugin/kotlin.vim +++ b/ftplugin/kotlin.vim @@ -8,6 +8,17 @@ set cpoptions&vim let b:doge_pattern_single_line_comment = '\m\(\/\*.\{-}\*\/\|\/\/.\{-}$\)' let b:doge_pattern_multi_line_comment = '\m\/\*.\{-}\*\/' + +let b:doge_supported_doc_standards = ['kdoc'] +let b:doge_doc_standard = get(g:, 'doge_doc_standard_kotlin', b:doge_supported_doc_standards[0]) +if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 + echoerr printf( + \ '[DoGe] %s is not a valid Kotlin doc standard, available doc standard are: %s', + \ b:doge_doc_standard, + \ join(b:doge_supported_doc_standards, ', ') + \ ) +endif + let b:doge_patterns = [] " Matches the following pattern: @@ -57,17 +68,21 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name'], -\ 'format': ['@param', '{name}', 'TODO'], +\ 'format': { +\ 'kdoc': '@param {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * TODO', -\ '! * {parameters}', -\ ' * @return TODO', -\ ' */', -\ ], +\ 'template': { +\ 'kdoc': [ +\ '/**', +\ ' * TODO', +\ '#(parameters| * {parameters})', +\ ' * @return TODO', +\ ' */', +\ ], +\ }, \ }, \}) @@ -104,16 +119,20 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name'], -\ 'format': ['@property', '{name}', 'TODO'], +\ 'format': { +\ 'kdoc': '@property {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * TODO', -\ '! * {parameters}', -\ ' */', -\ ], +\ 'template': { +\ 'kdoc': [ +\ '/**', +\ ' * TODO', +\ '#(parameters| * {parameters})', +\ ' */', +\ ], +\ }, \ }, \}) @@ -130,16 +149,20 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name'], -\ 'format': ['@param', '{name}', 'TODO'], +\ 'format': { +\ 'kdoc': '@param {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * TODO', -\ '! * {parameters}', -\ ' */', -\ ], +\ 'template': { +\ 'kdoc': [ +\ '/**', +\ ' * TODO', +\ '#(parameters| * {parameters})', +\ ' */', +\ ], +\ }, \ }, \}) diff --git a/ftplugin/lua.vim b/ftplugin/lua.vim index 8e2cc388..41e49cdd 100644 --- a/ftplugin/lua.vim +++ b/ftplugin/lua.vim @@ -8,6 +8,17 @@ set cpoptions&vim let b:doge_pattern_single_line_comment = '\m--\+\([[\)\@!.\{-}$' let b:doge_pattern_multi_line_comment = '\m--\+[[.\{-}]]--\+' + +let b:doge_supported_doc_standards = ['ldoc'] +let b:doge_doc_standard = get(g:, 'doge_doc_standard_lua', b:doge_supported_doc_standards[0]) +if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 + echoerr printf( + \ '[DoGe] %s is not a valid Lua doc standard, available doc standard are: %s', + \ b:doge_doc_standard, + \ join(b:doge_supported_doc_standards, ', ') + \ ) +endif + let b:doge_patterns = [] let s:parameters_match_pattern = '\m\([^,]\+\)' @@ -33,14 +44,18 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name'], -\ 'format': ['@param', '{name}', 'TODO'], +\ 'format': { +\ 'ldoc': '@param {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '-- TODO', -\ '!-- {parameters}', -\ ], +\ 'template': { +\ 'ldoc': [ +\ '-- TODO', +\ '#(parameters|-- {parameters})', +\ ], +\ }, \ }, \}) @@ -60,14 +75,18 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name'], -\ 'format': ['@param', '{name}', 'TODO'], +\ 'format': { +\ 'ldoc': '@param {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '-- TODO', -\ '!-- {parameters}', -\ ], +\ 'template': { +\ 'ldoc': [ +\ '-- TODO', +\ '#(parameters|-- {parameters})', +\ ], +\ }, \ }, \}) diff --git a/ftplugin/php.vim b/ftplugin/php.vim index f242d5fb..28e4d1de 100644 --- a/ftplugin/php.vim +++ b/ftplugin/php.vim @@ -8,6 +8,17 @@ set cpoptions&vim let b:doge_pattern_single_line_comment = '\m\(\/\*.\{-}\*\/\|\/\/.\{-}$\)' let b:doge_pattern_multi_line_comment = '\m\/\*.\{-}\*\/' + +let b:doge_supported_doc_standards = ['phpdoc'] +let b:doge_doc_standard = get(g:, 'doge_doc_standard_php', b:doge_supported_doc_standards[0]) +if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 + echoerr printf( + \ '[DoGe] %s is not a valid PHP doc standard, available doc standard are: %s', + \ b:doge_doc_standard, + \ join(b:doge_supported_doc_standards, ', ') + \ ) +endif + let b:doge_patterns = [] " ============================================================================== @@ -29,11 +40,13 @@ call add(b:doge_patterns, { \ 'match_group_names': ['propertyName'], \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * @var {type}', -\ ' */', -\ ], +\ 'template': { +\ 'phpdoc': [ +\ '/**', +\ ' * @var {type}', +\ ' */', +\ ], +\ }, \ }, \}) @@ -60,17 +73,21 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': '\m\%(\([[:alnum:]_\\]\+\)\s\+\)\?&\?\($[[:alnum:]_]\+\)\%(\s*=\s*\%([[:alnum:]_]\+(.\{-})\|[^,]\+\)\+\)\?', \ 'match_group_names': ['type', 'name'], -\ 'format': ['@param', '{type|mixed}', '{name}', 'TODO'], +\ 'format': { +\ 'phpdoc': '@param {type|mixed} {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * TODO', -\ ' *', -\ '! * {parameters}', -\ ' */', -\ ], +\ 'template': { +\ 'phpdoc': [ +\ '/**', +\ ' * TODO', +\ '#(parameters| *)', +\ '#(parameters| * {parameters})', +\ ' */', +\ ], +\ }, \ }, \}) diff --git a/ftplugin/python.vim b/ftplugin/python.vim index 4bb58af0..2b83af47 100644 --- a/ftplugin/python.vim +++ b/ftplugin/python.vim @@ -1,5 +1,5 @@ " ============================================================================== -" The python documentation should follow the 'Sphinx reST' conventions. +" The Python documentation should follow the 'reST' or 'Numpy' conventions. " see: http://daouzli.com/blog/docstring.html#restructuredtext " ============================================================================== @@ -8,6 +8,17 @@ set cpoptions&vim let b:doge_pattern_single_line_comment = '\m#.\{-}$' let b:doge_pattern_multi_line_comment = '\m\(""".\{-}"""\|' . "'''.\\{-}'''" . '\)' + +let b:doge_supported_doc_standards = ['reST', 'numpy'] +let b:doge_doc_standard = get(g:, 'doge_doc_standard_python', 'reST') +if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 + echoerr printf( + \ '[DoGe] %s is not a valid Python doc standard, available doc standard are: %s', + \ b:doge_doc_standard, + \ join(b:doge_supported_doc_standards, ', ') + \ ) +endif + let b:doge_patterns = [] " ============================================================================== @@ -28,19 +39,41 @@ call add(b:doge_patterns, { \ 'match_group_names': ['parameters', 'returnType'], \ 'parameters': { \ 'match': '\m\([[:alnum:]_]\+\)\%(:\s*\([[:alnum:]_]\+\%(\[[[:alnum:]_[\],[:space:]]*\]\)\?\)\)\?\%(\s*=\s*\([^,]\+\)\)\?', -\ 'match_group_names': ['name', 'type', 'default'], -\ 'format': [':param', '{name}', '{type|any}:', 'TODO'], +\ 'match_group_names': ['name', 'type'], +\ 'format': { +\ 'reST': ':param {name} {type|any}: TODO', +\ 'numpy': [ +\ '{name} : {type|any}', +\ "\tTODO", +\ ], +\ }, \ }, \ 'comment': { \ 'insert': 'below', -\ 'template': [ -\ '"""', -\ 'TODO', -\ '', -\ '!{parameters}', -\ '!:rtype {returnType}: TODO', -\ '"""', -\ ], +\ 'template': { +\ 'reST': [ +\ '"""', +\ 'TODO', +\ '', +\ '#(parameters|{parameters})', +\ '#(returnType|:rtype {returnType}: TODO)', +\ '"""', +\ ], +\ 'numpy': [ +\ '"""', +\ 'TODO', +\ '#(parameters|)', +\ '#(parameters|Parameters)', +\ '#(parameters|----------)', +\ '#(parameters|{parameters})', +\ '#(returnType|)', +\ '#(returnType|Returns)', +\ '#(returnType|-------)', +\ '#(returnType|{returnType|any}:)', +\ "#(returnType|\tTODO)", +\ '"""', +\ ], +\ }, \ }, \}) diff --git a/ftplugin/r.vim b/ftplugin/r.vim index ad190558..2995472b 100644 --- a/ftplugin/r.vim +++ b/ftplugin/r.vim @@ -8,6 +8,17 @@ set cpoptions&vim let b:doge_pattern_single_line_comment = '\m#.\{-}$' let b:doge_pattern_multi_line_comment = '\m#.\{-}$' + +let b:doge_supported_doc_standards = ['roxygen2'] +let b:doge_doc_standard = get(g:, 'doge_doc_standard_r', b:doge_supported_doc_standards[0]) +if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 + echoerr printf( + \ '[DoGe] %s is not a valid R doc standard, available doc standard are: %s', + \ b:doge_doc_standard, + \ join(b:doge_supported_doc_standards, ', ') + \ ) +endif + let b:doge_patterns = [] " ============================================================================== @@ -40,18 +51,22 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': '\m\([[:alnum:]_]\+\%(.\%([[:alnum:]_]\+\)\)*\)\%(\s*=\s*\%([[:alnum:]_]\+(.\{-})\|[^,]\+\)\)\?', \ 'match_group_names': ['name'], -\ 'format': ['@param', '{name}', 'TODO'], +\ 'format': { +\ 'roxygen2': '@param {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ "#' TODO", -\ "#'", -\ "!#' {parameters}", -\ "#'", -\ "#' @export", -\ "#'", -\ ], +\ 'template': { +\ 'roxygen2': [ +\ "#' TODO", +\ "#(parameters|#')", +\ "#(parameters|#' {parameters})", +\ "#'", +\ "#' @export", +\ "#'", +\ ], +\ }, \ }, \}) diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index 30736edb..b566373b 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -8,6 +8,17 @@ set cpoptions&vim let b:doge_pattern_single_line_comment = '\m#.\{-}$' let b:doge_pattern_multi_line_comment = '\m\(=begin.\{-}=end\|<<-DOC.\{-}DOC\)' + +let b:doge_supported_doc_standards = ['YARD'] +let b:doge_doc_standard = get(g:, 'doge_doc_standard_ruby', b:doge_supported_doc_standards[0]) +if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 + echoerr printf( + \ '[DoGe] %s is not a valid Ruby doc standard, available doc standard are: %s', + \ b:doge_doc_standard, + \ join(b:doge_supported_doc_standards, ', ') + \ ) +endif + let b:doge_patterns = [] " ============================================================================== @@ -29,14 +40,18 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': '\m\([[:alnum:]_]\+\)\%(\s*=\s*[^,]\+\)\?', \ 'match_group_names': ['name'], -\ 'format': ['@param', '{name}', '[type] TODO'], +\ 'format': { +\ 'YARD': '@param {name} [type] TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '# TODO', -\ '!# {parameters}', -\ ], +\ 'template': { +\ 'YARD': [ +\ '# TODO', +\ '#(parameters|# {parameters})', +\ ], +\ }, \ }, \}) diff --git a/ftplugin/scala.vim b/ftplugin/scala.vim index ce857c32..b5cdefa2 100644 --- a/ftplugin/scala.vim +++ b/ftplugin/scala.vim @@ -8,6 +8,17 @@ set cpoptions&vim let b:doge_pattern_single_line_comment = '\m\(\/\*.\{-}\*\/\|\/\/.\{-}$\)' let b:doge_pattern_multi_line_comment = '\m\/\*.\{-}\*\/' + +let b:doge_supported_doc_standards = ['scaladoc'] +let b:doge_doc_standard = get(g:, 'doge_doc_standard_scala', b:doge_supported_doc_standards[0]) +if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 + echoerr printf( + \ '[DoGe] %s is not a valid Scala doc standard, available doc standard are: %s', + \ b:doge_doc_standard, + \ join(b:doge_supported_doc_standards, ', ') + \ ) +endif + let b:doge_patterns = [] " Matches the following pattern: @@ -29,17 +40,21 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], -\ 'format': ['@param', '{name}', '{type}', 'TODO'], +\ 'format': { +\ 'scaladoc': '@param {name} {type} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/** TODO', -\ ' *', -\ '! * {parameters}', -\ ' * @return TODO', -\ ' */', -\ ], +\ 'template': { +\ 'scaladoc': [ +\ '/** TODO', +\ ' *', +\ '#(parameters| * {parameters})', +\ ' * @return TODO', +\ ' */', +\ ], +\ }, \ }, \}) @@ -61,17 +76,21 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], -\ 'format': ['@param', '{name}', '{type}', 'TODO'], +\ 'format': { +\ 'scaladoc': '@param {name} {type} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/** TODO', -\ ' *', -\ '! * {parameters}', -\ ' * @return TODO', -\ ' */', -\ ], +\ 'template': { +\ 'scaladoc': [ +\ '/** TODO', +\ ' *', +\ '#(parameters| * {parameters})', +\ ' * @return TODO', +\ ' */', +\ ], +\ }, \ }, \}) @@ -92,16 +111,20 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], -\ 'format': ['@param', '{name}', '{type}', 'TODO'], +\ 'format': { +\ 'scaladoc': '@param {name} {type} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/** TODO', -\ ' *', -\ '! * {parameters}', -\ ' */', -\ ], +\ 'template': { +\ 'scaladoc': [ +\ '/** TODO', +\ ' *', +\ '#(parameters| * {parameters})', +\ ' */', +\ ], +\ }, \ }, \}) diff --git a/ftplugin/typescript.vim b/ftplugin/typescript.vim index dd2e124d..765a0717 100644 --- a/ftplugin/typescript.vim +++ b/ftplugin/typescript.vim @@ -11,6 +11,17 @@ set cpoptions&vim let b:doge_pattern_single_line_comment = '\m\(\/\*.\{-}\*\/\|\/\/.\{-}$\)' let b:doge_pattern_multi_line_comment = '\m\/\*.\{-}\*\/' + +let b:doge_supported_doc_standards = ['jsdoc'] +let b:doge_doc_standard = get(g:, 'doge_doc_standard_typescript', b:doge_supported_doc_standards[0]) +if index(b:doge_supported_doc_standards, b:doge_doc_standard) < 0 + echoerr printf( + \ '[DoGe] %s is not a valid TypeScript doc standard, available doc standard are: %s', + \ b:doge_doc_standard, + \ join(b:doge_supported_doc_standards, ', ') + \ ) +endif + let b:doge_patterns = [] " Matches the following pattern: @@ -35,13 +46,15 @@ call add(b:doge_patterns, { \ 'match_group_names': ['parentClassName', 'interfaceName'], \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * @description TODO', -\ '! * @extends {parentClassName}', -\ '! * @implements {interfaceName}', -\ ' */', -\ ], +\ 'template': { +\ 'jsdoc': [ +\ '/**', +\ ' * @description TODO', +\ '#(parentClassName| * @extends {parentClassName})', +\ '#(interfaceName| * @implements {interfaceName})', +\ ' */', +\ ], +\ }, \ }, \}) @@ -67,18 +80,22 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], -\ 'format': ['@param', '{{type|*}}', '{name}', 'TODO'], +\ 'format': { +\ 'jsdoc': '@param {{type|*}} {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * @description TODO', -\ '! * @{async}', -\ '! * {parameters}', -\ '! * @return {{returnType}} TODO', -\ ' */', -\ ], +\ 'template': { +\ 'jsdoc': [ +\ '/**', +\ ' * @description TODO', +\ '#(async| * @{async})', +\ '#(parameters| * {parameters})', +\ '#(returnType| * @return {{returnType}} TODO)', +\ ' */', +\ ], +\ }, \ }, \}) @@ -99,19 +116,23 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], -\ 'format': ['@param', '{{type|*}}', '{name}', 'TODO'], +\ 'format': { +\ 'jsdoc': '@param {{type|*}} {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * @description TODO', -\ '! * @{async}', -\ ' * @function {className}#{funcName}', -\ '! * {parameters}', -\ '! * @return {{returnType}} TODO', -\ ' */', -\ ], +\ 'template': { +\ 'jsdoc': [ +\ '/**', +\ ' * @description TODO', +\ '#(async| * @{async})', +\ ' * @function {className}#{funcName}', +\ '#(parameters| * {parameters})', +\ '#(returnType| * @return {{returnType}} TODO)', +\ ' */', +\ ], +\ }, \ }, \}) @@ -144,19 +165,23 @@ call add(b:doge_patterns, { \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name', 'type'], -\ 'format': ['@param', '{{type|*}}', '{name}', 'TODO'], +\ 'format': { +\ 'jsdoc': '@param {{type|*}} {name} TODO', +\ }, \ }, \ 'comment': { \ 'insert': 'above', -\ 'template': [ -\ '/**', -\ ' * @description TODO', -\ '! * @{async}', -\ ' * @function {funcName|}', -\ '! * {parameters}', -\ '! * @return {{returnType}} TODO', -\ ' */', -\ ], +\ 'template': { +\ 'jsdoc': [ +\ '/**', +\ ' * @description TODO', +\ '#(async| * @{async})', +\ ' * @function {funcName|}', +\ '#(parameters| * {parameters})', +\ '#(returnType| * @return {{returnType}} TODO)', +\ ' */', +\ ], +\ }, \ }, \}) diff --git a/playground/test.js b/playground/test.js index a414d1c8..167c8aeb 100644 --- a/playground/test.js +++ b/playground/test.js @@ -188,7 +188,11 @@ const user = (p1 = 'default') => (subp1, subp2 = 'default') => 5; * @param {float} p6 TODO * @return {number[]} TODO */ -(p1: string = 'default', p2: int = 5, p3, p4: Immutable.List = [], p5: string[] = [], p6: float = 0.5): number[] => { }; +/** + * @description TODO + * @function {funcName|} + */ +(): number[] => { }; /** * @description TODO diff --git a/test/filetypes/php/class-methods.vader b/test/filetypes/php/class-methods.vader index e5c32de4..83acc7ef 100644 --- a/test/filetypes/php/class-methods.vader +++ b/test/filetypes/php/class-methods.vader @@ -17,7 +17,6 @@ Expect php (class method with nothing but the text 'TODO'): /** * TODO - * */ public function myMethod() {} diff --git a/test/filetypes/php/functions.vader b/test/filetypes/php/functions.vader index c51f0a5c..fc66e30f 100644 --- a/test/filetypes/php/functions.vader +++ b/test/filetypes/php/functions.vader @@ -10,7 +10,6 @@ Do (trigger doge): Expect php (generated comment with nothing but the text 'TODO'): /** * TODO - * */ function myFunc(/* inline comment */) {} diff --git a/test/filetypes/python/functions.vader b/test/filetypes/python/functions.vader index 934bf3c4..fe3b1873 100644 --- a/test/filetypes/python/functions.vader +++ b/test/filetypes/python/functions.vader @@ -92,3 +92,75 @@ Expect python (generated comments with :param tags): :rtype Generator[int, float, str]: TODO """ pass + +# ============================================================================== +# Functions using the Numpy doc standard. +# ============================================================================== +Given python(function without paramters without return type where b:doge_doc_standard='numpy'): + def myFunc(): + pass + + +Do (trigger doge): + :let b:doge_doc_standard='numpy'\ + \ + +Expect python (generated comment with nothing but the text 'TODO'): + def myFunc(): + """ + TODO + """ + pass + +# ------------------------------------------------------------------------------ + +Given python(function with parameters without return type where b:doge_doc_standard='numpy'): + def myFunc(p1: Callable[[int], None] = False, p2: Callable[[int, Exception], None] = {}): + pass + +Do (trigger doge): + :let b:doge_doc_standard='numpy'\ + \ + +Expect python (generated comment with :param tags): + def myFunc(p1: Callable[[int], None] = False, p2: Callable[[int, Exception], None] = {}): + """ + TODO + + Parameters + ---------- + p1 : Callable[[int], None] + TODO + p2 : Callable[[int, Exception], None] + TODO + """ + pass + +# ------------------------------------------------------------------------------ + +Given python(function with parameters with return type where b:doge_doc_standard='numpy'): + def myFunc(p1: Callable[[int], None] = False, p2: Callable[[int, Exception], None] = {}) -> Sequence[T]: + pass + +Do (trigger doge): + :let b:doge_doc_standard='numpy'\ + \ + +Expect python (generated comment with :param tags): + def myFunc(p1: Callable[[int], None] = False, p2: Callable[[int, Exception], None] = {}) -> Sequence[T]: + """ + TODO + + Parameters + ---------- + p1 : Callable[[int], None] + TODO + p2 : Callable[[int, Exception], None] + TODO + + Returns + ------- + Sequence[T]: + TODO + """ + pass diff --git a/test/filetypes/r/functions.vader b/test/filetypes/r/functions.vader index f58fa73e..16782d4a 100644 --- a/test/filetypes/r/functions.vader +++ b/test/filetypes/r/functions.vader @@ -12,13 +12,12 @@ Given r (functions without parameters): Do (trigger doge): \ - :10\ + :9\ \ Expect r (generated comments with nothing but the text 'TODO' and @export tag): #' TODO #' - #' #' @export #' myFunc = function() { # inline comment @@ -27,7 +26,6 @@ Expect r (generated comments with nothing but the text 'TODO' and @export tag): #' TODO #' - #' #' @export #' myFunc <- function() { # inline comment