snacks + tabline changes

This commit is contained in:
iofq 2025-07-18 09:36:11 -05:00
parent 97d6553252
commit ac39b0585d
No known key found for this signature in database
GPG key ID: ECF3B2DA38BF7183
11 changed files with 120 additions and 70 deletions

View file

@ -1,7 +1,6 @@
local diff = require('mini.diff')
local M = {
cache = {},
jj_cache = {},
}
M.get_buf_realpath = function(buf_id)
@ -20,10 +19,10 @@ M.jj_start_watching_tree_state = function(buf_id, path)
local on_not_in_jj = vim.schedule_wrap(function()
if not vim.api.nvim_buf_is_valid(buf_id) then
M.cache[buf_id] = nil
return
return false
end
diff.fail_attach(buf_id)
M.jj_cache[buf_id] = {}
M.cache[buf_id] = {}
end)
local process, stdout_feed = nil, {}
@ -61,12 +60,11 @@ M.jj_setup_tree_state_watch = function(buf_id, jj_dir_path)
timer:stop()
timer:start(50, 0, buf_jj_set_ref_text)
end
buf_fs_event:start(jj_dir_path, { recursive = false }, watch_tree_state)
buf_fs_event:start(jj_dir_path, { stat = true }, watch_tree_state)
M.jj_invalidate_cache(M.jj_cache[buf_id])
M.jj_cache[buf_id] = { fs_event = buf_fs_event, timer = timer }
M.jj_invalidate_cache(M.cache[buf_id])
M.cache[buf_id] = { fs_event = buf_fs_event, timer = timer }
end
M.jj_set_ref_text = vim.schedule_wrap(function(buf_id)
if not vim.api.nvim_buf_is_valid(buf_id) then
return
@ -86,13 +84,13 @@ M.jj_set_ref_text = vim.schedule_wrap(function(buf_id)
-- Set
local stdout = vim.loop.new_pipe()
local spawn_opts = {
args = { 'file', 'show', '--ignore-working-copy', '-r', '@-', './' .. basename },
args = { 'file', 'show', '--no-pager', '--ignore-working-copy', '-r', '@-', './' .. basename },
cwd = cwd,
stdio = { nil, stdout, nil },
}
local process, stdout_feed = nil, {}
local on_exit = function(exit_code)
process = vim.loop.spawn('jj', spawn_opts, function(exit_code)
process:close()
if exit_code ~= 0 or stdout_feed[1] == nil then
@ -102,9 +100,8 @@ M.jj_set_ref_text = vim.schedule_wrap(function(buf_id)
-- Set reference text accounting for possible 'crlf' end of line in index
local text = table.concat(stdout_feed, ''):gsub('\r\n', '\n')
buf_set_ref_text(text)
end
end)
process = vim.loop.spawn('jj', spawn_opts, on_exit)
M.jj_read_stream(stdout, stdout_feed)
end)
@ -132,7 +129,7 @@ end
M.gen_source = function()
local attach = function(buf_id)
-- Try attaching to a buffer only once
if M.jj_cache[buf_id] ~= nil then
if M.cache[buf_id] ~= nil then
return false
end
-- - Possibly resolve symlinks to get data from the original repo
@ -141,13 +138,13 @@ M.gen_source = function()
return false
end
M.jj_cache[buf_id] = {}
M.cache[buf_id] = {}
M.jj_start_watching_tree_state(buf_id, path)
end
local detach = function(buf_id)
local cache = M.jj_cache[buf_id]
M.jj_cache[buf_id] = nil
local cache = M.cache[buf_id]
M.cache[buf_id] = nil
M.jj_invalidate_cache(cache)
end

View file

@ -50,7 +50,7 @@ M.load = function()
-- load session (buffers, etc) as well as shada (marks)
sessions.read(id)
vim.cmd('rshada')
vim.notify('loaded jj session: ' .. id)
Snacks.notify('loaded jj session: ' .. id)
end
end)
else

View file

@ -1,10 +1,10 @@
M = {}
M.marks = function()
return {
finder = 'vim_marks',
format = 'file',
Snacks.picker.marks {
['local'] = false,
global = true,
on_show = function()
vim.cmd.delmarks { args = { '0-9' } }
end,
actions = {
markdel = function(picker)
for _, item in ipairs(picker:selected()) do
@ -17,10 +17,42 @@ M.marks = function()
end,
},
win = {
list = {
keys = { ['dd'] = 'markdel' },
input = {
keys = { ['<c-x>'] = 'markdel' },
},
},
}
end
M.diagnostics = function(filter)
Snacks.picker.diagnostics {
filter = filter,
focus = 'list',
format = function(item, picker)
P = require('snacks.picker.format')
local ret = {} ---@type snacks.picker.Highlight[]
vim.list_extend(ret, P.filename(item, picker))
local diag = item.item ---@type vim.Diagnostic
if item.severity then
vim.list_extend(ret, P.severity(item, picker))
end
local message = diag.message
ret[#ret + 1] = { message }
Snacks.picker.highlight.markdown(ret)
ret[#ret + 1] = { ' ' }
if diag.source then
ret[#ret + 1] = { diag.source, 'SnacksPickerDiagnosticSource' }
ret[#ret + 1] = { ' ' }
end
if diag.code then
ret[#ret + 1] = { ('(%s)'):format(diag.code), 'SnacksPickerDiagnosticCode' }
ret[#ret + 1] = { ' ' }
end
return ret
end,
}
end
return M