diff --git a/extra.nix b/extra.nix index 60d6cf9..8463fb2 100644 --- a/extra.nix +++ b/extra.nix @@ -185,6 +185,7 @@ inputs: let nix = 110; ruby = 120; java = 130; + go = [90 130]; }; }; colorizer.enable = true; diff --git a/lib/lua.nix b/lib/lua.nix index f665159..be285c1 100644 --- a/lib/lua.nix +++ b/lib/lua.nix @@ -12,21 +12,29 @@ then "nil" else "'${value}'"; - # Helper function to convert an attribute name to a Lua table key - attrToKey = name: name; + expToLua = exp: + if builtins.isList exp + then listToLuaTable exp + else if builtins.isAttrs exp + then attrsetToLuaTable exp + else ("\"" + builtins.toJSON exp + "\""); + + listToLuaTable = list: + "{ " + (builtins.concatStringsSep ", " (map expToLua list)) + " }"; - # Function to convert a Nix attrset to a Lua table attrsetToLuaTable = attrset: "{ " + ( builtins.concatStringsSep ", " - (builtins.attrValues ( - builtins.mapAttrs ( + ( + lib.mapAttrsToList ( name: value: - attrToKey name + " = " + ("\"" + builtins.toJSON value + "\"") + name + + " = " + + (expToLua value) ) attrset - )) + ) ) + " }"; } diff --git a/modules/ui/smartcolumn/config.nix b/modules/ui/smartcolumn/config.nix index afa9fc7..6b611ad 100644 --- a/modules/ui/smartcolumn/config.nix +++ b/modules/ui/smartcolumn/config.nix @@ -15,11 +15,11 @@ in { vim.luaConfigRC.smartcolumn = nvim.dag.entryAnywhere '' require("smartcolumn").setup({ - colorcolumn = "${toString cfg.showColumnAt}", - -- { "help", "text", "markdown", "NvimTree", "alpha"}, - disabled_filetypes = { ${concatStringsSep ", " (map (x: "\"" + x + "\"") cfg.disabledFiletypes)} }, - custom_colorcolumn = ${nvim.lua.attrsetToLuaTable cfg.columnAt.languages}, - scope = "file", + colorcolumn = "${toString cfg.showColumnAt}", + -- { "help", "text", "markdown", "NvimTree", "alpha"}, + disabled_filetypes = { ${concatStringsSep ", " (map (x: "\"" + x + "\"") cfg.disabledFiletypes)} }, + custom_colorcolumn = ${nvim.lua.attrsetToLuaTable cfg.columnAt.languages}, + scope = "file", }) ''; }; diff --git a/modules/ui/smartcolumn/smartcolumn.nix b/modules/ui/smartcolumn/smartcolumn.nix index 1b965a0..349bf48 100644 --- a/modules/ui/smartcolumn/smartcolumn.nix +++ b/modules/ui/smartcolumn/smartcolumn.nix @@ -17,13 +17,21 @@ with builtins; { }; columnAt = { - # TODO: the current implementation only allows for options such as { ruby = "120", java = "120" } - # whereas the lua config would allow { ruby = "120", java = { "180", "200"} }, this needs to be fixed in the custom lib languages = lib.mkOption { description = "The position at which smart column should be displayed for each individual buffer type"; type = lib.types.submodule { - freeformType = with lib.types; attrsOf int; + freeformType = with lib.types; attrsOf (either int (listOf int)); }; + + example = lib.literalExpression '' + vim.ui.smartcolumn.columnAt.languages = { + nix = 110; + ruby = 120; + java = 130; + go = [90 130]; + }; + + ''; }; }; };