diff --git a/autoload/doge/preprocessors/cpp.vim b/autoload/doge/preprocessors/cpp.vim new file mode 100644 index 00000000..f9deb3f8 --- /dev/null +++ b/autoload/doge/preprocessors/cpp.vim @@ -0,0 +1,14 @@ +let s:save_cpo = &cpoptions +set cpoptions&vim + +" A callback function being called after the tokens have been extracted. This +" function will adjust the input if needed. +function! doge#preprocessors#cpp#tokens(tokens) abort + " See https://github.com/kkoomen/vim-doge/issues/5 + if has_key(a:tokens, 'returnType') && !empty(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/autoload/doge/token.vim b/autoload/doge/token.vim index e44e9154..72cdeef5 100644 --- a/autoload/doge/token.vim +++ b/autoload/doge/token.vim @@ -38,8 +38,7 @@ function! s:token_replace(tokens, text) abort 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) + 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 diff --git a/ftplugin/cpp.vim b/ftplugin/cpp.vim index 79803fbd..d90515a2 100644 --- a/ftplugin/cpp.vim +++ b/ftplugin/cpp.vim @@ -37,8 +37,8 @@ let s:parameters_match_pattern = '\m\%(\%(const\)\s\+\)\?\%(\%([[:alnum:]_]\+(.\ " template " decltype(auto) PerfectForward(F fun, Args&&... args) {} call add(b:doge_patterns, { -\ 'match': '\m^\%(template\s*<[[:alnum:][:space:]_<>.,]*>\s\+\)\?\%(static\s\+\)\?\%(decltype(auto[&*]*)\|auto[&*]*\)\s\+\%([[:alnum:]_:]\+\)\s*(\(.\{-}\))\s*\%(\%([[:alnum:]_:]\+\s*(\(.\{-}\))\)*\s\+\)\?\%(\s*->\s*[[:alnum:]_:&*.]\+\%(<[[:alnum:][:space:]_(),]\+>\%([[:alnum:]_:&*.]\+\)*\)*\)\?\s*[;{]', -\ 'match_group_names': ['parameters'], +\ 'match': '\m^\%(template\s*<[[:alnum:][:space:]_<>.,]*>\s\+\)\?\%(static\s\+\)\?\%(decltype(auto[&*]*)\|auto[&*]*\)\s\+\%([[:alnum:]_:]\+\)\s*(\(.\{-}\))\s*\%(\%([[:alnum:]_:]\+\s*(\%(.\{-}\))\)*\s\+\)\?\s*->\s*\([[:alnum:]_:&*.]\+\%(<[[:alnum:][:space:]_(),]\+>\%([[:alnum:]_:&*.]\+\)*\)*\)\s*[;{]', +\ 'match_group_names': ['parameters', 'returnType'], \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name'], @@ -52,9 +52,9 @@ call add(b:doge_patterns, { \ 'doxygen': [ \ '/**', \ ' * TODO', -\ ' *', +\ '#(parameters| *)', \ '#(parameters| * {parameters})', -\ ' * @return TODO', +\ '#(returnType| * @return TODO)', \ ' */', \ ], \ }, @@ -78,8 +78,8 @@ call add(b:doge_patterns, { " template " static T* create(Args&& ... args) {} call add(b:doge_patterns, { -\ 'match': '\m^\%(\%(template\s*<[[:alnum:][:space:]_<>.,]*>\|const\|inline\)\s\+\)\?\%(static\s\+\)\?\%([[:alnum:]_:&*]\+\s*\%(<[[:alnum:][:space:]_<>.,]\+>\)\?\|[[:alnum:]_]\+(.\{-})\)\s\+\%([[:alnum:]_:]\+\)\s*(\(.\{-}\))\s*[;{]', -\ 'match_group_names': ['parameters'], +\ 'match': '\m^\%(\%(template\s*<[[:alnum:][:space:]_<>.,]*>\|const\|inline\)\s\+\)\?\%(static\s\+\)\?\([[:alnum:]_:&*]\+\s*\%(<[[:alnum:][:space:]_<>.,]\+>\)\?\|[[:alnum:]_]\+(.\{-})\)\s\+\%([[:alnum:]_:]\+\)\s*(\(.\{-}\))\s*[;{]', +\ 'match_group_names': ['returnType', 'parameters'], \ 'parameters': { \ 'match': s:parameters_match_pattern, \ 'match_group_names': ['name'], @@ -93,9 +93,9 @@ call add(b:doge_patterns, { \ 'doxygen': [ \ '/**', \ ' * TODO', -\ ' *', +\ '#(parameters| *)', \ '#(parameters| * {parameters})', -\ ' * @return TODO', +\ '#(returnType| * @return TODO)', \ ' */', \ ], \ }, diff --git a/test/filetypes/cpp/auto-functions.vader b/test/filetypes/cpp/auto-functions.vader index 2024bf14..64c9968f 100644 --- a/test/filetypes/cpp/auto-functions.vader +++ b/test/filetypes/cpp/auto-functions.vader @@ -24,6 +24,7 @@ Expect cpp (generated comment with @param and @return tags): { // } + # ============================================================================== # Auto-functions with parameters with advanced type hints. # ============================================================================== @@ -51,6 +52,32 @@ Expect cpp (generated comment with @param and @return tags): // } +# ============================================================================== +# Auto-functions with parameters with advanced type hints and void return type. +# ============================================================================== +Given cpp (auto-function with parameters with advanced type hints with void return type using return type 'auto'): + template + auto f(std::enable_if, T>::type& it_begin, T& _end) -> void // inline comment + { + // + } + +Do (trigger doge): + \ + +Expect cpp (generated comment with @param and @return tags): + /** + * TODO + * + * @param it_begin TODO + * @param _end TODO + */ + template + auto f(std::enable_if, T>::type& it_begin, T& _end) -> void // inline comment + { + // + } + # ============================================================================== # Auto-functions with advanced syntax. # ============================================================================== diff --git a/test/filetypes/cpp/function-declarations.vader b/test/filetypes/cpp/function-declarations.vader index bcea6de6..5fa154ac 100644 --- a/test/filetypes/cpp/function-declarations.vader +++ b/test/filetypes/cpp/function-declarations.vader @@ -13,7 +13,6 @@ Expect cpp (generated comment with @param and @return tags): * * @param text TODO * @param node TODO - * @return TODO */ void Emitter::append_token(const std::string& text /* inline comment */, const AST_Node* node); diff --git a/test/filetypes/cpp/functions.vader b/test/filetypes/cpp/functions.vader index f4a870ad..e10be4a6 100644 --- a/test/filetypes/cpp/functions.vader +++ b/test/filetypes/cpp/functions.vader @@ -13,8 +13,6 @@ Do (trigger doge): Expect cpp (generated comment with nothing but the text 'TODO' and @return tag): /** * TODO - * - * @return TODO */ void Emitter::append_token(/* inline comment */) // another comment { @@ -39,7 +37,6 @@ Expect cpp (generated comment with @param and @return tags): * * @param text TODO * @param node TODO - * @return TODO */ void Emitter::append_token(const std::string& text /* inline comment */, const AST_Node* node) // another comment { @@ -63,7 +60,6 @@ Expect cpp (generated comment with @param and @return tags): * TODO * * @param p TODO - * @return TODO */ void f(A* p = this) { diff --git a/test/filetypes/cpp/template-functions.vader b/test/filetypes/cpp/template-functions.vader index 9f86c1f1..ae4e04cf 100644 --- a/test/filetypes/cpp/template-functions.vader +++ b/test/filetypes/cpp/template-functions.vader @@ -45,7 +45,6 @@ Expect cpp (generated comment with @param and @return tags): * * @param i TODO * @param args TODO - * @return TODO */ template void h(int i = 0, T... args) { //