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,62 +6,150 @@
... ...
}: }:
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 = {
replEnable = mkList "[]" "Enable REPL-like behavior for the given interpreters"; selected_interpreters = helpers.defaultNullOpts.mkListOf types.str [ ] ''
Use those instead of the default for the current filetype.
replDisable = mkList "[]" "Disable REPL-like behavior for the given interpreters";
interpreterOptions =
helpers.defaultNullOpts.mkNullable types.attrs "{}"
"interpreter-specific options, see docs / :SnipInfo <name>";
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
]
```
''; '';
liveDisplay = repl_enable = helpers.defaultNullOpts.mkListOf types.str [ ] ''
helpers.defaultNullOpts.mkNullable (types.listOf types.str) ''["VirtualTextOk"]'' Enable REPL-like behavior for the given interpreters.
"Display modes used in live_mode"; '';
displayOptions = { repl_disable = helpers.defaultNullOpts.mkListOf types.str [ ] ''
terminalWidth = helpers.defaultNullOpts.mkInt 45 "Change the terminal display option width."; 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 <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";
};
}
'';
}; };
showNoOutput = mkList ''["Classic" "TempFloatingWindow"]'' '' display = helpers.defaultNullOpts.mkListOf' {
You can use the same keys to customize whether a sniprun producing no output should display type = types.str;
nothing or '(no output)'. 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 = snipruncolors =
let let
@ -79,61 +167,68 @@ in
ctermfg = helpers.defaultNullOpts.mkStr ctermfg "Foreground color"; ctermfg = helpers.defaultNullOpts.mkStr ctermfg "Foreground color";
}; };
in in
mapAttrs (optionName: colorOption) { helpers.defaultNullOpts.mkNullable' {
SniprunVirtualTextOk = { description = ''
bg = "#66eeff"; Customize highlight groups (setting this overrides colorscheme)
fg = "#000000"; any parameters of `nvim_set_hl()` can be passed as-is.
ctermbg = "Cyan"; '';
ctermfg = "Black"; type = types.submodule {
}; freeformType = types.attrsOf types.anything;
SniprunFloatingWinOk = { options = mapAttrs (optionName: colorOption) {
fg = "#66eeff"; SniprunVirtualTextOk = {
ctermfg = "Cyan"; bg = "#66eeff";
}; fg = "#000000";
SniprunVirtualTextErr = { ctermbg = "Cyan";
bg = "#881515"; ctermfg = "Black";
fg = "#000000"; };
ctermbg = "DarkRed"; SniprunFloatingWinOk = {
ctermfg = "Black"; fg = "#66eeff";
}; ctermfg = "Cyan";
SniprunFloatingWinErr = { };
fg = "#881515"; SniprunVirtualTextErr = {
ctermfg = "DarkRed"; 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 { settingsExample = {
extraPlugins = display = [ "NvimNotify" ];
with pkgs.vimPlugins; inline_messages = true;
[ cfg.package ] interpreter_options = {
++ (optional ((cfg.display != null) && (any (hasPrefix "NvimNotify") cfg.display)) nvim-notify); "<Interpreter_name>" = {
some_specific_option = "value";
extraConfigLua = some_other_option = "other_value";
let };
options = { C_original.compiler = "clang";
selected_interpreters = cfg.selectedInterpreters; GFM_original.use_on_filetypes = [ "markdown.pandoc" ];
repl_enable = cfg.replEnable; Python3_original.error_truncate = "auto";
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})
'';
}; };
} }

View file

@ -6,47 +6,57 @@
default = { default = {
plugins.sniprun = { plugins.sniprun = {
enable = true; enable = true;
selectedInterpreters = [ ];
replEnable = [ ]; settings = {
replDisable = [ ]; selected_interpreters = [ ];
interpreterOptions = { }; repl_enable = [ ];
display = [ repl_disable = [ ];
"Classic" interpreter_options = { };
"VirtualTextOk" display = [
]; "Classic"
liveDisplay = [ "VirtualTextOk" ]; "VirtualTextOk"
displayOptions = { ];
terminalWidth = 45; live_display = [ "VirtualTextOk" ];
notificationTimeout = 5; 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";
}; };
}; };
} }