Skip to content

Commit

Permalink
modules: make lib calls explicit where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAShelf committed Feb 26, 2024
1 parent bf1118e commit 0b69e17
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 69 deletions.
15 changes: 9 additions & 6 deletions modules/assistant/copilot/config.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
pkgs,
config,
lib,
...
}: let
inherit (builtins) toJSON;
inherit (lib) mkIf nvim mkLuaBinding mkMerge;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.lists) optionals;
inherit (lib.trivial) boolToString;
inherit (lib.nvim.binds) mkLuaBinding;

cfg = config.vim.assistant.copilot;

Expand All @@ -27,16 +30,16 @@ in {
"copilot-lua"
cfg.copilotNodePackage
]
++ lib.optionals (cfg.cmp.enable) [
++ optionals (cfg.cmp.enable) [
"copilot-cmp"
];

vim.luaConfigRC.copilot = nvim.dag.entryAnywhere ''
vim.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,
Expand All @@ -50,7 +53,7 @@ in {
},
},
suggestion = {
enabled = ${lib.boolToString (!cfg.cmp.enable)},
enabled = ${boolToString (!cfg.cmp.enable)},
keymap = {
accept = false,
accept_word = false,
Expand Down
47 changes: 29 additions & 18 deletions modules/assistant/copilot/copilot.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
pkgs,
config,
pkgs,
lib,
...
}: let
inherit (lib) mkEnableOption mkOption types;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) enum float nullOr str package;
inherit (lib.meta) getExe;

cfg = config.vim.assistant.copilot;
in {
Expand All @@ -14,7 +16,7 @@ in {

panel = {
position = mkOption {
type = types.enum [
type = enum [
"bottom"
"top"
"left"
Expand All @@ -24,7 +26,7 @@ in {
description = "Panel position";
};
ratio = mkOption {
type = types.float;
type = float;
default = 0.4;
description = "Panel size";
};
Expand All @@ -33,76 +35,85 @@ 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}";
type = str;
default = "${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
Expand Down
2 changes: 1 addition & 1 deletion modules/assistant/copilot/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_: {
{
imports = [
./copilot.nix
./config.nix
Expand Down
2 changes: 1 addition & 1 deletion modules/autopairs/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_: {
{
imports = [
./nvim-autopairs
];
Expand Down
36 changes: 19 additions & 17 deletions modules/autopairs/nvim-autopairs/config.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
{
lib,
config,
lib,
...
}: let
inherit (lib) mkIf nvim optionalString boolToString;
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.strings) optionalString;
inherit (lib.trivial) boolToString;

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 ''
require("nvim-autopairs").setup{}
${optionalString (config.vim.autocomplete.type == "nvim-compe") ''
require('nvim-autopairs.completion.compe').setup({
map_cr = ${boolToString cfg.nvim-compe.map_cr},
map_complete = ${boolToString cfg.nvim-compe.map_complete},
auto_select = ${boolToString cfg.nvim-compe.auto_select},
})
''}
'';
};
vim.luaConfigRC.autopairs = entryAnywhere ''
require("nvim-autopairs").setup{}
${optionalString (config.vim.autocomplete.type == "nvim-compe") ''
-- nvim-compe integration
require('nvim-autopairs.completion.compe').setup({
map_cr = ${boolToString cfg.nvim-compe.map_cr},
map_complete = ${boolToString cfg.nvim-compe.map_complete},
auto_select = ${boolToString cfg.nvim-compe.auto_select},
})
''}
'';
};
}
2 changes: 1 addition & 1 deletion modules/autopairs/nvim-autopairs/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_: {
{
imports = [
./config.nix
./nvim-autopairs.nix
Expand Down
11 changes: 6 additions & 5 deletions modules/autopairs/nvim-autopairs/nvim-autopairs.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{lib, ...}: let
inherit (lib) mkEnableOption mkOption types;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) enum bool;
in {
options.vim = {
autopairs = {
enable = mkEnableOption "autopairs" // {default = false;};

type = mkOption {
type = types.enum ["nvim-autopairs"];
type = enum ["nvim-autopairs"];
default = "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";
};
Expand Down
3 changes: 2 additions & 1 deletion modules/comments/comment-nvim/comment-nvim.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{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";
Expand Down
12 changes: 6 additions & 6 deletions modules/comments/comment-nvim/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
lib,
...
}: let
inherit (lib) mkIf mkMerge mkExprBinding mkBinding nvim;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.binds) mkExprBinding mkBinding;
inherit (lib.nvim.dag) entryAnywhere;

cfg = config.vim.comments.comment-nvim;
self = import ./comment-nvim.nix {
inherit lib;
};
mappings = self.options.vim.comments.comment-nvim.mappings;
self = import ./comment-nvim.nix {inherit lib;};
inherit (self.options.vim.comments.comment-nvim) mappings;
in {
config = mkIf cfg.enable {
vim.startPlugins = [
Expand Down Expand Up @@ -41,7 +41,7 @@ in {
(mkBinding cfg.mappings.toggleSelectedBlock "<Plug>(comment_toggle_blockwise_visual)" mappings.toggleSelectedBlock.description)
];

vim.luaConfigRC.comment-nvim = nvim.dag.entryAnywhere ''
vim.luaConfigRC.comment-nvim = entryAnywhere ''
require('Comment').setup({
mappings = { basic = false, extra = false, },
})
Expand Down
2 changes: 1 addition & 1 deletion modules/comments/comment-nvim/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_: {
{
imports = [
./config.nix
./comment-nvim.nix
Expand Down
2 changes: 1 addition & 1 deletion modules/comments/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_: {
{
imports = [
./comment-nvim
];
Expand Down
2 changes: 1 addition & 1 deletion modules/completion/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_: {
{
imports = [
./nvim-cmp
];
Expand Down
13 changes: 8 additions & 5 deletions modules/completion/nvim-cmp/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.modules) mkIf mkMerge;
inherit (lib.attrsets) attrNames mapAttrsToList;
inherit (lib.strings) concatMapStringsSep concatStringsSep optionalString;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding;
inherit (lib.nvim.dag) entryAnywhere entryAfter;

cfg = config.vim.autocomplete;
lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable;
Expand Down Expand Up @@ -33,8 +36,8 @@

dagPlacement =
if lspkindEnabled
then dag.entryAfter ["lspkind"]
else dag.entryAnywhere;
then entryAfter ["lspkind"]
else entryAnywhere;
in {
config = mkIf cfg.enable {
vim.startPlugins = [
Expand Down Expand Up @@ -195,7 +198,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 = {
Expand Down
Loading

0 comments on commit 0b69e17

Please sign in to comment.