From b75e389edb4b0ccd54dd1ae02d864f19aef2748f Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Sat, 17 Oct 2020 09:32:58 -0400 Subject: [PATCH] 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 --- autoload/SpaceVim/plugins/todo.vim | 53 +++++++++++++++++++----------- doc/SpaceVim.txt | 10 ++++++ syntax/SpaceVimTodoManager.vim | 6 ++-- 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/autoload/SpaceVim/plugins/todo.vim b/autoload/SpaceVim/plugins/todo.vim index 46f549e1d..2985c6b58 100644 --- a/autoload/SpaceVim/plugins/todo.vim +++ b/autoload/SpaceVim/plugins/todo.vim @@ -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. diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index caba54413..e31c85741 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -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. > diff --git a/syntax/SpaceVimTodoManager.vim b/syntax/SpaceVimTodoManager.vim index fdcf14c42..96d54b405 100644 --- a/syntax/SpaceVimTodoManager.vim +++ b/syntax/SpaceVimTodoManager.vim @@ -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\+/