plugins/sniprun: switch to mkNeovimPlugin

This commit is contained in:
Matt Sturgeon 2024-06-17 20:00:44 +01:00
parent b822078ec1
commit 5755ff0958
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
2 changed files with 242 additions and 137 deletions

View file

@ -6,33 +6,88 @@
... ...
}: }:
with lib; with lib;
let helpers.neovim-plugin.mkNeovimPlugin config {
cfg = config.plugins.sniprun; name = "sniprun";
defaultPackage = pkgs.vimPlugins.sniprun;
url = "https://github.com/michaelb/sniprun";
mkList = helpers.defaultNullOpts.mkNullable (types.listOf types.str); maintainers = with maintainers; [
in traxys
{ MattSturgeon
options.plugins.sniprun = helpers.neovim-plugin.extraOptionsOptions // { ];
enable = mkEnableOption "sniprun";
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"; # 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.
'';
replEnable = mkList "[]" "Enable REPL-like behavior for the given interpreters"; repl_enable = helpers.defaultNullOpts.mkListOf types.str [ ] ''
Enable REPL-like behavior for the given interpreters.
'';
replDisable = mkList "[]" "Disable REPL-like behavior for the given interpreters"; repl_disable = helpers.defaultNullOpts.mkListOf types.str [ ] ''
Disable REPL-like behavior for the given interpreters.
'';
interpreterOptions = interpreter_options = helpers.defaultNullOpts.mkAttrsOf' {
helpers.defaultNullOpts.mkNullable types.attrs "{}" type = types.anything;
"interpreter-specific options, see docs / :SnipInfo <name>"; pluginDefault = { };
description = ''
Interpreter-specific options, see doc / `:SnipInfo <name>`.
'';
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";
};
}
'';
};
display = mkList ''["Classic" "VirtualTextOk"]'' '' 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 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) only successful runs (or errored-out runs respectively)
'';
Example: example = literalExpression ''
```nix
[ [
"Classic" # display results in the command-line area "Classic" # display results in the command-line area
"VirtualTextOk" # display ok results as virtual text (multiline is shortened) "VirtualTextOk" # display ok results as virtual text (multiline is shortened)
@ -45,22 +100,55 @@ in
# "NvimNotify" # display with the nvim-notify plugin # "NvimNotify" # display with the nvim-notify plugin
# "Api" # return output to a programming interface # "Api" # return output to a programming interface
] ]
```
''; '';
liveDisplay =
helpers.defaultNullOpts.mkNullable (types.listOf types.str) ''["VirtualTextOk"]''
"Display modes used in live_mode";
displayOptions = {
terminalWidth = helpers.defaultNullOpts.mkInt 45 "Change the terminal display option width.";
notificationTimeout = helpers.defaultNullOpts.mkInt 5 "Timeout for nvim_notify output.";
}; };
showNoOutput = mkList ''["Classic" "TempFloatingWindow"]'' '' live_display = helpers.defaultNullOpts.mkListOf types.str [
You can use the same keys to customize whether a sniprun producing no output should display "VirtualTextOk"
nothing or '(no output)'. ] "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 = snipruncolors =
@ -79,7 +167,14 @@ in
ctermfg = helpers.defaultNullOpts.mkStr ctermfg "Foreground color"; ctermfg = helpers.defaultNullOpts.mkStr ctermfg "Foreground color";
}; };
in in
mapAttrs (optionName: colorOption) { 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 = { SniprunVirtualTextOk = {
bg = "#66eeff"; bg = "#66eeff";
fg = "#000000"; fg = "#000000";
@ -101,39 +196,39 @@ in
ctermfg = "DarkRed"; ctermfg = "DarkRed";
}; };
}; };
};
liveModeToggle = helpers.defaultNullOpts.mkStr "off" "Live mode toggle, see Usage - Running for more info.";
borders = helpers.defaultNullOpts.mkBorder "single" "floating windows" "";
}; };
config = mkIf cfg.enable { live_mode_toggle = helpers.defaultNullOpts.mkStr "off" ''
extraPlugins = Live mode toggle, see [Usage - Running] for more info.
with pkgs.vimPlugins;
[ cfg.package ]
++ (optional ((cfg.display != null) && (any (hasPrefix "NvimNotify") cfg.display)) nvim-notify);
extraConfigLua = [Usage - Running]: https://michaelb.github.io/sniprun/sources/README.html#running
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})
''; '';
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.";
};
settingsExample = {
display = [ "NvimNotify" ];
inline_messages = true;
interpreter_options = {
"<Interpreter_name>" = {
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";
};
}; };
} }

View file

@ -6,20 +6,27 @@
default = { default = {
plugins.sniprun = { plugins.sniprun = {
enable = true; enable = true;
selectedInterpreters = [ ];
replEnable = [ ]; settings = {
replDisable = [ ]; selected_interpreters = [ ];
interpreterOptions = { }; repl_enable = [ ];
repl_disable = [ ];
interpreter_options = { };
display = [ display = [
"Classic" "Classic"
"VirtualTextOk" "VirtualTextOk"
]; ];
liveDisplay = [ "VirtualTextOk" ]; live_display = [ "VirtualTextOk" ];
displayOptions = { display_options = {
terminalWidth = 45; terminal_scrollback.__raw = "vim.o.scrollback";
notificationTimeout = 5; terminal_line_number = false;
terminal_signcolumn = false;
terminal_position = "vertical";
terminal_width = 45;
terminal_height = 20;
notification_timeout = 5;
}; };
showNoOutput = [ show_no_output = [
"Classic" "Classic"
"TempFloatingWindow" "TempFloatingWindow"
]; ];
@ -43,10 +50,13 @@
SniprunFloatingWinErr = { SniprunFloatingWinErr = {
fg = "#881515"; fg = "#881515";
ctermfg = "DarkRed"; ctermfg = "DarkRed";
bold = true;
}; };
}; };
liveModeToggle = "off"; live_mode_toggle = "off";
inline_messages = false;
borders = "single"; borders = "single";
}; };
}; };
};
} }