mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-11-27 15:36:46 +00:00
21fcace3ed
* flake: add lz.n and lzn-auto-require * lazy: init module * lzn-auto-require: add init lua code * wrapper: fix opt plugin format * lib.binds: add lz.n variant of bind functions * telescope: lazy load * nvim-tree: lazy load * dapui: lazy load * trouble: lazy load * toggleterm: lazy load * cheatsheet: lazy load * diffview: lazy load * icon-picker: lazy load * leap: lazy load * fidget: lazy load * docs: add section on lazy plugins * lazy: support lazy.enable=false * comment-nvim: lazy load * surround-nvim: lazy load * neo-tree: lazy load * fixup! lazy: init module * dap: appease the nix gods (fix statix lint) * flake.lock: fix merge mistake * doc: update release note * fixup! doc: update release note * neo-tree: fix duplicate neo-tree install * lazy: use attrsOf for lazy.plugins * treewide: update lazy.plugins syntax * docs: update lazy.plugins syntax * lazy: cleanup * Update docs/manual/hacking/additional-plugins.md Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * formatting nitpick Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * typo tee hee :3 Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * typo tee hee :4 Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * flake: update lz.n * lazy: update lz.n plugin spec * lazy: allow lines in place of str for lua code * copilot: lazy load * 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 * luasnip: lazy load * flake: add rtp.nvim * cmp: actually lazy load source * fixup! cmp: actually lazy load source * format * docs: fix broken link * cmp-nvim-lsp: lazy load * lazy: allow key mode of str type * cmp: install sourcess via cmp.sourcePlugins * Update docs/manual/hacking/additional-plugins.md Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * lazy: refactor common var * nvim-dap-ui: add setupOpts * refactor: re-order plugin and lz.n configs lazy: make lzn-auto-require togglable * docs: update dag-entries * trouble: remove redundant import * lazy: remove unused module arg * toggleterm: make lazygit keybind optional * toggleterm: use toLuaObject for clarity * surround: rework keymap config * remove stale FIXME * lsp: use cmp_nvim_lsp capabilities * cmp: deduplicate attr key * theme: ensure themes load before lazy plugins * doc: update description of `theme` dag entry * lsp: avoid loading cmp on startup * doc: update configuration docs on custom plugins * cmp: skip trigger_load if lazy disabled * treesitter: remove redundant code * lsp: mark hack as HACK * comment: remove redundant plugin * Squash merge v0.7 into feature/lzn --------- Co-authored-by: raf <raf@notashelf.dev> Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com>
126 lines
4 KiB
Nix
126 lines
4 KiB
Nix
{
|
|
lib,
|
|
config,
|
|
...
|
|
}: let
|
|
inherit (lib.modules) mkIf mkMerge;
|
|
inherit (lib.strings) optionalString;
|
|
inherit (lib.generators) mkLuaInline;
|
|
inherit (lib.nvim.lua) toLuaObject;
|
|
inherit (lib.nvim.attrsets) mapListToAttrs;
|
|
inherit (builtins) attrNames typeOf tryEval concatStringsSep;
|
|
|
|
cfg = config.vim.autocomplete.nvim-cmp;
|
|
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;
|
|
in {
|
|
config = mkIf cfg.enable {
|
|
vim = {
|
|
startPlugins = ["rtp-nvim"];
|
|
lazy.plugins = mkMerge [
|
|
(mapListToAttrs (package: {
|
|
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')"}
|
|
local cmp = require("cmp")
|
|
cmp.setup(${toLuaObject cfg.setupOpts})
|
|
|
|
${optionalString config.vim.lazy.enable
|
|
(concatStringsSep "\n" (map
|
|
(package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})")
|
|
cfg.sourcePlugins))}
|
|
'';
|
|
|
|
event = ["InsertEnter" "CmdlineEnter"];
|
|
};
|
|
}
|
|
];
|
|
|
|
autocomplete.nvim-cmp = {
|
|
sources = {
|
|
nvim-cmp = null;
|
|
buffer = "[Buffer]";
|
|
path = "[Path]";
|
|
};
|
|
|
|
sourcePlugins = ["cmp-buffer" "cmp-path"];
|
|
|
|
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;
|
|
|
|
# `cmp` and `luasnip` are defined above, in the `nvim-cmp` section
|
|
mapping = {
|
|
${mappings.complete} = mkLuaInline "cmp.mapping.complete()";
|
|
${mappings.close} = mkLuaInline "cmp.mapping.abort()";
|
|
${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 ''
|
|
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.select_next_item()
|
|
${optionalString luasnipEnable ''
|
|
elseif luasnip.locally_jumpable(1) then
|
|
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)
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|