diff --git a/plugins/languages/sniprun.nix b/plugins/languages/sniprun.nix index 60a43ccd..8f73ef62 100644 --- a/plugins/languages/sniprun.nix +++ b/plugins/languages/sniprun.nix @@ -6,62 +6,150 @@ ... }: with lib; -let - cfg = config.plugins.sniprun; +helpers.neovim-plugin.mkNeovimPlugin config { + name = "sniprun"; + defaultPackage = pkgs.vimPlugins.sniprun; + url = "https://github.com/michaelb/sniprun"; - mkList = helpers.defaultNullOpts.mkNullable (types.listOf types.str); -in -{ - options.plugins.sniprun = helpers.neovim-plugin.extraOptionsOptions // { - enable = mkEnableOption "sniprun"; + maintainers = with maintainers; [ + traxys + MattSturgeon + ]; - package = helpers.mkPluginPackageOption "sniprun" pkgs.vimPlugins.sniprun; + # TODO: Added 2024-06-17; remove 2024-09-17 + deprecateExtraOptions = true; + optionsRenamedToSettings = [ + "selectedInterpreters" + "replEnable" + "replDisable" + "interpreterOptions" + "display" + "liveDisplay" + [ + "displayOptions" + "terminalWidth" + ] + [ + "displayOptions" + "notificationTimeout" + ] + "showNoOutput" + "snipruncolors" + "liveModeToggle" + "borders" + ]; - selectedInterpreters = mkList "[]" "use those instead of the default for the current filetype"; - - replEnable = mkList "[]" "Enable REPL-like behavior for the given interpreters"; - - replDisable = mkList "[]" "Disable REPL-like behavior for the given interpreters"; - - interpreterOptions = - helpers.defaultNullOpts.mkNullable types.attrs "{}" - "interpreter-specific options, see docs / :SnipInfo "; - - display = mkList ''["Classic" "VirtualTextOk"]'' '' - You can combo different display modes as desired and with the 'Ok' or 'Err' suffix to filter - only successful runs (or errored-out runs respectively) - - Example: - ```nix - [ - "Classic" # display results in the command-line area - "VirtualTextOk" # display ok results as virtual text (multiline is shortened) - - # "VirtualText" # display results as virtual text - # "TempFloatingWindow" # display results in a floating window - # "LongTempFloatingWindow" # same as above, but only long results. To use with VirtualText[Ok/Err] - # "Terminal" # display results in a vertical split - # "TerminalWithCode" # display results and code history in a vertical split - # "NvimNotify" # display with the nvim-notify plugin - # "Api" # return output to a programming interface - ] - ``` + # https://michaelb.github.io/sniprun/sources/README.html#configuration + settingsOptions = { + selected_interpreters = helpers.defaultNullOpts.mkListOf types.str [ ] '' + Use those instead of the default for the current filetype. ''; - liveDisplay = - helpers.defaultNullOpts.mkNullable (types.listOf types.str) ''["VirtualTextOk"]'' - "Display modes used in live_mode"; + repl_enable = helpers.defaultNullOpts.mkListOf types.str [ ] '' + Enable REPL-like behavior for the given interpreters. + ''; - displayOptions = { - terminalWidth = helpers.defaultNullOpts.mkInt 45 "Change the terminal display option width."; + repl_disable = helpers.defaultNullOpts.mkListOf types.str [ ] '' + Disable REPL-like behavior for the given interpreters. + ''; - notificationTimeout = helpers.defaultNullOpts.mkInt 5 "Timeout for nvim_notify output."; + interpreter_options = helpers.defaultNullOpts.mkAttrsOf' { + type = types.anything; + pluginDefault = { }; + description = '' + Interpreter-specific options, see doc / `:SnipInfo `. + ''; + example = literalExpression '' + { + # use the interpreter name as key + GFM_original = { + # the 'use_on_filetypes' configuration key is + # available for every interpreter + use_on_filetypes = [ "markdown.pandoc" ]; + }; + Python3_original = { + # Truncate runtime errors 'long', 'short' or 'auto' + # the hint is available for every interpreter + # but may not be always respected + error_truncate = "auto"; + }; + } + ''; }; - showNoOutput = mkList ''["Classic" "TempFloatingWindow"]'' '' - You can use the same keys to customize whether a sniprun producing no output should display - nothing or '(no output)'. - ''; + display = helpers.defaultNullOpts.mkListOf' { + type = types.str; + pluginDefault = [ + "Classic" + "VirtualTextOk" + ]; + description = '' + You can combo different display modes as desired and with the 'Ok' or 'Err' suffix to filter + only successful runs (or errored-out runs respectively) + ''; + example = literalExpression '' + [ + "Classic" # display results in the command-line area + "VirtualTextOk" # display ok results as virtual text (multiline is shortened) + + # "VirtualText" # display results as virtual text + # "TempFloatingWindow" # display results in a floating window + # "LongTempFloatingWindow" # same as above, but only long results. To use with VirtualText[Ok/Err] + # "Terminal" # display results in a vertical split + # "TerminalWithCode" # display results and code history in a vertical split + # "NvimNotify" # display with the nvim-notify plugin + # "Api" # return output to a programming interface + ] + ''; + }; + + live_display = helpers.defaultNullOpts.mkListOf types.str [ + "VirtualTextOk" + ] "Display modes used in `live_mode`."; + + display_options = { + terminal_scrollback = helpers.defaultNullOpts.mkUnsignedInt { __raw = "vim.o.scrollback"; } '' + Change terminal display scrollback lines. + ''; + + terminal_line_number = helpers.defaultNullOpts.mkBool false '' + Whether show line number in terminal window. + ''; + + terminal_signcolumn = helpers.defaultNullOpts.mkBool false '' + Whether show signcolumn in terminal window. + ''; + + terminal_position = helpers.defaultNullOpts.mkEnumFirstDefault [ + "vertical" + "horizontal" + ] "Terminal split position."; + + terminal_width = helpers.defaultNullOpts.mkUnsignedInt 45 '' + Change the terminal display option width (if vertical). + ''; + + terminal_height = helpers.defaultNullOpts.mkUnsignedInt 20 '' + Change the terminal display option height (if horizontal). + ''; + + notification_timeout = helpers.defaultNullOpts.mkUnsignedInt 5 '' + Timeout for nvim_notify output. + ''; + }; + + show_no_output = + helpers.defaultNullOpts.mkListOf types.str + [ + "Classic" + "TempFloatingWindow" + ] + '' + You can use the same keys to customize whether a sniprun producing + no output should display nothing or '(no output)'. + + `"TempFloatingWindow"` implies `"LongTempFloatingWindow"`, which has no effect on its own. + ''; snipruncolors = let @@ -79,61 +167,68 @@ in ctermfg = helpers.defaultNullOpts.mkStr ctermfg "Foreground color"; }; in - mapAttrs (optionName: colorOption) { - SniprunVirtualTextOk = { - bg = "#66eeff"; - fg = "#000000"; - ctermbg = "Cyan"; - ctermfg = "Black"; - }; - SniprunFloatingWinOk = { - fg = "#66eeff"; - ctermfg = "Cyan"; - }; - SniprunVirtualTextErr = { - bg = "#881515"; - fg = "#000000"; - ctermbg = "DarkRed"; - ctermfg = "Black"; - }; - SniprunFloatingWinErr = { - fg = "#881515"; - ctermfg = "DarkRed"; + helpers.defaultNullOpts.mkNullable' { + description = '' + Customize highlight groups (setting this overrides colorscheme) + any parameters of `nvim_set_hl()` can be passed as-is. + ''; + type = types.submodule { + freeformType = types.attrsOf types.anything; + options = mapAttrs (optionName: colorOption) { + SniprunVirtualTextOk = { + bg = "#66eeff"; + fg = "#000000"; + ctermbg = "Cyan"; + ctermfg = "Black"; + }; + SniprunFloatingWinOk = { + fg = "#66eeff"; + ctermfg = "Cyan"; + }; + SniprunVirtualTextErr = { + bg = "#881515"; + fg = "#000000"; + ctermbg = "DarkRed"; + ctermfg = "Black"; + }; + SniprunFloatingWinErr = { + fg = "#881515"; + ctermfg = "DarkRed"; + }; + }; }; }; - liveModeToggle = helpers.defaultNullOpts.mkStr "off" "Live mode toggle, see Usage - Running for more info."; + live_mode_toggle = helpers.defaultNullOpts.mkStr "off" '' + Live mode toggle, see [Usage - Running] for more info. - borders = helpers.defaultNullOpts.mkBorder "single" "floating windows" ""; + [Usage - Running]: https://michaelb.github.io/sniprun/sources/README.html#running + ''; + + inline_messages = helpers.defaultNullOpts.mkBool false '' + Boolean toggle for a one-line way to display messages + to workaround sniprun not being able to display anything. + ''; + + borders = helpers.defaultNullOpts.mkEnum [ + "none" + "single" + "double" + "shadow" + ] "single" "Display borders around floating windows."; }; - config = mkIf cfg.enable { - extraPlugins = - with pkgs.vimPlugins; - [ cfg.package ] - ++ (optional ((cfg.display != null) && (any (hasPrefix "NvimNotify") cfg.display)) nvim-notify); - - extraConfigLua = - let - options = { - selected_interpreters = cfg.selectedInterpreters; - repl_enable = cfg.replEnable; - repl_disable = cfg.replDisable; - interpreter_options = cfg.interpreterOptions; - inherit (cfg) display; - live_display = cfg.liveDisplay; - display_options = with cfg.displayOptions; { - terminal_width = terminalWidth; - notification_timeout = notificationTimeout; - }; - show_no_output = cfg.showNoOutput; - inherit (cfg) snipruncolors; - live_mode_toggle = cfg.liveModeToggle; - inherit (cfg) borders; - } // cfg.extraOptions; - in - '' - require('sniprun').setup(${helpers.toLuaObject options}) - ''; + settingsExample = { + display = [ "NvimNotify" ]; + inline_messages = true; + interpreter_options = { + "" = { + some_specific_option = "value"; + some_other_option = "other_value"; + }; + C_original.compiler = "clang"; + GFM_original.use_on_filetypes = [ "markdown.pandoc" ]; + Python3_original.error_truncate = "auto"; + }; }; } diff --git a/tests/test-sources/plugins/languages/sniprun.nix b/tests/test-sources/plugins/languages/sniprun.nix index 75744584..591e68a1 100644 --- a/tests/test-sources/plugins/languages/sniprun.nix +++ b/tests/test-sources/plugins/languages/sniprun.nix @@ -6,47 +6,57 @@ default = { plugins.sniprun = { enable = true; - selectedInterpreters = [ ]; - replEnable = [ ]; - replDisable = [ ]; - interpreterOptions = { }; - display = [ - "Classic" - "VirtualTextOk" - ]; - liveDisplay = [ "VirtualTextOk" ]; - displayOptions = { - terminalWidth = 45; - notificationTimeout = 5; + + settings = { + selected_interpreters = [ ]; + repl_enable = [ ]; + repl_disable = [ ]; + interpreter_options = { }; + display = [ + "Classic" + "VirtualTextOk" + ]; + live_display = [ "VirtualTextOk" ]; + display_options = { + terminal_scrollback.__raw = "vim.o.scrollback"; + terminal_line_number = false; + terminal_signcolumn = false; + terminal_position = "vertical"; + terminal_width = 45; + terminal_height = 20; + notification_timeout = 5; + }; + show_no_output = [ + "Classic" + "TempFloatingWindow" + ]; + snipruncolors = { + SniprunVirtualTextOk = { + bg = "#66eeff"; + fg = "#000000"; + ctermbg = "Cyan"; + ctermfg = "Black"; + }; + SniprunFloatingWinOk = { + fg = "#66eeff"; + ctermfg = "Cyan"; + }; + SniprunVirtualTextErr = { + bg = "#881515"; + fg = "#000000"; + ctermbg = "DarkRed"; + ctermfg = "Black"; + }; + SniprunFloatingWinErr = { + fg = "#881515"; + ctermfg = "DarkRed"; + bold = true; + }; + }; + live_mode_toggle = "off"; + inline_messages = false; + borders = "single"; }; - showNoOutput = [ - "Classic" - "TempFloatingWindow" - ]; - snipruncolors = { - SniprunVirtualTextOk = { - bg = "#66eeff"; - fg = "#000000"; - ctermbg = "Cyan"; - ctermfg = "Black"; - }; - SniprunFloatingWinOk = { - fg = "#66eeff"; - ctermfg = "Cyan"; - }; - SniprunVirtualTextErr = { - bg = "#881515"; - fg = "#000000"; - ctermbg = "DarkRed"; - ctermfg = "Black"; - }; - SniprunFloatingWinErr = { - fg = "#881515"; - ctermfg = "DarkRed"; - }; - }; - liveModeToggle = "off"; - borders = "single"; }; }; }