Compare commits

..

No commits in common. "2cc6d4a8e556e309837ceb69bccd3f008ee4f332" and "8dc91c01e2d2b52368bc8001cc404fe5d796f53e" have entirely different histories.

34 changed files with 481 additions and 508 deletions

View file

@ -106,10 +106,12 @@ isMaximal: {
transparent = false; transparent = false;
}; };
autopairs.nvim-autopairs.enable = true; autopairs.enable = true;
autocomplete.nvim-cmp.enable = true; autocomplete = {
snippets.luasnip.enable = true; enable = true;
type = "nvim-cmp";
};
filetree = { filetree = {
nvimTree = { nvimTree = {

View file

@ -154,20 +154,6 @@ everyone.
aren't defined in nvf. Move the alternate nvim-surround keybinds to use aren't defined in nvf. Move the alternate nvim-surround keybinds to use
`setupOpts`. `setupOpts`.
- Remove `autopairs.type`, and rename `autopairs.enable` to
`autopairs.nvim-autopairs.enable`. The new
[](#opt-vim.autopairs.nvim-autopairs.enable) supports `setupOpts` format by
default.
- Refactor of `nvim-cmp` and completion related modules
- Remove `autocomplete.type` in favor of per-plugin enable options such as
[](#opt-vim.autocomplete.nvim-cmp.enable).
- Deprecate legacy Vimsnip in favor of Luasnip, and integrate
friendly-snippets for bundled snippets. [](#opt-vim.snippets.luasnip.enable)
can be used to toggle Luasnip.
- Add sorting function options for completion sources under
[](#opt-vim.autocomplete.nvim-cmp.setupOpts.sorting.comparators)
[Neovim documentation on `vim.cmd`]: https://neovim.io/doc/user/lua.html#vim.cmd() [Neovim documentation on `vim.cmd`]: https://neovim.io/doc/user/lua.html#vim.cmd()
- Make Neovim's configuration file entirely Lua based. This comes with a few - Make Neovim's configuration file entirely Lua based. This comes with a few

85
flake.lock generated
View file

@ -316,22 +316,6 @@
"type": "github" "type": "github"
} }
}, },
"plugin-cmp-luasnip": {
"flake": false,
"locked": {
"lastModified": 1696878902,
"narHash": "sha256-nUJJl2zyK/oSwz5RzI9j3gf9zpDfCImCYbPbVsyXgz8=",
"owner": "saadparwaiz1",
"repo": "cmp_luasnip",
"rev": "05a9ab28b53f71d1aece421ef32fee2cb857a843",
"type": "github"
},
"original": {
"owner": "saadparwaiz1",
"repo": "cmp_luasnip",
"type": "github"
}
},
"plugin-cmp-nvim-lsp": { "plugin-cmp-nvim-lsp": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -380,6 +364,22 @@
"type": "github" "type": "github"
} }
}, },
"plugin-cmp-vsnip": {
"flake": false,
"locked": {
"lastModified": 1669100283,
"narHash": "sha256-2mkN03noOr5vBvRbSb35xZKorSH+8savQNZtgM9+QcM=",
"owner": "hrsh7th",
"repo": "cmp-vsnip",
"rev": "989a8a73c44e926199bfd05fa7a516d51f2d2752",
"type": "github"
},
"original": {
"owner": "hrsh7th",
"repo": "cmp-vsnip",
"type": "github"
}
},
"plugin-codewindow-nvim": { "plugin-codewindow-nvim": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -588,22 +588,6 @@
"type": "github" "type": "github"
} }
}, },
"plugin-friendly-snippets": {
"flake": false,
"locked": {
"lastModified": 1727061933,
"narHash": "sha256-yTsuV5unoujY0mhLINssYYBWCeefe+nJaxQHJKm7hlk=",
"owner": "rafamadriz",
"repo": "friendly-snippets",
"rev": "00ba9dd3df89509f95437b8d595553707c46d5ea",
"type": "github"
},
"original": {
"owner": "rafamadriz",
"repo": "friendly-snippets",
"type": "github"
}
},
"plugin-gesture-nvim": { "plugin-gesture-nvim": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -844,22 +828,6 @@
"type": "github" "type": "github"
} }
}, },
"plugin-luasnip": {
"flake": false,
"locked": {
"lastModified": 1726165831,
"narHash": "sha256-nkaa1NGOI28Et2QitQB+Spv+J42QVdHE1oywteLcJJw=",
"owner": "L3MON4D3",
"repo": "LuaSnip",
"rev": "e808bee352d1a6fcf902ca1a71cee76e60e24071",
"type": "github"
},
"original": {
"owner": "L3MON4D3",
"repo": "LuaSnip",
"type": "github"
}
},
"plugin-mind-nvim": { "plugin-mind-nvim": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -1789,6 +1757,22 @@
"type": "github" "type": "github"
} }
}, },
"plugin-vim-vsnip": {
"flake": false,
"locked": {
"lastModified": 1704937299,
"narHash": "sha256-gvm6z4pgSULBVPukewRyjwxZ0vZgreQWbG/0kOB1QBo=",
"owner": "hrsh7th",
"repo": "vim-vsnip",
"rev": "02a8e79295c9733434aab4e0e2b8c4b7cea9f3a9",
"type": "github"
},
"original": {
"owner": "hrsh7th",
"repo": "vim-vsnip",
"type": "github"
}
},
"plugin-which-key": { "plugin-which-key": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -1843,10 +1827,10 @@
"plugin-cheatsheet-nvim": "plugin-cheatsheet-nvim", "plugin-cheatsheet-nvim": "plugin-cheatsheet-nvim",
"plugin-cinnamon-nvim": "plugin-cinnamon-nvim", "plugin-cinnamon-nvim": "plugin-cinnamon-nvim",
"plugin-cmp-buffer": "plugin-cmp-buffer", "plugin-cmp-buffer": "plugin-cmp-buffer",
"plugin-cmp-luasnip": "plugin-cmp-luasnip",
"plugin-cmp-nvim-lsp": "plugin-cmp-nvim-lsp", "plugin-cmp-nvim-lsp": "plugin-cmp-nvim-lsp",
"plugin-cmp-path": "plugin-cmp-path", "plugin-cmp-path": "plugin-cmp-path",
"plugin-cmp-treesitter": "plugin-cmp-treesitter", "plugin-cmp-treesitter": "plugin-cmp-treesitter",
"plugin-cmp-vsnip": "plugin-cmp-vsnip",
"plugin-codewindow-nvim": "plugin-codewindow-nvim", "plugin-codewindow-nvim": "plugin-codewindow-nvim",
"plugin-comment-nvim": "plugin-comment-nvim", "plugin-comment-nvim": "plugin-comment-nvim",
"plugin-copilot-cmp": "plugin-copilot-cmp", "plugin-copilot-cmp": "plugin-copilot-cmp",
@ -1860,7 +1844,6 @@
"plugin-fastaction-nvim": "plugin-fastaction-nvim", "plugin-fastaction-nvim": "plugin-fastaction-nvim",
"plugin-fidget-nvim": "plugin-fidget-nvim", "plugin-fidget-nvim": "plugin-fidget-nvim",
"plugin-flutter-tools": "plugin-flutter-tools", "plugin-flutter-tools": "plugin-flutter-tools",
"plugin-friendly-snippets": "plugin-friendly-snippets",
"plugin-gesture-nvim": "plugin-gesture-nvim", "plugin-gesture-nvim": "plugin-gesture-nvim",
"plugin-gitsigns-nvim": "plugin-gitsigns-nvim", "plugin-gitsigns-nvim": "plugin-gitsigns-nvim",
"plugin-glow-nvim": "plugin-glow-nvim", "plugin-glow-nvim": "plugin-glow-nvim",
@ -1876,7 +1859,6 @@
"plugin-lspkind": "plugin-lspkind", "plugin-lspkind": "plugin-lspkind",
"plugin-lspsaga": "plugin-lspsaga", "plugin-lspsaga": "plugin-lspsaga",
"plugin-lualine": "plugin-lualine", "plugin-lualine": "plugin-lualine",
"plugin-luasnip": "plugin-luasnip",
"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",
@ -1935,6 +1917,7 @@
"plugin-vim-markdown": "plugin-vim-markdown", "plugin-vim-markdown": "plugin-vim-markdown",
"plugin-vim-repeat": "plugin-vim-repeat", "plugin-vim-repeat": "plugin-vim-repeat",
"plugin-vim-startify": "plugin-vim-startify", "plugin-vim-startify": "plugin-vim-startify",
"plugin-vim-vsnip": "plugin-vim-vsnip",
"plugin-which-key": "plugin-which-key", "plugin-which-key": "plugin-which-key",
"rnix-lsp": "rnix-lsp", "rnix-lsp": "rnix-lsp",
"systems": "systems_2" "systems": "systems_2"

View file

@ -277,6 +277,11 @@
flake = false; flake = false;
}; };
plugin-cmp-vsnip = {
url = "github:hrsh7th/cmp-vsnip";
flake = false;
};
plugin-cmp-path = { plugin-cmp-path = {
url = "github:hrsh7th/cmp-path"; url = "github:hrsh7th/cmp-path";
flake = false; flake = false;
@ -287,19 +292,9 @@
flake = false; flake = false;
}; };
plugin-cmp-luasnip = {
url = "github:saadparwaiz1/cmp_luasnip";
flake = false;
};
# snippets # snippets
plugin-luasnip = { plugin-vim-vsnip = {
url = "github:L3MON4D3/LuaSnip"; url = "github:hrsh7th/vim-vsnip";
flake = false;
};
plugin-friendly-snippets = {
url = "github:rafamadriz/friendly-snippets";
flake = false; flake = false;
}; };

View file

@ -1,5 +0,0 @@
{lib}: let
inherit (builtins) listToAttrs;
in {
mapListToAttrs = f: list: listToAttrs (map f list);
}

View file

@ -10,7 +10,6 @@
dag = import ./dag.nix {inherit lib;}; dag = import ./dag.nix {inherit lib;};
languages = import ./languages.nix {inherit lib;}; languages = import ./languages.nix {inherit lib;};
lists = import ./lists.nix {inherit lib;}; lists = import ./lists.nix {inherit lib;};
attrsets = import ./attrsets.nix {inherit lib;};
lua = import ./lua.nix {inherit lib;}; lua = import ./lua.nix {inherit lib;};
neovimConfiguration = import ../modules {inherit inputs lib;}; neovimConfiguration = import ../modules {inherit inputs lib;};
} }

View file

@ -2,8 +2,8 @@
{lib}: let {lib}: let
inherit (builtins) isString getAttr; inherit (builtins) isString getAttr;
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.attrsets) listToAttrs;
inherit (lib.types) bool; inherit (lib.types) bool;
inherit (lib.nvim.attrsets) mapListToAttrs;
in { in {
# Converts a boolean to a yes/no string. This is used in lots of # Converts a boolean to a yes/no string. This is used in lots of
# configuration formats. # configuration formats.
@ -12,8 +12,8 @@ in {
config, config,
diagnosticsProviders, diagnosticsProviders,
}: }:
mapListToAttrs listToAttrs
(v: let (map (v: let
type = type =
if isString v if isString v
then v then v
@ -26,7 +26,7 @@ in {
name = "${lang}-diagnostics-${type}"; name = "${lang}-diagnostics-${type}";
value = diagnosticsProviders.${type}.nullConfig package; value = diagnosticsProviders.${type}.nullConfig package;
}) })
config; config);
mkEnable = desc: mkEnable = desc:
mkOption { mkOption {

View file

@ -6,10 +6,10 @@
typesDag = import ./dag.nix {inherit lib;}; typesDag = import ./dag.nix {inherit lib;};
typesPlugin = import ./plugins.nix {inherit inputs lib;}; typesPlugin = import ./plugins.nix {inherit inputs lib;};
typesLanguage = import ./languages.nix {inherit lib;}; typesLanguage = import ./languages.nix {inherit lib;};
customTypes = import ./custom.nix {inherit lib;}; typesTypes = import ./types.nix {inherit lib;};
in { in {
inherit (typesDag) dagOf; inherit (typesDag) dagOf;
inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType; inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType;
inherit (typesLanguage) diagnostics mkGrammarOption; inherit (typesLanguage) diagnostics mkGrammarOption;
inherit (customTypes) anythingConcatLists char hexColor mergelessListOf; inherit (typesTypes) anythingConcatLists char hexColor;
} }

View file

@ -1,7 +1,7 @@
{lib}: let {lib}: let
inherit (lib.options) showOption showFiles getFiles mergeOneOption mergeEqualOption; inherit (lib) isStringLike showOption showFiles getFiles mergeOneOption mergeEqualOption mkOptionType;
inherit (lib.strings) isString isStringLike; inherit (lib.strings) isString;
inherit (lib.types) anything attrsOf listOf mkOptionType; inherit (lib.types) anything attrsOf;
inherit (lib.nvim.types) anythingConcatLists; inherit (lib.nvim.types) anythingConcatLists;
inherit (builtins) typeOf isAttrs any head concatLists stringLength match; inherit (builtins) typeOf isAttrs any head concatLists stringLength match;
in { in {
@ -52,16 +52,6 @@ in {
(mergeFunctions.${commonType} or mergeEqualOption) loc defs; (mergeFunctions.${commonType} or mergeEqualOption) loc defs;
}; };
mergelessListOf = elemType: let
super = listOf elemType;
in
super
// {
name = "mergelessListOf";
description = "mergeless ${super.description}";
merge = mergeEqualOption;
};
char = mkOptionType { char = mkOptionType {
name = "char"; name = "char";
description = "character"; description = "character";

View file

@ -1,5 +1,5 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.modules) mkRemovedOptionModule mkRenamedOptionModule; inherit (lib.modules) mkRemovedOptionModule;
in { in {
imports = [ imports = [
# 2024-06-06 # 2024-06-06
@ -14,26 +14,5 @@ in {
available under `vim.ui.fastaction` as a replacement. Simply remove everything under available under `vim.ui.fastaction` as a replacement. Simply remove everything under
`vim.lsp.nvimCodeActionMenu`, and set `vim.ui.fastaction.enable` to `true`. `vim.lsp.nvimCodeActionMenu`, and set `vim.ui.fastaction.enable` to `true`.
'') '')
(mkRemovedOptionModule ["vim" "autopairs" "enable"] ''
vim.autopairs.enable has been removed in favor of per-plugin modules.
You can enable nvim-autopairs with vim.autopairs.nvim-autopairs.enable instead.
'')
(mkRemovedOptionModule ["vim" "autopairs" "type"] ''
vim.autopairs.type has been removed in favor of per-plugin modules.
You can enable nvim-autopairs with vim.autopairs.nvim-autopairs.enable instead.
'')
(mkRemovedOptionModule ["vim" "autocomplete" "enable"] ''
vim.autocomplete.enable has been removed in favor of per-plugin modules.
You can enable nvim-cmp with vim.autocomplete.nvim-cmp.enable instead.
'')
(mkRemovedOptionModule ["vim" "autocomplete" "type"] ''
vim.autocomplete.type has been removed in favor of per-plugin modules.
You can enable nvim-cmp with vim.autocomplete.nvim-cmp.enable instead.
'')
(mkRemovedOptionModule ["vim" "snippets" "vsnip" "enable"] ''
vim.snippets.vsnip.enable has been removed in favor of the more modern luasnip.
'')
(mkRenamedOptionModule ["vim" "lsp" "lspkind" "mode"] ["vim" "lsp" "lspkind" "setupOpts" "mode"])
]; ];
} }

View file

@ -34,8 +34,6 @@ in {
"copilot-cmp" "copilot-cmp"
]; ];
vim.autocomplete.nvim-cmp.sources = {copilot = "[Copilot]";};
vim.pluginRC.copilot = entryAnywhere '' vim.pluginRC.copilot = entryAnywhere ''
require("copilot").setup(${toLuaObject cfg.setupOpts}) require("copilot").setup(${toLuaObject cfg.setupOpts})

View file

@ -4,17 +4,16 @@
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.trivial) boolToString;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.autopairs.nvim-autopairs; cfg = config.vim.autopairs;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim.startPlugins = ["nvim-autopairs"];
startPlugins = ["nvim-autopairs"];
pluginRC.autopairs = entryAnywhere '' vim.pluginRC.autopairs = entryAnywhere ''
require('nvim-autopairs').setup(${toLuaObject cfg.setupOpts}) require("nvim-autopairs").setup({ map_cr = ${boolToString (!config.vim.autocomplete.enable)} })
''; '';
}; };
};
} }

View file

@ -1,14 +1,21 @@
{lib, ...}: let {lib, ...}: let
inherit (lib) mkRemovedOptionModule; inherit (lib) mkRemovedOptionModule;
inherit (lib.options) mkEnableOption; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.nvim.types) mkPluginSetupOption; inherit (lib.types) enum;
in { in {
imports = [ imports = [
(mkRemovedOptionModule ["vim" "autopairs" "nvim-compe"] "nvim-compe is deprecated and no longer suported.") (mkRemovedOptionModule ["vim" "autopairs" "nvim-compe"] "nvim-compe is deprecated and no longer suported.")
]; ];
options.vim.autopairs.nvim-autopairs = { options.vim = {
enable = mkEnableOption "autopairs"; autopairs = {
setupOpts = mkPluginSetupOption "nvim-autopairs" {}; enable = mkEnableOption "autopairs" // {default = false;};
type = mkOption {
type = enum ["nvim-autopairs"];
default = "nvim-autopairs";
description = "Set the autopairs type. Options: nvim-autopairs [nvim-autopairs]";
};
};
}; };
} }

View file

@ -3,115 +3,246 @@
config, config,
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (builtins) toJSON;
inherit (lib.strings) optionalString; inherit (lib.modules) mkIf mkMerge;
inherit (lib.generators) mkLuaInline; inherit (lib.attrsets) attrNames mapAttrsToList;
inherit (lib.nvim.binds) addDescriptionsToMappings; inherit (lib.strings) concatMapStringsSep concatStringsSep optionalString;
inherit (lib.nvim.dag) entryAfter; inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.dag) entryAnywhere entryAfter;
inherit (builtins) attrNames;
cfg = config.vim.autocomplete.nvim-cmp; cfg = config.vim.autocomplete;
luasnipEnable = config.vim.snippets.luasnip.enable; lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable;
self = import ./nvim-cmp.nix {inherit lib;};
mappingDefinitions = self.options.vim.autocomplete.mappings;
self = import ./nvim-cmp.nix {inherit lib config;};
mappingDefinitions = self.options.vim.autocomplete.nvim-cmp.mappings;
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
builtSources =
concatMapStringsSep
"\n"
(n: "{ name = '${n}'},")
(attrNames cfg.sources);
builtMaps =
concatStringsSep
"\n"
(mapAttrsToList
(n: v:
if v == null
then ""
else "${n} = '${v}',")
cfg.sources);
dagPlacement =
if lspkindEnabled
then entryAfter ["lspkind"]
else entryAnywhere;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim.startPlugins = [
startPlugins = [
"nvim-cmp" "nvim-cmp"
"cmp-buffer" "cmp-buffer"
"cmp-vsnip"
"cmp-path" "cmp-path"
"vim-vsnip"
]; ];
autocomplete.nvim-cmp.sources = { vim.autocomplete.sources = {
nvim-cmp = null; "nvim-cmp" = null;
buffer = "[Buffer]"; "vsnip" = "[VSnip]";
path = "[Path]"; "buffer" = "[Buffer]";
"crates" = "[Crates]";
"path" = "[Path]";
"copilot" = "[Copilot]";
}; };
autocomplete.nvim-cmp.setupOpts = { vim.maps.insert = mkMerge [
sources = map (s: {name = s;}) (attrNames cfg.sources); (mkSetLuaBinding mappings.complete ''
require('cmp').complete
# TODO: try to get nvim-cmp to follow global border style '')
window = mkIf config.vim.ui.borders.enable { (let
completion = mkLuaInline "cmp.config.window.bordered()"; defaultKeys =
documentation = mkLuaInline "cmp.config.window.bordered()"; if config.vim.autopairs.enable
}; then "require('nvim-autopairs').autopairs_cr()"
else "vim.api.nvim_replace_termcodes(${toJSON mappings.confirm.value}, true, false, true)";
formatting.format = cfg.format; in
}; mkSetLuaBinding mappings.confirm ''
function()
pluginRC.nvim-cmp = mkIf cfg.enable (entryAfter ["autopairs" "luasnip"] '' if not require('cmp').confirm({ select = true }) then
local luasnip = require("luasnip") vim.fn.feedkeys(${defaultKeys}, 'n')
local cmp = require("cmp")
cmp.setup(${toLuaObject cfg.setupOpts})
'');
# `cmp` and `luasnip` are defined above, in the `nvim-cmp` section
autocomplete.nvim-cmp.setupOpts.mapping = {
${mappings.complete.value} = mkLuaInline "cmp.mapping.complete()";
${mappings.close.value} = mkLuaInline "cmp.mapping.abort()";
${mappings.scrollDocsUp.value} = mkLuaInline "cmp.mapping.scroll_docs(-4)";
${mappings.scrollDocsDown.value} = mkLuaInline "cmp.mapping.scroll_docs(4)";
${mappings.confirm.value} = mkLuaInline ''
cmp.mapping(function(fallback)
if cmp.visible() then
${
if luasnipEnable
then ''
if luasnip.expandable() then
luasnip.expand()
else
cmp.confirm({ select = true })
end end
''
else "cmp.confirm({ select = true })"
}
else
fallback()
end end
end) '')
''; (mkSetLuaBinding mappings.next ''
function()
${mappings.next.value} = mkLuaInline ''
cmp.mapping(function(fallback)
local has_words_before = function() local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0)) 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 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end end
local cmp = require('cmp')
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
${optionalString luasnipEnable '' elseif vim.fn['vsnip#available'](1) == 1 then
elseif luasnip.locally_jumpable(1) then feedkey("<Plug>(vsnip-expand-or-jump)", "")
luasnip.jump(1)
''}
elseif has_words_before() then elseif has_words_before() then
cmp.complete() cmp.complete()
else else
fallback() local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true)
end
end) vim.fn.feedkeys(termcode, 'n')
''; end
end
'')
(mkSetLuaBinding mappings.previous ''
function()
local cmp = require('cmp')
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
${mappings.previous.value} = mkLuaInline ''
cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
${optionalString luasnipEnable '' elseif vim.fn['vsnip#available'](-1) == 1 then
elseif luasnip.locally_jumpable(-1) then feedkeys("<Plug>(vsnip-jump-prev)", "")
luasnip.jump(-1)
''}
else
fallback()
end end
end) end
''; '')
}; (mkSetLuaBinding mappings.close ''
}; require('cmp').mapping.abort()
'')
(mkSetLuaBinding mappings.scrollDocsUp ''
require('cmp').mapping.scroll_docs(-4)
'')
(mkSetLuaBinding mappings.scrollDocsDown ''
require('cmp').mapping.scroll_docs(4)
'')
];
vim.maps.command = mkMerge [
(mkSetLuaBinding mappings.complete ''
require('cmp').complete
'')
(mkSetLuaBinding mappings.close ''
require('cmp').mapping.close()
'')
(mkSetLuaBinding mappings.scrollDocsUp ''
require('cmp').mapping.scroll_docs(-4)
'')
(mkSetLuaBinding mappings.scrollDocsDown ''
require('cmp').mapping.scroll_docs(4)
'')
];
vim.maps.select = mkMerge [
(mkSetLuaBinding mappings.next ''
function()
local cmp = require('cmp')
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
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn['vsnip#available'](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true)
vim.fn.feedkeys(termcode, 'n')
end
end
'')
(mkSetLuaBinding mappings.previous ''
function()
local cmp = require('cmp')
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn['vsnip#available'](-1) == 1 then
feedkeys("<Plug>(vsnip-jump-prev)", "")
end
end
'')
];
# TODO: alternative snippet engines to vsnip
# https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L82
vim.pluginRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement ''
local nvim_cmp_menu_map = function(entry, vim_item)
-- name for each source
vim_item.menu = ({
${builtMaps}
})[entry.source.name]
return vim_item
end
${optionalString lspkindEnabled ''
lspkind_opts.before = ${cfg.formatting.format}
''}
local cmp = require'cmp'
cmp.setup({
${optionalString config.vim.ui.borders.enable ''
-- explicitly enabled by setting ui.borders.enable = true
-- TODO: try to get nvim-cmp to follow global border style
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
''}
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
sources = {
${builtSources}
},
completion = {
completeopt = 'menu,menuone,noinsert',
${optionalString (!cfg.alwaysComplete) "autocomplete = false"}
},
formatting = {
format =
${
if lspkindEnabled
then "lspkind.cmp_format(lspkind_opts)"
else cfg.formatting.format
},
}
})
${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") ''
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { text = ""} }))
''}
'');
vim.snippets.vsnip.enable =
if (cfg.type == "nvim-cmp")
then true
else config.vim.snippets.vsnip.enable;
}; };
} }

View file

@ -1,4 +1,4 @@
{ _: {
imports = [ imports = [
./config.nix ./config.nix
./nvim-cmp.nix ./nvim-cmp.nix

View file

@ -1,56 +1,16 @@
{ {lib, ...}: let
lib, inherit (lib.options) mkEnableOption mkOption literalMD;
config,
...
}: let
inherit (lib.options) mkEnableOption mkOption literalExpression literalMD;
inherit (lib.types) str attrsOf nullOr either;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf; inherit (lib.types) enum attrsOf nullOr str bool;
inherit (lib.nvim.lua) toLuaObject;
inherit (builtins) isString;
cfg = config.vim.autocomplete.nvim-cmp;
in { in {
options.vim.autocomplete.nvim-cmp = { options.vim = {
enable = mkEnableOption "nvim-cmp"; autocomplete = {
setupOpts = mkPluginSetupOption "the autocomplete plugin" { enable = mkEnableOption "autocomplete" // {default = false;};
completion.completeopt = mkOption {
type = str;
default = "menu,menuone,noinsert";
description = ''
A comma-separated list of options for completion.
See `:help completeopt` for the complete list. alwaysComplete = mkOption {
''; type = bool;
}; description = "Automatically show completion.";
default = true;
sorting.comparators = mkOption {
type = mergelessListOf (either str luaInline);
default = [
"offset"
"exact"
"score"
"kind"
"length"
"sort_text"
];
description = ''
The comparator functions used for sorting completions.
You can either pass a valid inline lua function
(see `:help cmp-config.sorting.comparators`),
or a string, in which case the builtin comparator with that name will
be used.
'';
apply = map (
c:
if isString c
then mkLuaInline ("cmp.config.compare." + c)
else c
);
};
}; };
mappings = { mappings = {
@ -63,41 +23,50 @@ in {
scrollDocsDown = mkMappingOption "Scroll docs down [nvim-cmp]" "<C-f>"; scrollDocsDown = mkMappingOption "Scroll docs down [nvim-cmp]" "<C-f>";
}; };
format = mkOption { type = mkOption {
type = luaInline; type = enum ["nvim-cmp"];
default = mkLuaInline '' default = "nvim-cmp";
function(entry, vim_item) description = "Set the autocomplete plugin. Options: [nvim-cmp]";
vim_item.menu = (${toLuaObject cfg.sources})[entry.source.name] };
return vim_item
end sources = mkOption {
description = ''
Attribute set of source names for nvim-cmp.
If an attribute set is provided, then the menu value of
`vim_item` in the format will be set to the value (if
utilizing the `nvim_cmp_menu_map` function).
Note: only use a single attribute name per attribute set
''; '';
defaultText = literalMD '' type = attrsOf (nullOr str);
default = {};
example = ''
{nvim-cmp = null; buffer = "[Buffer]";}
'';
};
formatting = {
format = mkOption {
description = ''
The function used to customize the appearance of the completion menu.
If [](#opt-vim.lsp.lspkind.enable) is true, then the function
will be called before modifications from lspkind.
Default is to call the menu mapping function.
'';
type = str;
default = "nvim_cmp_menu_map";
example = literalMD ''
```lua ```lua
function(entry, vim_item) function(entry, vim_item)
vim_item.menu = (''${toLuaObject config.vim.autocomplete.nvim-cmp.sources})[entry.source.name]
return vim_item return vim_item
end end
``` ```
''; '';
description = ''
The function used to customize the completion menu entires. This is
outside of `setupOpts` to allow for an easier integration with
lspkind.nvim.
See `:help cmp-config.formatting.format`.
'';
}; };
};
sources = mkOption {
type = attrsOf (nullOr str);
default = {};
description = "The list of sources used by nvim-cmp";
example = literalExpression ''
{
nvim-cmp = null;
buffer = "[Buffer]";
}
'';
}; };
}; };
} }

View file

@ -16,10 +16,9 @@
in { in {
config = mkMerge [ config = mkMerge [
(mkIf cfg.enable { (mkIf cfg.enable {
vim = { vim.startPlugins = ["nvim-dap"];
startPlugins = ["nvim-dap"];
pluginRC = vim.pluginRC =
{ {
# TODO customizable keymaps # TODO customizable keymaps
nvim-dap = entryAnywhere '' nvim-dap = entryAnywhere ''
@ -29,7 +28,7 @@ in {
} }
// mapAttrs (_: v: (entryAfter ["nvim-dap"] v)) cfg.sources; // mapAttrs (_: v: (entryAfter ["nvim-dap"] v)) cfg.sources;
maps.normal = mkMerge [ vim.maps.normal = mkMerge [
(mkSetLuaBinding mappings.continue "require('dap').continue") (mkSetLuaBinding mappings.continue "require('dap').continue")
(mkSetLuaBinding mappings.restart "require('dap').restart") (mkSetLuaBinding mappings.restart "require('dap').restart")
(mkSetLuaBinding mappings.terminate "require('dap').terminate") (mkSetLuaBinding mappings.terminate "require('dap').terminate")
@ -48,13 +47,11 @@ in {
(mkSetLuaBinding mappings.goUp "require('dap').up") (mkSetLuaBinding mappings.goUp "require('dap').up")
(mkSetLuaBinding mappings.goDown "require('dap').down") (mkSetLuaBinding mappings.goDown "require('dap').down")
]; ];
};
}) })
(mkIf (cfg.enable && cfg.ui.enable) { (mkIf (cfg.enable && cfg.ui.enable) {
vim = { vim.startPlugins = ["nvim-dap-ui" "nvim-nio"];
startPlugins = ["nvim-dap-ui" "nvim-nio"];
pluginRC.nvim-dap-ui = entryAfter ["nvim-dap"] ('' vim.pluginRC.nvim-dap-ui = entryAfter ["nvim-dap"] (''
local dapui = require("dapui") local dapui = require("dapui")
dapui.setup() dapui.setup()
'' ''
@ -69,8 +66,7 @@ in {
dapui.close() dapui.close()
end end
''); '');
maps.normal = mkSetLuaBinding mappings.toggleDapUI "require('dapui').toggle"; vim.maps.normal = mkSetLuaBinding mappings.toggleDapUI "require('dapui').toggle";
};
}) })
]; ];
} }

View file

@ -82,7 +82,7 @@ in {
(mkIf cfg.extraDiagnostics.enable { (mkIf cfg.extraDiagnostics.enable {
vim.lsp.null-ls.enable = true; vim.lsp.null-ls.enable = true;
vim.lsp.null-ls.sources = diagnosticsToLua { vim.lsp.null-ls.sources = diagnosticsToLua {
lang = "kotlin"; lang = "ts";
config = cfg.extraDiagnostics.types; config = cfg.extraDiagnostics.types;
inherit diagnosticsProviders; inherit diagnosticsProviders;
}; };

View file

@ -9,7 +9,7 @@
inherit (lib.options) mkOption mkEnableOption; inherit (lib.options) mkOption mkEnableOption;
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.trivial) boolToString; inherit (lib.trivial) boolToString;
inherit (lib.lists) isList; inherit (lib.lists) isList optionals;
inherit (lib.types) bool package str listOf either enum; inherit (lib.types) bool package str listOf either enum;
inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.lua) expToLua; inherit (lib.nvim.lua) expToLua;
@ -101,7 +101,7 @@ in {
vim = { vim = {
startPlugins = ["crates-nvim"]; startPlugins = ["crates-nvim"];
lsp.null-ls.enable = mkIf cfg.crates.codeActions true; lsp.null-ls.enable = mkIf cfg.crates.codeActions true;
autocomplete.nvim-cmp.sources = {crates = "[Crates]";}; autocomplete.sources = {"crates" = "[Crates]";};
pluginRC.rust-crates = entryAnywhere '' pluginRC.rust-crates = entryAnywhere ''
require('crates').setup { require('crates').setup {
null_ls = { null_ls = {

View file

@ -11,7 +11,7 @@
inherit (lib.nvim.binds) addDescriptionsToMappings; inherit (lib.nvim.binds) addDescriptionsToMappings;
cfg = config.vim.lsp; cfg = config.vim.lsp;
usingNvimCmp = config.vim.autocomplete.nvim-cmp.enable; usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp";
self = import ./module.nix {inherit config lib pkgs;}; self = import ./module.nix {inherit config lib pkgs;};
mappingDefinitions = self.options.vim.lsp.mappings; mappingDefinitions = self.options.vim.lsp.mappings;
@ -25,7 +25,7 @@ in {
vim = { vim = {
startPlugins = optional usingNvimCmp "cmp-nvim-lsp"; startPlugins = optional usingNvimCmp "cmp-nvim-lsp";
autocomplete.nvim-cmp.sources = {nvim_lsp = "[LSP]";}; autocomplete.sources = {"nvim_lsp" = "[LSP]";};
pluginRC.lsp-setup = '' pluginRC.lsp-setup = ''
vim.g.formatsave = ${boolToString cfg.formatOnSave}; vim.g.formatsave = ${boolToString cfg.formatOnSave};

View file

@ -3,32 +3,18 @@
lib, lib,
... ...
}: let }: let
inherit (lib.modules) mkIf mkForce; inherit (lib.modules) mkIf;
inherit (lib.generators) mkLuaInline; inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.lsp.lspkind; cfg = config.vim.lsp;
in { in {
config = mkIf cfg.enable { config = mkIf (cfg.enable && cfg.lspkind.enable) {
assertions = [ vim.startPlugins = ["lspkind"];
{ vim.pluginRC.lspkind = entryAnywhere ''
assertion = config.vim.autocomplete.nvim-cmp.enable; local lspkind = require'lspkind'
message = '' local lspkind_opts = {
While lspkind supports Neovim's native lsp upstream, using that over mode = '${cfg.lspkind.mode}'
nvim-cmp isn't recommended, nor supported by nvf.
Please migrate to nvim-cmp if you want to use lspkind.
'';
} }
]; '';
vim = {
startPlugins = ["lspkind"];
lsp.lspkind.setupOpts.before = config.vim.autocomplete.nvim-cmp.format;
autocomplete.nvim-cmp.setupOpts.formatting.format = mkForce (mkLuaInline ''
require("lspkind").cmp_format(${toLuaObject cfg.setupOpts})
'');
};
}; };
} }

View file

@ -1,22 +1,16 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) enum nullOr; inherit (lib.types) enum;
inherit (lib.nvim.types) mkPluginSetupOption luaInline;
in { in {
options.vim.lsp.lspkind = { options.vim.lsp = {
lspkind = {
enable = mkEnableOption "vscode-like pictograms for lsp [lspkind]"; enable = mkEnableOption "vscode-like pictograms for lsp [lspkind]";
setupOpts = mkPluginSetupOption "lspkind.nvim" {
mode = mkOption { mode = mkOption {
description = "Defines how annotations are shown"; description = "Defines how annotations are shown";
type = enum ["text" "text_symbol" "symbol_text" "symbol"]; type = enum ["text" "text_symbol" "symbol_text" "symbol"];
default = "symbol_text"; default = "symbol_text";
}; };
before = mkOption {
description = "The function that will be called before lspkind's modifications are applied";
type = nullOr luaInline;
default = null;
};
}; };
}; };
} }

View file

@ -45,10 +45,10 @@ in {
completion = { completion = {
nvim_cmp = mkOption { nvim_cmp = mkOption {
# If using nvim-cmp, otherwise set to false # if using nvim-cmp, otherwise set to false
type = bool; type = bool;
description = "If using nvim-cmp, otherwise set to false"; description = "If using nvim-cmp, otherwise set to false";
default = config.vim.autocomplete.nvim-cmp.enable; default = config.vim.autocomplete.type == "nvim-cmp";
}; };
}; };
}; };

View file

@ -1,5 +1,5 @@
{ {
imports = [ imports = [
./luasnip ./vsnip
]; ];
} }

View file

@ -1,17 +0,0 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf;
cfg = config.vim.snippets.luasnip;
in {
config = mkIf cfg.enable {
vim = {
startPlugins = ["luasnip" "cmp-luasnip"] ++ cfg.providers;
autocomplete.nvim-cmp.sources = {luasnip = "[LuaSnip]";};
pluginRC.luasnip = cfg.loaders;
};
};
}

View file

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

View file

@ -1,36 +0,0 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption mkOption literalExpression literalMD;
inherit (lib.types) listOf lines;
inherit (lib.nvim.types) pluginType;
in {
options.vim.snippets.luasnip = {
enable = mkEnableOption "luasnip";
providers = mkOption {
type = listOf pluginType;
default = ["friendly-snippets"];
description = ''
The snippet provider packages.
::: {.note}
These are simply appended to {option} `vim.startPlugins`.
:::
'';
example = literalExpression "[\"vimPlugins.vim-snippets\"]";
};
loaders = mkOption {
type = lines;
default = "require('luasnip.loaders.from_vscode').lazy_load()";
defaultText = literalMD ''
```lua
require('luasnip.loaders.from_vscode').lazy_load()
```
'';
description = "Lua code used to load snippet providers.";
example = literalMD ''
```lua
require("luasnip.loaders.from_snipmate").lazy_load()
```
'';
};
};
}

View file

@ -0,0 +1,13 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf;
cfg = config.vim.snippets.vsnip;
in {
config = mkIf cfg.enable {
vim.startPlugins = ["vim-vsnip"];
};
}

View file

@ -0,0 +1,5 @@
{
imports = [
./vsnip.nix
];
}

View file

@ -0,0 +1,7 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption;
in {
options.vim.snippets.vsnip = {
enable = mkEnableOption "vim-vsnip: snippet LSP/VSCode's format";
};
}

View file

@ -4,11 +4,10 @@
... ...
}: let }: let
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.attrsets) attrNames; inherit (lib.attrsets) attrNames listToAttrs;
inherit (lib.strings) hasPrefix; inherit (lib.strings) hasPrefix;
inherit (lib.types) bool lines enum; inherit (lib.types) bool lines enum;
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.nvim.attrsets) mapListToAttrs;
inherit (lib.nvim.dag) entryBefore; inherit (lib.nvim.dag) entryBefore;
inherit (lib.nvim.types) hexColor; inherit (lib.nvim.types) hexColor;
@ -18,8 +17,7 @@
}; };
numbers = ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"]; numbers = ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F"];
base16Options = base16Options = listToAttrs (map (n: {
mapListToAttrs (n: {
name = "base0${n}"; name = "base0${n}";
value = mkOption { value = mkOption {
description = "The base0${n} color to use"; description = "The base0${n} color to use";
@ -30,7 +28,7 @@
else "#${v}"; else "#${v}";
}; };
}) })
numbers; numbers);
in { in {
options.vim.theme = { options.vim.theme = {
enable = mkOption { enable = mkOption {

View file

@ -11,7 +11,7 @@
inherit (lib.nvim.dag) entryBefore entryAfter; inherit (lib.nvim.dag) entryBefore entryAfter;
cfg = config.vim.treesitter; cfg = config.vim.treesitter;
usingNvimCmp = config.vim.autocomplete.nvim-cmp.enable; usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp";
self = import ./treesitter.nix {inherit pkgs lib;}; self = import ./treesitter.nix {inherit pkgs lib;};
mappingDefinitions = self.options.vim.treesitter.mappings; mappingDefinitions = self.options.vim.treesitter.mappings;
@ -21,7 +21,7 @@ in {
vim = { vim = {
startPlugins = ["nvim-treesitter"] ++ optional usingNvimCmp "cmp-treesitter"; startPlugins = ["nvim-treesitter"] ++ optional usingNvimCmp "cmp-treesitter";
autocomplete.nvim-cmp.sources = {treesitter = "[Treesitter]";}; autocomplete.sources = {"treesitter" = "[Treesitter]";};
treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars; treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars;
maps = { maps = {

View file

@ -21,7 +21,7 @@ in {
mkBool true "override the lsp markdown formatter with Noice"; mkBool true "override the lsp markdown formatter with Noice";
"cmp.entry.get_documentation" = "cmp.entry.get_documentation" =
mkBool config.vim.autocomplete.nvim-cmp.enable "override cmp documentation with Noice"; mkBool (config.vim.autocomplete.type == "nvim-cmp") "override cmp documentation with Noice";
}; };
signature = { signature = {

View file

@ -4,7 +4,7 @@
... ...
}: let }: let
inherit (builtins) map mapAttrs filter; inherit (builtins) map mapAttrs filter;
inherit (lib.attrsets) mapAttrsToList; inherit (lib.attrsets) mapAttrsToList filterAttrs;
inherit (lib.strings) concatLines concatMapStringsSep; inherit (lib.strings) concatLines concatMapStringsSep;
inherit (lib.trivial) showWarnings; inherit (lib.trivial) showWarnings;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;