mirror of
https://github.com/iofq/nvim.nix.git
synced 2026-01-23 08:55:16 -06:00
nvim-ts-main
This commit is contained in:
parent
ac26b74e43
commit
095e78128b
12 changed files with 195 additions and 413 deletions
|
|
@ -4,18 +4,12 @@ local M = {
|
|||
}
|
||||
|
||||
M.get_buf_realpath = function(buf_id)
|
||||
return vim.loop.fs_realpath(vim.api.nvim_buf_get_name(buf_id)) or ''
|
||||
local path = vim.loop.fs_realpath(vim.api.nvim_buf_get_name(buf_id)) or ''
|
||||
local cwd, basename = vim.fn.fnamemodify(path, ':h'), vim.fn.fnamemodify(path, ':t')
|
||||
return path, cwd, basename
|
||||
end
|
||||
|
||||
M.jj_start_watching_tree_state = function(buf_id, path)
|
||||
local stdout = vim.loop.new_pipe()
|
||||
local args = { 'workspace', 'root', '--ignore-working-copy' }
|
||||
local spawn_opts = {
|
||||
args = args,
|
||||
cwd = vim.fn.fnamemodify(path, ':h'),
|
||||
stdio = { nil, stdout, nil },
|
||||
}
|
||||
|
||||
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
|
||||
|
|
@ -25,105 +19,57 @@ M.jj_start_watching_tree_state = function(buf_id, path)
|
|||
M.cache[buf_id] = {}
|
||||
end)
|
||||
|
||||
local process, stdout_feed = nil, {}
|
||||
local on_exit = function(exit_code)
|
||||
process:close()
|
||||
vim.system(
|
||||
{ 'jj', 'workspace', 'root', '--ignore-working-copy' },
|
||||
{cwd = vim.fn.fnamemodify(path, ':h')},
|
||||
function(obj)
|
||||
if obj.code ~= 0 then
|
||||
return on_not_in_jj()
|
||||
end
|
||||
|
||||
-- Watch index only if there was no error retrieving path to it
|
||||
if exit_code ~= 0 or stdout_feed[1] == nil then
|
||||
return on_not_in_jj()
|
||||
-- Set up index watching
|
||||
local root = obj.stdout:gsub('\n+$', '') .. '/.jj/working_copy/tree_state'
|
||||
local buf_fs_event = vim.loop.new_fs_event()
|
||||
|
||||
buf_fs_event:start(root, { stat = true }, function()
|
||||
M.jj_set_ref_text(buf_id)
|
||||
end)
|
||||
M.cache[buf_id] = { fs_event = buf_fs_event }
|
||||
|
||||
-- Set reference text immediately
|
||||
M.jj_set_ref_text(buf_id)
|
||||
end
|
||||
|
||||
-- Set up index watching
|
||||
local jj_dir_path = table.concat(stdout_feed, ''):gsub('\n+$', '') .. '/.jj/working_copy'
|
||||
M.jj_setup_tree_state_watch(buf_id, jj_dir_path)
|
||||
|
||||
-- Set reference text immediately
|
||||
M.jj_set_ref_text(buf_id)
|
||||
end
|
||||
|
||||
process = vim.loop.spawn('jj', spawn_opts, on_exit)
|
||||
M.jj_read_stream(stdout, stdout_feed)
|
||||
)
|
||||
end
|
||||
|
||||
M.jj_setup_tree_state_watch = function(buf_id, jj_dir_path)
|
||||
local buf_fs_event, timer = vim.loop.new_fs_event(), vim.loop.new_timer()
|
||||
local buf_jj_set_ref_text = function()
|
||||
M.jj_set_ref_text(buf_id)
|
||||
end
|
||||
|
||||
local watch_tree_state = function(_, filename, _)
|
||||
if filename ~= 'tree_state' then
|
||||
return
|
||||
end
|
||||
-- Debounce to not overload during incremental staging (like in script)
|
||||
timer:stop()
|
||||
timer:start(50, 0, buf_jj_set_ref_text)
|
||||
end
|
||||
buf_fs_event:start(jj_dir_path, { stat = true }, watch_tree_state)
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
local buf_set_ref_text = vim.schedule_wrap(function(text)
|
||||
local buf_set_ref_text = function(text)
|
||||
pcall(diff.set_ref_text, buf_id, text)
|
||||
end)
|
||||
end
|
||||
|
||||
-- NOTE: Do not cache buffer's name to react to its possible rename
|
||||
local path = M.get_buf_realpath(buf_id)
|
||||
-- react to possible rename
|
||||
local path, cwd, basename = M.get_buf_realpath(buf_id)
|
||||
if path == '' then
|
||||
return buf_set_ref_text {}
|
||||
end
|
||||
local cwd, basename = vim.fn.fnamemodify(path, ':h'), vim.fn.fnamemodify(path, ':t')
|
||||
|
||||
-- Set
|
||||
local stdout = vim.loop.new_pipe()
|
||||
local spawn_opts = {
|
||||
args = { 'file', 'show', '--no-pager', '--ignore-working-copy', '-r', '@-', './' .. basename },
|
||||
cwd = cwd,
|
||||
stdio = { nil, stdout, nil },
|
||||
}
|
||||
|
||||
local process, stdout_feed = nil, {}
|
||||
process = vim.loop.spawn('jj', spawn_opts, function(exit_code)
|
||||
process:close()
|
||||
|
||||
if exit_code ~= 0 or stdout_feed[1] == nil then
|
||||
return buf_set_ref_text {}
|
||||
end
|
||||
|
||||
-- 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)
|
||||
|
||||
M.jj_read_stream(stdout, stdout_feed)
|
||||
vim.system(
|
||||
{ 'jj', 'file', 'show', '--no-pager', '--ignore-working-copy', '-r', '@-', './' .. basename },
|
||||
{ cwd = cwd },
|
||||
vim.schedule_wrap(function(obj)
|
||||
if obj.code ~= 0 then return buf_set_ref_text {} end
|
||||
buf_set_ref_text(obj.stdout:gsub('\r\n', '\n'))
|
||||
end)
|
||||
)
|
||||
end)
|
||||
|
||||
M.jj_read_stream = function(stream, feed)
|
||||
local callback = function(err, data)
|
||||
if data ~= nil then
|
||||
return table.insert(feed, data)
|
||||
end
|
||||
if err then
|
||||
feed[1] = nil
|
||||
end
|
||||
stream:close()
|
||||
end
|
||||
stream:read_start(callback)
|
||||
end
|
||||
|
||||
M.jj_invalidate_cache = function(cache)
|
||||
if cache == nil then
|
||||
return
|
||||
end
|
||||
pcall(vim.loop.fs_event_stop, cache.fs_event)
|
||||
pcall(vim.loop.timer_stop, cache.timer)
|
||||
M.jj_invalidate_cache = function(buf_id)
|
||||
pcall(vim.loop.fs_event_stop, M.cache[buf_id].fs_event)
|
||||
M.cache[buf_id] = nil
|
||||
end
|
||||
|
||||
M.gen_source = function()
|
||||
|
|
@ -143,20 +89,15 @@ M.gen_source = function()
|
|||
end
|
||||
|
||||
local detach = function(buf_id)
|
||||
local cache = M.cache[buf_id]
|
||||
M.cache[buf_id] = nil
|
||||
M.jj_invalidate_cache(cache)
|
||||
M.jj_invalidate_cache(buf_id)
|
||||
end
|
||||
|
||||
local apply_hunks = function(_, _)
|
||||
-- staging does not apply for jj
|
||||
end
|
||||
|
||||
return {
|
||||
name = 'jj',
|
||||
attach = attach,
|
||||
detach = detach,
|
||||
apply_hunks = apply_hunks,
|
||||
apply_hunks = function(_, _) end -- staging does not apply for jj
|
||||
}
|
||||
end
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -67,5 +67,4 @@ M.load = function()
|
|||
end
|
||||
end
|
||||
|
||||
_G.M = M
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -55,67 +55,4 @@ function M.status()
|
|||
}
|
||||
end
|
||||
|
||||
function M.revs()
|
||||
local function jj_new(picker, item)
|
||||
picker:close()
|
||||
if item then
|
||||
if not item.rev then
|
||||
vim.notify.warn('No branch or commit found', { title = 'Snacks Picker' })
|
||||
return
|
||||
end
|
||||
local cmd = { 'jj', 'new', '-r', item.rev }
|
||||
Snacks.picker.util.cmd(cmd, function()
|
||||
vim.notify('Checking out revision: ' .. item.rev, { title = 'Snacks Picker' })
|
||||
vim.cmd.checktime()
|
||||
require('plugins.lib.session_jj').load()
|
||||
end, { cwd = item.cwd })
|
||||
end
|
||||
end
|
||||
|
||||
local function jj_rev_cmd(ctx)
|
||||
if ctx.item.rev then
|
||||
Snacks.picker.preview.cmd({ 'jj', 'show', '--ignore-working-copy', '--git', '-r', ctx.item.rev }, ctx)
|
||||
else
|
||||
ctx.preview:reset()
|
||||
return 'No preview available.'
|
||||
end
|
||||
end
|
||||
|
||||
local function jj_log(revset)
|
||||
if revset == nil then
|
||||
revset = '-r "ancestors(@,25)"'
|
||||
else
|
||||
revset = '-r ' .. revset
|
||||
end
|
||||
local status_raw = vim.fn.system(
|
||||
'jj log --ignore-working-copy '
|
||||
.. revset
|
||||
..
|
||||
' --template \'if(root, format_root_commit(self), label(if(current_working_copy, "working_copy"), concat(separate(" ", self.change_id().shortest(8), self.bookmarks()), " | ", if(empty, label("empty", "(empty)")), if(description, description.first_line(), label(if(empty, "empty"), description_placeholder),),) ++ "\n",),)\''
|
||||
)
|
||||
local lines = {}
|
||||
|
||||
for line in status_raw:gmatch('[^\r\n]+') do
|
||||
local sign, rev = string.match(line, '(.)%s(%a+)%s.*')
|
||||
table.insert(lines, {
|
||||
text = line,
|
||||
sign = sign,
|
||||
rev = rev,
|
||||
})
|
||||
end
|
||||
|
||||
return lines
|
||||
end
|
||||
|
||||
Snacks.picker.pick {
|
||||
source = 'jj_revs',
|
||||
layout = 'ivy',
|
||||
format = 'text',
|
||||
title = 'jj log',
|
||||
items = jj_log(),
|
||||
confirm = jj_new,
|
||||
preview = jj_rev_cmd,
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
return {
|
||||
{
|
||||
'echasnovski/mini.nvim',
|
||||
'nvim-mini/mini.nvim',
|
||||
lazy = false,
|
||||
keys = {
|
||||
{
|
||||
|
|
@ -24,37 +24,23 @@ return {
|
|||
'<Cmd>Git blame -- %<CR>',
|
||||
desc = 'git blame',
|
||||
},
|
||||
{
|
||||
'<leader>gg',
|
||||
':Git ',
|
||||
desc = 'git command',
|
||||
},
|
||||
},
|
||||
config = function()
|
||||
require('mini.basics').setup { mappings = { windows = true } }
|
||||
require('mini.icons').setup()
|
||||
vim.schedule(function()
|
||||
local ai = require('mini.ai')
|
||||
local extra_ai = require('mini.extra').gen_ai_spec
|
||||
ai.setup {
|
||||
n_lines = 300,
|
||||
custom_textobjects = {
|
||||
i = extra_ai.indent(),
|
||||
g = extra_ai.buffer(),
|
||||
l = extra_ai.line(),
|
||||
i = require('mini.extra').gen_ai_spec.indent(),
|
||||
u = ai.gen_spec.function_call(),
|
||||
a = ai.gen_spec.treesitter { a = '@parameter.outer', i = '@parameter.inner' },
|
||||
k = ai.gen_spec.treesitter { a = '@assignment.lhs', i = '@assignment.lhs' },
|
||||
v = ai.gen_spec.treesitter { a = '@assignment.rhs', i = '@assignment.rhs' },
|
||||
f = ai.gen_spec.treesitter { a = '@function.outer', i = '@function.inner' },
|
||||
o = ai.gen_spec.treesitter {
|
||||
a = { '@block.outer', '@conditional.outer', '@loop.outer' },
|
||||
i = { '@block.inner', '@conditional.inner', '@loop.inner' },
|
||||
},
|
||||
},
|
||||
}
|
||||
require('mini.align').setup()
|
||||
require('mini.bracketed').setup { file = { suffix = 'm' } }
|
||||
require('mini.icons').setup()
|
||||
require('mini.pairs').setup()
|
||||
require('mini.git').setup()
|
||||
require('mini.surround').setup()
|
||||
require('mini.splitjoin').setup { detect = { separator = '[,;\n]' } }
|
||||
|
|
@ -111,7 +97,7 @@ return {
|
|||
clues = {
|
||||
miniclue.gen_clues.g(),
|
||||
miniclue.gen_clues.marks(),
|
||||
miniclue.gen_clues.registers(),
|
||||
miniclue.gen_clues.registers({show_contents = true}),
|
||||
miniclue.gen_clues.windows(),
|
||||
miniclue.gen_clues.z(),
|
||||
},
|
||||
|
|
@ -153,10 +139,6 @@ return {
|
|||
Snacks.rename.on_rename_file(event.data.from, event.data.to)
|
||||
end,
|
||||
})
|
||||
|
||||
local multi = require('mini.keymap').map_multistep
|
||||
multi({ 'i', 's' }, '<Tab>', { 'blink_accept', 'vimsnippet_next', 'increase_indent' })
|
||||
multi({ 'i', 's' }, '<S-Tab>', { 'vimsnippet_prev', 'decrease_indent' })
|
||||
end)
|
||||
end,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@ return {
|
|||
'iofq/dart.nvim',
|
||||
lazy = false,
|
||||
priority = 1001,
|
||||
config = true,
|
||||
},
|
||||
{
|
||||
'windwp/nvim-autopairs',
|
||||
event = 'VeryLazy',
|
||||
config = true,
|
||||
dependencies = 'nvim-mini/mini.nvim',
|
||||
opts = {
|
||||
label_marked_fg = 'cyan'
|
||||
},
|
||||
},
|
||||
{
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
|
|
@ -20,20 +18,8 @@ return {
|
|||
branch = 'main',
|
||||
config = true,
|
||||
},
|
||||
{
|
||||
'nvim-treesitter/nvim-treesitter-context',
|
||||
opts = {
|
||||
max_lines = 5,
|
||||
min_window_height = 50,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
'jinh0/eyeliner.nvim',
|
||||
event = 'VeryLazy',
|
||||
config = true,
|
||||
},
|
||||
{
|
||||
'MeanderingProgrammer/render-markdown.nvim',
|
||||
event = 'VeryLazy',
|
||||
|
|
@ -86,21 +72,6 @@ return {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
'ThePrimeagen/refactoring.nvim',
|
||||
event = 'VeryLazy',
|
||||
config = true,
|
||||
keys = {
|
||||
{ '<leader>rv', '<cmd>Refactor inline_var<cr>dd', mode = { 'n', 'x' } },
|
||||
{
|
||||
'<leader>rr',
|
||||
function()
|
||||
require('refactoring').select_refactor { prefer_ex_cmd = true }
|
||||
end,
|
||||
mode = { 'n', 'x' },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
'stevearc/quicker.nvim',
|
||||
event = 'VeryLazy',
|
||||
|
|
|
|||
|
|
@ -13,9 +13,6 @@ return {
|
|||
notification = {
|
||||
wo = { wrap = true },
|
||||
},
|
||||
terminal = {
|
||||
border = 'rounded',
|
||||
},
|
||||
},
|
||||
terminal = { enabled = true },
|
||||
indent = { enabled = true },
|
||||
|
|
@ -88,13 +85,6 @@ return {
|
|||
end,
|
||||
desc = 'Fuzzy find smart',
|
||||
},
|
||||
{
|
||||
'<leader>fe',
|
||||
function()
|
||||
Snacks.explorer()
|
||||
end,
|
||||
desc = 'snacks explorer',
|
||||
},
|
||||
{
|
||||
'<leader>ff',
|
||||
function()
|
||||
|
|
@ -151,13 +141,6 @@ return {
|
|||
end,
|
||||
desc = 'Fuzzy find buffers',
|
||||
},
|
||||
{
|
||||
'<leader>fn',
|
||||
function()
|
||||
Snacks.picker.notifications()
|
||||
end,
|
||||
desc = 'pick notifications',
|
||||
},
|
||||
{
|
||||
'gO',
|
||||
function()
|
||||
|
|
@ -179,13 +162,6 @@ return {
|
|||
end,
|
||||
desc = 'pick notifications',
|
||||
},
|
||||
{
|
||||
'<leader>jj',
|
||||
function()
|
||||
require('plugins.lib.snacks_jj').revs()
|
||||
end,
|
||||
desc = 'pick notifications',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue