Compare commits

...

62 commits

Author SHA1 Message Date
Ching Pei Yang
9261611d23
Merge bf54ca3cb2 into 42c5228dc1 2024-10-31 13:19:13 +00:00
Ching Pei Yang
bf54ca3cb2
remove stale FIXME 2024-10-31 14:19:07 +01:00
Ching Pei Yang
de6e701386
surround: rework keymap config 2024-10-31 14:17:29 +01:00
Ching Pei Yang
11e0b9a031
toggleterm: use toLuaObject for clarity 2024-10-31 13:58:59 +01:00
Ching Pei Yang
7543cc2725
toggleterm: make lazygit keybind optional 2024-10-31 13:57:13 +01:00
Ching Pei Yang
9360becd30
lazy: remove unused module arg 2024-10-31 13:51:51 +01:00
Ching Pei Yang
b59689dbd9
trouble: remove redundant import 2024-10-28 03:14:36 +01:00
Ching Pei Yang
536feac331
docs: update dag-entries 2024-10-28 03:14:36 +01:00
Ching Pei Yang
192340494b
refactor: re-order plugin and lz.n configs
lazy: make lzn-auto-require togglable
2024-10-28 03:14:36 +01:00
Ching Pei Yang
eb95f77e75
nvim-dap-ui: add setupOpts 2024-10-28 03:04:59 +01:00
Ching Pei Yang
12ed05bcfb
lazy: refactor common var 2024-10-28 03:04:58 +01:00
Ching Pei Yang
aac776f7a4
Update docs/manual/hacking/additional-plugins.md
Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com>
2024-10-28 02:31:47 +01:00
Ching Pei Yang
eff15d27b4
cmp: install sourcess via cmp.sourcePlugins 2024-10-26 01:51:58 +02:00
Ching Pei Yang
0397d0722f
lazy: allow key mode of str type 2024-10-22 15:46:04 +02:00
Ching Pei Yang
70e988bb33
cmp-nvim-lsp: lazy load 2024-10-22 15:33:18 +02:00
Ching Pei Yang
6664304f7e
docs: fix broken link 2024-10-22 15:32:57 +02:00
Ching Pei Yang
1952f41632
format 2024-10-22 15:31:11 +02:00
Ching Pei Yang
2f502f1790
fixup! cmp: actually lazy load source 2024-10-22 15:25:59 +02:00
Ching Pei Yang
4b703964e1
cmp: actually lazy load source 2024-10-22 15:14:15 +02:00
Ching Pei Yang
f107cc45eb
flake: add rtp.nvim 2024-10-22 13:00:48 +02:00
Ching Pei Yang
e829a0964a
luasnip: lazy load 2024-10-22 12:59:56 +02:00
Ching Pei Yang
46a1f0427f
cmp: lazy load
this moves cmp itself to lazy.plugins but other plugins that call cmp
are not yet lazy so cmp is technically not yet lazy
2024-10-22 12:59:50 +02:00
Ching Pei Yang
b636b22046
copilot: lazy load 2024-10-21 20:19:18 +02:00
Ching Pei Yang
7e10870363
lazy: allow lines in place of str for lua code 2024-10-21 18:08:31 +02:00
Ching Pei Yang
132d83e588
lazy: update lz.n plugin spec 2024-10-21 18:08:09 +02:00
Ching Pei Yang
d1c410b3ff
flake: update lz.n 2024-10-21 18:07:30 +02:00
Ching Pei Yang
2d16be3ceb
typo tee hee :4
Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com>
2024-10-18 10:52:27 +02:00
Ching Pei Yang
9e551aa427
typo tee hee :3
Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com>
2024-10-18 10:51:43 +02:00
Ching Pei Yang
66a03f53f8
formatting nitpick
Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com>
2024-10-18 10:48:50 +02:00
Ching Pei Yang
e7cc55225a
Update docs/manual/hacking/additional-plugins.md
Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com>
2024-10-18 10:40:14 +02:00
Ching Pei Yang
88393d6a78
Merge branch 'v0.7' into feature/lzn 2024-10-17 19:14:05 +02:00
Pei Yang Ching
665f0fa106 lazy: cleanup 2024-10-17 17:29:25 +02:00
Pei Yang Ching
256a8cf62c docs: update lazy.plugins syntax 2024-10-17 17:20:35 +02:00
Pei Yang Ching
d49e46ab16 treewide: update lazy.plugins syntax 2024-10-17 17:20:35 +02:00
Pei Yang Ching
854fd340e3 lazy: use attrsOf for lazy.plugins 2024-10-17 17:20:35 +02:00
Pei Yang Ching
d76d673dd4 neo-tree: fix duplicate neo-tree install 2024-10-16 01:28:34 +02:00
Ching Pei Yang
03c922a3bc
fixup! doc: update release note 2024-10-14 22:04:16 +02:00
Ching Pei Yang
72da674a2b
doc: update release note 2024-10-11 00:07:03 +02:00
Ching Pei Yang
5cc76714b7
flake.lock: fix merge mistake 2024-10-11 00:04:55 +02:00
raf
d1c24c8eae
Merge branch 'v0.7' into feature/lzn 2024-10-09 17:52:13 +00:00
Ching Pei Yang
20302afeca
dap: appease the nix gods (fix statix lint) 2024-10-09 17:53:25 +02:00
Ching Pei Yang
3b7a11cb42
fixup! lazy: init module 2024-10-06 22:43:06 +02:00
Ching Pei Yang
b7a34ad52b
neo-tree: lazy load 2024-10-06 20:51:33 +02:00
Ching Pei Yang
4701bb15c5
surround-nvim: lazy load 2024-10-06 20:13:39 +02:00
Ching Pei Yang
6ae18403a8
comment-nvim: lazy load 2024-10-06 19:35:10 +02:00
Ching Pei Yang
283ea5b92c
lazy: support lazy.enable=false 2024-10-06 19:35:10 +02:00
Ching Pei Yang
f3a41aa2b4
docs: add section on lazy plugins 2024-10-06 19:35:10 +02:00
Ching Pei Yang
d649939b24
fidget: lazy load 2024-10-06 19:35:10 +02:00
Ching Pei Yang
f7b099e6f8
leap: lazy load 2024-10-06 19:35:10 +02:00
Ching Pei Yang
fb36de0aac
icon-picker: lazy load 2024-10-06 19:35:10 +02:00
Ching Pei Yang
a9ce2fe101
diffview: lazy load 2024-10-06 19:35:10 +02:00
Ching Pei Yang
127ae0200d
cheatsheet: lazy load 2024-10-06 19:35:10 +02:00
Ching Pei Yang
bb2b3ff225
toggleterm: lazy load 2024-10-06 19:35:09 +02:00
Ching Pei Yang
6c92f6cec5
trouble: lazy load 2024-10-06 19:35:09 +02:00
Ching Pei Yang
0608e107cd
dapui: lazy load 2024-10-06 19:35:09 +02:00
Ching Pei Yang
edab575b52
nvim-tree: lazy load 2024-10-06 19:35:09 +02:00
Ching Pei Yang
bc6597c36a
telescope: lazy load 2024-10-06 19:35:09 +02:00
Ching Pei Yang
7e144707d9
lib.binds: add lz.n variant of bind functions 2024-10-06 19:35:09 +02:00
Ching Pei Yang
96954beece
wrapper: fix opt plugin format 2024-10-06 19:35:08 +02:00
Ching Pei Yang
3e48cea536
lzn-auto-require: add init lua code 2024-10-06 19:35:08 +02:00
Ching Pei Yang
937d0f22af
lazy: init module 2024-10-06 19:35:08 +02:00
Ching Pei Yang
6ede63c170 flake: add lz.n and lzn-auto-require 2024-10-06 14:50:07 +02:00
36 changed files with 1107 additions and 482 deletions

View file

@ -15,9 +15,11 @@ entries in nvf:
5. `theme` (this is simply placed before `pluginConfigs`, meaning that 5. `theme` (this is simply placed before `pluginConfigs`, meaning that
surrounding entries don't depend on it) - used to set up the theme, which has surrounding entries don't depend on it) - used to set up the theme, which has
to be done before other plugins to be done before other plugins
6. `pluginConfigs` - the result of the nested `vim.pluginRC` (internal option, 6. `lazyConfigs` - `lz.n` and `lzn-auto-require` configs. If `vim.lazy.enable`
is false, this will contain each plugin's config instead.
7. `pluginConfigs` - the result of the nested `vim.pluginRC` (internal option,
see the [Custom Plugins](/index.xhtml#ch-custom-plugins) page for adding your see the [Custom Plugins](/index.xhtml#ch-custom-plugins) page for adding your
own plugins) DAG, used to set up internal plugins own plugins) DAG, used to set up internal plugins
7. `extraPluginConfigs` - the result of `vim.extraPlugins`, which is not a 8. `extraPluginConfigs` - the result of `vim.extraPlugins`, which is not a
direct DAG, but is converted to, and resolved as one internally direct DAG, but is converted to, and resolved as one internally
8. `mappings` - the result of `vim.maps` 9. `mappings` - the result of `vim.maps`

View file

@ -124,3 +124,61 @@ vim.your-plugin.setupOpts = {
''; '';
} }
``` ```
## Lazy plugins {#sec-lazy-plugins}
If the plugin can be lazy-loaded, `vim.lazy.plugins` should be used to add it. Lazy
plugins are managed by `lz.n`.
```nix
# in modules/.../your-plugin/config.nix
{lib, config, ...}:
let
cfg = config.vim.your-plugin;
in {
vim.lazy.plugins.your-plugin = {
# instead of vim.startPlugins, use this:
package = "your-plugin";
# if your plugin uses the `require('your-plugin').setup{...}` pattern
setupModule = "your-plugin";
inherit (cfg) setupOpts;
# events that trigger this plugin to be loaded
event = ["DirChanged"];
cmd = ["YourPluginCommand"];
# keymaps
keys = [
# we'll cover this in detail in the keymaps section
{
key = "<leader>d";
mode = "n";
action = ":YourPluginCommand";
}
];
};
;
}
```
This results in the following lua code:
```lua
require('lz.n').load({
{
"name-of-your-plugin",
after = function()
require('your-plugin').setup({--[[ your setupOpts ]]})
end,
event = {"DirChanged"},
cmd = {"YourPluginCommand"},
keys = {
{"<leader>d", ":YourPluginCommand", mode = {"n"}},
},
}
})
```
A full list of options can be found
[here](https://notashelf.github.io/nvf/options.html#opt-vim.lazy.plugins

View file

@ -123,6 +123,10 @@ To migrate to `nixfmt`, simply change `vim.languages.nix.format.type` to
recommended to go through rustacean.nvim's README to take a closer look at its recommended to go through rustacean.nvim's README to take a closer look at its
features and usage features and usage
- Add [lz.n] support and lazy-load some builtin plugins.
[lz.n]: https://github.com/mrcjkb/lz.n
[jacekpoz](https://jacekpoz.pl): [jacekpoz](https://jacekpoz.pl):
[ocaml-lsp]: https://github.com/ocaml/ocaml-lsp [ocaml-lsp]: https://github.com/ocaml/ocaml-lsp

View file

@ -892,6 +892,39 @@
"type": "github" "type": "github"
} }
}, },
"plugin-lz-n": {
"flake": false,
"locked": {
"lastModified": 1729525284,
"narHash": "sha256-fk+ejqcqqOQz3q4D3VB2Q+U/6wCpCDk1tiDMp2YrPNE=",
"owner": "nvim-neorocks",
"repo": "lz.n",
"rev": "ffd9991400ba7137f4fa8560ff50bccd7f8fb3ee",
"type": "github"
},
"original": {
"owner": "nvim-neorocks",
"repo": "lz.n",
"type": "github"
}
},
"plugin-lzn-auto-require": {
"flake": false,
"locked": {
"lastModified": 1727636949,
"narHash": "sha256-BAOzN+XOrFAJwHmsF8JtZ2EyjP9283FD/I2TbFqGSEw=",
"owner": "horriblename",
"repo": "lzn-auto-require",
"rev": "55ecd60831dac8c01d6f3dcb63a30a63a1690eb8",
"type": "github"
},
"original": {
"owner": "horriblename",
"ref": "require-rewrite",
"repo": "lzn-auto-require",
"type": "github"
}
},
"plugin-mind-nvim": { "plugin-mind-nvim": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -1629,6 +1662,22 @@
"type": "github" "type": "github"
} }
}, },
"plugin-rtp-nvim": {
"flake": false,
"locked": {
"lastModified": 1724409589,
"narHash": "sha256-lmJbiD7I7MTEEpukESs67uAmLyn+p66hrUKLbEHp0Kw=",
"owner": "nvim-neorocks",
"repo": "rtp.nvim",
"rev": "494ddfc888bb466555d90ace731856de1320fe45",
"type": "github"
},
"original": {
"owner": "nvim-neorocks",
"repo": "rtp.nvim",
"type": "github"
}
},
"plugin-rustaceanvim": { "plugin-rustaceanvim": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -1991,6 +2040,8 @@
"plugin-lua-utils-nvim": "plugin-lua-utils-nvim", "plugin-lua-utils-nvim": "plugin-lua-utils-nvim",
"plugin-lualine": "plugin-lualine", "plugin-lualine": "plugin-lualine",
"plugin-luasnip": "plugin-luasnip", "plugin-luasnip": "plugin-luasnip",
"plugin-lz-n": "plugin-lz-n",
"plugin-lzn-auto-require": "plugin-lzn-auto-require",
"plugin-mind-nvim": "plugin-mind-nvim", "plugin-mind-nvim": "plugin-mind-nvim",
"plugin-minimap-vim": "plugin-minimap-vim", "plugin-minimap-vim": "plugin-minimap-vim",
"plugin-modes-nvim": "plugin-modes-nvim", "plugin-modes-nvim": "plugin-modes-nvim",
@ -2037,6 +2088,7 @@
"plugin-project-nvim": "plugin-project-nvim", "plugin-project-nvim": "plugin-project-nvim",
"plugin-registers": "plugin-registers", "plugin-registers": "plugin-registers",
"plugin-rose-pine": "plugin-rose-pine", "plugin-rose-pine": "plugin-rose-pine",
"plugin-rtp-nvim": "plugin-rtp-nvim",
"plugin-rustaceanvim": "plugin-rustaceanvim", "plugin-rustaceanvim": "plugin-rustaceanvim",
"plugin-scrollbar-nvim": "plugin-scrollbar-nvim", "plugin-scrollbar-nvim": "plugin-scrollbar-nvim",
"plugin-smartcolumn": "plugin-smartcolumn", "plugin-smartcolumn": "plugin-smartcolumn",

View file

@ -113,6 +113,22 @@
}; };
## Plugins ## Plugins
# Lazy loading
plugin-lz-n = {
url = "github:nvim-neorocks/lz.n";
flake = false;
};
plugin-lzn-auto-require = {
url = "github:horriblename/lzn-auto-require/require-rewrite";
flake = false;
};
plugin-rtp-nvim = {
url = "github:nvim-neorocks/rtp.nvim";
flake = false;
};
# LSP plugins # LSP plugins
plugin-nvim-lspconfig = { plugin-nvim-lspconfig = {
url = "github:neovim/nvim-lspconfig"; url = "github:neovim/nvim-lspconfig";

View file

@ -67,6 +67,30 @@
mkLuaBinding binding.value action binding.description; mkLuaBinding binding.value action binding.description;
pushDownDefault = attr: mapAttrs (_: mkDefault) attr; pushDownDefault = attr: mapAttrs (_: mkDefault) attr;
mkLznBinding = mode: key: action: desc: {
inherit mode desc key action;
};
mkLznExprBinding = mode: key: action: desc: {
inherit mode desc key action;
lua = true;
silent = true;
expr = true;
};
mkSetLznBinding = binding: action: {
inherit action;
key = binding.value;
desc = binding.description;
};
mkSetLuaLznBinding = binding: action: {
inherit action;
key = binding.value;
lua = true;
desc = binding.description;
};
}; };
in in
binds binds

View file

@ -84,10 +84,7 @@
# built (or "normalized") plugins that are modified # built (or "normalized") plugins that are modified
builtStartPlugins = buildConfigPlugins vimOptions.startPlugins; builtStartPlugins = buildConfigPlugins vimOptions.startPlugins;
builtOptPlugins = map (package: { builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins);
plugin = package;
optional = true;
}) (buildConfigPlugins vimOptions.optPlugins);
# additional Lua and Python3 packages, mapped to their respective functions # additional Lua and Python3 packages, mapped to their respective functions
# to conform to the format mnw expects. end user should # to conform to the format mnw expects. end user should

View file

@ -50,6 +50,7 @@
"build" "build"
"rc" "rc"
"warnings" "warnings"
"lazy"
]; ];
# Extra modules, such as deprecation warnings # Extra modules, such as deprecation warnings

View file

@ -4,11 +4,8 @@
... ...
}: let }: let
inherit (builtins) toJSON; inherit (builtins) toJSON;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.modules) mkIf;
inherit (lib.modules) mkIf mkMerge; inherit (lib.strings) optionalString;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.lists) optionals;
inherit (lib.nvim.binds) mkLuaBinding;
cfg = config.vim.assistant.copilot; cfg = config.vim.assistant.copilot;
@ -23,65 +20,68 @@
end end
end end
''; '';
mkLuaKeymap = mode: key: action: desc: opts:
opts
// {
inherit mode key action desc;
lua = true;
};
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = vim = {
[ lazy.plugins = {
"copilot-lua" copilot-lua = {
# cfg.copilotNodePackage package = "copilot-lua";
] setupModule = "copilot";
++ optionals cfg.cmp.enable [ inherit (cfg) setupOpts;
"copilot-cmp" after = mkIf cfg.cmp.enable "require('copilot_cmp').setup()";
];
vim.autocomplete.nvim-cmp.sources = {copilot = "[Copilot]";}; cmd = ["Copilot" "CopilotAuth" "CopilotDetach" "CopilotPanel" "CopilotStop"];
keys = [
(mkLuaKeymap ["n"] cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion" {})
(mkLuaKeymap ["n"] cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion" {})
(mkLuaKeymap ["n"] cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion" {})
(mkLuaKeymap ["n"] cfg.mappings.panel.refresh (wrapPanelBinding "require(\"copilot.panel\").refresh" cfg.mappings.panel.refresh) "[copilot] Accept suggestion" {})
(mkLuaKeymap ["n"] cfg.mappings.panel.open (wrapPanelBinding ''
function() require("copilot.panel").open({ position = "${cfg.setupOpts.panel.layout.position}", ratio = ${toString cfg.setupOpts.panel.layout.ratio}, }) end
''
cfg.mappings.panel.open) "[copilot] Accept suggestion" {})
vim.pluginRC.copilot = entryAnywhere '' (mkLuaKeymap ["i"] cfg.mappings.suggestion.accept "function() require('copilot.suggestion').accept() end" "[copilot] Accept suggestion" {})
require("copilot").setup(${toLuaObject cfg.setupOpts}) (mkLuaKeymap ["i"] cfg.mappings.suggestion.acceptLine "function() require('copilot.suggestion').accept_line() end" "[copilot] Accept suggestion (line)" {})
(mkLuaKeymap ["i"] cfg.mappings.suggestion.acceptWord "function() require('copilot.suggestion').accept_word() end" "[copilot] Accept suggestion (word)" {})
${lib.optionalString cfg.cmp.enable '' (mkLuaKeymap ["i"] cfg.mappings.suggestion.dismiss "function() require('copilot.suggestion').dismiss() end" "[copilot] dismiss suggestion" {})
require("copilot_cmp").setup() (mkLuaKeymap ["i"] cfg.mappings.suggestion.next "function() require('copilot.suggestion').next() end" "[copilot] next suggestion" {})
''} (mkLuaKeymap ["i"] cfg.mappings.suggestion.prev "function() require('copilot.suggestion').prev() end" "[copilot] previous suggestion" {})
''; ];
};
# Disable plugin handled keymaps.
# Setting it here so that it doesn't show up in user docs
vim.assistant.copilot.setupOpts = {
panel.keymap = {
jump_prev = lib.mkDefault false;
jump_next = lib.mkDefault false;
accept = lib.mkDefault false;
refresh = lib.mkDefault false;
open = lib.mkDefault false;
}; };
suggestion.keymap = {
accept = lib.mkDefault false; autocomplete.nvim-cmp = {
accept_word = lib.mkDefault false; sources = {copilot = "[Copilot]";};
accept_line = lib.mkDefault false; sourcePlugins = ["copilot-cmp"];
next = lib.mkDefault false; };
prev = lib.mkDefault false;
dismiss = lib.mkDefault false; # Disable plugin handled keymaps.
# Setting it here so that it doesn't show up in user docs
assistant.copilot.setupOpts = {
panel.keymap = {
jump_prev = lib.mkDefault false;
jump_next = lib.mkDefault false;
accept = lib.mkDefault false;
refresh = lib.mkDefault false;
open = lib.mkDefault false;
};
suggestion.keymap = {
accept = lib.mkDefault false;
accept_word = lib.mkDefault false;
accept_line = lib.mkDefault false;
next = lib.mkDefault false;
prev = lib.mkDefault false;
dismiss = lib.mkDefault false;
};
}; };
}; };
vim.maps.normal = mkMerge [
(mkLuaBinding cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion")
(mkLuaBinding cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion")
(mkLuaBinding cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion")
(mkLuaBinding cfg.mappings.panel.refresh (wrapPanelBinding "require(\"copilot.panel\").refresh" cfg.mappings.panel.refresh) "[copilot] Accept suggestion")
(mkLuaBinding cfg.mappings.panel.open (wrapPanelBinding ''
function() require("copilot.panel").open({ position = "${cfg.setupOpts.panel.layout.position}", ratio = ${toString cfg.setupOpts.panel.layout.ratio}, }) end
''
cfg.mappings.panel.open) "[copilot] Accept suggestion")
];
vim.maps.insert = mkMerge [
(mkLuaBinding cfg.mappings.suggestion.accept "require(\"copilot.suggestion\").accept" "[copilot] Accept suggestion")
(mkLuaBinding cfg.mappings.suggestion.acceptLine "require(\"copilot.suggestion\").accept_line" "[copilot] Accept suggestion (line)")
(mkLuaBinding cfg.mappings.suggestion.acceptWord "require(\"copilot.suggestion\").accept_word" "[copilot] Accept suggestion (word)")
(mkLuaBinding cfg.mappings.suggestion.next "require(\"copilot.suggestion\").next" "[copilot] next suggestion")
(mkLuaBinding cfg.mappings.suggestion.prev "require(\"copilot.suggestion\").prev" "[copilot] previous suggestion")
(mkLuaBinding cfg.mappings.suggestion.dismiss "require(\"copilot.suggestion\").dismiss" "[copilot] dismiss suggestion")
];
}; };
} }

View file

@ -1,6 +1,7 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkEnableOption; inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption;
in { in {
options.vim.comments.comment-nvim = { options.vim.comments.comment-nvim = {
enable = mkEnableOption "smart and powerful comment plugin for neovim comment-nvim"; enable = mkEnableOption "smart and powerful comment plugin for neovim comment-nvim";
@ -15,5 +16,12 @@ in {
toggleSelectedLine = mkMappingOption "Toggle selected comment" "gc"; toggleSelectedLine = mkMappingOption "Toggle selected comment" "gc";
toggleSelectedBlock = mkMappingOption "Toggle selected block" "gb"; toggleSelectedBlock = mkMappingOption "Toggle selected block" "gb";
}; };
setupOpts = mkPluginSetupOption "Comment-nvim" {
mappings = {
basic = mkEnableOption "basic mappings";
extra = mkEnableOption "extra mappings";
};
};
}; };
} }

View file

@ -3,9 +3,8 @@
lib, lib,
... ...
}: let }: let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) mkExprBinding mkBinding; inherit (lib.nvim.binds) mkLznExprBinding mkLznBinding;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.comments.comment-nvim; cfg = config.vim.comments.comment-nvim;
self = import ./comment-nvim.nix {inherit lib;}; self = import ./comment-nvim.nix {inherit lib;};
@ -14,35 +13,30 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = ["comment-nvim"]; vim.startPlugins = ["comment-nvim"];
vim.maps.normal = mkMerge [ vim.lazy.plugins.comment-nvim = {
(mkBinding cfg.mappings.toggleOpLeaderLine "<Plug>(comment_toggle_linewise)" mappings.toggleOpLeaderLine.description) package = "comment-nvim";
(mkBinding cfg.mappings.toggleOpLeaderBlock "<Plug>(comment_toggle_blockwise)" mappings.toggleOpLeaderBlock.description) setupModule = "Comment";
inherit (cfg) setupOpts;
(mkExprBinding cfg.mappings.toggleCurrentLine '' keys = [
function() (mkLznBinding ["n"] cfg.mappings.toggleOpLeaderLine "<Plug>(comment_toggle_linewise)" mappings.toggleOpLeaderLine.description)
return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)' (mkLznBinding ["n"] cfg.mappings.toggleOpLeaderBlock "<Plug>(comment_toggle_blockwise)" mappings.toggleOpLeaderBlock.description)
or '<Plug>(comment_toggle_linewise_count)' (mkLznExprBinding ["n"] cfg.mappings.toggleCurrentLine ''
end function()
'' return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)'
mappings.toggleCurrentLine.description) or '<Plug>(comment_toggle_linewise_count)'
(mkExprBinding cfg.mappings.toggleCurrentBlock '' end
function() ''
return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_blockwise_current)' mappings.toggleCurrentLine.description)
or '<Plug>(comment_toggle_blockwise_count)' (mkLznExprBinding ["n"] cfg.mappings.toggleCurrentBlock ''
end function()
'' return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_blockwise_current)'
mappings.toggleCurrentBlock.description) or '<Plug>(comment_toggle_blockwise_count)'
]; end
''
vim.maps.visual = mkMerge [ mappings.toggleCurrentBlock.description)
(mkBinding cfg.mappings.toggleSelectedLine "<Plug>(comment_toggle_linewise_visual)" mappings.toggleSelectedLine.description) (mkLznBinding ["x"] cfg.mappings.toggleSelectedLine "<Plug>(comment_toggle_linewise_visual)" mappings.toggleSelectedLine.description)
(mkBinding cfg.mappings.toggleSelectedBlock "<Plug>(comment_toggle_blockwise_visual)" mappings.toggleSelectedBlock.description) (mkLznBinding ["x"] cfg.mappings.toggleSelectedBlock "<Plug>(comment_toggle_blockwise_visual)" mappings.toggleSelectedBlock.description)
]; ];
};
vim.pluginRC.comment-nvim = entryAnywhere ''
require('Comment').setup({
mappings = { basic = false, extra = false, },
})
'';
}; };
} }

View file

@ -3,91 +3,122 @@
config, config,
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf mkMerge;
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.dag) entryAfter;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (builtins) attrNames; inherit (lib.nvim.attrsets) mapListToAttrs;
inherit (builtins) attrNames typeOf tryEval concatStringsSep;
cfg = config.vim.autocomplete.nvim-cmp; cfg = config.vim.autocomplete.nvim-cmp;
luasnipEnable = config.vim.snippets.luasnip.enable; luasnipEnable = config.vim.snippets.luasnip.enable;
getPluginName = plugin:
if typeOf plugin == "string"
then plugin
else if (plugin ? pname && (tryEval plugin.pname).success)
then plugin.pname
else plugin.name;
inherit (cfg) mappings; inherit (cfg) mappings;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim = {
startPlugins = [ startPlugins = ["rtp-nvim"];
"nvim-cmp" lazy.plugins = mkMerge [
"cmp-buffer" (mapListToAttrs (package: {
"cmp-path" name = getPluginName package;
value = {
inherit package;
lazy = true;
after = ''
local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/${getPluginName package}')
require("rtp_nvim").source_after_plugin_dir(path)
'';
};
})
cfg.sourcePlugins)
{
nvim-cmp = {
package = "nvim-cmp";
after = ''
${optionalString luasnipEnable "local luasnip = require('luasnip')"}
require("lz.n").trigger_load("cmp-path")
local cmp = require("cmp")
cmp.setup(${toLuaObject cfg.setupOpts})
${concatStringsSep "\n" (map
(package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})")
cfg.sourcePlugins)}
'';
event = ["InsertEnter" "CmdlineEnter"];
};
}
]; ];
autocomplete.nvim-cmp.sources = { autocomplete.nvim-cmp = {
nvim-cmp = null; sources = {
buffer = "[Buffer]"; nvim-cmp = null;
path = "[Path]"; buffer = "[Buffer]";
}; path = "[Path]";
autocomplete.nvim-cmp.setupOpts = {
sources = map (s: {name = s;}) (attrNames cfg.sources);
# TODO: try to get nvim-cmp to follow global border style
window = mkIf config.vim.ui.borders.enable {
completion = mkLuaInline "cmp.config.window.bordered()";
documentation = mkLuaInline "cmp.config.window.bordered()";
}; };
formatting.format = cfg.format; sourcePlugins = ["cmp-buffer" "cmp-path"];
};
pluginRC.nvim-cmp = mkIf cfg.enable (entryAfter ["autopairs" "luasnip"] '' setupOpts = {
${optionalString luasnipEnable "local luasnip = require('luasnip')"} sources = map (s: {name = s;}) (attrNames cfg.sources);
local cmp = require("cmp")
cmp.setup(${toLuaObject cfg.setupOpts})
'');
# `cmp` and `luasnip` are defined above, in the `nvim-cmp` section # TODO: try to get nvim-cmp to follow global border style
autocomplete.nvim-cmp.setupOpts.mapping = { window = mkIf config.vim.ui.borders.enable {
${mappings.complete} = mkLuaInline "cmp.mapping.complete()"; completion = mkLuaInline "cmp.config.window.bordered()";
${mappings.close} = mkLuaInline "cmp.mapping.abort()"; documentation = mkLuaInline "cmp.config.window.bordered()";
${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)"; };
${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)";
${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })";
${mappings.next} = mkLuaInline '' formatting.format = cfg.format;
cmp.mapping(function(fallback) };
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
if cmp.visible() then # `cmp` and `luasnip` are defined above, in the `nvim-cmp` section
cmp.select_next_item() setupOpts.mapping = {
${optionalString luasnipEnable '' ${mappings.complete} = mkLuaInline "cmp.mapping.complete()";
elseif luasnip.locally_jumpable(1) then ${mappings.close} = mkLuaInline "cmp.mapping.abort()";
luasnip.jump(1) ${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)";
''} ${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)";
elseif has_words_before() then ${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })";
cmp.complete()
else
fallback()
end
end)
'';
${mappings.previous} = mkLuaInline '' ${mappings.next} = mkLuaInline ''
cmp.mapping(function(fallback) cmp.mapping(function(fallback)
if cmp.visible() then local has_words_before = function()
cmp.select_prev_item() local line, col = unpack(vim.api.nvim_win_get_cursor(0))
${optionalString luasnipEnable '' return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
elseif luasnip.locally_jumpable(-1) then end
luasnip.jump(-1)
''} if cmp.visible() then
else cmp.select_next_item()
fallback() ${optionalString luasnipEnable ''
end elseif luasnip.locally_jumpable(1) then
end) luasnip.jump(1)
''; ''}
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end)
'';
${mappings.previous} = mkLuaInline ''
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
${optionalString luasnipEnable ''
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
''}
else
fallback()
end
end)
'';
};
}; };
}; };
}; };

View file

@ -4,10 +4,10 @@
... ...
}: let }: let
inherit (lib.options) mkEnableOption mkOption literalExpression literalMD; inherit (lib.options) mkEnableOption mkOption literalExpression literalMD;
inherit (lib.types) str attrsOf nullOr either; inherit (lib.types) str attrsOf nullOr either listOf;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf; inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf pluginType;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (builtins) isString; inherit (builtins) isString;
@ -99,5 +99,11 @@ in {
} }
''; '';
}; };
sourcePlugins = mkOption {
type = listOf pluginType;
default = [];
description = "List of source plugins used by nvim-cmp.";
};
}; };
} }

View file

@ -6,7 +6,7 @@
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.attrsets) mapAttrs; inherit (lib.attrsets) mapAttrs;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding; inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding mkSetLuaLznBinding;
inherit (lib.nvim.dag) entryAnywhere entryAfter; inherit (lib.nvim.dag) entryAnywhere entryAfter;
cfg = config.vim.debugger.nvim-dap; cfg = config.vim.debugger.nvim-dap;
@ -52,24 +52,31 @@ in {
}) })
(mkIf (cfg.enable && cfg.ui.enable) { (mkIf (cfg.enable && cfg.ui.enable) {
vim = { vim = {
startPlugins = ["nvim-dap-ui" "nvim-nio"]; startPlugins = ["nvim-nio"];
pluginRC.nvim-dap-ui = entryAfter ["nvim-dap"] ('' lazy.plugins.nvim-dap-ui = {
local dapui = require("dapui") package = "nvim-dap-ui";
dapui.setup() setupModule = "dapui";
'' inherit (cfg.ui) setupOpts;
+ optionalString cfg.ui.autoStart ''
keys = [
(mkSetLuaLznBinding mappings.toggleDapUI "function() require('dapui').toggle() end")
];
};
pluginRC.nvim-dap-ui = entryAfter ["nvim-dap"] (
optionalString cfg.ui.autoStart ''
dap.listeners.after.event_initialized["dapui_config"] = function() dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open() require("dapui").open()
end end
dap.listeners.before.event_terminated["dapui_config"] = function() dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close() require("dapui").close()
end end
dap.listeners.before.event_exited["dapui_config"] = function() dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close() require("dapui").close()
end end
''); ''
maps.normal = mkSetLuaBinding mappings.toggleDapUI "require('dapui').toggle"; );
}; };
}) })
]; ];

View file

@ -2,12 +2,16 @@
inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) bool attrsOf str; inherit (lib.types) bool attrsOf str;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption;
in { in {
options.vim.debugger.nvim-dap = { options.vim.debugger.nvim-dap = {
enable = mkEnableOption "debugging via nvim-dap"; enable = mkEnableOption "debugging via nvim-dap";
ui = { ui = {
enable = mkEnableOption "UI extension for nvim-dap"; enable = mkEnableOption "UI extension for nvim-dap";
setupOpts = mkPluginSetupOption "nvim-dap-ui" {};
autoStart = mkOption { autoStart = mkOption {
type = bool; type = bool;
default = true; default = true;

View file

@ -4,8 +4,6 @@
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.filetree.neo-tree; cfg = config.vim.filetree.neo-tree;
in { in {
@ -16,15 +14,17 @@ in {
"plenary-nvim" # commons library "plenary-nvim" # commons library
"image-nvim" # optional for image previews "image-nvim" # optional for image previews
"nui-nvim" # ui library "nui-nvim" # ui library
# neotree
"neo-tree-nvim"
]; ];
visuals.nvimWebDevicons.enable = true; lazy.plugins.neo-tree-nvim = {
package = "neo-tree-nvim";
setupModule = "neo-tree";
inherit (cfg) setupOpts;
pluginRC.neo-tree = entryAnywhere '' cmd = ["Neotree"];
require("neo-tree").setup(${toLuaObject cfg.setupOpts}) };
'';
visuals.nvimWebDevicons.enable = true;
}; };
}; };
} }

View file

@ -5,10 +5,9 @@
... ...
}: let }: let
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) mkBinding; inherit (lib.nvim.binds) mkLznBinding;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.binds) pushDownDefault; inherit (lib.nvim.binds) pushDownDefault;
cfg = config.vim.filetree.nvimTree; cfg = config.vim.filetree.nvimTree;
@ -16,69 +15,74 @@
inherit (self.options.vim.filetree.nvimTree) mappings; inherit (self.options.vim.filetree.nvimTree) mappings;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = ["nvim-tree-lua"]; vim = {
binds.whichKey.register = pushDownDefault {
"<leader>t" = "+NvimTree";
};
vim.maps.normal = mkMerge [ lazy.plugins.nvim-tree-lua = {
(mkBinding cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description) package = "nvim-tree-lua";
(mkBinding cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description) setupModule = "nvim-tree";
(mkBinding cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description) inherit (cfg) setupOpts;
(mkBinding cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description) cmd = ["NvimTreeClipboard" "NvimTreeClose" "NvimTreeCollapse" "NvimTreeCollapseKeepBuffers" "NvimTreeFindFile" "NvimTreeFindFileToggle" "NvimTreeFocus" "NvimTreeHiTest" "NvimTreeOpen" "NvimTreeRefresh" "NvimTreeResize" "NvimTreeToggle"];
]; keys = [
(mkLznBinding ["n"] cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description)
(mkLznBinding ["n"] cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description)
(mkLznBinding ["n"] cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description)
(mkLznBinding ["n"] cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description)
];
};
vim.binds.whichKey.register = pushDownDefault { pluginRC.nvimtreelua = entryAnywhere ''
"<leader>t" = "+NvimTree"; ${
optionalString cfg.setupOpts.disable_netrw ''
-- disable netrew completely
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
''
}
${
optionalString cfg.openOnSetup ''
${optionalString config.vim.lazy.enable ''require('lz.n').trigger_load("nvim-tree-lua")''}
-- autostart behaviour
-- Open on startup has been deprecated
-- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup
-- use a nix eval to dynamically insert the open on startup function
local function open_nvim_tree(data)
local IGNORED_FT = {
"markdown",
}
-- buffer is a real file on the disk
local real_file = vim.fn.filereadable(data.file) == 1
-- buffer is a [No Name]
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
-- &ft
local filetype = vim.bo[data.buf].ft
-- only files please
if not real_file and not no_name then
return
end
-- skip ignored filetypes
if vim.tbl_contains(IGNORED_FT, filetype) then
return
end
-- open the tree but don't focus it
require("nvim-tree.api").tree.toggle({ focus = false })
end
-- function to automatically open the tree on VimEnter
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
''
}
'';
}; };
vim.pluginRC.nvimtreelua = entryAnywhere ''
${
optionalString cfg.setupOpts.disable_netrw ''
-- disable netrew completely
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
''
}
require'nvim-tree'.setup(${toLuaObject cfg.setupOpts})
${
optionalString cfg.openOnSetup ''
-- autostart behaviour
-- Open on startup has been deprecated
-- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup
-- use a nix eval to dynamically insert the open on startup function
local function open_nvim_tree(data)
local IGNORED_FT = {
"markdown",
}
-- buffer is a real file on the disk
local real_file = vim.fn.filereadable(data.file) == 1
-- buffer is a [No Name]
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
-- &ft
local filetype = vim.bo[data.buf].ft
-- only files please
if not real_file and not no_name then
return
end
-- skip ignored filetypes
if vim.tbl_contains(IGNORED_FT, filetype) then
return
end
-- open the tree but don't focus it
require("nvim-tree.api").tree.toggle({ focus = false })
end
-- function to automatically open the tree on VimEnter
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
''
}
'';
}; };
} }

View file

@ -5,7 +5,6 @@
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.lists) optional;
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.trivial) boolToString; inherit (lib.trivial) boolToString;
inherit (lib.nvim.binds) addDescriptionsToMappings; inherit (lib.nvim.binds) addDescriptionsToMappings;
@ -23,9 +22,10 @@
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim = {
startPlugins = optional usingNvimCmp "cmp-nvim-lsp"; autocomplete.nvim-cmp = {
sources = {nvim_lsp = "[LSP]";};
autocomplete.nvim-cmp.sources = {nvim_lsp = "[LSP]";}; sourcePlugins = ["cmp-nvim-lsp"];
};
pluginRC.lsp-setup = '' pluginRC.lsp-setup = ''
vim.g.formatsave = ${boolToString cfg.formatOnSave}; vim.g.formatsave = ${boolToString cfg.formatOnSave};
@ -116,7 +116,7 @@ in {
end end
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
${optionalString usingNvimCmp "capabilities = require('cmp_nvim_lsp').default_capabilities()"} -- ${optionalString usingNvimCmp "capabilities = require('cmp_nvim_lsp').default_capabilities()"}
''; '';
}; };
}; };

View file

@ -1,41 +1,40 @@
{ {
config, config,
lib, lib,
options,
... ...
}: let }: let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLznBinding pushDownDefault;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding pushDownDefault;
cfg = config.vim.lsp; cfg = config.vim.lsp;
self = import ./trouble.nix {inherit lib;}; mappingDefinitions = options.vim.lsp.trouble.mappings;
mappingDefinitions = self.options.vim.lsp.trouble.mappings;
mappings = addDescriptionsToMappings cfg.trouble.mappings mappingDefinitions; mappings = addDescriptionsToMappings cfg.trouble.mappings mappingDefinitions;
in { in {
config = mkIf (cfg.enable && cfg.trouble.enable) { config = mkIf (cfg.enable && cfg.trouble.enable) {
vim = { vim = {
startPlugins = ["trouble"]; lazy.plugins.trouble = {
package = "trouble";
setupModule = "trouble";
inherit (cfg.trouble) setupOpts;
maps.normal = mkMerge [ cmd = "Trouble";
(mkSetBinding mappings.toggle "<cmd>TroubleToggle<CR>") keys = [
(mkSetBinding mappings.workspaceDiagnostics "<cmd>TroubleToggle workspace_diagnostics<CR>") (mkSetLznBinding mappings.toggle "<cmd>TroubleToggle<CR>")
(mkSetBinding mappings.documentDiagnostics "<cmd>TroubleToggle document_diagnostics<CR>") (mkSetLznBinding mappings.workspaceDiagnostics "<cmd>TroubleToggle workspace_diagnostics<CR>")
(mkSetBinding mappings.lspReferences "<cmd>TroubleToggle lsp_references<CR>") (mkSetLznBinding mappings.documentDiagnostics "<cmd>TroubleToggle document_diagnostics<CR>")
(mkSetBinding mappings.quickfix "<cmd>TroubleToggle quickfix<CR>") (mkSetLznBinding mappings.lspReferences "<cmd>TroubleToggle lsp_references<CR>")
(mkSetBinding mappings.locList "<cmd>TroubleToggle loclist<CR>") (mkSetLznBinding mappings.quickfix "<cmd>TroubleToggle quickfix<CR>")
]; (mkSetLznBinding mappings.locList "<cmd>TroubleToggle loclist<CR>")
];
};
binds.whichKey.register = pushDownDefault { binds.whichKey.register = pushDownDefault {
"<leader>l" = "Trouble"; "<leader>l" = "Trouble";
"<leader>x" = "+Trouble"; "<leader>x" = "+Trouble";
"<leader>lw" = "Workspace"; "<leader>lw" = "Workspace";
}; };
pluginRC.trouble = entryAnywhere ''
-- Enable trouble diagnostics viewer
require("trouble").setup {}
'';
}; };
}; };
} }

View file

@ -1,11 +1,14 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkEnableOption; inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption;
in { in {
options.vim.lsp = { options.vim.lsp = {
trouble = { trouble = {
enable = mkEnableOption "trouble diagnostics viewer"; enable = mkEnableOption "trouble diagnostics viewer";
setupOpts = mkPluginSetupOption "Trouble" {};
mappings = { mappings = {
toggle = mkMappingOption "Toggle trouble [trouble]" "<leader>xx"; toggle = mkMappingOption "Toggle trouble [trouble]" "<leader>xx";
workspaceDiagnostics = mkMappingOption "Workspace diagnostics [trouble]" "<leader>lwd"; workspaceDiagnostics = mkMappingOption "Workspace diagnostics [trouble]" "<leader>lwd";

View file

@ -9,9 +9,18 @@
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim = {
startPlugins = ["luasnip" "cmp-luasnip"] ++ cfg.providers; lazy.plugins = {
autocomplete.nvim-cmp.sources = {luasnip = "[LuaSnip]";}; luasnip = {
pluginRC.luasnip = cfg.loaders; package = "luasnip";
lazy = true;
after = cfg.loaders;
};
};
startPlugins = cfg.providers;
autocomplete.nvim-cmp = {
sources = {luasnip = "[LuaSnip]";};
sourcePlugins = ["cmp-luasnip"];
};
}; };
}; };
} }

View file

@ -3,39 +3,31 @@
lib, lib,
... ...
}: let }: let
inherit (builtins) toJSON; inherit (lib.strings) optionalString;
inherit (lib.lists) optionals; inherit (lib.lists) optional;
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf;
inherit (lib.meta) getExe; inherit (lib.meta) getExe;
inherit (lib.nvim.binds) mkBinding; inherit (lib.nvim.binds) mkLznBinding;
inherit (lib.nvim.dag) entryAnywhere entryAfter;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.terminal.toggleterm; cfg = config.vim.terminal.toggleterm;
lazygitMapDesc = "Open lazygit [toggleterm]";
in { in {
config = mkMerge [ config = mkIf cfg.enable {
( vim = {
mkIf cfg.enable { lazy.plugins.toggleterm-nvim = {
vim = { package = "toggleterm-nvim";
startPlugins = [ cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"];
"toggleterm-nvim" keys =
]; [(mkLznBinding ["n"] cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal")]
++ optional cfg.lazygit.enable {
key = cfg.lazygit.mappings.open;
desc = lazygitMapDesc;
};
maps.normal = mkBinding cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal"; setupModule = "toggleterm";
inherit (cfg) setupOpts;
pluginRC.toggleterm = entryAnywhere '' after = optionalString cfg.lazygit.enable ''
require("toggleterm").setup(${toLuaObject cfg.setupOpts})
'';
};
}
)
(
mkIf (cfg.enable && cfg.lazygit.enable)
{
vim.startPlugins = optionals (cfg.lazygit.package != null) [
cfg.lazygit.package
];
vim.pluginRC.toggleterm-lazygit = entryAfter ["toggleterm"] ''
local terminal = require 'toggleterm.terminal' local terminal = require 'toggleterm.terminal'
local lazygit = terminal.Terminal:new({ local lazygit = terminal.Terminal:new({
cmd = '${ cmd = '${
@ -50,9 +42,9 @@ in {
end end
}) })
vim.keymap.set('n', ${toJSON cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = 'Open lazygit [toggleterm]'}) vim.keymap.set('n', ${toLuaObject cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'})
''; '';
} };
) };
]; };
} }

View file

@ -5,7 +5,7 @@
... ...
}: let }: let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) optional optionals; inherit (lib.lists) optionals;
inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings; inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.dag) entryBefore entryAfter; inherit (lib.nvim.dag) entryBefore entryAfter;
@ -19,9 +19,24 @@
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim = {
startPlugins = ["nvim-treesitter"] ++ optional usingNvimCmp "cmp-treesitter"; startPlugins = ["nvim-treesitter"];
lazy.plugins = {
cmp-treesitter = mkIf usingNvimCmp {
package = "cmp-treesitter";
after = ''
local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/cmp-treesitter')
require("rtp_nvim").source_after_plugin_dir(path)
'';
};
nvim-cmp.after = mkIf usingNvimCmp "require('lz.n').trigger_load('cmp-treesitter')";
};
autocomplete.nvim-cmp = {
sources = {treesitter = "[Treesitter]";};
sourcePlugins = ["cmp-treesitter"];
};
autocomplete.nvim-cmp.sources = {treesitter = "[Treesitter]";};
treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars; treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars;
maps = { maps = {

View file

@ -4,15 +4,18 @@
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.strings) optionalString;
cfg = config.vim.binds.cheatsheet; cfg = config.vim.binds.cheatsheet;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = ["cheatsheet-nvim"]; vim.lazy.plugins.cheatsheet-nvim = {
package = "cheatsheet-nvim";
setupModule = "cheatsheet";
setupOpts = {};
cmd = ["Cheatsheet" "CheatsheetEdit"];
vim.pluginRC.cheaetsheet-nvim = entryAnywhere '' before = optionalString config.vim.lazy.enable "require('lz.n').trigger_load('telescope')";
require('cheatsheet').setup({}) };
'';
}; };
} }

View file

@ -8,9 +8,14 @@
cfg = config.vim.utility.diffview-nvim; cfg = config.vim.utility.diffview-nvim;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = [ vim = {
"diffview-nvim" startPlugins = ["plenary-nvim"];
"plenary-nvim" lazy.plugins.diffview-nvim = {
]; package = "diffview-nvim";
cmd = ["DiffviewClose" "DiffviewFileHistory" "DiffviewFocusFiles" "DiffviewLog" "DiffviewOpen" "DiffviewRefresh" "DiffviewToggleFiles"];
setupModule = "diffview";
inherit (cfg) setupOpts;
};
};
}; };
} }

View file

@ -1,7 +1,9 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkEnableOption; inherit (lib.options) mkEnableOption;
inherit (lib.nvim.types) mkPluginSetupOption;
in { in {
options.vim.utility.diffview-nvim = { options.vim.utility.diffview-nvim = {
enable = mkEnableOption "diffview-nvim: cycle through diffs for all modified files for any git rev"; enable = mkEnableOption "diffview-nvim: cycle through diffs for all modified files for any git rev";
setupOpts = mkPluginSetupOption "Fidget" {};
}; };
} }

View file

@ -4,20 +4,20 @@
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.utility.icon-picker; cfg = config.vim.utility.icon-picker;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = [ vim.startPlugins = ["dressing-nvim"];
"icon-picker-nvim"
"dressing-nvim"
];
vim.pluginRC.icon-picker = entryAnywhere '' vim.lazy.plugins.icon-picker-nvim = {
require("icon-picker").setup({ package = "icon-picker-nvim";
disable_legacy_commands = true setupModule = "icon-picker";
}) setupOpts = {
''; disable_legacy_commands = true;
};
cmd = ["IconPickerInsert" "IconPickerNormal" "IconPickerYank"];
};
}; };
} }

View file

@ -3,73 +3,59 @@
lib, lib,
... ...
}: let }: let
inherit (lib.modules) mkIf mkMerge mkDefault; inherit (lib.modules) mkIf mkDefault;
inherit (lib.nvim.binds) mkBinding; inherit (lib.nvim.binds) mkLznBinding;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.utility.motion.leap; cfg = config.vim.utility.motion.leap;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = [ vim = {
"leap-nvim" startPlugins = ["vim-repeat"];
"vim-repeat" lazy.plugins.leap-nvim = {
]; package = "leap-nvim";
keys = [
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapForwardTo "<Plug>(leap-forward-to)" "Leap forward to")
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapBackwardTo "<Plug>(leap-backward-to)" "Leap backward to")
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapForwardTill "<Plug>(leap-forward-till)" "Leap forward till")
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapBackwardTill "<Plug>(leap-backward-till)" "Leap backward till")
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapFromWindow "<Plug>(leap-from-window)" "Leap from window")
];
vim.maps.normal = mkMerge [ after = ''
(mkBinding cfg.mappings.leapForwardTo "<Plug>(leap-forward-to)" "Leap forward to") require('leap').opts = {
(mkBinding cfg.mappings.leapBackwardTo "<Plug>(leap-backward-to)" "Leap backward to") max_phase_one_targets = nil,
(mkBinding cfg.mappings.leapFromWindow "<Plug>(leap-from-window)" "Leap from window") highlight_unlabeled_phase_one_targets = false,
]; max_highlighted_traversal_targets = 10,
case_sensitive = false,
equivalence_classes = { ' \t\r\n', },
substitute_chars = {},
safe_labels = {
"s", "f", "n", "u", "t", "/",
"S", "F", "N", "L", "H", "M", "U", "G", "T", "?", "Z"
},
labels = {
"s", "f", "n",
"j", "k", "l", "h", "o", "d", "w", "e", "m", "b",
"u", "y", "v", "r", "g", "t", "c", "x", "/", "z",
"S", "F", "N",
"J", "K", "L", "H", "O", "D", "W", "E", "M", "B",
"U", "Y", "V", "R", "G", "T", "C", "X", "?", "Z"
},
special_keys = {
repeat_search = '<enter>',
next_phase_one_target = '<enter>',
next_target = {'<enter>', ';'},
prev_target = {'<tab>', ','},
next_group = '<space>',
prev_group = '<tab>',
multi_accept = '<enter>',
multi_revert = '<backspace>',
},
}
'';
};
vim.maps.operator = mkMerge [ binds.whichKey.register."<leader>s" = mkDefault "+Leap";
(mkBinding cfg.mappings.leapForwardTo "<Plug>(leap-forward-to)" "Leap forward to") };
(mkBinding cfg.mappings.leapBackwardTo "<Plug>(leap-backward-to)" "Leap backward to")
(mkBinding cfg.mappings.leapForwardTill "<Plug>(leap-forward-till)" "Leap forward till")
(mkBinding cfg.mappings.leapBackwardTill "<Plug>(leap-backward-till)" "Leap backward till")
(mkBinding cfg.mappings.leapFromWindow "<Plug>(leap-from-window)" "Leap from window")
];
vim.maps.visualOnly = mkMerge [
(mkBinding cfg.mappings.leapForwardTo "<Plug>(leap-forward-to)" "Leap forward to")
(mkBinding cfg.mappings.leapBackwardTo "<Plug>(leap-backward-to)" "Leap backward to")
(mkBinding cfg.mappings.leapForwardTill "<Plug>(leap-forward-till)" "Leap forward till")
(mkBinding cfg.mappings.leapBackwardTill "<Plug>(leap-backward-till)" "Leap backward till")
(mkBinding cfg.mappings.leapFromWindow "<Plug>(leap-from-window)" "Leap from window")
];
vim.binds.whichKey.register."<leader>s" = mkDefault "+Leap";
vim.pluginRC.leap-nvim = entryAnywhere ''
require('leap').opts = {
max_phase_one_targets = nil,
highlight_unlabeled_phase_one_targets = false,
max_highlighted_traversal_targets = 10,
case_sensitive = false,
equivalence_classes = { ' \t\r\n', },
substitute_chars = {},
safe_labels = {
"s", "f", "n", "u", "t", "/",
"S", "F", "N", "L", "H", "M", "U", "G", "T", "?", "Z"
},
labels = {
"s", "f", "n",
"j", "k", "l", "h", "o", "d", "w", "e", "m", "b",
"u", "y", "v", "r", "g", "t", "c", "x", "/", "z",
"S", "F", "N",
"J", "K", "L", "H", "O", "D", "W", "E", "M", "B",
"U", "Y", "V", "R", "G", "T", "C", "X", "?", "Z"
},
special_keys = {
repeat_search = '<enter>',
next_phase_one_target = '<enter>',
next_target = {'<enter>', ';'},
prev_target = {'<tab>', ','},
next_group = '<space>',
prev_group = '<tab>',
multi_accept = '<enter>',
multi_revert = '<backspace>',
},
}
'';
}; };
} }

View file

@ -8,24 +8,47 @@
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.utility.surround; cfg = config.vim.utility.surround;
mkLznKey = mode: key: {
inherit key mode;
};
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim = {
startPlugins = ["nvim-surround"]; startPlugins = ["nvim-surround"];
pluginRC.surround = entryAnywhere "require('nvim-surround').setup(${toLuaObject cfg.setupOpts})"; pluginRC.surround = entryAnywhere "require('nvim-surround').setup(${toLuaObject cfg.setupOpts})";
utility.surround.setupOpts.keymaps = mkIf cfg.useVendoredKeybindings { lazy.plugins.nvim-surround = {
insert = "<C-g>z"; package = "nvim-surround";
insert_line = "<C-g>Z"; setupModule = "nvim-surround";
normal = "gz"; inherit (cfg) setupOpts;
normal_cur = "gZ";
normal_line = "gzz"; keys =
normal_cur_line = "gZZ"; [
visual = "gz"; (mkLznKey ["i"] cfg.setupOpts.keymaps.insert)
visual_line = "gZ"; (mkLznKey ["i"] cfg.setupOpts.keymaps.insert_line)
delete = "gzd"; (mkLznKey ["x"] cfg.setupOpts.keymaps.visual)
change = "gzr"; (mkLznKey ["x"] cfg.setupOpts.keymaps.visual_line)
change_line = "gZR"; (mkLznKey ["n"] cfg.setupOpts.keymaps.normal)
(mkLznKey ["n"] cfg.setupOpts.keymaps.normal_cur)
(mkLznKey ["n"] cfg.setupOpts.keymaps.normal_line)
(mkLznKey ["n"] cfg.setupOpts.keymaps.normal_cur_line)
(mkLznKey ["n"] cfg.setupOpts.keymaps.delete)
(mkLznKey ["n"] cfg.setupOpts.keymaps.change)
(mkLznKey ["n"] cfg.setupOpts.keymaps.change_line)
]
++ map (mkLznKey ["n" "i" "v"]) [
"<Plug>(nvim-surround-insert)"
"<Plug>(nvim-surround-insert-line)"
"<Plug>(nvim-surround-normal)"
"<Plug>(nvim-surround-normal-cur)"
"<Plug>(nvim-surround-normal-line)"
"<Plug>(nvim-surround-normal-cur-line)"
"<Plug>(nvim-surround-visual)"
"<Plug>(nvim-surround-visual-line)"
"<Plug>(nvim-surround-delete)"
"<Plug>(nvim-surround-change)"
"<Plug>(nvim-surround-change-line)"
];
}; };
}; };
}; };

View file

@ -1,7 +1,36 @@
{lib, ...}: let {
lib,
config,
...
}: let
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.types) bool; inherit (lib.types) bool str;
inherit (lib.nvim.types) mkPluginSetupOption; inherit (lib.nvim.types) mkPluginSetupOption;
cfg = config.vim.utility.surround;
vendoredKeybinds = {
insert = "<C-g>z";
insert_line = "<C-g>Z";
normal = "gz";
normal_cur = "gZ";
normal_line = "gzz";
normal_cur_line = "gZZ";
visual = "gz";
visual_line = "gZ";
delete = "gzd";
change = "gzr";
change_line = "gZR";
};
mkKeymapOption = name: default:
mkOption {
description = "keymap for ${name}";
type = str;
default =
if cfg.useVendoredKeybindings
then vendoredKeybinds.${name}
else default;
};
in { in {
options.vim.utility.surround = { options.vim.utility.surround = {
enable = mkOption { enable = mkOption {
@ -13,7 +42,21 @@ in {
with nvim-leap. with nvim-leap.
''; '';
}; };
setupOpts = mkPluginSetupOption "nvim-surround" {}; setupOpts = mkPluginSetupOption "nvim-surround" {
keymaps = {
insert = mkKeymapOption "insert" "<C-g>s";
insert_line = mkKeymapOption "insert_line" "<C-g>S";
normal = mkKeymapOption "normal" "ys";
normal_cur = mkKeymapOption "normal_cur" "yss";
normal_line = mkKeymapOption "normal_line" "yS";
normal_cur_line = mkKeymapOption "normal_cur_line" "ySS";
visual = mkKeymapOption "visual" "S";
visual_line = mkKeymapOption "visual_line" "gS";
delete = mkKeymapOption "delete" "ds";
change = mkKeymapOption "change" "cs";
change_line = mkKeymapOption "change_line" "cS";
};
};
useVendoredKeybindings = mkOption { useVendoredKeybindings = mkOption {
type = bool; type = bool;

View file

@ -1,63 +1,72 @@
{ {
options,
config, config,
pkgs,
lib, lib,
... ...
}: let }: let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding; inherit (lib.nvim.binds) addDescriptionsToMappings;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.strings) optionalString;
inherit (lib.nvim.binds) pushDownDefault; inherit (lib.lists) optionals;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.binds) pushDownDefault mkSetLznBinding;
cfg = config.vim.telescope; cfg = config.vim.telescope;
self = import ./telescope.nix {inherit pkgs lib;}; mappingDefinitions = options.vim.telescope.mappings;
mappingDefinitions = self.options.vim.telescope.mappings;
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim = {
startPlugins = [ startPlugins = ["plenary-nvim"];
"telescope"
"plenary-nvim"
];
maps.normal = mkMerge [ lazy.plugins.telescope = {
(mkSetBinding mappings.findFiles "<cmd> Telescope find_files<CR>") package = "telescope";
(mkSetBinding mappings.liveGrep "<cmd> Telescope live_grep<CR>") setupModule = "telescope";
(mkSetBinding mappings.buffers "<cmd> Telescope buffers<CR>") inherit (cfg) setupOpts;
(mkSetBinding mappings.helpTags "<cmd> Telescope help_tags<CR>") after = ''
(mkSetBinding mappings.open "<cmd> Telescope<CR>") local telescope = require("telescope")
(mkSetBinding mappings.resume "<cmd> Telescope resume<CR>") ${optionalString config.vim.ui.noice.enable "telescope.load_extension('noice')"}
${optionalString config.vim.notify.nvim-notify.enable "telescope.load_extension('notify')"}
${optionalString config.vim.projects.project-nvim.enable "telescope.load_extension('projects')"}
'';
(mkSetBinding mappings.gitCommits "<cmd> Telescope git_commits<CR>") cmd = ["Telescope"];
(mkSetBinding mappings.gitBufferCommits "<cmd> Telescope git_bcommits<CR>")
(mkSetBinding mappings.gitBranches "<cmd> Telescope git_branches<CR>")
(mkSetBinding mappings.gitStatus "<cmd> Telescope git_status<CR>")
(mkSetBinding mappings.gitStash "<cmd> Telescope git_stash<CR>")
(mkIf config.vim.lsp.enable (mkMerge [ keys =
(mkSetBinding mappings.lspDocumentSymbols "<cmd> Telescope lsp_document_symbols<CR>") [
(mkSetBinding mappings.lspWorkspaceSymbols "<cmd> Telescope lsp_workspace_symbols<CR>") (mkSetLznBinding mappings.findFiles "<cmd> Telescope find_files<CR>")
(mkSetLznBinding mappings.liveGrep "<cmd> Telescope live_grep<CR>")
(mkSetLznBinding mappings.buffers "<cmd> Telescope buffers<CR>")
(mkSetLznBinding mappings.helpTags "<cmd> Telescope help_tags<CR>")
(mkSetLznBinding mappings.open "<cmd> Telescope<CR>")
(mkSetBinding mappings.lspReferences "<cmd> Telescope lsp_references<CR>") (mkSetLznBinding mappings.gitCommits "<cmd> Telescope git_commits<CR>")
(mkSetBinding mappings.lspImplementations "<cmd> Telescope lsp_implementations<CR>") (mkSetLznBinding mappings.gitBufferCommits "<cmd> Telescope git_bcommits<CR>")
(mkSetBinding mappings.lspDefinitions "<cmd> Telescope lsp_definitions<CR>") (mkSetLznBinding mappings.gitBranches "<cmd> Telescope git_branches<CR>")
(mkSetBinding mappings.lspTypeDefinitions "<cmd> Telescope lsp_type_definitions<CR>") (mkSetLznBinding mappings.gitStatus "<cmd> Telescope git_status<CR>")
(mkSetBinding mappings.diagnostics "<cmd> Telescope diagnostics<CR>") (mkSetLznBinding mappings.gitStash "<cmd> Telescope git_stash<CR>")
])) ]
++ (optionals config.vim.lsp.enable [
(mkSetLznBinding mappings.lspDocumentSymbols "<cmd> Telescope lsp_document_symbols<CR>")
(mkSetLznBinding mappings.lspWorkspaceSymbols "<cmd> Telescope lsp_workspace_symbols<CR>")
( (mkSetLznBinding mappings.lspReferences "<cmd> Telescope lsp_references<CR>")
mkIf config.vim.treesitter.enable (mkSetLznBinding mappings.lspImplementations "<cmd> Telescope lsp_implementations<CR>")
(mkSetBinding mappings.treesitter "<cmd> Telescope treesitter<CR>") (mkSetLznBinding mappings.lspDefinitions "<cmd> Telescope lsp_definitions<CR>")
) (mkSetLznBinding mappings.lspTypeDefinitions "<cmd> Telescope lsp_type_definitions<CR>")
(mkSetLznBinding mappings.diagnostics "<cmd> Telescope diagnostics<CR>")
( ])
mkIf config.vim.projects.project-nvim.enable ++ (
(mkSetBinding mappings.findProjects "<cmd> Telescope projects<CR>") optionals config.vim.treesitter.enable [
) (mkSetLznBinding mappings.treesitter "<cmd> Telescope treesitter<CR>")
]; ]
)
++ (
optionals config.vim.projects.project-nvim.enable [
(mkSetLznBinding mappings.findProjects "<cmd Telescope projects<CR>")
]
);
};
binds.whichKey.register = pushDownDefault { binds.whichKey.register = pushDownDefault {
"<leader>f" = "+Telescope"; "<leader>f" = "+Telescope";
@ -66,29 +75,6 @@ in {
"<leader>fv" = "Telescope Git"; "<leader>fv" = "Telescope Git";
"<leader>fvc" = "Commits"; "<leader>fvc" = "Commits";
}; };
pluginRC.telescope = entryAnywhere ''
local telescope = require('telescope')
telescope.setup(${toLuaObject cfg.setupOpts})
${
if config.vim.ui.noice.enable
then "telescope.load_extension('noice')"
else ""
}
${
if config.vim.notify.nvim-notify.enable
then "telescope.load_extension('notify')"
else ""
}
${
if config.vim.projects.project-nvim.enable
then "telescope.load_extension('projects')"
else ""
}
'';
}; };
}; };
} }

View file

@ -4,16 +4,15 @@
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.visuals.fidget-nvim; cfg = config.vim.visuals.fidget-nvim;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = ["fidget-nvim"]; vim.lazy.plugins.fidget-nvim = {
package = "fidget-nvim";
vim.pluginRC.fidget-nvim = entryAnywhere '' setupModule = "fidget";
require'fidget'.setup(${toLuaObject cfg.setupOpts}) event = "LspAttach";
''; inherit (cfg) setupOpts;
};
}; };
} }

View file

@ -0,0 +1,108 @@
{
lib,
config,
...
}: let
inherit (builtins) toJSON typeOf head length filter concatLists concatStringsSep;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.generators) mkLuaInline;
inherit (lib.strings) optionalString;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.dag) entryBefore entryAfter;
cfg = config.vim.lazy;
toLuaLznKeySpec = keySpec:
(removeAttrs keySpec ["key" "lua" "action"])
// {
"@1" = keySpec.key;
"@2" =
if keySpec.lua
then mkLuaInline keySpec.action
else keySpec.action;
};
toLuaLznSpec = name: spec:
(removeAttrs spec ["package" "setupModule" "setupOpts" "keys"])
// {
"@1" = name;
before =
if spec.before != null
then
mkLuaInline ''
function()
${spec.before}
end
''
else null;
after =
if spec.setupModule == null && spec.after == null
then null
else
mkLuaInline ''
function()
${
optionalString (spec.setupModule != null)
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})"
}
${optionalString (spec.after != null) spec.after}
end
'';
keys =
if typeOf spec.keys == "list" && length spec.keys > 0 && typeOf (head spec.keys) == "set"
then map toLuaLznKeySpec (filter (keySpec: keySpec.key != null) spec.keys)
# empty list or str or (listOf str)
else spec.keys;
};
lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins;
pluginPackages = mapAttrsToList (_: plugin: plugin.package) cfg.plugins;
specToNotLazyConfig = _: spec: ''
do
${optionalString (spec.before != null) spec.before}
${optionalString (spec.setupModule != null)
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})"}
${optionalString (spec.after != null) spec.after}
end
'';
specToKeymaps = _: spec:
if typeOf spec.keys == "list"
then map (x: removeAttrs x ["ft"]) (filter (lznKey: lznKey.action != null && lznKey.ft == null) spec.keys)
else if spec.keys == null || typeOf spec.keys == "string"
then []
else [spec.keys];
notLazyConfig =
concatStringsSep "\n"
(mapAttrsToList specToNotLazyConfig cfg.plugins);
beforeAllJoined =
concatStringsSep "\n"
(filter (x: x != null) (mapAttrsToList (_: spec: spec.beforeAll) cfg.plugins));
in {
config.vim = mkMerge [
(mkIf cfg.enable {
startPlugins = ["lz-n" "lzn-auto-require"];
optPlugins = pluginPackages;
lazy.builtLazyConfig = ''
require('lz.n').load(${toLuaObject lznSpecs})
${optionalString cfg.enableLznAutoRequire "require('lzn-auto-require').enable()"}
'';
})
(mkIf (!cfg.enable) {
startPlugins = pluginPackages;
lazy.builtLazyConfig = ''
${beforeAllJoined}
${notLazyConfig}
'';
keymaps = concatLists (mapAttrsToList specToKeymaps cfg.plugins);
})
];
}

View file

@ -0,0 +1,6 @@
{
imports = [
./lazy.nix
./config.nix
];
}

View file

@ -0,0 +1,237 @@
{lib, ...}: let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) enum listOf submodule nullOr str bool int attrsOf anything either oneOf lines;
inherit (lib.nvim.types) pluginType;
inherit (lib.nvim.config) mkBool;
lznKeysSpec = submodule {
options = {
key = mkOption {
type = nullOr str;
description = "Key to bind to. If key is null this entry is ignored.";
};
action = mkOption {
type = nullOr str;
default = null;
description = "Action to trigger.";
};
lua = mkBool false ''
If true, `action` is considered to be lua code.
Thus, it will not be wrapped in `""`.
'';
desc = mkOption {
description = "Description of the key map";
type = nullOr str;
default = null;
};
ft = mkOption {
description = "TBD";
type = nullOr (listOf str);
default = null;
};
mode = mkOption {
description = "Modes to bind in";
type = either str (listOf str);
default = ["n" "x" "s" "o"];
};
silent = mkBool true "Whether this mapping should be silent. Equivalent to adding <silent> to a map.";
nowait = mkBool false "Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map.";
script = mkBool false "Equivalent to adding <script> to a map.";
expr = mkBool false "Means that the action is actually an expression. Equivalent to adding <expr> to a map.";
unique = mkBool false "Whether to fail if the map is already defined. Equivalent to adding <unique> to a map.";
noremap = mkBool true "Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default.";
};
};
lznPluginType = submodule {
options = {
package = mkOption {
type = pluginType;
description = "Plugin package";
};
setupModule = mkOption {
type = nullOr str;
description = "Lua module to run setup function on.";
default = null;
};
setupOpts = mkOption {
type = submodule {freeformType = attrsOf anything;};
description = "Options to pass to the setup function";
default = {};
};
# lz.n options
enabled = mkOption {
type = nullOr (either bool str);
description = "When false, or if the lua function returns false, this plugin will not be included in the spec";
default = null;
};
beforeAll = mkOption {
type = nullOr lines;
description = "Lua code to run before any plugins are loaded. This will be wrapped in a function.";
default = null;
};
before = mkOption {
type = nullOr lines;
description = "Lua code to run before plugin is loaded. This will be wrapped in a function.";
default = null;
};
after = mkOption {
type = nullOr lines;
description = ''
Lua code to run after plugin is loaded. This will be wrapped in a function.
If [](#opt-vim.lazy.plugins._name_.setupModule) is provided, the setup will be ran before `after`.
'';
default = null;
};
event = mkOption {
description = "Lazy-load on event";
default = null;
type = let
event = submodule {
options = {
event = mkOption {
type = nullOr (either str (listOf str));
description = "Exact event name";
example = "BufEnter";
};
pattern = mkOption {
type = nullOr (either str (listOf str));
description = "Event pattern";
example = "BufEnter *.lua";
};
};
};
in
nullOr (oneOf [str (listOf str) event]);
};
cmd = mkOption {
description = "Lazy-load on command";
default = null;
type = nullOr (either str (listOf str));
};
ft = mkOption {
description = "Lazy-load on filetype";
default = null;
type = nullOr (either str (listOf str));
};
keys = mkOption {
description = "Lazy-load on key mapping";
default = null;
type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]);
example = ''
keys = [
{
mode = "n";
key = "<leader>s";
action = ":DapStepOver<cr>";
desc = "DAP Step Over";
}
{
mode = ["n", "x"];
key = "<leader>dc";
action = "function() require('dap').continue() end";
lua = true;
desc = "DAP Continue";
}
]
'';
};
colorscheme = mkOption {
description = "Lazy-load on colorscheme.";
type = nullOr (either str (listOf str));
default = null;
};
lazy = mkBool false "Lazy-load manually, e.g. using `trigger_load`.";
priority = mkOption {
type = nullOr int;
description = "Only useful for stat plugins (not lazy-loaded) to force loading certain plugins first.";
default = null;
};
load = mkOption {
type = nullOr lines;
default = null;
description = ''
Lua code to override the `vim.g.lz_n.load()` function for a single plugin.
This will be wrapped in a function.
'';
};
};
};
in {
options.vim.lazy = {
enable = mkEnableOption "plugin lazy-loading via lz.n and lzn-auto-require" // {default = true;};
loader = mkOption {
description = "Lazy loader to use";
type = enum ["lz.n"];
default = "lz.n";
};
plugins = mkOption {
default = [];
type = attrsOf lznPluginType;
description = ''
Plugins to lazy load.
The attribute key is used as the plugin name: for the default `vim.g.lz_n.load`
function this should be either the `package.pname` or `package.name`.
'';
example = ''
{
toggleterm-nvim = {
package = "toggleterm-nvim";
setupModule = "toggleterm";
setupOpts = cfg.setupOpts;
after = "require('toggleterm').do_something()";
cmd = ["ToggleTerm"];
};
$${pkgs.vimPlugins.vim-bbye.pname} = {
package = pkgs.vimPlugins.vim-bbye;
cmd = ["Bdelete" "Bwipeout"];
};
}
'';
};
enableLznAutoRequire = mkOption {
description = ''
Enable lzn-auto-require. Since builtin plugins rely on this, only turn
off for debugging.
'';
type = bool;
default = true;
};
builtLazyConfig = mkOption {
internal = true;
type = lines;
description = ''
The built config for lz.n, or if `vim.lazy.enable` is false, the
individual plugin configs.
'';
};
};
}

View file

@ -5,7 +5,7 @@
}: let }: let
inherit (builtins) map mapAttrs filter; inherit (builtins) map mapAttrs filter;
inherit (lib.attrsets) mapAttrsToList; inherit (lib.attrsets) mapAttrsToList;
inherit (lib.strings) concatLines concatMapStringsSep; inherit (lib.strings) concatLines concatMapStringsSep optionalString;
inherit (lib.trivial) showWarnings; inherit (lib.trivial) showWarnings;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere; inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
@ -52,7 +52,8 @@ in {
optionsScript = entryAfter ["basic"] (concatLines optionsScript); optionsScript = entryAfter ["basic"] (concatLines optionsScript);
# Basic # Basic
pluginConfigs = entryAfter ["optionsScript"] pluginConfigs; lazyConfigs = entryAfter ["optionsScript"] cfg.lazy.builtLazyConfig;
pluginConfigs = entryAfter ["lazyConfigs"] pluginConfigs;
extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs; extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs;
mappings = entryAfter ["extraPluginConfigs"] keymaps; mappings = entryAfter ["extraPluginConfigs"] keymaps;
}; };