Skip to content

Commit

Permalink
feat: Initial rewrite for all languages
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Nov 28, 2019
1 parent ca27745 commit c67974d
Show file tree
Hide file tree
Showing 21 changed files with 1,275 additions and 1,277 deletions.
4 changes: 2 additions & 2 deletions autoload/doge.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
16 changes: 5 additions & 11 deletions autoload/doge/generate.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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/
Expand All @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions autoload/doge/helpers.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions autoload/doge/preprocessors/groovy.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit c67974d

Please sign in to comment.