more tweaks

This commit is contained in:
Barrett Ruth 2026-03-27 18:08:42 -04:00
parent 5ee2cc567a
commit e31b2777f9
No known key found for this signature in database
GPG key ID: A6C96C9349D2FC81
4 changed files with 17 additions and 65 deletions

View file

@ -1,6 +1,6 @@
local forge = require('forge') local forge = require('forge')
---@type forge.Forge ---@class forge.Codeberg: forge.Forge
local M = { local M = {
name = 'codeberg', name = 'codeberg',
cli = 'tea', cli = 'tea',
@ -135,7 +135,7 @@ function M:pr_base_cmd(num)
return { 'tea', 'pr', num, '--fields', 'base', '--output', 'simple' } return { 'tea', 'pr', num, '--fields', 'base', '--output', 'simple' }
end end
---@param branch string ---@param _branch string
---@return string[] ---@return string[]
function M:pr_for_branch_cmd(_branch) function M:pr_for_branch_cmd(_branch)
return { return {

View file

@ -1,6 +1,6 @@
local forge = require('forge') local forge = require('forge')
---@type forge.Forge ---@class forge.GitHub: forge.Forge
local M = { local M = {
name = 'github', name = 'github',
cli = 'gh', cli = 'gh',

View file

@ -1,6 +1,6 @@
local forge = require('forge') local forge = require('forge')
---@type forge.Forge ---@class forge.GitLab: forge.Forge
local M = { local M = {
name = 'gitlab', name = 'gitlab',
cli = 'glab', cli = 'glab',

View file

@ -2,10 +2,10 @@ local M = {}
local hl_defaults = { local hl_defaults = {
ForgeComposeComment = 'Comment', ForgeComposeComment = 'Comment',
ForgeComposeBranch = 'Normal', ForgeComposeBranch = 'Special',
ForgeComposeForge = 'Type', ForgeComposeForge = 'Type',
ForgeComposeDraft = 'DiagnosticWarn', ForgeComposeDraft = 'DiagnosticWarn',
ForgeComposeFile = 'Normal', ForgeComposeFile = 'Directory',
ForgeComposeAdded = 'Added', ForgeComposeAdded = 'Added',
ForgeComposeRemoved = 'Removed', ForgeComposeRemoved = 'Removed',
} }
@ -14,33 +14,7 @@ for group, link in pairs(hl_defaults) do
vim.api.nvim_set_hl(0, group, { default = true, link = link }) vim.api.nvim_set_hl(0, group, { default = true, link = link })
end end
---@type table<integer, table<integer, {col: integer, end_col: integer, hl: string}[]>> local compose_ns = vim.api.nvim_create_namespace('forge_compose')
local compose_marks = {}
local compose_ns = vim.api.nvim_create_namespace('forge_pr_compose')
vim.api.nvim_set_decoration_provider(compose_ns, {
on_win = function(_, _, bufnr)
return compose_marks[bufnr] ~= nil
end,
on_line = function(_, _, bufnr, row)
local by_line = compose_marks[bufnr]
if not by_line then
return
end
local row_marks = by_line[row]
if not row_marks then
return
end
for _, m in ipairs(row_marks) do
vim.api.nvim_buf_set_extmark(bufnr, compose_ns, row, m.col, {
end_col = m.end_col,
hl_group = m.hl,
ephemeral = true,
priority = 4097,
})
end
end,
})
---@param msg string ---@param msg string
---@param level integer? ---@param level integer?
@ -177,7 +151,6 @@ function M.detect()
return nil return nil
end end
if forge_cache[root] then if forge_cache[root] then
M.log('forge cache hit (' .. forge_cache[root].name .. ')')
return forge_cache[root] return forge_cache[root]
end end
local remote = vim.trim(vim.fn.system('git remote get-url origin')) local remote = vim.trim(vim.fn.system('git remote get-url origin'))
@ -190,7 +163,6 @@ function M.detect()
end end
local f = require('forge.' .. name) local f = require('forge.' .. name)
forge_cache[root] = f forge_cache[root] = f
M.log('detected ' .. name .. ' via origin remote')
return f return f
end end
@ -199,15 +171,12 @@ end
function M.repo_info(f) function M.repo_info(f)
local root = git_root() local root = git_root()
if root and repo_info_cache[root] then if root and repo_info_cache[root] then
M.log('repo_info cache hit')
return repo_info_cache[root] return repo_info_cache[root]
end end
M.log('fetching repo info...')
local info = f:repo_info() local info = f:repo_info()
if root then if root then
repo_info_cache[root] = info repo_info_cache[root] = info
end end
M.log('repo_info fetched (permission: ' .. info.permission .. ')')
return info return info
end end
@ -222,9 +191,6 @@ end
---@param key string ---@param key string
---@return table[]? ---@return table[]?
function M.get_list(key) function M.get_list(key)
if list_cache[key] then
M.log('list cache hit (' .. key .. ')')
end
return list_cache[key] return list_cache[key]
end end
@ -232,17 +198,14 @@ end
---@param data table[] ---@param data table[]
function M.set_list(key, data) function M.set_list(key, data)
list_cache[key] = data list_cache[key] = data
M.log('list cache set (' .. key .. ', ' .. #data .. ' items)')
end end
---@param key string? ---@param key string?
function M.clear_list(key) function M.clear_list(key)
if key then if key then
list_cache[key] = nil list_cache[key] = nil
M.log('list cache cleared (' .. key .. ')')
else else
list_cache = {} list_cache = {}
M.log('list cache cleared (all)')
end end
end end
@ -251,7 +214,6 @@ function M.clear_cache()
repo_info_cache = {} repo_info_cache = {}
root_cache = {} root_cache = {}
list_cache = {} list_cache = {}
M.log('all caches cleared')
end end
---@return string ---@return string
@ -844,29 +806,19 @@ local function open_compose_buffer(f, branch, base, draft)
end end
end end
local by_line = {}
for _, m in ipairs(marks) do for _, m in ipairs(marks) do
local row = m.line - 1 vim.api.nvim_buf_set_extmark(buf, compose_ns, m.line - 1, m.col, {
if not by_line[row] then end_col = m.end_col,
by_line[row] = {} hl_group = m.hl,
end priority = 200,
table.insert(by_line[row], { col = m.col, end_col = m.end_col, hl = m.hl }) })
end end
compose_marks[buf] = by_line for i = comment_start, #lines do
vim.api.nvim_buf_set_extmark(buf, compose_ns, i - 1, 0, {
local comment_ns = vim.api.nvim_create_namespace('forge_pr_comment') line_hl_group = 'ForgeComposeComment',
for i = comment_start, #lines do priority = 200,
vim.api.nvim_buf_set_extmark(buf, comment_ns, i - 1, 0, {
line_hl_group = 'ForgeComposeComment',
}) })
end end
vim.api.nvim_create_autocmd('BufWipeout', {
buffer = buf,
callback = function()
compose_marks[buf] = nil
end,
})
---@return boolean, string[], string ---@return boolean, string[], string
local function parse_comment() local function parse_comment()