From 84ecf8f3fd87d92ec6dc8866a2042291325c8a7a Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 18 Apr 2023 00:55:12 +0300 Subject: [PATCH] feat: gitsigns-codeactions --- modules/git/config.nix | 59 +++++++++++++++++++++++++++++++++++++----- modules/git/git.nix | 53 +++++-------------------------------- 2 files changed, 58 insertions(+), 54 deletions(-) diff --git a/modules/git/config.nix b/modules/git/config.nix index ae2c1b4..fffda35 100644 --- a/modules/git/config.nix +++ b/modules/git/config.nix @@ -1,13 +1,58 @@ { + pkgs, config, lib, ... }: -with lib; { - config = { - vim.git = { - enable = mkDefault false; - gitsigns.enable = mkDefault false; - }; - }; +with lib; +with builtins; let + cfg = config.vim.git; +in { + config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.gitsigns.enable (mkMerge [ + { + vim.startPlugins = ["gitsigns-nvim"]; + + vim.luaConfigRC.gitsigns = nvim.dag.entryAnywhere '' + require('gitsigns').setup { + keymaps = { + noremap = true, + + ['n gn'] = { expr = true, "&diff ? \'\' : 'Gitsigns next_hunk'"}, + ['n gp'] = { expr = true, "&diff ? \'\' : 'Gitsigns prev_hunk'"}, + + ['n gs'] = 'Gitsigns stage_hunk', + ['v gs'] = ':Gitsigns stage_hunk', + ['n gu'] = 'Gitsigns undo_stage_hunk', + ['n gr'] = 'Gitsigns reset_hunk', + ['v gr'] = ':Gitsigns reset_hunk', + ['n gR'] = 'Gitsigns reset_buffer', + ['n gp'] = 'Gitsigns preview_hunk', + ['n gb'] = 'lua require"gitsigns".blame_line{full=true}', + ['n gS'] = 'Gitsigns stage_buffer', + ['n gU'] = 'Gitsigns reset_buffer_index', + ['n gts'] = ':Gitsigns toggle_signs', + ['n gtn'] = ':Gitsigns toggle_numhl', + ['n gtl'] = ':Gitsigns toggle_linehl', + ['n gtw'] = ':Gitsigns toggle_word_diff', + + -- Text objects + ['o ih'] = ':Gitsigns select_hunk', + ['x ih'] = ':Gitsigns select_hunk' + }, + } + ''; + } + + (mkIf cfg.gitsigns.codeActions { + vim.lsp.null-ls.enable = true; + vim.lsp.null-ls.sources.gitsigns-ca = '' + table.insert( + ls_sources, + null_ls.builtins.code_actions.gitsigns + ) + ''; + }) + ])) + ]); } diff --git a/modules/git/git.nix b/modules/git/git.nix index e9af83b..80da18c 100644 --- a/modules/git/git.nix +++ b/modules/git/git.nix @@ -1,4 +1,5 @@ { + pkgs, config, lib, ... @@ -8,54 +9,12 @@ with builtins; let cfg = config.vim.git; in { options.vim.git = { - enable = mkOption { - type = types.bool; - description = "Enable git plugins"; - }; + enable = mkEnableOption "Git support"; - gitsigns.enable = mkOption { - type = types.bool; - description = "Enable git options"; + gitsigns = { + enable = mkEnableOption "gitsigns"; + + codeActions = mkEnableOption "gitsigns codeactions through null-ls"; }; }; - - config = - mkIf cfg.enable - { - vim.startPlugins = - if (cfg.gitsigns.enable) - then ["gitsigns-nvim"] - else []; - - vim.luaConfigRC.gitsigns = mkIf (cfg.gitsigns.enable) (nvim.dag.entryAnywhere '' - -- GitSigns setup - require('gitsigns').setup { - keymaps = { - noremap = true, - - ['n gn'] = { expr = true, "&diff ? \'\' : 'Gitsigns next_hunk'"}, - ['n gp'] = { expr = true, "&diff ? \'\' : 'Gitsigns prev_hunk'"}, - - ['n gs'] = 'Gitsigns stage_hunk', - ['v gs'] = ':Gitsigns stage_hunk', - ['n gu'] = 'Gitsigns undo_stage_hunk', - ['n gr'] = 'Gitsigns reset_hunk', - ['v gr'] = ':Gitsigns reset_hunk', - ['n gR'] = 'Gitsigns reset_buffer', - ['n gp'] = 'Gitsigns preview_hunk', - ['n gb'] = 'lua require"gitsigns".blame_line{full=true}', - ['n gS'] = 'Gitsigns stage_buffer', - ['n gU'] = 'Gitsigns reset_buffer_index', - ['n gts'] = ':Gitsigns toggle_signs', - ['n gtn'] = ':Gitsigns toggle_numhl', - ['n gtl'] = ':Gitsigns toggle_linehl', - ['n gtw'] = ':Gitsigns toggle_word_diff', - - -- Text objects - ['o ih'] = ':Gitsigns select_hunk', - ['x ih'] = ':Gitsigns select_hunk' - }, - } - ''); - }; }