Skip to content

Commit

Permalink
Merge pull request #178 from NotAShelf/assert-assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAShelf authored Nov 16, 2023
2 parents 84fc8eb + 4dc7576 commit a535f87
Show file tree
Hide file tree
Showing 144 changed files with 678 additions and 622 deletions.
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@
};

perSystem = {
self',
config,
pkgs,
...
}: {
devShells.default = pkgs.mkShell {nativeBuildInputs = [config.packages.nix];};
formatter = pkgs.alejandra;
devShells = {
default = self'.devShells.lsp;
nvim-nix = pkgs.mkShell {nativeBuildInputs = [config.packages.nix];};
lsp = pkgs.mkShell {
nativeBuildInputs = with pkgs; [nil statix deadnix];
};
};
};
};

Expand Down
1 change: 1 addition & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
types = import ./types {inherit lib;};
languages = import ./languages.nix {inherit lib;};
lua = import ./lua.nix {inherit lib;};
vim = import ./vim.nix {inherit lib;};
}
51 changes: 44 additions & 7 deletions lib/lua.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Helpers for converting values to lua
{lib}: rec {
# yes? no.
yesNo = value:
if value
then "yes"
else "no";

{lib}: let
inherit (lib) mapAttrsToList filterAttrs concatStringsSep concatMapStringsSep stringToCharacters boolToString;
inherit (builtins) hasAttr head;
in rec {
# Convert a null value to lua's nil
nullString = value:
if value == null
Expand Down Expand Up @@ -46,4 +43,44 @@
+ " }";
# Convert a list of lua expressions to a lua table. The difference to listToLuaTable is that the elements here are expected to be lua expressions already, whereas listToLuaTable converts from nix types to lua first
luaTable = items: ''{${builtins.concatStringsSep "," items}}'';

toLuaObject = args:
if builtins.isAttrs args
then
if hasAttr "__raw" args
then args.__raw
else if hasAttr "__empty" args
then "{ }"
else
"{"
+ (concatStringsSep ","
(mapAttrsToList
(n: v:
if head (stringToCharacters n) == "@"
then toLuaObject v
else "[${toLuaObject n}] = " + (toLuaObject v))
(filterAttrs
(
_: v:
(v != null) && (toLuaObject v != "{}")
)
args)))
+ "}"
else if builtins.isList args
then "{" + concatMapStringsSep "," toLuaObject args + "}"
else if builtins.isString args
then
# This should be enough!
builtins.toJSON args
else if builtins.isPath args
then builtins.toJSON (toString args)
else if builtins.isBool args
then "${boolToString args}"
else if builtins.isFloat args
then "${toString args}"
else if builtins.isInt args
then "${toString args}"
else if (args != null)
then "nil"
else "";
}
26 changes: 26 additions & 0 deletions lib/vim.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{lib}: let
inherit (builtins) isInt isBool toJSON;
in rec {
# yes? no.
yesNo = value:
if value
then "yes"
else "no";

# convert a boolean to a vim compliant boolean string
mkVimBool = val:
if val
then "1"
else "0";

# convert a literal value to a vim compliant value
valToVim = val:
if (isInt val)
then (builtins.toString val)
else
(
if (isBool val)
then (mkVimBool val)
else (toJSON val)
);
}
27 changes: 0 additions & 27 deletions modules/assertions.nix

This file was deleted.

9 changes: 5 additions & 4 deletions modules/assistant/copilot/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
config,
lib,
...
}:
with lib;
with builtins; let
}: let
inherit (builtins) toJSON;
inherit (lib) mkIf nvim mkLuaBinding mkMerge;

cfg = config.vim.assistant.copilot;

wrapPanelBinding = luaFunction: key: ''
function()
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
6 changes: 3 additions & 3 deletions modules/assistant/copilot/copilot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
config,
lib,
...
}:
with lib;
with builtins; let
}: let
inherit (lib) mkEnableOption mkOption types;

cfg = config.vim.assistant.copilot;
in {
options.vim.assistant.copilot = {
Expand Down
11 changes: 6 additions & 5 deletions modules/assistant/tabnine/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
config,
lib,
...
}:
with lib;
with builtins; let
}: let
inherit (builtins) toJSON;
inherit (lib) mkIf mkMerge mkExprBinding boolToString nvim;

cfg = config.vim.assistant.tabnine;
in {
config = mkIf cfg.enable {
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
6 changes: 3 additions & 3 deletions modules/assistant/tabnine/tabnine.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{lib, ...}:
with lib;
with builtins; {
{lib, ...}: let
inherit (lib) mkEnableOption mkOption types mkMappingOption;
in {
options.vim.assistant.tabnine = {
enable = mkEnableOption "Tabnine assistant";

Expand Down
6 changes: 3 additions & 3 deletions modules/autopairs/nvim-autopairs/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
lib,
config,
...
}:
with lib;
with builtins; let
}: let
inherit (lib) mkIf nvim optionalString boolToString;

cfg = config.vim.autopairs;
in {
config =
Expand Down
6 changes: 3 additions & 3 deletions modules/autopairs/nvim-autopairs/nvim-autopairs.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{lib, ...}:
with lib;
with builtins; {
{lib, ...}: let
inherit (lib) mkEnableOption mkOption types;
in {
options.vim = {
autopairs = {
enable = mkEnableOption "autopairs" // {default = false;};
Expand Down
11 changes: 6 additions & 5 deletions modules/basic/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
lib,
config,
...
}:
with lib;
with builtins; let
}: let
inherit (builtins) concatStringsSep;
inherit (lib) optionalString mkIf nvim;

cfg = config.vim;
in {
config = {
Expand Down Expand Up @@ -57,8 +58,8 @@ in {
};

vim.configRC.basic = nvim.dag.entryAfter ["globalsScript"] ''
" Debug mode settings
${optionalString cfg.debugMode.enable ''
" Debug mode settings
set verbose=${toString cfg.debugMode.level}
set verbosefile=${cfg.debugMode.logFile}
''}
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
7 changes: 4 additions & 3 deletions modules/basic/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
pkgs,
lib,
...
}:
with lib;
with builtins; {
}: let
inherit (lib) mkEnableOption mkOption;
inherit (lib.types) types;
in {
options.vim = {
package = mkOption {
type = types.package;
Expand Down
6 changes: 3 additions & 3 deletions modules/comments/comment-nvim/comment-nvim.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{lib, ...}:
with lib;
with builtins; {
{lib, ...}: let
inherit (lib) mkEnableOption mkMappingOption;
in {
options.vim.comments.comment-nvim = {
enable = mkEnableOption "smart and powerful comment plugin for neovim comment-nvim";

Expand Down
6 changes: 3 additions & 3 deletions modules/comments/comment-nvim/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
config,
lib,
...
}:
with lib;
with builtins; let
}: let
inherit (lib) mkIf mkMerge mkExprBinding mkBinding nvim;

cfg = config.vim.comments.comment-nvim;
self = import ./comment-nvim.nix {
inherit lib;
Expand Down
18 changes: 10 additions & 8 deletions modules/completion/nvim-cmp/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
lib,
config,
...
}:
with lib;
with builtins; let
}: let
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 All @@ -31,8 +33,8 @@ with builtins; let

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
Loading

0 comments on commit a535f87

Please sign in to comment.