mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-01-11 05:06:31 +00:00
modules: explicit lib usage
This commit is contained in:
parent
9b2e2ef833
commit
caf342adb1
27 changed files with 673 additions and 684 deletions
105
lib/binds.nix
Normal file
105
lib/binds.nix
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
{lib}: let
|
||||
inherit (lib.options) mkOption;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.types) nullOr str submodule bool;
|
||||
inherit (lib.attrsets) isAttrs mapAttrs attrsOf;
|
||||
in rec {
|
||||
# mkLuaBinding creates a binding with Lua and silent flags.
|
||||
#
|
||||
# Arguments:
|
||||
# - key: The name of the binding.
|
||||
# - action: The action to be performed when the binding is activated.
|
||||
# - desc: The description of the binding.
|
||||
mkLuaBinding = key: action: desc:
|
||||
mkIf (key != null) {
|
||||
"${key}" = {
|
||||
inherit action desc;
|
||||
lua = true;
|
||||
silent = true;
|
||||
};
|
||||
};
|
||||
|
||||
# mkExprBinding creates a binding with Lua, silent, and expr flags.
|
||||
#
|
||||
# Arguments:
|
||||
# - key: The name of the binding.
|
||||
# - action: The action to be performed when the binding is activated.
|
||||
# - desc: The description of the binding.
|
||||
mkExprBinding = key: action: desc:
|
||||
mkIf (key != null) {
|
||||
"${key}" = {
|
||||
inherit action desc;
|
||||
lua = true;
|
||||
silent = true;
|
||||
expr = true;
|
||||
};
|
||||
};
|
||||
|
||||
# mkBinding creates a binding with silent flag.
|
||||
#
|
||||
# Arguments:
|
||||
# - key: The name of the binding.
|
||||
# - action: The action to be performed when the binding is activated.
|
||||
# - desc: The description of the binding.
|
||||
mkBinding = key: action: desc:
|
||||
mkIf (key != null) {
|
||||
"${key}" = {
|
||||
inherit action desc;
|
||||
silent = true;
|
||||
};
|
||||
};
|
||||
|
||||
# mkMappingOption creates an option that can be null or a string.
|
||||
#
|
||||
# Arguments:
|
||||
# - description: The description of the option.
|
||||
# - default: The default value of the option.
|
||||
mkMappingOption = description: default:
|
||||
mkOption {
|
||||
type = nullOr str;
|
||||
inherit default description;
|
||||
};
|
||||
|
||||
# Utility function that takes two attrsets:
|
||||
# { someKey = "some_value" } and
|
||||
# { someKey = { description = "Some Description"; }; }
|
||||
# and merges them into
|
||||
# { someKey = { value = "some_value"; description = "Some Description"; }; }
|
||||
addDescriptionsToMappings = actualMappings: mappingDefinitions:
|
||||
mapAttrs (name: value: let
|
||||
isNested = isAttrs value;
|
||||
returnedValue =
|
||||
if isNested
|
||||
then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}"
|
||||
else {
|
||||
inherit value;
|
||||
inherit (mappingDefinitions."${name}") description;
|
||||
};
|
||||
in
|
||||
returnedValue)
|
||||
actualMappings;
|
||||
|
||||
# mkSetBinding creates a binding with the provided action and description.
|
||||
#
|
||||
# Arguments:
|
||||
# - binding: The binding to be set.
|
||||
# - action: The action to be performed when the binding is activated.
|
||||
mkSetBinding = binding: action:
|
||||
mkBinding binding.value action binding.description;
|
||||
|
||||
# mkSetExprBinding creates an expression binding with the provided action and description.
|
||||
#
|
||||
# Arguments:
|
||||
# - binding: The binding to be set.
|
||||
# - action: The action to be performed when the binding is activated.
|
||||
mkSetExprBinding = binding: action:
|
||||
mkExprBinding binding.value action binding.description;
|
||||
|
||||
# mkSetLuaBinding creates a Lua binding with the provided action and description.
|
||||
#
|
||||
# Arguments:
|
||||
# - binding: The binding to be set.
|
||||
# - action: The action to be performed when the binding is activated.
|
||||
mkSetLuaBinding = binding: action:
|
||||
mkLuaBinding binding.value action binding.description;
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
{lib}: {
|
||||
modules = import ./modules.nix {inherit lib;};
|
||||
dag = import ./dag.nix {inherit lib;};
|
||||
types = import ./types {inherit lib;};
|
||||
|
||||
binds = import ./binds.nix {inherit lib;};
|
||||
dag = import ./dag.nix {inherit lib;};
|
||||
languages = import ./languages.nix {inherit lib;};
|
||||
lua = import ./lua.nix {inherit lib;};
|
||||
modules = import ./modules.nix {inherit lib;};
|
||||
vim = import ./vim.nix {inherit lib;};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,70 +4,9 @@
|
|||
nixpkgsLib: let
|
||||
mkNvimLib = import ./.;
|
||||
in
|
||||
nixpkgsLib.extend (self: super: rec {
|
||||
nixpkgsLib.extend (self: super: {
|
||||
nvim = mkNvimLib {lib = self;};
|
||||
|
||||
mkLuaBinding = key: action: desc:
|
||||
self.mkIf (key != null) {
|
||||
"${key}" = {
|
||||
inherit action desc;
|
||||
lua = true;
|
||||
silent = true;
|
||||
};
|
||||
};
|
||||
|
||||
mkExprBinding = key: action: desc:
|
||||
self.mkIf (key != null) {
|
||||
"${key}" = {
|
||||
inherit action desc;
|
||||
lua = true;
|
||||
silent = true;
|
||||
expr = true;
|
||||
};
|
||||
};
|
||||
|
||||
mkBinding = key: action: desc:
|
||||
self.mkIf (key != null) {
|
||||
"${key}" = {
|
||||
inherit action desc;
|
||||
silent = true;
|
||||
};
|
||||
};
|
||||
|
||||
mkMappingOption = description: default:
|
||||
self.mkOption {
|
||||
type = self.types.nullOr self.types.str;
|
||||
inherit default description;
|
||||
};
|
||||
|
||||
# Utility function that takes two attrsets:
|
||||
# { someKey = "some_value" } and
|
||||
# { someKey = { description = "Some Description"; }; }
|
||||
# and merges them into
|
||||
# { someKey = { value = "some_value"; description = "Some Description"; }; }
|
||||
addDescriptionsToMappings = actualMappings: mappingDefinitions:
|
||||
self.attrsets.mapAttrs (name: value: let
|
||||
isNested = self.isAttrs value;
|
||||
returnedValue =
|
||||
if isNested
|
||||
then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}"
|
||||
else {
|
||||
value = value;
|
||||
description = mappingDefinitions."${name}".description;
|
||||
};
|
||||
in
|
||||
returnedValue)
|
||||
actualMappings;
|
||||
|
||||
mkSetBinding = binding: action:
|
||||
mkBinding binding.value action binding.description;
|
||||
|
||||
mkSetExprBinding = binding: action:
|
||||
mkExprBinding binding.value action binding.description;
|
||||
|
||||
mkSetLuaBinding = binding: action:
|
||||
mkLuaBinding binding.value action binding.description;
|
||||
|
||||
# For forward compatibility.
|
||||
literalExpression = super.literalExpression or super.literalExample;
|
||||
})
|
||||
|
|
|
|||
|
|
@ -39,13 +39,12 @@
|
|||
|
||||
core = map (p: ./core + "/${p}") [
|
||||
"build"
|
||||
"mappings"
|
||||
"warnings"
|
||||
];
|
||||
|
||||
neovim = map (p: ./neovim + "/${p}") [
|
||||
"basic"
|
||||
"maps"
|
||||
"mappings"
|
||||
"spellcheck"
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib) mkOption types;
|
||||
inherit (lib) nvim;
|
||||
inherit (nvim.modules) mkBoolOption;
|
||||
inherit (lib.types) submodule str bool attrsOf nullOr;
|
||||
inherit (lib.options) mkOption;
|
||||
inherit (lib.nvim.modules) mkBoolOption;
|
||||
|
||||
# Most of the keybindings code is highly inspired by pta2002/nixvim. Thank you!
|
||||
mapConfigOptions = {
|
||||
|
|
@ -30,23 +30,23 @@
|
|||
"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.";
|
||||
|
||||
desc = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
description = "A description of this keybind, to be shown in which-key, if you have it enabled.";
|
||||
};
|
||||
};
|
||||
|
||||
mapOption = types.submodule {
|
||||
mapOption = submodule {
|
||||
options =
|
||||
mapConfigOptions
|
||||
// {
|
||||
action = mkOption {
|
||||
type = types.str;
|
||||
type = str;
|
||||
description = "The action to execute.";
|
||||
};
|
||||
|
||||
lua = mkOption {
|
||||
type = types.bool;
|
||||
type = bool;
|
||||
description = ''
|
||||
If true, `action` is considered to be lua code.
|
||||
Thus, it will not be wrapped in `""`.
|
||||
|
|
@ -59,14 +59,14 @@
|
|||
mapOptions = mode:
|
||||
mkOption {
|
||||
description = "Mappings for ${mode} mode";
|
||||
type = types.attrsOf mapOption;
|
||||
type = attrsOf mapOption;
|
||||
default = {};
|
||||
};
|
||||
in {
|
||||
options = {
|
||||
vim = {
|
||||
maps = mkOption {
|
||||
type = types.submodule {
|
||||
type = submodule {
|
||||
options = {
|
||||
normal = mapOptions "normal";
|
||||
insert = mapOptions "insert";
|
||||
|
|
@ -1,11 +1,15 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) toJSON;
|
||||
inherit (lib) mkIf nvim mkLuaBinding mkMerge;
|
||||
inherit (lib.trivial) boolToString toString;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.lists) optionals;
|
||||
inherit (lib.nvim.binds) mkLuaBinding;
|
||||
inherit (lib.nvim.dag) entryAnywhere;
|
||||
|
||||
cfg = config.vim.assistant.copilot;
|
||||
|
||||
|
|
@ -22,21 +26,22 @@
|
|||
'';
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins =
|
||||
vim = {
|
||||
startPlugins =
|
||||
[
|
||||
"copilot-lua"
|
||||
cfg.copilotNodePackage
|
||||
]
|
||||
++ lib.optionals (cfg.cmp.enable) [
|
||||
++ optionals cfg.cmp.enable [
|
||||
"copilot-cmp"
|
||||
];
|
||||
|
||||
vim.luaConfigRC.copilot = nvim.dag.entryAnywhere ''
|
||||
luaConfigRC.copilot = entryAnywhere ''
|
||||
require("copilot").setup({
|
||||
-- available options: https://github.com/zbirenbaum/copilot.lua
|
||||
copilot_node_command = "${cfg.copilotNodeCommand}",
|
||||
panel = {
|
||||
enabled = ${lib.boolToString (!cfg.cmp.enable)},
|
||||
enabled = ${boolToString (!cfg.cmp.enable)},
|
||||
keymap = {
|
||||
jump_prev = false,
|
||||
jump_next = false,
|
||||
|
|
@ -50,7 +55,7 @@ in {
|
|||
},
|
||||
},
|
||||
suggestion = {
|
||||
enabled = ${lib.boolToString (!cfg.cmp.enable)},
|
||||
enabled = ${boolToString (!cfg.cmp.enable)},
|
||||
keymap = {
|
||||
accept = false,
|
||||
accept_word = false,
|
||||
|
|
@ -62,12 +67,13 @@ in {
|
|||
},
|
||||
})
|
||||
|
||||
${lib.optionalString (cfg.cmp.enable) ''
|
||||
${optionalString cfg.cmp.enable ''
|
||||
require("copilot_cmp").setup()
|
||||
''}
|
||||
'';
|
||||
|
||||
vim.maps.normal = mkMerge [
|
||||
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")
|
||||
|
|
@ -78,7 +84,7 @@ in {
|
|||
cfg.mappings.panel.open) "[copilot] Accept suggestion")
|
||||
];
|
||||
|
||||
vim.maps.insert = mkMerge [
|
||||
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)")
|
||||
|
|
@ -87,4 +93,6 @@ in {
|
|||
(mkLuaBinding cfg.mappings.suggestion.dismiss "require(\"copilot.suggestion\").dismiss" "[copilot] dismiss suggestion")
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
inherit (lib.types) enum float nullOr package str;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.meta) getExe;
|
||||
|
||||
cfg = config.vim.assistant.copilot;
|
||||
in {
|
||||
|
|
@ -14,7 +16,7 @@ in {
|
|||
|
||||
panel = {
|
||||
position = mkOption {
|
||||
type = types.enum [
|
||||
type = enum [
|
||||
"bottom"
|
||||
"top"
|
||||
"left"
|
||||
|
|
@ -24,7 +26,7 @@ in {
|
|||
description = "Panel position";
|
||||
};
|
||||
ratio = mkOption {
|
||||
type = types.float;
|
||||
type = float;
|
||||
default = 0.4;
|
||||
description = "Panel size";
|
||||
};
|
||||
|
|
@ -33,81 +35,81 @@ in {
|
|||
mappings = {
|
||||
panel = {
|
||||
jumpPrev = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "[[";
|
||||
description = "Jump to previous suggestion";
|
||||
};
|
||||
jumpNext = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "]]";
|
||||
description = "Jump to next suggestion";
|
||||
};
|
||||
accept = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "<CR>";
|
||||
description = "Accept suggestion";
|
||||
};
|
||||
refresh = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "gr";
|
||||
description = "Refresh suggestions";
|
||||
};
|
||||
open = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "<M-CR>";
|
||||
description = "Open suggestions";
|
||||
};
|
||||
};
|
||||
suggestion = {
|
||||
accept = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "<M-l>";
|
||||
description = "Accept suggetion";
|
||||
};
|
||||
acceptWord = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
description = "Accept next word";
|
||||
};
|
||||
acceptLine = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
description = "Accept next line";
|
||||
};
|
||||
prev = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "<M-[>";
|
||||
description = "Previous suggestion";
|
||||
};
|
||||
next = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "<M-]>";
|
||||
description = "Next suggestion";
|
||||
};
|
||||
dismiss = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "<C-]>";
|
||||
description = "Dismiss suggestion";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
copilotNodeCommand = mkOption {
|
||||
type = types.str;
|
||||
default = "${lib.getExe cfg.copilotNodePackage}";
|
||||
description = ''
|
||||
The command that will be executed to initiate nodejs for GitHub Copilot.
|
||||
Recommended to leave as default.
|
||||
'';
|
||||
};
|
||||
|
||||
copilotNodePackage = mkOption {
|
||||
type = with types; nullOr package;
|
||||
type = nullOr package;
|
||||
default = pkgs.nodejs-slim;
|
||||
description = ''
|
||||
The nodeJS package that will be used for GitHub Copilot. If you are using a custom node command
|
||||
you may want to set this option to null so that the package is not pulled from nixpkgs.
|
||||
'';
|
||||
};
|
||||
|
||||
copilotNodeCommand = mkOption {
|
||||
type = str;
|
||||
default = "${getExe cfg.copilotNodePackage}";
|
||||
description = ''
|
||||
The command that will be executed to initiate nodejs for GitHub Copilot.
|
||||
Recommended to leave as default.
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./copilot
|
||||
# ./tabnine.nix # removed until I find a way around the initialisation script the plugin requires
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) toJSON;
|
||||
inherit (lib) mkIf mkMerge mkExprBinding boolToString nvim;
|
||||
|
||||
cfg = config.vim.assistant.tabnine;
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins = ["tabnine-nvim"];
|
||||
|
||||
vim.maps.insert = mkMerge [
|
||||
(mkExprBinding cfg.mappings.accept ''
|
||||
function()
|
||||
local state = require("tabnine.state")
|
||||
local completion = require("tabnine.completion")
|
||||
|
||||
if not state.completions_cache then
|
||||
return "${toJSON cfg.mappings.accept}"
|
||||
end
|
||||
|
||||
vim.schedule(completion.accept)
|
||||
end
|
||||
'' "orzel")
|
||||
(mkExprBinding cfg.mappings.dismiss ''
|
||||
function()
|
||||
local state = require("tabnine.state")
|
||||
local completion = require("tabnine.completion")
|
||||
|
||||
if not state.completions_cache then
|
||||
return "${toJSON cfg.mappings.dismiss}"
|
||||
end
|
||||
|
||||
vim.schedule(function()
|
||||
completion.clear()
|
||||
state.completions_cache = nil
|
||||
end)
|
||||
end
|
||||
'' "orzel")
|
||||
];
|
||||
|
||||
vim.luaConfigRC.tabnine-nvim = nvim.dag.entryAnywhere ''
|
||||
require('tabnine').setup({
|
||||
disable_auto_comment = ${boolToString cfg.disable_auto_comment},
|
||||
accept_keymap = null,
|
||||
dismiss_keymap = null,
|
||||
debounce_ms = ${cfg.debounce_ms},
|
||||
exclude_filetypes = ${cfg.exclude_filetypes},
|
||||
})
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
_: {
|
||||
imports = [
|
||||
./config.nix
|
||||
./tabnine.nix
|
||||
];
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib) mkEnableOption mkOption types mkMappingOption;
|
||||
in {
|
||||
options.vim.assistant.tabnine = {
|
||||
enable = mkEnableOption "Tabnine assistant";
|
||||
|
||||
disable_auto_comment = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Disable auto comment";
|
||||
};
|
||||
|
||||
mappings = {
|
||||
accept = mkMappingOption "Accept [Tabnine]" "<Tab>";
|
||||
dismiss = mkMappingOption "Dismiss [Tabnine]" "<C-]>";
|
||||
};
|
||||
|
||||
debounce_ms = mkOption {
|
||||
type = types.int;
|
||||
default = 800;
|
||||
description = "Debounce ms";
|
||||
};
|
||||
|
||||
exclude_filetypes = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = ["TelescopePrompt" "NvimTree" "alpha"];
|
||||
description = "Exclude filetypes";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./nvim-autopairs
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,18 +1,20 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf nvim optionalString boolToString;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.trivial) boolToString;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.nvim.dag) entryAnywhere;
|
||||
|
||||
cfg = config.vim.autopairs;
|
||||
in {
|
||||
config =
|
||||
mkIf (cfg.enable)
|
||||
{
|
||||
vim.startPlugins = ["nvim-autopairs"];
|
||||
config = mkIf cfg.enable {
|
||||
vim = {
|
||||
startPlugins = ["nvim-autopairs"];
|
||||
|
||||
vim.luaConfigRC.autopairs = nvim.dag.entryAnywhere ''
|
||||
luaConfigRC.autopairs = entryAnywhere ''
|
||||
require("nvim-autopairs").setup{}
|
||||
${optionalString (config.vim.autocomplete.type == "nvim-compe") ''
|
||||
require('nvim-autopairs.completion.compe').setup({
|
||||
|
|
@ -23,4 +25,5 @@ in {
|
|||
''}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./config.nix
|
||||
./nvim-autopairs.nix
|
||||
|
|
|
|||
|
|
@ -1,31 +1,37 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
inherit (lib.options) mkEnableOption mkOption;
|
||||
inherit (lib.tyoes) enum bool;
|
||||
in {
|
||||
options.vim = {
|
||||
autopairs = {
|
||||
enable = mkEnableOption "autopairs" // {default = false;};
|
||||
enable = mkEnableOption "autopairs";
|
||||
|
||||
type = mkOption {
|
||||
type = types.enum ["nvim-autopairs"];
|
||||
type = enum ["nvim-autopairs"];
|
||||
default = "nvim-autopairs";
|
||||
description = "Set the autopairs type. Options: nvim-autopairs [nvim-autopairs]";
|
||||
description = ''
|
||||
Set the autopairs type.
|
||||
|
||||
Options:
|
||||
- nvim-autopairs [nvim-autopairs]
|
||||
'';
|
||||
};
|
||||
|
||||
nvim-compe = {
|
||||
map_cr = mkOption {
|
||||
type = types.bool;
|
||||
type = bool;
|
||||
default = true;
|
||||
description = ''map <CR> on insert mode'';
|
||||
};
|
||||
|
||||
map_complete = mkOption {
|
||||
type = types.bool;
|
||||
type = bool;
|
||||
default = true;
|
||||
description = "auto insert `(` after select function or method item";
|
||||
};
|
||||
|
||||
auto_select = mkOption {
|
||||
type = types.bool;
|
||||
type = bool;
|
||||
default = false;
|
||||
description = "auto select first item";
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib) mkEnableOption mkMappingOption;
|
||||
inherit (lib.options) mkEnableOption;
|
||||
inherit (lib.nvim.binds) mkMappingOption;
|
||||
in {
|
||||
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]";
|
||||
|
||||
mappings = {
|
||||
toggleCurrentLine = mkMappingOption "Toggle current line comment" "gcc";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./comment-nvim
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./nvim-cmp
|
||||
];
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@
|
|||
...
|
||||
}: let
|
||||
inherit (builtins) toJSON;
|
||||
inherit (lib) addDescriptionsToMappings concatMapStringsSep attrNames concatStringsSep mapAttrsToList mkIf mkSetLuaBinding mkMerge optionalString;
|
||||
inherit (lib.nvim) dag;
|
||||
inherit (lib.binds) addDescriptionsToMappings mkSetLuaBinding;
|
||||
inherit (lib.strings) concatMapStringsSep concatStringsSep optionalString;
|
||||
inherit (lib.attrsets) attrNames mapAttrsToList;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.nvim.dag) entryAfter entryAnywhere;
|
||||
|
||||
cfg = config.vim.autocomplete;
|
||||
lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable;
|
||||
|
|
@ -33,11 +36,12 @@
|
|||
|
||||
dagPlacement =
|
||||
if lspkindEnabled
|
||||
then dag.entryAfter ["lspkind"]
|
||||
else dag.entryAnywhere;
|
||||
then entryAfter ["lspkind"]
|
||||
else entryAnywhere;
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins = [
|
||||
vim = {
|
||||
startPlugins = [
|
||||
"nvim-cmp"
|
||||
"cmp-buffer"
|
||||
"cmp-vsnip"
|
||||
|
|
@ -45,7 +49,7 @@ in {
|
|||
"vim-vsnip"
|
||||
];
|
||||
|
||||
vim.autocomplete.sources = {
|
||||
autocomplete.sources = {
|
||||
"nvim-cmp" = null;
|
||||
"vsnip" = "[VSnip]";
|
||||
"buffer" = "[Buffer]";
|
||||
|
|
@ -54,7 +58,8 @@ in {
|
|||
"copilot" = "[Copilot]";
|
||||
};
|
||||
|
||||
vim.maps.insert = mkMerge [
|
||||
maps = {
|
||||
insert = mkMerge [
|
||||
(mkSetLuaBinding mappings.complete ''
|
||||
require('cmp').complete
|
||||
'')
|
||||
|
|
@ -119,7 +124,7 @@ in {
|
|||
'')
|
||||
];
|
||||
|
||||
vim.maps.command = mkMerge [
|
||||
command = mkMerge [
|
||||
(mkSetLuaBinding mappings.complete ''
|
||||
require('cmp').complete
|
||||
'')
|
||||
|
|
@ -134,7 +139,7 @@ in {
|
|||
'')
|
||||
];
|
||||
|
||||
vim.maps.select = mkMerge [
|
||||
select = mkMerge [
|
||||
(mkSetLuaBinding mappings.next ''
|
||||
function()
|
||||
local cmp = require('cmp')
|
||||
|
|
@ -176,10 +181,11 @@ in {
|
|||
end
|
||||
'')
|
||||
];
|
||||
};
|
||||
|
||||
# TODO: alternative snippet engines to vsnip
|
||||
# https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L82
|
||||
vim.luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement ''
|
||||
luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement ''
|
||||
local nvim_cmp_menu_map = function(entry, vim_item)
|
||||
-- name for each source
|
||||
vim_item.menu = ({
|
||||
|
|
@ -195,7 +201,7 @@ in {
|
|||
|
||||
local cmp = require'cmp'
|
||||
cmp.setup({
|
||||
${optionalString (config.vim.ui.borders.enable) ''
|
||||
${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 = {
|
||||
|
|
@ -233,9 +239,10 @@ in {
|
|||
''}
|
||||
'');
|
||||
|
||||
vim.snippets.vsnip.enable =
|
||||
snippets.vsnip.enable =
|
||||
if (cfg.type == "nvim-cmp")
|
||||
then true
|
||||
else config.vim.snippets.vsnip.enable;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./config.nix
|
||||
./nvim-cmp.nix
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib) mkEnableOption mkMappingOption mkOption types;
|
||||
inherit (lib.types) enum nullOr attrsOf str;
|
||||
inherit (lib) mkEnableOption mkMappingOption mkOption;
|
||||
in {
|
||||
options.vim = {
|
||||
autocomplete = {
|
||||
enable = mkEnableOption "enable autocomplete" // {default = false;};
|
||||
enable = mkEnableOption "enable autocomplete";
|
||||
|
||||
mappings = {
|
||||
complete = mkMappingOption "Complete [nvim-cmp]" "<C-Space>";
|
||||
|
|
@ -16,9 +17,14 @@ in {
|
|||
};
|
||||
|
||||
type = mkOption {
|
||||
type = types.enum ["nvim-cmp"];
|
||||
type = enum ["nvim-cmp"];
|
||||
default = "nvim-cmp";
|
||||
description = "Set the autocomplete plugin. Options: [nvim-cmp]";
|
||||
description = ''
|
||||
Set the autocomplete plugin.
|
||||
|
||||
Options:
|
||||
- [nvim-cmp]
|
||||
'';
|
||||
};
|
||||
|
||||
sources = mkOption {
|
||||
|
|
@ -31,7 +37,7 @@ in {
|
|||
|
||||
Note: only use a single attribute name per attribute set
|
||||
'';
|
||||
type = with types; attrsOf (nullOr str);
|
||||
type = attrsOf (nullOr str);
|
||||
default = {};
|
||||
example = ''
|
||||
{nvim-cmp = null; buffer = "[Buffer]";}
|
||||
|
|
@ -48,9 +54,9 @@ in {
|
|||
|
||||
Default is to call the menu mapping function.
|
||||
'';
|
||||
type = types.str;
|
||||
type = str;
|
||||
default = "nvim_cmp_menu_map";
|
||||
example = lib.literalMD ''
|
||||
example = ''
|
||||
```lua
|
||||
function(entry, vim_item)
|
||||
return vim_item
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkEnableOption;
|
||||
{lib, ...}: let
|
||||
inherit (lib.options) mkEnableOption;
|
||||
in {
|
||||
options.vim.dashboard.alpha = {
|
||||
enable = mkEnableOption "dashboard via alpha.nvim";
|
||||
enable = mkEnableOption "dashboard [alpha-nvim]";
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,19 +3,21 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf nvim;
|
||||
inherit (lib.options) mkIf;
|
||||
inherit (lib.nvim.dag) entryAnywhere;
|
||||
|
||||
cfg = config.vim.dashboard.alpha;
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins = [
|
||||
vim = {
|
||||
startPlugins = [
|
||||
"alpha-nvim"
|
||||
"nvim-web-devicons"
|
||||
];
|
||||
|
||||
# the entire credit for this dashboard configuration to https://github.com/Rishabh672003
|
||||
# honestly, excellent work
|
||||
vim.luaConfigRC.alpha = nvim.dag.entryAnywhere ''
|
||||
luaConfigRC.alpha = entryAnywhere ''
|
||||
local alpha = require("alpha")
|
||||
local plenary_path = require("plenary.path")
|
||||
local dashboard = require("alpha.themes.dashboard")
|
||||
|
|
@ -216,4 +218,5 @@ in {
|
|||
alpha.setup(config)
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./alpha.nix
|
||||
./config.nix
|
||||
|
|
|
|||
|
|
@ -3,17 +3,20 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf nvim;
|
||||
inherit (lib.options) mkIf;
|
||||
inherit (lib.nvim.dag) entryAnywhere;
|
||||
|
||||
cfg = config.vim.dashboard.dashboard-nvim;
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins = [
|
||||
vim = {
|
||||
startPlugins = [
|
||||
"dashboard-nvim"
|
||||
];
|
||||
|
||||
vim.luaConfigRC.dashboard-nvim = nvim.dag.entryAnywhere ''
|
||||
luaConfigRC.dashboard-nvim = entryAnywhere ''
|
||||
require("dashboard").setup{}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{...}: {
|
||||
{
|
||||
imports = [
|
||||
./alpha
|
||||
./dashboard-nvim
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue