Skip to content

Commit

Permalink
treewide: change modules to use 'inherit (builtins) ...
Browse files Browse the repository at this point in the history
  • Loading branch information
FrothyMarrow committed Nov 14, 2023
1 parent c77b007 commit 5d282f4
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 40 deletions.
3 changes: 2 additions & 1 deletion modules/assistant/copilot/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
lib,
...
}: let
inherit (builtins) toJSON;
inherit (lib) mkIf nvim mkLuaBinding mkMerge;

cfg = config.vim.assistant.copilot;
Expand All @@ -13,7 +14,7 @@
local s, _ = pcall(${luaFunction})
if not s then
local termcode = vim.api.nvim_replace_termcodes(${builtins.toJSON key}, true, false, true)
local termcode = vim.api.nvim_replace_termcodes(${toJSON key}, true, false, true)
vim.fn.feedkeys(termcode, 'n')
end
Expand Down
5 changes: 3 additions & 2 deletions modules/assistant/tabnine/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
lib,
...
}: let
inherit (builtins) toJSON;
inherit (lib) mkIf mkMerge mkExprBinding boolToString nvim;

cfg = config.vim.assistant.tabnine;
Expand All @@ -17,7 +18,7 @@ in {
local completion = require("tabnine.completion")
if not state.completions_cache then
return "${builtins.toJSON cfg.mappings.accept}"
return "${toJSON cfg.mappings.accept}"
end
vim.schedule(completion.accept)
Expand All @@ -29,7 +30,7 @@ in {
local completion = require("tabnine.completion")
if not state.completions_cache then
return "${builtins.toJSON cfg.mappings.dismiss}"
return "${toJSON cfg.mappings.dismiss}"
end
vim.schedule(function()
Expand Down
3 changes: 2 additions & 1 deletion modules/basic/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
config,
...
}: let
inherit (builtins) concatStringsSep;
inherit (lib) optionalString mkIf nvim;

cfg = config.vim;
Expand Down Expand Up @@ -141,7 +142,7 @@ in {
''}
${optionalString cfg.spellChecking.enable ''
set spell
set spelllang=${builtins.concatStringsSep "," cfg.spellChecking.languages}${optionalString cfg.spellChecking.enableProgrammingWordList ",programming"}
set spelllang=${concatStringsSep "," cfg.spellChecking.languages}${optionalString cfg.spellChecking.enableProgrammingWordList ",programming"}
''}
${optionalString (cfg.leaderKey != null) ''
let mapleader = "${toString cfg.leaderKey}"
Expand Down
14 changes: 8 additions & 6 deletions modules/completion/nvim-cmp/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
config,
...
}: let
inherit (lib) addDescriptionsToMappings concatMapStringsSep attrNames concatStringsSep mapAttrsToList nvim mkIf mkSetLuaBinding mkMerge optionalString;
inherit (builtins) toJSON;
inherit (lib) addDescriptionsToMappings concatMapStringsSep attrNames concatStringsSep mapAttrsToList mkIf mkSetLuaBinding mkMerge optionalString;
inherit (lib.nvim) dag;

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

dagPlacement =
if lspkindEnabled
then nvim.dag.entryAfter ["lspkind"]
else nvim.dag.entryAnywhere;
then dag.entryAfter ["lspkind"]
else dag.entryAnywhere;
in {
config = mkIf cfg.enable {
vim.startPlugins = [
Expand All @@ -59,7 +61,7 @@ in {
(mkSetLuaBinding mappings.confirm ''
function()
if not require('cmp').confirm({ select = true }) then
local termcode = vim.api.nvim_replace_termcodes(${builtins.toJSON mappings.confirm.value}, true, false, true)
local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.confirm.value}, true, false, true)
vim.fn.feedkeys(termcode, 'n')
end
Expand All @@ -85,7 +87,7 @@ in {
elseif has_words_before() then
cmp.complete()
else
local termcode = vim.api.nvim_replace_termcodes(${builtins.toJSON mappings.next.value}, true, false, true)
local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true)
vim.fn.feedkeys(termcode, 'n')
end
Expand Down Expand Up @@ -152,7 +154,7 @@ in {
elseif has_words_before() then
cmp.complete()
else
local termcode = vim.api.nvim_replace_termcodes(${builtins.toJSON mappings.next.value}, true, false, true)
local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true)
vim.fn.feedkeys(termcode, 'n')
end
Expand Down
11 changes: 6 additions & 5 deletions modules/core/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
lib,
...
}:
with builtins; let
let
inherit (builtins) attrValues attrNames map mapAttrs toJSON isString concatStringsSep filter;
inherit (lib) mkOption types mapAttrsFlatten filterAttrs optionalString getAttrs literalExpression;
inherit (lib) nvim;
inherit (nvim.lua) toLuaObject;
Expand Down Expand Up @@ -84,7 +85,7 @@ with builtins; let
else action.action;
};
in
builtins.attrValues (builtins.mapAttrs
attrValues (mapAttrs
(key: action: let
normalizedAction = normalizeAction action;
in {
Expand Down Expand Up @@ -258,7 +259,7 @@ in {
(filterNonNull cfg.globals);

toLuaBindings = mode: maps:
builtins.map (value: ''
map (value: ''
vim.keymap.set(${toLuaObject mode}, ${toLuaObject value.key}, ${toLuaObject value.action}, ${toLuaObject value.config})
'') (genMaps mode maps);

Expand All @@ -282,15 +283,15 @@ in {
}: let
# When the value is a string, default it to dag.entryAnywhere
finalDag = lib.mapAttrs (_: value:
if builtins.isString value
if isString value
then nvim.dag.entryAnywhere value
else value)
dag;
sortedDag = nvim.dag.topoSort finalDag;
result =
if sortedDag ? result
then mapResult sortedDag.result
else abort ("Dependency cycle in ${name}: " + toJSON sortedConfig);
else abort ("Dependency cycle in ${name}: " + toJSON sortedDag);
in
result;
in {
Expand Down
2 changes: 1 addition & 1 deletion modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ inputs: {
check ? true,
extraSpecialArgs ? {},
}: let
inherit (pkgs) wrapNeovim vimPlugins;
inherit (builtins) map filter isString toString getAttr;
inherit (pkgs) wrapNeovim vimPlugins;
inherit (pkgs.vimUtils) buildVimPlugin;

extendedLib = import ../lib/stdlib-extended.nix lib;
Expand Down
10 changes: 6 additions & 4 deletions modules/git/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
lib,
...
}: let
inherit (lib) addDescriptionsToMappings mkIf mkMerge mkSetExprBinding toJSON mkSetLuaBinding nvim;
inherit (builtins) toJSON;
inherit (lib) addDescriptionsToMappings mkIf mkMerge mkSetExprBinding mkSetLuaBinding nvim;

cfg = config.vim.git;

self = import ./git.nix {inherit lib;};
Expand All @@ -19,7 +21,7 @@ in {
vim.maps.normal = mkMerge [
(mkSetExprBinding gsMappings.nextHunk ''
function()
if vim.wo.diff then return ${builtins.toJSON gsMappings.nextHunk.value} end
if vim.wo.diff then return ${toJSON gsMappings.nextHunk.value} end
vim.schedule(function() package.loaded.gitsigns.next_hunk() end)
Expand All @@ -28,7 +30,7 @@ in {
'')
(mkSetExprBinding gsMappings.previousHunk ''
function()
if vim.wo.diff then return ${builtins.toJSON gsMappings.previousHunk.value} end
if vim.wo.diff then return ${toJSON gsMappings.previousHunk.value} end
vim.schedule(function() package.loaded.gitsigns.prev_hunk() end)
Expand Down Expand Up @@ -69,7 +71,7 @@ in {
vim.lsp.null-ls.sources.gitsigns-ca = ''
table.insert(
ls_sources,
null_ls.builtins.code_actions.gitsigns
null_ls.gcode_actions.gitsigns
)
'';
})
Expand Down
5 changes: 3 additions & 2 deletions modules/languages/bash/bash.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib) mkOption mkEnableOption types isList nvim;

cfg = config.vim.languages.bash;
Expand Down Expand Up @@ -69,7 +70,7 @@ in {

server = mkOption {
description = "Bash LSP server to use";
type = with types; enum (builtins.attrNames servers);
type = with types; enum (attrNames servers);
default = defaultServer;
};

Expand All @@ -89,7 +90,7 @@ in {
};
type = mkOption {
description = "Bash formatter to use";
type = with types; enum (builtins.attrNames formats);
type = with types; enum (attrNames formats);
default = defaultFormat;
};

Expand Down
5 changes: 3 additions & 2 deletions modules/languages/clang.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib) isList nvim optionalString mkEnableOption mkOption types mkIf mkMerge;

cfg = config.vim.languages.clang;
Expand Down Expand Up @@ -93,7 +94,7 @@ in {

server = mkOption {
description = "The clang LSP server to use";
type = with types; enum (builtins.attrNames servers);
type = with types; enum (attrNames servers);
default = defaultServer;
};

Expand All @@ -119,7 +120,7 @@ in {
};
debugger = mkOption {
description = "clang debugger to use";
type = with types; enum (builtins.attrNames debuggers);
type = with types; enum (attrNames debuggers);
default = defaultDebugger;
};
package = mkOption {
Expand Down
3 changes: 2 additions & 1 deletion modules/languages/dart/dart.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pkgs,
...
}: let
inherit (builtins) attrNames;
inherit (lib) isList nvim mkEnableOption mkOption types optionalString;

cfg = config.vim.languages.dart;
Expand Down Expand Up @@ -38,7 +39,7 @@ in {
enable = mkEnableOption "Dart LSP support";
server = mkOption {
description = "The Dart LSP server to use";
type = with types; enum (builtins.attrNames servers);
type = with types; enum (attrNames servers);
default = defaultServer;
};
package = mkOption {
Expand Down
5 changes: 3 additions & 2 deletions modules/languages/go.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib) isList nvim getExe mkEnableOption mkOption types mkMerge mkIf;

cfg = config.vim.languages.go;
Expand Down Expand Up @@ -80,7 +81,7 @@ in {

server = mkOption {
description = "Go LSP server to use";
type = with types; enum (builtins.attrNames servers);
type = with types; enum (attrNames servers);
default = defaultServer;
};

Expand All @@ -100,7 +101,7 @@ in {
};
debugger = mkOption {
description = "Go debugger to use";
type = with types; enum (builtins.attrNames debuggers);
type = with types; enum (attrNames debuggers);
default = defaultDebugger;
};
package = mkOption {
Expand Down
3 changes: 2 additions & 1 deletion modules/languages/nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib) isList nvim mkEnableOption mkOption types mkIf mkMerge optionalString;

cfg = config.vim.languages.nix;
Expand Down Expand Up @@ -146,7 +147,7 @@ in {

type = mkOption {
description = "Nix formatter to use";
type = with types; enum (builtins.attrNames formats);
type = with types; enum (attrNames formats);
default = defaultFormat;
};
package = mkOption {
Expand Down
3 changes: 2 additions & 1 deletion modules/languages/php.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib) isList nvim mkEnableOption mkOption types mkIf mkMerge getExe;

cfg = config.vim.languages.php;
Expand Down Expand Up @@ -72,7 +73,7 @@ in {

server = mkOption {
description = "PHP LSP server to use";
type = with types; enum (builtins.attrNames servers);
type = with types; enum (attrNames servers);
default = defaultServer;
};

Expand Down
7 changes: 4 additions & 3 deletions modules/languages/python.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib) isList nvim mkEnableOption mkOption types mkIf mkMerge getExe literalExpression;

cfg = config.vim.languages.python;
Expand Down Expand Up @@ -149,7 +150,7 @@ in {

server = mkOption {
description = "Python LSP server to use";
type = with types; enum (builtins.attrNames servers);
type = with types; enum (attrNames servers);
default = defaultServer;
};

Expand All @@ -166,7 +167,7 @@ in {

type = mkOption {
description = "Python formatter to use";
type = with types; enum (builtins.attrNames formats);
type = with types; enum (attrNames formats);
default = defaultFormat;
};

Expand All @@ -186,7 +187,7 @@ in {
};
debugger = mkOption {
description = "Python debugger to use";
type = with types; enum (builtins.attrNames debuggers);
type = with types; enum (attrNames debuggers);
default = defaultDebugger;
};
package = mkOption {
Expand Down
5 changes: 3 additions & 2 deletions modules/languages/sql.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib) isList nvim mkEnableOption mkOption types mkIf mkMerge;

cfg = config.vim.languages.sql;
Expand Down Expand Up @@ -86,7 +87,7 @@ in {

server = mkOption {
description = "SQL LSP server to use";
type = with types; enum (builtins.attrNames servers);
type = with types; enum (attrNames servers);
default = defaultServer;
};

Expand All @@ -103,7 +104,7 @@ in {

type = mkOption {
description = "SQL formatter to use";
type = with types; enum (builtins.attrNames formats);
type = with types; enum (attrNames formats);
default = defaultFormat;
};

Expand Down
Loading

0 comments on commit 5d282f4

Please sign in to comment.