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

Hot fix for vim-todo (#3910)

This commit is contained in:
Wang Shidong 2020-10-17 23:21:52 +08:00 committed by GitHub
parent b75e389edb
commit eb26c88238
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 68 additions and 58 deletions

View File

@ -198,6 +198,7 @@ EOT
_detect autoload/SpaceVim/api/data/string.vim _detect autoload/SpaceVim/api/data/string.vim
_detect autoload/SpaceVim/api/file.vim _detect autoload/SpaceVim/api/file.vim
_detect autoload/SpaceVim/api/vim/buffer.vim _detect autoload/SpaceVim/api/vim/buffer.vim
_detect autoload/SpaceVim/api/vim/regex.vim
_detect autoload/SpaceVim/api/vim/compatible.vim _detect autoload/SpaceVim/api/vim/compatible.vim
_detect autoload/SpaceVim/logger.vim _detect autoload/SpaceVim/logger.vim
_detect autoload/SpaceVim/mapping/search.vim _detect autoload/SpaceVim/mapping/search.vim

View File

@ -91,7 +91,7 @@ endfunction
function! s:self.win_close(id, focuce) abort function! s:self.win_close(id, focuce) abort
return nvim_win_close(a:id, a:focuce) return nvim_win_close(a:id, a:focuce)
" @fixme: nvim_win_close only support one argv in old version " @fixme nvim_win_close only support one argv in old version
try try
return nvim_win_close(a:id, a:focuce) return nvim_win_close(a:id, a:focuce)
catch /^Vim\%((\a\+)\)\=:E118/ catch /^Vim\%((\a\+)\)\=:E118/

View File

@ -44,7 +44,15 @@ function! s:self.parser(regex, is_perl) abort
" word boundary " word boundary
" \bword\b => <word> " \bword\b => <word>
let vim_regex = substitute(vim_regex, '\\b\(\w\+\)\\b', '\\<\1\\>', 'g') let vim_regex = substitute(vim_regex, '\\b\(\w\+\)\\b', '<\1>', 'g')
" right word boundary
" \bword => \<word
let vim_regex = substitute(vim_regex, '\\b\(\w\+\)', '<\1', 'g')
" left word boundary
" word\b => word\>
let vim_regex = substitute(vim_regex, '\(\w\+\)\\b', '\1>', 'g')
" case-insensitive " case-insensitive
" (?i)abc => \cabc " (?i)abc => \cabc

View File

@ -913,7 +913,7 @@ endfunction
" }}} " }}}
function! s:update_statusline() abort function! s:update_statusline() abort
if !g:FlyGrep_enable_statusline if !get(g:, 'FlyGrep_enable_statusline', 1)
return return
endif endif

View File

@ -10,6 +10,7 @@ let s:JOB = SpaceVim#api#import('job')
let s:BUFFER = SpaceVim#api#import('vim#buffer') let s:BUFFER = SpaceVim#api#import('vim#buffer')
let s:SYS = SpaceVim#api#import('system') let s:SYS = SpaceVim#api#import('system')
let s:LOG = SpaceVim#logger#derive('todo') let s:LOG = SpaceVim#logger#derive('todo')
let s:REG = SpaceVim#api#import('vim#regex')
let [ let [
@ -65,10 +66,12 @@ function! s:update_todo_content() abort
let s:todos = [] let s:todos = []
let s:todo = {} let s:todo = {}
let s:labels_regex = s:get_labels_regex()
let s:labels_partten = s:get_labels_pattern()
let argv = [s:grep_default_exe] + let argv = [s:grep_default_exe] +
\ s:grep_default_opt + \ s:grep_default_opt +
\ s:grep_default_expr_opt \ s:grep_default_expr_opt
let argv += [s:get_labels_regex()] let argv += [s:labels_regex]
if s:SYS.isWindows && (s:grep_default_exe ==# 'rg' || s:grep_default_exe ==# 'ag' || s:grep_default_exe ==# 'pt' ) if s:SYS.isWindows && (s:grep_default_exe ==# 'rg' || s:grep_default_exe ==# 'ag' || s:grep_default_exe ==# 'pt' )
let argv += ['.'] let argv += ['.']
elseif s:SYS.isWindows && s:grep_default_exe ==# 'findstr' elseif s:SYS.isWindows && s:grep_default_exe ==# 'findstr'
@ -76,24 +79,27 @@ function! s:update_todo_content() abort
endif endif
let argv += s:grep_default_ropt let argv += s:grep_default_ropt
call s:LOG.info('cmd: ' . string(argv)) call s:LOG.info('cmd: ' . string(argv))
let jobid = s:JOB.start(argv, { call s:LOG.info(' labels_partten: ' . s:labels_partten)
let s:todo_jobid = s:JOB.start(argv, {
\ 'on_stdout' : function('s:stdout'), \ 'on_stdout' : function('s:stdout'),
\ 'on_stderr' : function('s:stderr'), \ 'on_stderr' : function('s:stderr'),
\ 'on_exit' : function('s:exit'), \ 'on_exit' : function('s:exit'),
\ }) \ })
call s:LOG.info('jobid: ' . string(jobid)) call s:LOG.info('jobid: ' . string(s:todo_jobid))
endfunction endfunction
function! s:stdout(id, data, event) abort function! s:stdout(id, data, event) abort
if a:id !=# s:todo_jobid
return
endif
for data in a:data for data in a:data
call s:LOG.info('stdout: ' . data) call s:LOG.info('stdout: ' . data)
if !empty(data) if !empty(data)
let file = fnameescape(split(data, ':\d\+:')[0]) let file = fnameescape(split(data, ':\d\+:')[0])
let line = matchstr(data, ':\d\+:')[1:-2] let line = matchstr(data, ':\d\+:')[1:-2]
let column = matchstr(data, '\(:\d\+\)\@<=:\d\+:')[1:-2] let column = matchstr(data, '\(:\d\+\)\@<=:\d\+:')[1:-2]
let full_label = matchstr(data, s:get_labels_pattern()) let label = matchstr(data, s:labels_partten)
let trimmed_label = substitute(full_label, '\W', '', 'g') let title = get(split(data, label), 1, '')
let title = get(split(data, full_label), 1, '')
" @todo add time tag " @todo add time tag
call add(s:todos, call add(s:todos,
\ { \ {
@ -101,7 +107,7 @@ function! s:stdout(id, data, event) abort
\ 'line' : line, \ 'line' : line,
\ 'column' : column, \ 'column' : column,
\ 'title' : title, \ 'title' : title,
\ 'label' : trimmed_label, \ 'label' : label,
\ } \ }
\ ) \ )
endif endif
@ -109,21 +115,28 @@ function! s:stdout(id, data, event) abort
endfunction endfunction
function! s:stderr(id, data, event) abort function! s:stderr(id, data, event) abort
if a:id !=# s:todo_jobid
return
endif
for date in a:data for date in a:data
call s:LOG.info('stderr: ' . string(a:data)) call s:LOG.info('stderr: ' . string(a:data))
endfor endfor
endfunction endfunction
function! s:exit(id, data, event ) abort function! s:exit(id, data, event ) abort
call s:LOG.info('exit code: ' . string(a:data)) if a:id !=# s:todo_jobid
return
endif
call s:LOG.info('todomanager exit: ' . string(a:data))
let s:todos = sort(s:todos, function('s:compare_todo')) let s:todos = sort(s:todos, function('s:compare_todo'))
let label_w = max(map(deepcopy(s:todos), 'strlen(v:val.label)')) 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 file_w = max(map(deepcopy(s:todos), 'strlen(v:val.file)'))
let expr = "tolower(v:val.label) . repeat(' ', label_w - strlen(v:val.label)) . ' ' ." let expr = "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)) . ' ' ." \ . "SpaceVim#api#import('file').unify_path(v:val.file, ':.') . repeat(' ', file_w - strlen(v:val.file)) . ' ' ."
\ . 'v:val.title' \ . "v:val.title"
let lines = map(deepcopy(s:todos),expr) let lines = map(deepcopy(s:todos),expr)
call s:BUFFER.buf_set_lines(s:bufnr, 0 , -1, 0, lines) call s:BUFFER.buf_set_lines(s:bufnr, 0 , -1, 0, lines)
let g:wsd = s:todos
endfunction endfunction
function! s:compare_todo(a, b) abort function! s:compare_todo(a, b) abort
@ -159,13 +172,12 @@ function! s:get_labels_regex()
let separator = '|' let separator = '|'
endif endif
return join(map(copy(s:labels), return join(map(copy(s:labels), "v:val . '\\b'"),
\ "(v:val[0] =~ '\w' ? '\\b' : '') . v:val . '\\b:?'"),
\ separator) \ separator)
endfunc endfunc
function! s:get_labels_pattern () function! s:get_labels_pattern()
return '\C' . join(map(copy(s:labels), "(v:val[0] =~ '\w' ? '\\<' : '') . v:val . '\\>:\\?'"), '\|') return s:REG.parser(s:get_labels_regex(), 0)
endfunc endfunc

View File

@ -1242,17 +1242,7 @@ Config the command line prompt for flygrep and denite etc.
*g:spacevim_todo_labels* *g:spacevim_todo_labels*
Option for setting todo labels in current project. 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* *g:spacevim_lint_on_the_fly*
Enable/Disable lint on the fly feature of SpaceVim's maker. Default is 0. Enable/Disable lint on the fly feature of SpaceVim's maker. Default is 0.
> >

View File

@ -4,12 +4,10 @@ endif
let b:current_syntax = 'SpaceVimTodoManager' let b:current_syntax = 'SpaceVimTodoManager'
syntax case ignore syntax case ignore
syn match FileName /\(^\S\+\s\+\)\@<=[^ ]*/ syn match FileName /\(@[a-zA-Z]*\s\+\)\@<=[^ ]*/
syn match TODOTAG /^\s*@[a-zA-Z]*/ syn match TODOTAG /^\s*@[a-zA-Z]*/
syn match TODOTAG /^\s*@\?todo*/
syn match TODOQUESTION /^\s*@ques[a-z]*/ 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 TODOCHECKBOX /[\d\+/\d\+\]/
syn match TODOINDEX /^\s\+\d\+\.\s/ syn match TODOINDEX /^\s\+\d\+\.\s/
syn match TODOCHECKBOXPANDING /\s\+√\s\+/ syn match TODOCHECKBOXPANDING /\s\+√\s\+/
@ -20,4 +18,3 @@ hi def link FileName Comment
hi def link TODOTAG Todo hi def link TODOTAG Todo
hi def link TODOQUESTION Question hi def link TODOQUESTION Question
hi def link TODOFIXME ErrorMsg hi def link TODOFIXME ErrorMsg

View File

@ -5,7 +5,9 @@ Execute ( SpaceVim api: vim#key ):
AssertEqual regex.parser('(?:exp)', 0), '\v%(exp)' AssertEqual regex.parser('(?:exp)', 0), '\v%(exp)'
AssertEqual regex.parser('\a\f\v', 0), '\v%x07%x0C%x0B' AssertEqual regex.parser('\a\f\v', 0), '\v%x07%x0C%x0B'
AssertEqual regex.parser('[:word:]', 0), '\v[0-9A-Za-z_]' AssertEqual regex.parser('[:word:]', 0), '\v[0-9A-Za-z_]'
AssertEqual regex.parser('\bspace\b', 0), '\v\<space\>' AssertEqual regex.parser('\bspace\b', 0), '\v<space>'
AssertEqual regex.parser('\bspace', 0), '\v<space'
AssertEqual regex.parser('space\b', 0), '\vspace>'
AssertEqual regex.parser('if%@&ab', 0), '\vif\%\@\&ab' AssertEqual regex.parser('if%@&ab', 0), '\vif\%\@\&ab'
AssertEqual regex.parser('(?P<name>exp)', 0), '\v(exp)' AssertEqual regex.parser('(?P<name>exp)', 0), '\v(exp)'