From 3ed69945b062faae2ccd95248f1f9b7b98dddc0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Lepage?= <33058747+GaetanLepage@users.noreply.github.com> Date: Fri, 24 Mar 2023 15:46:16 +0100 Subject: [PATCH] plugins/magma-nvim: refactor + tests (#286) --- plugins/plugin-defs.nix | 2 +- plugins/utils/magma-nvim.nix | 221 +++++++++++------- .../test-sources/plugins/utils/magma-nvim.nix | 19 ++ 3 files changed, 154 insertions(+), 88 deletions(-) create mode 100644 tests/test-sources/plugins/utils/magma-nvim.nix diff --git a/plugins/plugin-defs.nix b/plugins/plugin-defs.nix index 78582210..62c46bee 100644 --- a/plugins/plugin-defs.nix +++ b/plugins/plugin-defs.nix @@ -63,7 +63,7 @@ in { hash = "sha256-CZUGDUkmttO0BzFYbGFSNMPkWzFC/BW4NmAeOwz4Y9M="; }; doCheck = false; - meta = with lib; { + meta = { homepage = "https://github.com/MaT1g3R/pnglatex"; description = "a small program that converts LaTeX snippets to png"; }; diff --git a/plugins/utils/magma-nvim.nix b/plugins/utils/magma-nvim.nix index 3c58691e..e64c8248 100644 --- a/plugins/utils/magma-nvim.nix +++ b/plugins/utils/magma-nvim.nix @@ -1,105 +1,152 @@ { pkgs, lib, - config, ... -}: -with lib; let - cfg = config.plugins.magma-nvim; +} @ args: +with lib; +with import ../helpers.nix {inherit lib;}; let plugins = import ../plugin-defs.nix {inherit pkgs;}; - package = pkgs.fetchFromGitHub { - owner = "dccsillag"; - repo = "magma-nvim"; - rev = version; - sha256 = "sha256-IaslJK1F2BxTvZzKGH9OKOl2RICi4d4rSgjliAIAqK4="; - }; -in { - options = { - plugins.magma-nvim = { - enable = mkEnableOption "Enable magma-nvim?"; - image_provider = mkOption { - type = types.enum ["none" "ueberzug" "kitty"]; - default = "none"; - example = "ueberzug"; - description = " This configures how to display images. The following options are available: - none -- don't show imagesmagma_image_provider. - ueberzug -- use Ueberzug to display images. - kitty -- use the Kitty protocol to display images."; - }; - automatically_open_output = mkOption { - type = types.bool; - default = true; - example = false; - description = " If this is true, then whenever you have an active cell its output window will be automatically shown. - If this is false, then the output window will only be automatically shown when you've just evaluated the code. So, if you take your cursor out of the cell, and then come back, the output window won't be opened (but the cell will be highlighted). This means that there will be nothing covering your code. You can then open the output window at will using :MagmaShowOutput."; + optionWarnings = import ../../lib/option-warnings.nix args; + basePluginPath = ["plugins" "magma-nvim"]; +in + { + # Those renames happended on 03-24-2023 (TODO remove in 1-2 months) + imports = + map ( + { + oldName, + newName, + }: + optionWarnings.mkRenamedOption { + option = basePluginPath ++ [oldName]; + newOption = basePluginPath ++ [newName]; + } + ) [ + { + oldName = "image_provider"; + newName = "imageProvider"; + } + { + oldName = "automatically_open_output"; + newName = "automaticallyOpenOutput"; + } + { + oldName = "wrap_output"; + newName = "wrapOutput"; + } + { + oldName = "output_window_borders"; + newName = "outputWindowBorders"; + } + { + oldName = "cell_highlight_group"; + newName = "cellHighlightGroup"; + } + { + oldName = "save_path"; + newName = "savePath"; + } + { + oldName = "show_mimetype_debug"; + newName = "showMimetypeDebug"; + } + ]; + } + // mkPlugin args { + name = "magma-nvim"; + description = "magma-nvim"; + package = plugins.magma-nvim; + globalPrefix = "magma_"; + + options = { + imageProvider = mkDefaultOpt { + global = "image_provider"; + description = '' + This configures how to display images. The following options are available: + - "none" -- don't show images. + - "ueberzug" -- use Ueberzug to display images. + - "kitty" -- use the Kitty protocol to display images. + + Default: "none" + ''; + type = types.enum ["none" "uberzug" "kitty"]; }; - wrap_output = mkOption { + automaticallyOpenOutput = mkDefaultOpt { + global = "automatically_open_output"; + description = '' + If this is true, then whenever you have an active cell its output window will be + automatically shown. + + If this is false, then the output window will only be automatically shown when you've just + evaluated the code. + So, if you take your cursor out of the cell, and then come back, the output window won't + be opened (but the cell will be highlighted). + This means that there will be nothing covering your code. + You can then open the output window at will using `:MagmaShowOutput`. + + Default: true + ''; type = types.bool; - default = true; example = false; - description = " If this is true, then text output in the output window will be wrapped (akin to set wrap)."; }; - output_window_borders = mkOption { + wrapOutput = mkDefaultOpt { + global = "wrap_output"; type = types.bool; - default = true; example = false; - description = " If this is true, then the output window will have rounded borders. If it is false, it will have no borders."; + description = '' + If this is true, then text output in the output window will be wrapped + (akin to `set wrap`). + + Default: true + ''; }; - cell_highlight_group = mkOption { + outputWindowBorders = mkDefaultOpt { + global = "output_window_borders"; + type = types.bool; + example = false; + description = '' + If this is true, then the output window will have rounded borders. + If it is false, it will have no borders. + + Default: true + ''; + }; + + cellHighlightGroup = mkDefaultOpt { + global = "cell_highlight_group"; type = types.str; - default = "CursorLine"; - # example = ""; - description = " The highlight group to be used for highlighting cells."; - }; - save_path = mkOption { - type = types.nullOr types.str; - default = null; - description = "Where to save/load with :MagmaSave and :MagmaLoad (with no parameters). - The generated file is placed in this directory, with the filename itself being the buffer's name, with % replaced by %% and / replaced by %, and postfixed with the extension .json."; - }; - show_mimetype_debug = mkOption { - type = types.bool; - default = false; - example = true; - description = " If this is true, then before any non-iostream output chunk, Magma shows the mimetypes it received for it. - This is meant for debugging and adding new mimetypes."; - }; - package = mkOption { - type = types.nullOr types.package; - default = null; - example = "package = pkgs.fetchFromGitHub { - owner = \"WhiteBlackGoose\"; - repo = \"magma-nvim-goose\"; - rev = version; - sha256 = \"sha256-IaslJK1F2BxTvZzKGH9OKOl2RICi4d4rSgjliAIAqK4=\";} "; - }; - }; - }; - config = mkIf cfg.enable { - extraPlugins = [ - ( - if cfg.package != null - then plugins.magma-nvim.override {src = cfg.package;} - else plugins.magma-nvim - ) - ]; + description = '' + The highlight group to be used for highlighting cells. - globals = { - magma_image_provider = - mkIf (cfg.image_provider != "none") cfg.image_provider; - magma_automatically_open_output = - mkIf (!cfg.automatically_open_output) cfg.automatically_open_output; - magma_wrap_output = mkIf (!cfg.wrap_output) cfg.wrap_output; - magma_output_window_borders = - mkIf (!cfg.output_window_borders) cfg.output_window_borders; - magma_highlight_group = - mkIf (cfg.cell_highlight_group != "CursorLine") - cfg.cell_highlight_group; - magma_show_mimetype_debug = - mkIf cfg.show_mimetype_debug cfg.show_mimetype_debug; + Default: "CursorLine" + ''; + }; + + savePath = mkDefaultOpt { + global = "save_path"; + type = types.str; + description = '' + Where to save/load with :MagmaSave and :MagmaLoad (with no parameters). + The generated file is placed in this directory, with the filename itself being the + buffer's name, with % replaced by %% and / replaced by %, and postfixed with the extension + .json. + ''; + }; + + showMimetypeDebug = mkDefaultOpt { + global = "show_mimetype_debug"; + type = types.bool; + example = true; + description = '' + If this is true, then before any non-iostream output chunk, Magma shows the mimetypes it + received for it. + This is meant for debugging and adding new mimetypes. + + Default: false + ''; + }; }; - }; -} + } diff --git a/tests/test-sources/plugins/utils/magma-nvim.nix b/tests/test-sources/plugins/utils/magma-nvim.nix new file mode 100644 index 00000000..894667ee --- /dev/null +++ b/tests/test-sources/plugins/utils/magma-nvim.nix @@ -0,0 +1,19 @@ +{ + empty = { + plugins.magma-nvim.enable = true; + }; + + defaults = { + plugins.magma-nvim = { + enable = true; + + imageProvider = "none"; + automaticallyOpenOutput = true; + wrapOutput = true; + outputWindowBorders = true; + cellHighlightGroup = "CursorLine"; + savePath = null; + showMimetypeDebug = false; + }; + }; +}