Merge branch 'main' into main

This commit is contained in:
Theodor Björkman 2025-03-05 15:07:17 +01:00 committed by GitHub
commit 8a69ab087f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 338 additions and 55 deletions

View file

@ -2,7 +2,7 @@
inherit (lib.options) mkEnableOption mkOption literalMD;
inherit (lib.types) listOf str either attrsOf submodule enum anything int nullOr;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.types) mkPluginSetupOption luaInline;
inherit (lib.nvim.types) mkPluginSetupOption luaInline pluginType;
inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.config) mkBool;
@ -118,5 +118,66 @@ in {
scrollDocsUp = mkMappingOption "Scroll docs up [blink.cmp]" "<C-d>";
scrollDocsDown = mkMappingOption "Scroll docs down [blink.cmp]" "<C-f>";
};
sourcePlugins = let
sourcePluginType = submodule {
options = {
package = mkOption {
type = pluginType;
description = ''
`blink-cmp` source plugin package.
'';
};
module = mkOption {
type = str;
description = ''
Value of {option}`vim.autocomplete.blink-cmp.setupOpts.sources.providers.<name>.module`.
Should be present in the source's documentation.
'';
};
enable = mkEnableOption "this source";
};
};
in
mkOption {
type = submodule {
freeformType = attrsOf sourcePluginType;
options = let
defaultSourcePluginOption = name: package: module: {
package = mkOption {
type = pluginType;
default = package;
description = ''
`blink-cmp` ${name} source plugin package.
'';
};
module = mkOption {
type = str;
default = module;
description = ''
Value of {option}`vim.autocomplete.blink-cmp.setupOpts.sources.providers.${name}.module`.
'';
};
enable = mkEnableOption "${name} source";
};
in {
# emoji completion after :
emoji = defaultSourcePluginOption "emoji" "blink-emoji-nvim" "blink-emoji";
# spelling suggestions as completions
spell = defaultSourcePluginOption "spell" "blink-cmp-spell" "blink-cmp-spell";
# words from nearby files
ripgrep = defaultSourcePluginOption "ripgrep" "blink-ripgrep-nvim" "blink-ripgrep";
};
};
default = {};
description = ''
`blink.cmp` sources.
Attribute names must be source names used in {option}`vim.autocomplete.blink-cmp.setupOpts.sources.default`.
'';
};
friendly-snippets.enable = mkEnableOption "friendly-snippets for blink to source from automatically";
};
}

View file

@ -6,6 +6,8 @@
inherit (lib.modules) mkIf;
inherit (lib.strings) optionalString;
inherit (lib.generators) mkLuaInline;
inherit (lib.attrsets) attrValues filterAttrs;
inherit (lib.lists) map optional;
inherit (lib.nvim.lua) toLuaObject;
inherit (builtins) concatStringsSep typeOf tryEval attrNames mapAttrs;
@ -19,9 +21,12 @@
else if (plugin ? pname && (tryEval plugin.pname).success)
then plugin.pname
else plugin.name;
enabledBlinkSources = filterAttrs (_source: definition: definition.enable) cfg.sourcePlugins;
blinkSourcePlugins = map (definition: definition.package) (attrValues enabledBlinkSources);
in {
vim = mkIf cfg.enable {
startPlugins = ["blink-compat"];
startPlugins = ["blink-compat"] ++ blinkSourcePlugins ++ (optional cfg.friendly-snippets.enable "friendly-snippets");
lazy.plugins = {
blink-cmp = {
package = "blink-cmp";
@ -32,12 +37,14 @@ in {
#
# event = ["InsertEnter" "CmdlineEnter"];
after = ''
${optionalString config.vim.lazy.enable
(concatStringsSep "\n" (map
(package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})")
cmpCfg.sourcePlugins))}
'';
after =
# lua
''
${optionalString config.vim.lazy.enable
(concatStringsSep "\n" (map
(package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})")
cmpCfg.sourcePlugins))}
'';
};
};
@ -45,13 +52,26 @@ in {
enableSharedCmpSources = true;
blink-cmp.setupOpts = {
sources = {
default = ["lsp" "path" "snippets" "buffer"] ++ (attrNames cmpCfg.sources);
default =
[
"lsp"
"path"
"snippets"
"buffer"
]
++ (attrNames cmpCfg.sources)
++ (attrNames enabledBlinkSources);
providers =
mapAttrs (name: _: {
inherit name;
module = "blink.compat.source";
})
cmpCfg.sources;
cmpCfg.sources
// (mapAttrs (name: definition: {
inherit name;
inherit (definition) module;
})
enabledBlinkSources);
};
snippets = mkIf config.vim.snippets.luasnip.enable {
preset = "luasnip";
@ -67,16 +87,18 @@ in {
${mappings.next} = [
"select_next"
"snippet_forward"
(mkLuaInline ''
function(cmp)
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
has_words_before = col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
(mkLuaInline
# lua
''
function(cmp)
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
has_words_before = col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
if has_words_before then
return cmp.show()
if has_words_before then
return cmp.show()
end
end
end
'')
'')
"fallback"
];
${mappings.previous} = [

View file

@ -1,6 +1,10 @@
{lib, ...}: let
inherit (lib.types) nullOr str bool;
inherit (lib) mkEnableOption mkOption types mkRenamedOptionModule;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.modules) mkRenamedOptionModule;
inherit (lib.strings) isString;
inherit (lib.types) nullOr str bool int enum listOf either;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.types) luaInline mkPluginSetupOption;
in {
imports = let
renameSetupOpt = oldPath: newPath:
@ -50,68 +54,100 @@ in {
usePicker = mkOption {
type = bool;
default = true;
description = "Whether or not we should use dressing.nvim to build a session picker UI";
description = ''
Whether we should use `dressing.nvim` to build a session picker UI
'';
};
setupOpts = {
setupOpts = mkPluginSetupOption "which-key" {
path_replacer = mkOption {
type = types.str;
type = str;
default = "__";
description = "The character to which the path separator will be replaced for session files";
description = ''
The character to which the path separator will be replaced for session files
'';
};
colon_replacer = mkOption {
type = types.str;
type = str;
default = "++";
description = "The character to which the colon symbol will be replaced for session files";
description = ''
The character to which the colon symbol will be replaced for session files
'';
};
autoload_mode = mkOption {
type = types.enum ["Disabled" "CurrentDir" "LastSession"];
type = either (enum ["Disabled" "CurrentDir" "LastSession"]) luaInline;
# Variable 'sm' is defined in the pluginRC of nvim-session-manager. The
# definition is as follows: `local sm = require('session_manager.config')`
apply = val:
if isString val
then mkLuaInline "sm.AutoloadMode.${val}"
else val;
default = "LastSession";
description = "Define what to do when Neovim is started without arguments. Possible values: Disabled, CurrentDir, LastSession";
description = ''
Define what to do when Neovim is started without arguments.
Takes either one of `"Disabled"`, `"CurrentDir"`, `"LastSession` in which case the value
will be inserted into `sm.AutoloadMode.<value>`, or an inline Lua value.
'';
};
max_path_length = mkOption {
type = types.nullOr types.int;
type = nullOr int;
default = 80;
description = "Shorten the display path if length exceeds this threshold. Use 0 if don't want to shorten the path at all";
description = ''
Shorten the display path if length exceeds this threshold.
Use `0` if don't want to shorten the path at all
'';
};
autosave_last_session = mkOption {
type = types.bool;
type = bool;
default = true;
description = "Automatically save last session on exit and on session switch";
description = ''
Automatically save last session on exit and on session switch
'';
};
autosave_ignore_not_normal = mkOption {
type = types.bool;
type = bool;
default = true;
description = "Plugin will not save a session when no buffers are opened, or all of them aren't writable or listed";
description = ''
Plugin will not save a session when no buffers are opened, or all of them are
not writable or listed
'';
};
autosave_ignore_dirs = mkOption {
type = types.listOf types.str;
type = listOf str;
default = [];
description = "A list of directories where the session will not be autosaved";
};
autosave_ignore_filetypes = mkOption {
type = types.listOf types.str;
type = listOf str;
default = ["gitcommit"];
description = "All buffers of these file types will be closed before the session is saved";
description = ''
All buffers of these file types will be closed before the session is saved
'';
};
autosave_ignore_buftypes = mkOption {
type = types.listOf types.str;
type = listOf str;
default = [];
description = "All buffers of these buffer types will be closed before the session is saved";
description = ''
All buffers of these buffer types will be closed before the session is saved
'';
};
autosave_only_in_session = mkOption {
type = types.bool;
type = bool;
default = false;
description = "Always autosaves session. If true, only autosaves after a session is active";
description = ''
Always autosaves session. If `true`, only autosaves after a session is active
'';
};
};
};

View file

@ -3,15 +3,18 @@
./binds
./ccc
./diffview
./direnv
./fzf-lua
./gestures
./harpoon
./icon-picker
./images
./leetcode-nvim
./mkdir
./motion
./multicursors
./new-file-template
./nix-develop
./outline
./preview
./surround

View file

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

View file

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

View file

@ -0,0 +1,5 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption;
in {
options.vim.utility.direnv.enable = mkEnableOption "syncing nvim shell environment with direnv's using `direnv.vim`";
}

View file

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

View file

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

View file

@ -0,0 +1,7 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption;
in {
options.vim.utility.mkdir.enable = mkEnableOption ''
parent directory creation when editing a nested path that does not exist using `mkdir.nvim`
'';
}

View file

@ -0,0 +1,12 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf;
cfg = config.vim.utility.nix-develop;
in {
vim = mkIf cfg.enable {
startPlugins = ["nix-develop-nvim"];
};
}

View file

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

View file

@ -0,0 +1,5 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption;
in {
options.vim.utility.nix-develop.enable = mkEnableOption "in-neovim `nix develop`, `nix shell`, and more using `nix-develop.nvim`";
}