fix(forge): fix ghost extmarks, false auth warnings, and needless API calls
Problem: extmarks ghosted after `cc`/undo on task lines, auth warnings fired even when CLIs were authenticated, and `refresh()` hit forge APIs on every buffer open regardless of `auto_close`. Solution: add `invalidate = true` to all extmarks so Neovim cleans them up on text deletion. Run `auth status` before warning to verify the CLI is actually unauthenticated. Gate `refresh()` behind `auto_close` config.
This commit is contained in:
parent
e62f2f818c
commit
fe5ea8be78
2 changed files with 41 additions and 12 deletions
|
|
@ -128,6 +128,7 @@ local function apply_inline_row(bufnr, row, m, icons)
|
|||
vim.api.nvim_buf_set_extmark(bufnr, ns_inline, row, 0, {
|
||||
end_col = #line,
|
||||
hl_group = 'PendingFilter',
|
||||
invalidate = true,
|
||||
})
|
||||
elseif m.type == 'task' then
|
||||
if m.status == 'done' then
|
||||
|
|
@ -136,6 +137,7 @@ local function apply_inline_row(bufnr, row, m, icons)
|
|||
vim.api.nvim_buf_set_extmark(bufnr, ns_inline, row, col_start, {
|
||||
end_col = #line,
|
||||
hl_group = 'PendingDone',
|
||||
invalidate = true,
|
||||
})
|
||||
elseif m.status == 'blocked' then
|
||||
local line = vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false)[1] or ''
|
||||
|
|
@ -143,6 +145,7 @@ local function apply_inline_row(bufnr, row, m, icons)
|
|||
vim.api.nvim_buf_set_extmark(bufnr, ns_inline, row, col_start, {
|
||||
end_col = #line,
|
||||
hl_group = 'PendingBlocked',
|
||||
invalidate = true,
|
||||
})
|
||||
end
|
||||
local line = vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false)[1] or ''
|
||||
|
|
@ -167,6 +170,7 @@ local function apply_inline_row(bufnr, row, m, icons)
|
|||
virt_text = { { '[' .. icon .. ']', icon_hl } },
|
||||
virt_text_pos = 'overlay',
|
||||
priority = 100,
|
||||
invalidate = true,
|
||||
})
|
||||
if m.forge_spans then
|
||||
local forge = require('pending.forge')
|
||||
|
|
@ -178,6 +182,7 @@ local function apply_inline_row(bufnr, row, m, icons)
|
|||
virt_text = { { label_text, hl_group } },
|
||||
virt_text_pos = 'inline',
|
||||
priority = 90,
|
||||
invalidate = true,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
@ -186,11 +191,13 @@ local function apply_inline_row(bufnr, row, m, icons)
|
|||
vim.api.nvim_buf_set_extmark(bufnr, ns_inline, row, 0, {
|
||||
end_col = #line,
|
||||
hl_group = 'PendingHeader',
|
||||
invalidate = true,
|
||||
})
|
||||
vim.api.nvim_buf_set_extmark(bufnr, ns_inline, row, 0, {
|
||||
virt_text = { { icons.category .. ' ', 'PendingHeader' } },
|
||||
virt_text_pos = 'overlay',
|
||||
priority = 100,
|
||||
invalidate = true,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
@ -541,6 +548,7 @@ local function apply_extmarks(bufnr, line_meta)
|
|||
vim.api.nvim_buf_set_extmark(bufnr, ns_eol, row, 0, {
|
||||
virt_text = virt_parts,
|
||||
virt_text_pos = 'eol',
|
||||
invalidate = true,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ local log = require('pending.log')
|
|||
---@field default_host string
|
||||
---@field cli string
|
||||
---@field auth_cmd string
|
||||
---@field auth_status_args string[]
|
||||
---@field default_icon string
|
||||
---@field default_issue_format string
|
||||
---@field _warned boolean
|
||||
|
|
@ -231,17 +232,29 @@ function M.fetch_metadata(ref, callback)
|
|||
|
||||
vim.system(args, { text = true }, function(result)
|
||||
if result.code ~= 0 or not result.stdout or result.stdout == '' then
|
||||
vim.schedule(function()
|
||||
local forge_cfg = config.get().forge or {}
|
||||
local backend = _by_name[ref.forge]
|
||||
if backend and forge_cfg.warn_missing_cli ~= false and not backend._warned then
|
||||
backend._warned = true
|
||||
log.warn(
|
||||
('%s not found or not authenticated — run `%s`'):format(backend.cli, backend.auth_cmd)
|
||||
)
|
||||
end
|
||||
callback(nil)
|
||||
end)
|
||||
local forge_cfg = config.get().forge or {}
|
||||
local backend = _by_name[ref.forge]
|
||||
if
|
||||
backend
|
||||
and forge_cfg.warn_missing_cli ~= false
|
||||
and not backend._warned
|
||||
then
|
||||
backend._warned = true
|
||||
vim.system(backend.auth_status_args, { text = true }, function(auth_result)
|
||||
vim.schedule(function()
|
||||
if auth_result.code ~= 0 then
|
||||
log.warn(
|
||||
('%s not authenticated — run `%s`'):format(backend.cli, backend.auth_cmd)
|
||||
)
|
||||
end
|
||||
callback(nil)
|
||||
end)
|
||||
end)
|
||||
else
|
||||
vim.schedule(function()
|
||||
callback(nil)
|
||||
end)
|
||||
end
|
||||
return
|
||||
end
|
||||
local ok, decoded = pcall(vim.json.decode, result.stdout)
|
||||
|
|
@ -277,6 +290,10 @@ end
|
|||
|
||||
---@param s pending.Store
|
||||
function M.refresh(s)
|
||||
local forge_cfg = config.get().forge or {}
|
||||
if not forge_cfg.auto_close then
|
||||
return
|
||||
end
|
||||
local tasks = s:tasks()
|
||||
local pending_fetches = 0
|
||||
local any_changed = false
|
||||
|
|
@ -328,7 +345,7 @@ function M.refresh(s)
|
|||
end
|
||||
end
|
||||
|
||||
---@param opts {name: string, shorthand: string, default_host: string, cli?: string, auth_cmd?: string, default_icon?: string, default_issue_format?: string}
|
||||
---@param opts {name: string, shorthand: string, default_host: string, cli?: string, auth_cmd?: string, auth_status_args?: string[], default_icon?: string, default_issue_format?: string}
|
||||
---@return pending.ForgeBackend
|
||||
function M.gitea_backend(opts)
|
||||
return {
|
||||
|
|
@ -337,6 +354,7 @@ function M.gitea_backend(opts)
|
|||
default_host = opts.default_host,
|
||||
cli = opts.cli or 'tea',
|
||||
auth_cmd = opts.auth_cmd or 'tea login add',
|
||||
auth_status_args = opts.auth_status_args or { opts.cli or 'tea', 'login', 'list' },
|
||||
default_icon = opts.default_icon or '',
|
||||
default_issue_format = opts.default_issue_format or '%i %o/%r#%n',
|
||||
_warned = false,
|
||||
|
|
@ -387,6 +405,7 @@ M.register({
|
|||
default_host = 'github.com',
|
||||
cli = 'gh',
|
||||
auth_cmd = 'gh auth login',
|
||||
auth_status_args = { 'gh', 'auth', 'status' },
|
||||
default_icon = '',
|
||||
default_issue_format = '%i %o/%r#%n',
|
||||
_warned = false,
|
||||
|
|
@ -437,6 +456,7 @@ M.register({
|
|||
default_host = 'gitlab.com',
|
||||
cli = 'glab',
|
||||
auth_cmd = 'glab auth login',
|
||||
auth_status_args = { 'glab', 'auth', 'status' },
|
||||
default_icon = '',
|
||||
default_issue_format = '%i %o/%r#%n',
|
||||
_warned = false,
|
||||
|
|
@ -492,6 +512,7 @@ M.register({
|
|||
default_host = 'codeberg.org',
|
||||
cli = 'tea',
|
||||
auth_cmd = 'tea login add',
|
||||
auth_status_args = { 'tea', 'login', 'list' },
|
||||
default_icon = '',
|
||||
default_issue_format = '%i %o/%r#%n',
|
||||
_warned = false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue