refactor: remove file token feature (#50)
* refactor: remove file token feature Problem: The file metadata token (file:<path>:<line>) was implemented but is no longer wanted. Solution: Remove all traces — parse.lua token parsing, diff.lua reconciliation, views.lua LineMeta field, buffer.lua virtual text and PendingFile highlight, complete.lua omnifunc trigger, init.lua goto_file/add_here functions and -file edit token, plugin keymaps <Plug>(pending-goto-file) and <Plug>(pending-add-here), config.lua goto_file keymap field, vimdoc FILE TOKEN section, and spec/file_spec.lua. * ci: format
This commit is contained in:
parent
0e0568769d
commit
8c90d0ddd1
10 changed files with 6 additions and 598 deletions
|
|
@ -178,10 +178,6 @@ local function apply_extmarks(bufnr, line_meta)
|
|||
if m.due then
|
||||
table.insert(virt_parts, { icons.due .. ' ' .. m.due, due_hl })
|
||||
end
|
||||
if m.file then
|
||||
local display = m.file:match('([^/]+:%d+)$') or m.file
|
||||
table.insert(virt_parts, { display, 'PendingFile' })
|
||||
end
|
||||
if #virt_parts > 0 then
|
||||
for p = 1, #virt_parts - 1 do
|
||||
virt_parts[p][1] = virt_parts[p][1] .. ' '
|
||||
|
|
@ -238,7 +234,6 @@ local function setup_highlights()
|
|||
vim.api.nvim_set_hl(0, 'PendingPriority', { link = 'DiagnosticWarn', default = true })
|
||||
vim.api.nvim_set_hl(0, 'PendingRecur', { link = 'DiagnosticInfo', default = true })
|
||||
vim.api.nvim_set_hl(0, 'PendingFilter', { link = 'DiagnosticWarn', default = true })
|
||||
vim.api.nvim_set_hl(0, 'PendingFile', { link = 'Directory', default = true })
|
||||
end
|
||||
|
||||
local function snapshot_folds(bufnr)
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@ function M.omnifunc(findstart, base)
|
|||
{ vim.pesc(dk) .. ':([%S]*)$', dk },
|
||||
{ 'cat:([%S]*)$', 'cat' },
|
||||
{ vim.pesc(rk) .. ':([%S]*)$', rk },
|
||||
{ 'file:([%S]*)$', 'file' },
|
||||
}
|
||||
|
||||
for _, check in ipairs(checks) do
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
---@field prev_header? string|false
|
||||
---@field next_task? string|false
|
||||
---@field prev_task? string|false
|
||||
---@field goto_file? string|false
|
||||
|
||||
---@class pending.Config
|
||||
---@field data_path string
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ local parse = require('pending.parse')
|
|||
---@field due? string
|
||||
---@field rec? string
|
||||
---@field rec_mode? string
|
||||
---@field file? string
|
||||
---@field lnum integer
|
||||
|
||||
---@class pending.diff
|
||||
|
|
@ -57,7 +56,6 @@ function M.parse_buffer(lines)
|
|||
due = metadata.due,
|
||||
rec = metadata.rec,
|
||||
rec_mode = metadata.rec_mode,
|
||||
file = metadata.file,
|
||||
lnum = i,
|
||||
})
|
||||
end
|
||||
|
|
@ -135,19 +133,6 @@ function M.apply(lines, s, hidden_ids)
|
|||
task.recur_mode = entry.rec_mode
|
||||
changed = true
|
||||
end
|
||||
local old_file = (task._extra and task._extra.file) or nil
|
||||
if entry.file ~= old_file then
|
||||
task._extra = task._extra or {}
|
||||
if entry.file then
|
||||
task._extra.file = entry.file
|
||||
else
|
||||
task._extra.file = nil
|
||||
if next(task._extra) == nil then
|
||||
task._extra = nil
|
||||
end
|
||||
end
|
||||
changed = true
|
||||
end
|
||||
if entry.status and task.status ~= entry.status then
|
||||
task.status = entry.status
|
||||
if entry.status == 'done' then
|
||||
|
|
|
|||
|
|
@ -323,16 +323,6 @@ function M._setup_buf_mappings(bufnr)
|
|||
end, opts)
|
||||
end
|
||||
end
|
||||
|
||||
local goto_key = km.goto_file
|
||||
if goto_key == nil then
|
||||
goto_key = 'gf'
|
||||
end
|
||||
if goto_key and goto_key ~= false then
|
||||
vim.keymap.set('n', goto_key --[[@as string]], function()
|
||||
M.goto_file()
|
||||
end, opts)
|
||||
end
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
|
|
@ -664,10 +654,6 @@ local function parse_edit_token(token)
|
|||
if token == '-rec' or token == '-' .. rk then
|
||||
return 'recur', vim.NIL, nil
|
||||
end
|
||||
if token == '-file' then
|
||||
return 'file_clear', true, nil
|
||||
end
|
||||
|
||||
local due_val = token:match('^' .. vim.pesc(dk) .. ':(.+)$')
|
||||
if due_val then
|
||||
local resolved = parse.resolve_date(due_val)
|
||||
|
|
@ -711,11 +697,10 @@ local function parse_edit_token(token)
|
|||
.. dk
|
||||
.. ':<date>, cat:<name>, '
|
||||
.. rk
|
||||
.. ':<pattern>, file:<path>:<line>, +!, -!, -'
|
||||
.. ':<pattern>, +!, -!, -'
|
||||
.. dk
|
||||
.. ', -cat, -'
|
||||
.. rk
|
||||
.. ', -file'
|
||||
end
|
||||
|
||||
---@param id_str string
|
||||
|
|
@ -795,9 +780,6 @@ function M.edit(id_str, rest)
|
|||
elseif field == 'priority' then
|
||||
updates.priority = value
|
||||
table.insert(feedback, value == 1 and 'priority added' or 'priority removed')
|
||||
elseif field == 'file_clear' then
|
||||
updates.file_clear = true
|
||||
table.insert(feedback, 'file reference removed')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -810,17 +792,6 @@ function M.edit(id_str, rest)
|
|||
|
||||
s:update(id, updates)
|
||||
|
||||
if updates.file_clear then
|
||||
local t = s:get(id)
|
||||
if t and t._extra then
|
||||
t._extra.file = nil
|
||||
if next(t._extra) == nil then
|
||||
t._extra = nil
|
||||
end
|
||||
t.modified = os.date('!%Y-%m-%dT%H:%M:%SZ') --[[@as string]]
|
||||
end
|
||||
end
|
||||
|
||||
s:save()
|
||||
|
||||
local bufnr = buffer.bufnr()
|
||||
|
|
@ -831,91 +802,6 @@ function M.edit(id_str, rest)
|
|||
vim.notify('Task #' .. id .. ' updated: ' .. table.concat(feedback, ', '))
|
||||
end
|
||||
|
||||
---@return nil
|
||||
function M.goto_file()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
if vim.bo[bufnr].filetype ~= 'pending' then
|
||||
return
|
||||
end
|
||||
local lnum = vim.api.nvim_win_get_cursor(0)[1]
|
||||
local meta = buffer.meta()
|
||||
local m = meta and meta[lnum]
|
||||
if not m or m.type ~= 'task' then
|
||||
vim.notify('No task on this line', vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
local task = get_store():get(m.id)
|
||||
if not task or not task._extra or not task._extra.file then
|
||||
vim.notify('No file attached to this task', vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
local file_spec = task._extra.file
|
||||
local rel_path, line_str = file_spec:match('^(.+):(%d+)$')
|
||||
if not rel_path then
|
||||
vim.notify('Invalid file spec: ' .. file_spec, vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
local data_dir = vim.fn.fnamemodify(get_store().path, ':h')
|
||||
local abs_path = data_dir .. '/' .. rel_path
|
||||
if vim.fn.filereadable(abs_path) == 0 then
|
||||
vim.notify('File not found: ' .. abs_path, vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
vim.cmd.edit(abs_path)
|
||||
local lnum_target = tonumber(line_str) or 1
|
||||
vim.api.nvim_win_set_cursor(0, { lnum_target, 0 })
|
||||
end
|
||||
|
||||
---@return nil
|
||||
function M.add_here()
|
||||
local cur_bufnr = vim.api.nvim_get_current_buf()
|
||||
if vim.bo[cur_bufnr].filetype == 'pending' then
|
||||
vim.notify('Already in pending buffer', vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
local cur_file = vim.api.nvim_buf_get_name(cur_bufnr)
|
||||
if cur_file == '' or vim.fn.filereadable(cur_file) == 0 then
|
||||
vim.notify('Not editing a readable file', vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
local cur_lnum = vim.api.nvim_win_get_cursor(0)[1]
|
||||
local s = get_store()
|
||||
local data_dir = vim.fn.fnamemodify(s.path, ':h')
|
||||
local abs_file = vim.fn.fnamemodify(cur_file, ':p')
|
||||
local rel_file
|
||||
if abs_file:sub(1, #data_dir + 1) == data_dir .. '/' then
|
||||
rel_file = abs_file:sub(#data_dir + 2)
|
||||
else
|
||||
rel_file = abs_file
|
||||
end
|
||||
local file_spec = rel_file .. ':' .. cur_lnum
|
||||
s:load()
|
||||
local tasks = s:active_tasks()
|
||||
if #tasks == 0 then
|
||||
vim.notify('No active tasks', vim.log.levels.INFO)
|
||||
return
|
||||
end
|
||||
local items = {}
|
||||
for _, task in ipairs(tasks) do
|
||||
table.insert(items, task)
|
||||
end
|
||||
vim.ui.select(items, {
|
||||
prompt = 'Attach file to task:',
|
||||
format_item = function(task)
|
||||
return '[' .. task.id .. '] ' .. task.description
|
||||
end,
|
||||
}, function(task)
|
||||
if not task then
|
||||
return
|
||||
end
|
||||
task._extra = task._extra or {}
|
||||
task._extra.file = file_spec
|
||||
task.modified = os.date('!%Y-%m-%dT%H:%M:%SZ') --[[@as string]]
|
||||
s:save()
|
||||
vim.notify('Attached ' .. file_spec .. ' to task ' .. task.id)
|
||||
end)
|
||||
end
|
||||
|
||||
---@return nil
|
||||
function M.init()
|
||||
local path = vim.fn.getcwd() .. '/.pending.json'
|
||||
|
|
|
|||
|
|
@ -416,7 +416,7 @@ end
|
|||
|
||||
---@param text string
|
||||
---@return string description
|
||||
---@return { due?: string, cat?: string, rec?: string, rec_mode?: 'scheduled'|'completion', file?: string? } metadata
|
||||
---@return { due?: string, cat?: string, rec?: string, rec_mode?: 'scheduled'|'completion' } metadata
|
||||
function M.body(text)
|
||||
local tokens = {}
|
||||
for token in text:gmatch('%S+') do
|
||||
|
|
@ -481,18 +481,7 @@ function M.body(text)
|
|||
metadata.rec = raw_spec
|
||||
i = i - 1
|
||||
else
|
||||
local file_path_val, file_line_val = token:match('^file:(.+):(%d+)$')
|
||||
if file_path_val and file_line_val then
|
||||
if metadata.file then
|
||||
break
|
||||
end
|
||||
metadata.file = file_path_val .. ':' .. file_line_val
|
||||
i = i - 1
|
||||
elseif token:match('^file:') then
|
||||
break
|
||||
else
|
||||
break
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -510,7 +499,7 @@ end
|
|||
|
||||
---@param text string
|
||||
---@return string description
|
||||
---@return { due?: string, cat?: string, rec?: string, rec_mode?: 'scheduled'|'completion', file?: string? } metadata
|
||||
---@return { due?: string, cat?: string, rec?: string, rec_mode?: 'scheduled'|'completion' } metadata
|
||||
function M.command_add(text)
|
||||
local cat_prefix = text:match('^(%S.-):%s')
|
||||
if cat_prefix then
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ local parse = require('pending.parse')
|
|||
---@field show_category? boolean
|
||||
---@field priority? integer
|
||||
---@field recur? string
|
||||
---@field file? string
|
||||
|
||||
---@class pending.views
|
||||
local M = {}
|
||||
|
|
@ -160,7 +159,6 @@ function M.category_view(tasks)
|
|||
overdue = task.status == 'pending' and task.due ~= nil and parse.is_overdue(task.due)
|
||||
or nil,
|
||||
recur = task.recur,
|
||||
file = task._extra and task._extra.file or nil,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
@ -212,7 +210,6 @@ function M.priority_view(tasks)
|
|||
overdue = task.status == 'pending' and task.due ~= nil and parse.is_overdue(task.due) or nil,
|
||||
show_category = true,
|
||||
recur = task.recur,
|
||||
file = task._extra and task._extra.file or nil,
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue