1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 07:00:04 +08:00

todo manager: implement custom keywords (#3900)

* todo manager: implement custom keywords

* todo manager: use single option

* todo manager: lint

* todo manager: fix case sensitivity

* todo manager: remove echom
This commit is contained in:
Rom Grk 2020-10-17 09:32:58 -04:00 committed by GitHub
parent 3c795e6d42
commit b75e389edb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 21 deletions

View File

@ -62,23 +62,13 @@ function! s:update_todo_content() abort
else
let s:labels = map(['fixme', 'question', 'todo', 'idea'], '"@" . v:val')
endif
let s:todos = []
let s:todo = {}
let argv = [s:grep_default_exe] +
\ s:grep_default_opt +
\ s:grep_default_expr_opt
" @fixme expr for defferent tools
" when using rg, [join(s:labels, '|')]
" when using grep, [join(s:labels, '\|')]
if s:grep_default_exe ==# 'rg'
let argv += [join(s:labels, '|')]
elseif s:grep_default_exe ==# 'grep'
let argv += [join(s:labels, '\|')]
elseif s:grep_default_exe ==# 'findstr'
let argv += [join(s:labels, ' ')]
else
let argv += [join(s:labels, '|')]
endif
let argv += [s:get_labels_regex()]
if s:SYS.isWindows && (s:grep_default_exe ==# 'rg' || s:grep_default_exe ==# 'ag' || s:grep_default_exe ==# 'pt' )
let argv += ['.']
elseif s:SYS.isWindows && s:grep_default_exe ==# 'findstr'
@ -101,8 +91,9 @@ function! s:stdout(id, data, event) abort
let file = fnameescape(split(data, ':\d\+:')[0])
let line = matchstr(data, ':\d\+:')[1:-2]
let column = matchstr(data, '\(:\d\+\)\@<=:\d\+:')[1:-2]
let lebal = matchstr(data, join(s:labels, '\|'))
let title = get(split(data, lebal), 1, '')
let full_label = matchstr(data, s:get_labels_pattern())
let trimmed_label = substitute(full_label, '\W', '', 'g')
let title = get(split(data, full_label), 1, '')
" @todo add time tag
call add(s:todos,
\ {
@ -110,7 +101,7 @@ function! s:stdout(id, data, event) abort
\ 'line' : line,
\ 'column' : column,
\ 'title' : title,
\ 'lebal' : lebal,
\ 'label' : trimmed_label,
\ }
\ )
endif
@ -126,9 +117,9 @@ endfunction
function! s:exit(id, data, event ) abort
call s:LOG.info('exit code: ' . string(a:data))
let s:todos = sort(s:todos, function('s:compare_todo'))
let label_w = max(map(deepcopy(s:todos), 'strlen(v:val.lebal)'))
let label_w = max(map(deepcopy(s:todos), 'strlen(v:val.label)'))
let file_w = max(map(deepcopy(s:todos), 'strlen(v:val.file)'))
let expr = "v:val.lebal . repeat(' ', label_w - strlen(v:val.lebal)) . ' ' ."
let expr = "tolower(v:val.label) . repeat(' ', label_w - strlen(v:val.label)) . ' ' ."
\ . "SpaceVim#api#import('file').unify_path(v:val.file, ':.') . repeat(' ', file_w - strlen(v:val.file)) . ' ' ."
\ . 'v:val.title'
let lines = map(deepcopy(s:todos),expr)
@ -136,8 +127,8 @@ function! s:exit(id, data, event ) abort
endfunction
function! s:compare_todo(a, b) abort
let a = index(s:labels, a:a.lebal)
let b = index(s:labels, a:b.lebal)
let a = index(s:labels, a:a.label)
let b = index(s:labels, a:b.label)
return a == b ? 0 : a > b ? 1 : -1
endfunction
@ -154,6 +145,30 @@ function! s:open_todo() abort
noautocmd normal! :
endfunction
" @fixme expr for different tools
" when using rg, [join(s:labels, '|')]
" when using grep, [join(s:labels, '\|')]
function! s:get_labels_regex()
if s:grep_default_exe ==# 'rg'
let separator = '|'
elseif s:grep_default_exe ==# 'grep'
let separator = '\|'
elseif s:grep_default_exe ==# 'findstr'
let separator = ' '
else
let separator = '|'
endif
return join(map(copy(s:labels),
\ "(v:val[0] =~ '\w' ? '\\b' : '') . v:val . '\\b:?'"),
\ separator)
endfunc
function! s:get_labels_pattern ()
return '\C' . join(map(copy(s:labels), "(v:val[0] =~ '\w' ? '\\<' : '') . v:val . '\\>:\\?'"), '\|')
endfunc
" @todo fuzzy find todo list
" after open todo manager buffer, we should be able to fuzzy find the item we
" need.

View File

@ -1242,7 +1242,17 @@ Config the command line prompt for flygrep and denite etc.
*g:spacevim_todo_labels*
Option for setting todo labels in current project.
By default, it matches "@todo", "@question", "@fixme" and "@idea".
The following configuration will match todos in the form "TODO", "FIXME" and
"XXX".
>
let g:spacevim_todo_labels = [
\ 'FIXME',
\ 'TODO',
\ 'XXX',
\ ]
<
*g:spacevim_lint_on_the_fly*
Enable/Disable lint on the fly feature of SpaceVim's maker. Default is 0.
>

View File

@ -4,10 +4,12 @@ endif
let b:current_syntax = 'SpaceVimTodoManager'
syntax case ignore
syn match FileName /\(@[a-zA-Z]*\s\+\)\@<=[^ ]*/
syn match FileName /\(^\S\+\s\+\)\@<=[^ ]*/
syn match TODOTAG /^\s*@[a-zA-Z]*/
syn match TODOTAG /^\s*@\?todo*/
syn match TODOQUESTION /^\s*@ques[a-z]*/
syn match TODOFIXME /^\s*@fixm[a-z]*/
syn match TODOFIXME /^\s*@\?fixm[a-z]*/
syn match TODOFIXME /^\s*@\?xxx*/
" syn match TODOCHECKBOX /[\d\+/\d\+\]/
syn match TODOINDEX /^\s\+\d\+\.\s/
syn match TODOCHECKBOXPANDING /\s\+√\s\+/