diff --git a/flake.lock b/flake.lock index 15c4ba2..64a1675 100644 --- a/flake.lock +++ b/flake.lock @@ -178,6 +178,22 @@ "type": "github" } }, + "jj-nvim": { + "flake": false, + "locked": { + "lastModified": 1768169857, + "narHash": "sha256-8POSGuNYdAR2peyzN92vWR87GqWf+Y6I1arOwNxwd6U=", + "owner": "NicolasGB", + "repo": "jj.nvim", + "rev": "d13a5c9aec08318323f19fcdc1a1d2c469e00739", + "type": "github" + }, + "original": { + "owner": "NicolasGB", + "repo": "jj.nvim", + "type": "github" + } + }, "luvit-meta": { "flake": false, "locked": { @@ -296,6 +312,7 @@ "dart": "dart", "flake-utils": "flake-utils_2", "gen-luarc": "gen-luarc", + "jj-nvim": "jj-nvim", "neovim-nightly-overlay": "neovim-nightly-overlay", "nixpkgs": "nixpkgs_2" } diff --git a/flake.nix b/flake.nix index 5312b1a..c722d83 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,10 @@ dart = { url = "github:iofq/dart.nvim"; }; + jj-nvim = { + url = "github:NicolasGB/jj.nvim"; + flake = false; + }; }; outputs = inputs@{ diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index 6cf2234..d7f4cb0 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -4,12 +4,20 @@ final: prev: let mkNeovim = prev.callPackage ./mkNeovim.nix { pkgs = final; }; dart-nvim = inputs.dart.packages.x86_64-linux.default; + mkPlugin = + src: pname: + prev.vimUtils.buildVimPlugin { + inherit pname src; + version = src.lastModifiedDate; + }; + jj-nvim = mkPlugin inputs.jj-nvim "jj-nvim"; plugins = with prev.vimPlugins; [ blink-cmp blink-ripgrep-nvim conform-nvim dart-nvim + jj-nvim mini-nvim nvim-autopairs nvim-lint diff --git a/nvim/after/lua/iofq/jj.lua b/nvim/after/lua/iofq/jj.lua new file mode 100644 index 0000000..4556b7f --- /dev/null +++ b/nvim/after/lua/iofq/jj.lua @@ -0,0 +1,17 @@ +local M = {} + +M.is_jj_diffedit_open = function() + local qf = vim.fn.getqflist() + + local entry = qf[1] + if not entry or not entry.user_data or not entry.user_data.diff then + return 0 + else + return 1 + end +end + +M.diffedit = function() + vim.fn.jobstart('jj diffedit --tool diffview-new') +end +return M diff --git a/nvim/after/lua/iofq/snacks_jj.lua b/nvim/after/lua/iofq/snacks_jj.lua deleted file mode 100644 index aae14fa..0000000 --- a/nvim/after/lua/iofq/snacks_jj.lua +++ /dev/null @@ -1,90 +0,0 @@ -local M = {} - -function M.status() - local function get_files() - local status_raw = vim.fn.system('jj diff --no-pager --quiet --summary') - local files = {} - - for status in status_raw:gmatch('[^\r\n]+') do - local state, file = string.match(status, '^(%a)%s(.+)$') - - if state and file then - local hl = '' - if state == 'A' then - hl = 'SnacksPickerGitStatusAdded' - elseif state == 'M' then - hl = 'SnacksPickerGitStatusModified' - elseif state == 'D' then - hl = 'SnacksPickerGitStatusDeleted' - elseif state == 'R' then - hl = 'SnacksPickerGitStatusRenamed' - file = string.match(file, '{.-=>%s*(.-)}') - end - - local diff = vim.fn.system('jj diff ' .. file .. ' --no-pager --stat --git') - table.insert(files, { - file = file, - filename_hl = hl, - diff = diff, - }) - end - end - - return files - end - - Snacks.picker.pick { - source = 'jj_status', - items = get_files(), - format = 'file', - title = 'jj status', - preview = function(ctx) - if ctx.item.file then - Snacks.picker.preview.diff(ctx) - else - ctx.preview:reset() - ctx.preview:set_title('No preview') - end - end, - } -end - -function M.file_history(filename) - local function preview(ctx) - if ctx.item.rev then - Snacks.picker.preview.cmd( - { 'jj', 'log', '--ignore-working-copy', '--git', '-r', ctx.item.rev, '-p', filename }, - ctx - ) - else - ctx.preview:reset() - return 'No preview available.' - end - end - - local function get_history(f) - local status_raw = vim.fn.system( - 'jj log --ignore-working-copy --no-graph' - .. ' --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",),)\'' - .. ' -- ' - .. f - ) - local lines = {} - for line in status_raw:gmatch('[^\r\n]+') do - local rev = string.match(line, '(%w+)%s.*') - table.insert(lines, { - text = line, - rev = rev, - }) - end - return lines - end - - Snacks.picker.pick { - format = 'text', - title = 'jj file history for ' .. filename, - items = get_history(filename), - preview = preview, - } -end -return M diff --git a/nvim/after/plugin/mini.lua b/nvim/after/plugin/mini.lua index 30d5984..d4728c5 100644 --- a/nvim/after/plugin/mini.lua +++ b/nvim/after/plugin/mini.lua @@ -9,17 +9,12 @@ vim.schedule(function() ai.setup { n_lines = 300, custom_textobjects = { + i = require('mini.extra').gen_ai_spec.indent(), a = ai.gen_spec.treesitter { a = '@parameter.outer', i = '@parameter.inner' }, f = ai.gen_spec.treesitter { a = '@function.outer', i = '@function.inner' }, }, } - require('mini.git').setup() - map('n', 'gb', 'Git blame -- %') - map('n', 'go', function() - return MiniGit.show_at_cursor() - end) - local jump = require('mini.jump2d') jump.setup { mappings = { diff --git a/nvim/after/plugin/plugins.lua b/nvim/after/plugin/plugins.lua index abd3c45..730ed82 100644 --- a/nvim/after/plugin/plugins.lua +++ b/nvim/after/plugin/plugins.lua @@ -55,16 +55,22 @@ map('n', 'fj', Snacks.picker.jumps) map('n', 'f.', Snacks.picker.resume) map('n', 'fb', Snacks.picker.buffers) map('n', 'fq', Snacks.picker.qflist) -map('n', 'jf', require('iofq.snacks_jj').status) -map('n', 'jh', function() - require('iofq.snacks_jj').file_history(vim.api.nvim_buf_get_name(0)) -end) vim.schedule(function() require('nvim-treesitter').setup() require('nvim-treesitter-textobjects').setup() require('nvim-autopairs').setup() + require('jj').setup {} + map('n', 'gb', require('jj.annotate').file) + map('n', 'jf', require('jj.picker').status) + map('n', 'jj', require('jj.cmd').log) + map('n', 'jh', require('jj.picker').file_history) + map('n', 'je', require('iofq.jj').diffedit) + map('n', 'jd', function() + require('jj.diff').open_vdiff { rev = 'trunk()' } + end) + require('quicker').setup() map('n', 'qf', function() require('quicker').toggle { max_height = 20 }