mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-13 02:05:40 +08:00
fix(todo): fix todo manager for grep
This commit is contained in:
parent
d14af8a1d9
commit
f87f029b40
@ -27,7 +27,9 @@ local logger = require('spacevim.logger').derive('todo')
|
||||
|
||||
local jobstart = vim.fn.jobstart
|
||||
|
||||
-- the labels_partten is used for viml function: matchstr etc
|
||||
local labels_partten = ''
|
||||
-- labels_regex is for command line argv
|
||||
local labels_regex = ''
|
||||
|
||||
local function empty(d) -- {{{
|
||||
@ -46,26 +48,36 @@ local function stderr(id, data, event) -- {{{
|
||||
end
|
||||
end
|
||||
-- }}}
|
||||
|
||||
local function data_to_todo(d) -- {{{
|
||||
logger.debug('stdout:' .. d)
|
||||
local f = vim.split(d, ':%d+:')[1]
|
||||
logger.debug('file is:' .. f)
|
||||
local i, j = string.find(d, ':%d+:')
|
||||
local line = string.sub(d, i + 1, j - 1)
|
||||
logger.debug('line is:' .. line)
|
||||
local column = string.sub(vim.fn.matchstr(d, [[\(:\d\+\)\@<=:\d\+:]]), 1, -2)
|
||||
local label = string.sub(vim.fn.matchstr(d, labels_partten), #prefix + 1, -1)
|
||||
logger.debug('label is:' .. label)
|
||||
local title = vim.fn.get(vim.fn.split(d, prefix .. label), 1, '')
|
||||
logger.debug('title is:' .. title)
|
||||
return {
|
||||
file = f,
|
||||
line = line,
|
||||
column = column,
|
||||
title = title,
|
||||
label = label,
|
||||
}
|
||||
end
|
||||
-- }}}
|
||||
|
||||
local function stdout(id, data, event) -- {{{
|
||||
if id ~= todo_jobid then
|
||||
return
|
||||
end
|
||||
for _, d in ipairs(data) do
|
||||
if not empty(d) then
|
||||
logger.debug('stdout:' .. d)
|
||||
local f = vim.split(d, ':%d+:')[1]
|
||||
local i, j = string.find(d, ':%d+:')
|
||||
local line = string.sub(d, i + 1, j - 1)
|
||||
local column = string.sub(vim.fn.matchstr(d, [[\(:\d\+\)\@<=:\d\+:]]), 1, -2)
|
||||
local label = string.sub(vim.fn.matchstr(d, labels_partten), #prefix + 1, -1)
|
||||
local title = vim.fn.get(vim.fn.split(d, prefix .. label), 1, '')
|
||||
table.insert(todos, {
|
||||
file = f,
|
||||
line = line,
|
||||
column = column,
|
||||
title = title,
|
||||
label = label,
|
||||
})
|
||||
table.insert(todos, data_to_todo(d))
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -126,8 +138,14 @@ local function on_exit(id, data, event) -- {{{
|
||||
local fw = max_len(todos, 'file') + 1
|
||||
local lines = {}
|
||||
for _, v in ipairs(todos) do
|
||||
table.insert(lines,
|
||||
prefix .. v.label .. string.rep(' ', lw - #v.label) .. v.file .. string.rep(' ', fw - #v.file) .. v.title
|
||||
table.insert(
|
||||
lines,
|
||||
prefix
|
||||
.. v.label
|
||||
.. string.rep(' ', lw - #v.label)
|
||||
.. v.file
|
||||
.. string.rep(' ', fw - #v.file)
|
||||
.. v.title
|
||||
)
|
||||
end
|
||||
local ma = vim.fn.getbufvar(bufnr, '&ma')
|
||||
@ -140,6 +158,8 @@ local function on_exit(id, data, event) -- {{{
|
||||
end
|
||||
-- }}}
|
||||
|
||||
|
||||
-- labels to command line regex
|
||||
local function get_labels_regex() -- {{{
|
||||
local sep = ''
|
||||
if grep_default_exe == 'rg' then
|
||||
@ -162,8 +182,24 @@ local function get_labels_regex() -- {{{
|
||||
end
|
||||
-- }}}
|
||||
|
||||
-- labels to vim searching partten
|
||||
-- [ todo ] [00:00:03:498] [ Info ] labels_partten: \v\@bug>|\@question>|\@fixme>|\@todo>
|
||||
local function get_labels_partten() -- {{{
|
||||
return reg.parser(get_labels_regex(), false)
|
||||
local sep = '|'
|
||||
local rst = [[\v]]
|
||||
local i = 1
|
||||
local p = prefix
|
||||
if prefix == '@' then
|
||||
p = [[\@]]
|
||||
end
|
||||
for _, v in ipairs(labels) do
|
||||
rst = rst .. p .. v .. [[>]]
|
||||
if i ~= #labels then
|
||||
rst = rst .. sep
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
return rst
|
||||
end
|
||||
-- }}}
|
||||
|
||||
@ -217,7 +253,7 @@ local function open_win() -- {{{
|
||||
bufnr = vim.fn.bufnr('%')
|
||||
update_todo_content()
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Enter>', '', {
|
||||
callback = open_todo
|
||||
callback = open_todo,
|
||||
})
|
||||
end
|
||||
-- }}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user