nix-community.nixvim/plugins/languages/sniprun.nix

140 lines
4.6 KiB
Nix
Raw Normal View History

2023-03-18 17:23:59 +01:00
{
lib,
helpers,
config,
pkgs,
2023-03-18 17:23:59 +01:00
...
}:
2024-05-05 19:39:35 +02:00
with lib;
let
2023-03-18 17:23:59 +01:00
cfg = config.plugins.sniprun;
mkList = helpers.defaultNullOpts.mkNullable (types.listOf types.str);
2024-05-05 19:39:35 +02:00
in
{
options.plugins.sniprun = helpers.neovim-plugin.extraOptionsOptions // {
enable = mkEnableOption "sniprun";
2023-03-18 17:23:59 +01:00
2024-05-05 19:39:35 +02:00
package = helpers.mkPackageOption "sniprun" pkgs.vimPlugins.sniprun;
2023-03-18 17:23:59 +01:00
2024-05-05 19:39:35 +02:00
selectedInterpreters = mkList "[]" "use those instead of the default for the current filetype";
2023-03-18 17:23:59 +01:00
2024-05-05 19:39:35 +02:00
replEnable = mkList "[]" "Enable REPL-like behavior for the given interpreters";
2023-03-18 17:23:59 +01:00
2024-05-05 19:39:35 +02:00
replDisable = mkList "[]" "Disable REPL-like behavior for the given interpreters";
2023-03-18 17:23:59 +01:00
2024-05-05 19:39:35 +02:00
interpreterOptions =
helpers.defaultNullOpts.mkNullable types.attrs "{}"
2023-03-18 17:23:59 +01:00
"interpreter-specific options, see docs / :SnipInfo <name>";
2024-05-05 19:39:35 +02:00
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 =
helpers.defaultNullOpts.mkNullable (types.listOf types.str) ''["VirtualTextOk"]''
2023-03-18 17:23:59 +01:00
"Display modes used in live_mode";
2024-05-05 19:39:35 +02:00
displayOptions = {
terminalWidth = helpers.defaultNullOpts.mkInt 45 "Change the terminal display option width.";
2023-03-18 17:23:59 +01:00
2024-05-05 19:39:35 +02:00
notificationTimeout = helpers.defaultNullOpts.mkInt 5 "Timeout for nvim_notify output.";
};
2023-03-18 17:23:59 +01:00
2024-05-05 19:39:35 +02:00
showNoOutput = mkList ''["Classic" "TempFloatingWindow"]'' ''
You can use the same keys to customize whether a sniprun producing no output should display
nothing or '(no output)'.
'';
2023-03-18 17:23:59 +01:00
2024-05-05 19:39:35 +02:00
snipruncolors =
let
colorOption =
{
fg ? "",
bg ? "",
ctermbg ? "",
ctermfg ? "",
}:
{
bg = helpers.defaultNullOpts.mkStr fg "Background color";
fg = helpers.defaultNullOpts.mkStr bg "Foreground color";
ctermbg = helpers.defaultNullOpts.mkStr ctermbg "Foreground color";
ctermfg = helpers.defaultNullOpts.mkStr ctermfg "Foreground color";
};
2024-05-05 19:39:35 +02:00
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";
};
2024-05-05 19:39:35 +02:00
SniprunFloatingWinErr = {
fg = "#881515";
ctermfg = "DarkRed";
};
};
2023-03-18 17:23:59 +01:00
2024-05-05 19:39:35 +02:00
liveModeToggle = helpers.defaultNullOpts.mkStr "off" "Live mode toggle, see Usage - Running for more info.";
2023-03-18 17:23:59 +01:00
2024-05-05 19:39:35 +02:00
borders = helpers.defaultNullOpts.mkBorder "single" "floating windows" "";
};
2023-03-18 17:23:59 +01:00
config = mkIf cfg.enable {
2024-05-05 19:39:35 +02:00
extraPlugins =
with pkgs.vimPlugins;
[ cfg.package ]
++ (optional ((cfg.display != null) && (any (hasPrefix "NvimNotify") cfg.display)) nvim-notify);
extraConfigLua =
let
options = {
2023-03-18 17:23:59 +01:00
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;
};
2023-03-18 17:23:59 +01:00
show_no_output = cfg.showNoOutput;
inherit (cfg) snipruncolors;
live_mode_toggle = cfg.liveModeToggle;
inherit (cfg) borders;
2024-05-05 19:39:35 +02:00
} // cfg.extraOptions;
in
''
require('sniprun').setup(${helpers.toLuaObject options})
'';
2023-03-18 17:23:59 +01:00
};
}