plugins: Introduce helpers.defaultNullOpts.mkLuaFn (#855)

This allows to avoid calling `mkRaw` on lua functions, as they will get
applied automatically.

This could also help in the future to refactor the use of Lua code to
make it more user-friendly.
This commit is contained in:
traxys 2023-12-29 15:24:42 +01:00 committed by GitHub
parent b38dbdb0dc
commit 1d8e7906c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 140 additions and 119 deletions

View file

@ -140,6 +140,33 @@ with lib; rec {
# documentation # documentation
mkNullableWithRaw = type: mkNullable (maybeRaw type); mkNullableWithRaw = type: mkNullable (maybeRaw type);
mkLuaFn = default: desc:
lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = let
defaultDesc = ''
default:
```lua
${default}
```
'';
in
if desc == ""
then ''
(lua function)
${defaultDesc}
''
else ''
${desc}
(lua function)
${defaultDesc}
'';
apply = mkRaw;
};
mkNum = default: mkNullable (maybeRaw lib.types.number) (toString default); mkNum = default: mkNullable (maybeRaw lib.types.number) (toString default);
mkInt = default: mkNullable (maybeRaw lib.types.int) (toString default); mkInt = default: mkNullable (maybeRaw lib.types.int) (toString default);
# Positive: >0 # Positive: >0

View file

@ -59,7 +59,7 @@ in {
''; '';
modified = modified =
helpers.defaultNullOpts.mkStr helpers.defaultNullOpts.mkLuaFn
'' ''
function(bufnr) function(bufnr)
return vim.bo[bufnr].modified return vim.bo[bufnr].modified
@ -75,7 +75,7 @@ in {
''; '';
leadCustomSection = leadCustomSection =
helpers.defaultNullOpts.mkStr helpers.defaultNullOpts.mkLuaFn
'' ''
function() function()
return " " return " "
@ -87,7 +87,7 @@ in {
''; '';
customSection = customSection =
helpers.defaultNullOpts.mkStr helpers.defaultNullOpts.mkLuaFn
'' ''
function() function()
return " " return " "
@ -173,10 +173,10 @@ in {
show_dirname = showDirname; show_dirname = showDirname;
show_basename = showBasename; show_basename = showBasename;
show_modified = showModified; show_modified = showModified;
modified = helpers.mkRaw modified; inherit modified;
show_navic = showNavic; show_navic = showNavic;
lead_custom_section = helpers.mkRaw leadCustomSection; lead_custom_section = leadCustomSection;
custom_section = helpers.mkRaw customSection; custom_section = customSection;
inherit theme; inherit theme;
context_follow_icon_color = contextFollowIconColor; context_follow_icon_color = contextFollowIconColor;
symbols = { symbols = {

View file

@ -172,7 +172,7 @@ in {
"Separator style"; "Separator style";
nameFormatter = nameFormatter =
helpers.defaultNullOpts.mkStr "null" helpers.defaultNullOpts.mkLuaFn "null"
'' ''
A lua function that can be used to modify the buffer's label. A lua function that can be used to modify the buffer's label.
The argument 'buf' containing a name, path and bufnr is supplied. The argument 'buf' containing a name, path and bufnr is supplied.
@ -191,7 +191,7 @@ in {
showBufferCloseIcons = helpers.defaultNullOpts.mkBool true "Show buffer close icons"; showBufferCloseIcons = helpers.defaultNullOpts.mkBool true "Show buffer close icons";
getElementIcon = getElementIcon =
helpers.defaultNullOpts.mkStr "null" helpers.defaultNullOpts.mkLuaFn "null"
'' ''
Lua function returning an element icon. Lua function returning an element icon.
@ -231,7 +231,7 @@ in {
(with types; either bool (enum ["nvim_lsp" "coc"])) "false" "diagnostics"; (with types; either bool (enum ["nvim_lsp" "coc"])) "false" "diagnostics";
diagnosticsIndicator = diagnosticsIndicator =
helpers.defaultNullOpts.mkStr "null" helpers.defaultNullOpts.mkLuaFn "null"
"Either `null` or a function that returns the diagnistics indicator."; "Either `null` or a function that returns the diagnistics indicator.";
diagnosticsUpdateInInsert = diagnosticsUpdateInInsert =
@ -265,7 +265,7 @@ in {
}; };
customFilter = customFilter =
helpers.defaultNullOpts.mkStr "null" helpers.defaultNullOpts.mkLuaFn "null"
'' ''
``` ```
fun(buf: number, bufnums: number[]): boolean fun(buf: number, bufnums: number[]): boolean
@ -299,14 +299,14 @@ in {
left_trunc_marker = leftTruncMarker; left_trunc_marker = leftTruncMarker;
right_trunc_marker = rightTruncMarker; right_trunc_marker = rightTruncMarker;
separator_style = separatorStyle; separator_style = separatorStyle;
name_formatter = helpers.mkRaw nameFormatter; name_formatter = nameFormatter;
truncate_names = truncateNames; truncate_names = truncateNames;
tab_size = tabSize; tab_size = tabSize;
max_name_length = maxNameLength; max_name_length = maxNameLength;
color_icons = colorIcons; color_icons = colorIcons;
show_buffer_icons = showBufferIcons; show_buffer_icons = showBufferIcons;
show_buffer_close_icons = showBufferCloseIcons; show_buffer_close_icons = showBufferCloseIcons;
get_element_icon = helpers.mkRaw getElementIcon; get_element_icon = getElementIcon;
show_close_icon = showCloseIcon; show_close_icon = showCloseIcon;
show_tab_indicators = showTabIndicators; show_tab_indicators = showTabIndicators;
show_duplicate_prefix = showDuplicatePrefix; show_duplicate_prefix = showDuplicatePrefix;
@ -316,7 +316,7 @@ in {
max_prefix_length = maxPrefixLength; max_prefix_length = maxPrefixLength;
sort_by = sortBy; sort_by = sortBy;
inherit diagnostics; inherit diagnostics;
diagnostics_indicator = helpers.mkRaw diagnosticsIndicator; diagnostics_indicator = diagnosticsIndicator;
diagnostics_update_in_insert = diagnosticsUpdateInInsert; diagnostics_update_in_insert = diagnosticsUpdateInInsert;
inherit offsets; inherit offsets;
groups = { groups = {
@ -336,7 +336,7 @@ in {
debug = { debug = {
inherit (debug) logging; inherit (debug) logging;
}; };
custom_filter = helpers.mkRaw customFilter; custom_filter = customFilter;
} }
// cfg.extraOptions; // cfg.extraOptions;

View file

@ -51,14 +51,14 @@ in {
helpers.defaultNullOpts.mkBool false helpers.defaultNullOpts.mkBool false
"When true, section headers in the lualine theme will be bold"; "When true, section headers in the lualine theme will be bold";
onColors = onColors =
helpers.defaultNullOpts.mkStr "function(colors) end" helpers.defaultNullOpts.mkLuaFn "function(colors) end"
'' ''
Override specific color groups to use other groups or a hex color. Override specific color groups to use other groups or a hex color.
function will be called with a ColorScheme table. function will be called with a ColorScheme table.
`@param colors ColorScheme` `@param colors ColorScheme`
''; '';
onHighlights = onHighlights =
helpers.defaultNullOpts.mkStr "function(highlights, colors) end" helpers.defaultNullOpts.mkLuaFn "function(highlights, colors) end"
'' ''
Override specific highlights to use other groups or a hex color. Override specific highlights to use other groups or a hex color.
function will be called with a Highlights and ColorScheme table function will be called with a Highlights and ColorScheme table
@ -79,8 +79,8 @@ in {
dim_inactive = dimInactive; dim_inactive = dimInactive;
lualine_bold = lualineBold; lualine_bold = lualineBold;
day_brightness = dayBrightness; day_brightness = dayBrightness;
on_colors = helpers.mkRaw onColors; on_colors = onColors;
on_highlights = helpers.mkRaw onHighlights; on_highlights = onHighlights;
}; };
in '' in ''
require("tokyonight").setup(${helpers.toLuaObject setupOptions}) require("tokyonight").setup(${helpers.toLuaObject setupOptions})

View file

@ -212,7 +212,7 @@ in {
"An array of completion fields to specify their order."; "An array of completion fields to specify their order.";
format = format =
helpers.defaultNullOpts.mkStr helpers.defaultNullOpts.mkLuaFn
'' ''
function(_, vim_item) function(_, vim_item)
return vim_item return vim_item
@ -572,8 +572,7 @@ in {
formatting = with formatting; { formatting = with formatting; {
expandable_indicator = expandableIndicator; expandable_indicator = expandableIndicator;
inherit fields; inherit fields format;
format = helpers.mkRaw format;
}; };
matching = with matching; { matching = with matching; {

View file

@ -26,7 +26,7 @@ in {
includeConfigs = helpers.defaultNullOpts.mkBool true "Add default configurations."; includeConfigs = helpers.defaultNullOpts.mkBool true "Add default configurations.";
resolvePython = helpers.mkNullOrOption types.str '' resolvePython = helpers.defaultNullOpts.mkLuaFn "null" ''
Function to resolve path to python to use for program or test execution. Function to resolve path to python to use for program or test execution.
By default the `VIRTUAL_ENV` and `CONDA_PREFIX` environment variables are used if present. By default the `VIRTUAL_ENV` and `CONDA_PREFIX` environment variables are used if present.
''; '';
@ -75,7 +75,7 @@ in {
table.insert(require("dap").configurations.python, ${toLuaObject cfg.customConfigurations}) table.insert(require("dap").configurations.python, ${toLuaObject cfg.customConfigurations})
'') '')
+ (optionalString (cfg.resolvePython != null) '' + (optionalString (cfg.resolvePython != null) ''
require("dap-python").resolve_python = ${toLuaObject (mkRaw cfg.resolvePython)} require("dap-python").resolve_python = ${toLuaObject cfg.resolvePython}
'') '')
+ (optionalString (cfg.testRunner != null) '' + (optionalString (cfg.testRunner != null) ''
require("dap-python").test_runner = ${toLuaObject cfg.testRunner}; require("dap-python").test_runner = ${toLuaObject cfg.testRunner};

View file

@ -186,7 +186,7 @@ in {
maxValueLines = helpers.defaultNullOpts.mkInt 100 "Maximum number of lines to allow a value to fill before trimming."; maxValueLines = helpers.defaultNullOpts.mkInt 100 "Maximum number of lines to allow a value to fill before trimming.";
}; };
selectWindow = helpers.mkNullOrOption types.str '' selectWindow = helpers.defaultNullOpts.mkLuaFn "null" ''
A function which returns a window to be used for opening buffers such as a stack frame location. A function which returns a window to be used for opening buffers such as a stack frame location.
''; '';
}; };
@ -212,7 +212,7 @@ in {
max_value_lines = maxValueLines; max_value_lines = maxValueLines;
}; };
select_window = helpers.mkRaw selectWindow; select_window = selectWindow;
} }
// cfg.extraOptions; // cfg.extraOptions;
in in

View file

@ -36,7 +36,7 @@ in {
clearOnContinue = helpers.defaultNullOpts.mkBool false "Clear virtual text on `continue` (might cause flickering when stepping)."; clearOnContinue = helpers.defaultNullOpts.mkBool false "Clear virtual text on `continue` (might cause flickering when stepping).";
displayCallback = helpers.defaultNullOpts.mkStr '' displayCallback = helpers.defaultNullOpts.mkLuaFn ''
function(variable, buf, stackframe, node, options) function(variable, buf, stackframe, node, options)
if options.virt_text_pos == 'inline' then if options.virt_text_pos == 'inline' then
return ' = ' .. variable.value return ' = ' .. variable.value
@ -72,7 +72,7 @@ in {
only_first_definition = onlyFirstDefinition; only_first_definition = onlyFirstDefinition;
all_references = allReferences; all_references = allReferences;
clear_on_continue = clearOnContinue; clear_on_continue = clearOnContinue;
display_callback = helpers.mkRaw displayCallback; display_callback = displayCallback;
virt_text_pos = virtTextPos; virt_text_pos = virtTextPos;
all_frames = allFrames; all_frames = allFrames;
virt_lines = virtLines; virt_lines = virtLines;

View file

@ -153,7 +153,7 @@ in {
"Used when sorting files and directories in the tree"; "Used when sorting files and directories in the tree";
sortFunction = sortFunction =
helpers.defaultNullOpts.mkStr "nil" helpers.defaultNullOpts.mkLuaFn "nil"
"Uses a custom function for sorting files and directories in the tree"; "Uses a custom function for sorting files and directories in the tree";
usePopupsForInput = usePopupsForInput =
@ -1041,7 +1041,7 @@ in {
popup_border_style = popupBorderStyle; popup_border_style = popupBorderStyle;
resize_timer_interval = resizeTimerInterval; resize_timer_interval = resizeTimerInterval;
sort_case_insensitive = sortCaseInsensitive; sort_case_insensitive = sortCaseInsensitive;
sort_function = mkRaw sortFunction; sort_function = sortFunction;
use_popups_for_input = usePopupsForInput; use_popups_for_input = usePopupsForInput;
use_default_mappings = useDefaultMappings; use_default_mappings = useDefaultMappings;
source_selector = with sourceSelector; { source_selector = with sourceSelector; {

View file

@ -187,7 +187,7 @@ in {
height = helpers.defaultNullOpts.mkPositiveInt 5 "Height of the window."; height = helpers.defaultNullOpts.mkPositiveInt 5 "Height of the window.";
onLines = helpers.mkNullOrOption types.str '' onLines = helpers.defaultNullOpts.mkLuaFn "nil" ''
A callback which will be called with (multi-line) stderr output. A callback which will be called with (multi-line) stderr output.
e.g., use: e.g., use:
@ -302,7 +302,7 @@ in {
enable enable
height height
; ;
on_lines = helpers.mkRaw onLines; on_lines = onLines;
}; };
inherit lsp3; inherit lsp3;
} }

View file

@ -24,7 +24,7 @@ in {
"how to execute terminal commands"; "how to execute terminal commands";
onInitialized = onInitialized =
helpers.defaultNullOpts.mkStr "null" helpers.defaultNullOpts.mkLuaFn "null"
'' ''
Callback to execute once rust-analyzer is done initializing the workspace Callback to execute once rust-analyzer is done initializing the workspace
The callback receives one parameter indicating the `health` of the server: The callback receives one parameter indicating the `health` of the server:
@ -143,7 +143,7 @@ in {
helpers.ifNonNull' cfg.executor helpers.ifNonNull' cfg.executor
(helpers.mkRaw "require(${rust-tools.executors}).${cfg.executor}"); (helpers.mkRaw "require(${rust-tools.executors}).${cfg.executor}");
on_initialized = helpers.mkRaw cfg.onInitialized; on_initialized = cfg.onInitialized;
reload_workspace_from_cargo_toml = cfg.reloadWorkspaceFromCargoToml; reload_workspace_from_cargo_toml = cfg.reloadWorkspaceFromCargoToml;
inlay_hints = with cfg.inlayHints; { inlay_hints = with cfg.inlayHints; {

View file

@ -50,7 +50,7 @@ in {
The Z-index of the context window. The Z-index of the context window.
''; '';
onAttach = helpers.mkNullOrOption types.str '' onAttach = helpers.defaultNullOpts.mkLuaFn "nil" ''
The implementation of a lua function which takes an integer `buf` as parameter and returns a The implementation of a lua function which takes an integer `buf` as parameter and returns a
boolean. boolean.
Return `false` to disable attaching. Return `false` to disable attaching.
@ -70,7 +70,7 @@ in {
separator separator
zindex zindex
; ;
on_attach = helpers.mkRaw onAttach; on_attach = onAttach;
} }
// cfg.extraOptions; // cfg.extraOptions;
in in

View file

@ -61,7 +61,7 @@
`:LspStart` (|lspconfig-commands|). `:LspStart` (|lspconfig-commands|).
''; '';
rootDir = helpers.mkNullOrOption types.str '' rootDir = helpers.defaultNullOpts.mkLuaFn "nil" ''
A function (or function handle) which returns the root of the project used to A function (or function handle) which returns the root of the project used to
determine if lspconfig should launch a new language server, or attach a previously determine if lspconfig should launch a new language server, or attach a previously
launched server when you open a new buffer matching the filetype of the server. launched server when you open a new buffer matching the filetype of the server.
@ -110,7 +110,7 @@
extraOptions = extraOptions =
{ {
inherit (cfg) cmd filetypes autostart; inherit (cfg) cmd filetypes autostart;
root_dir = helpers.mkRaw cfg.rootDir; root_dir = cfg.rootDir;
on_attach = on_attach =
helpers.ifNonNull' cfg.onAttach helpers.ifNonNull' cfg.onAttach
( (

View file

@ -30,7 +30,7 @@ with lib; {
the type of the external input buffer to use the type of the external input buffer to use
''; '';
postHook = helpers.defaultNullOpts.mkNullable types.str "null" '' postHook = helpers.defaultNullOpts.mkLuaFn "null" ''
callback to run after renaming, receives the result table (from LSP handler) as an argument callback to run after renaming, receives the result table (from LSP handler) as an argument
''; '';
}; };
@ -43,7 +43,7 @@ with lib; {
preview_empty_name = cfg.previewEmptyName; preview_empty_name = cfg.previewEmptyName;
show_message = cfg.showMessage; show_message = cfg.showMessage;
input_buffer_type = cfg.inputBufferType; input_buffer_type = cfg.inputBufferType;
post_hook = helpers.mkRaw cfg.postHook; post_hook = cfg.postHook;
}; };
in in
mkIf cfg.enable { mkIf cfg.enable {

View file

@ -72,9 +72,9 @@ in {
"Default search engine."; "Default search engine.";
hooks = { hooks = {
requestStarted = helpers.mkNullOrOption types.str "Callback for request start."; requestStarted = helpers.defaultNullOpts.mkLuaFn "nil" "Callback for request start.";
requestFinished = helpers.mkNullOrOption types.str "Callback for request finished."; requestFinished = helpers.defaultNullOpts.mkLuaFn "nil" "Callback for request finished.";
}; };
winhighlight = helpers.defaultNullOpts.mkStr "Normal:Normal,FloatBorder:FloatBorder" '' winhighlight = helpers.defaultNullOpts.mkStr "Normal:Normal,FloatBorder:FloatBorder" ''
@ -96,8 +96,8 @@ in {
additional_instructions = additionalInstructions; additional_instructions = additionalInstructions;
search_engine = searchEngine; search_engine = searchEngine;
hooks = { hooks = {
request_started = helpers.mkRaw hooks.requestStarted; request_started = hooks.requestStarted;
request_finished = helpers.mkRaw hooks.requestFinished; request_finished = hooks.requestFinished;
}; };
inherit winhighlight; inherit winhighlight;
} }

View file

@ -137,17 +137,17 @@ in {
custom callback for null-ls, or leave this undefined. custom callback for null-ls, or leave this undefined.
''; '';
onInit = helpers.defaultNullOpts.mkStr "null" '' onInit = helpers.defaultNullOpts.mkLuaFn "null" ''
Defines an `on_init` callback to run when null-ls initializes. From here, you Defines an `on_init` callback to run when null-ls initializes. From here, you
can make changes to the client (the first argument) or `initialize_result` (the can make changes to the client (the first argument) or `initialize_result` (the
second argument, which as of now is not used). second argument, which as of now is not used).
''; '';
onExit = helpers.defaultNullOpts.mkStr "null" '' onExit = helpers.defaultNullOpts.mkLuaFn "null" ''
Defines an `on_exit` callback to run when the null-ls client exits. Defines an `on_exit` callback to run when the null-ls client exits.
''; '';
rootDir = helpers.defaultNullOpts.mkStr "null" '' rootDir = helpers.defaultNullOpts.mkLuaFn "null" ''
Determines the root of the null-ls server. On startup, null-ls will call Determines the root of the null-ls server. On startup, null-ls will call
`root_dir` with the full path to the first file that null-ls attaches to. `root_dir` with the full path to the first file that null-ls attaches to.
@ -161,7 +161,7 @@ in {
directory. directory.
''; '';
shouldAttach = helpers.defaultNullOpts.mkStr "null" '' shouldAttach = helpers.defaultNullOpts.mkLuaFn "null" ''
A user-defined function that controls whether to enable null-ls for a given A user-defined function that controls whether to enable null-ls for a given
buffer. Receives `bufnr` as its first argument. buffer. Receives `bufnr` as its first argument.
@ -257,10 +257,10 @@ in {
log_level = logLevel; log_level = logLevel;
notify_format = notifyFormat; notify_format = notifyFormat;
on_attach = helpers.mkRaw onAttach'; on_attach = helpers.mkRaw onAttach';
on_init = helpers.mkRaw onInit; on_init = onInit;
on_exit = helpers.mkRaw onExit; on_exit = onExit;
root_dir = helpers.mkRaw rootDir; root_dir = rootDir;
should_attach = helpers.mkRaw shouldAttach; should_attach = shouldAttach;
temp_dir = tempDir; temp_dir = tempDir;
update_in_insert = updateInInsert; update_in_insert = updateInInsert;

View file

@ -29,9 +29,9 @@ in {
helpers.mkNullOrOption str helpers.mkNullOrOption str
"Specifies an alias under which to install the plugin"; "Specifies an alias under which to install the plugin";
installer = helpers.mkNullOrOption str "A custom installer"; installer = helpers.defaultNullOpts.mkLuaFn "nil" "A custom installer";
updater = helpers.mkNullOrOption str "A custom updater"; updater = helpers.defaultNullOpts.mkLuaFn "nil" "A custom updater";
after = after =
helpers.mkNullOrOption (either str (listOf str)) helpers.mkNullOrOption (either str (listOf str))
@ -157,14 +157,12 @@ in {
then { then {
"__unkeyed" = plugin.name; "__unkeyed" = plugin.name;
inherit (plugin) disable as;
installer = helpers.mkRaw plugin.installer;
updater = helpers.mkRaw plugin.updater;
inherit inherit
(plugin) (plugin)
disable
as
installer
updater
after after
rtp rtp
opt opt

View file

@ -78,11 +78,11 @@ in {
Induces slow-down w/ plenary finder (true if `fd` available). Induces slow-down w/ plenary finder (true if `fd` available).
''; '';
browseFiles = helpers.defaultNullOpts.mkStr "fb_finders.browse_files" '' browseFiles = helpers.defaultNullOpts.mkLuaFn "fb_finders.browse_files" ''
A custom lua function to override for the file browser. A custom lua function to override for the file browser.
''; '';
browseFolders = helpers.defaultNullOpts.mkStr "fb_finders.browse_folders" '' browseFolders = helpers.defaultNullOpts.mkLuaFn "fb_finders.browse_folders" ''
A custom lua function to override for the folder browser. A custom lua function to override for the folder browser.
''; '';
@ -151,8 +151,8 @@ in {
; ;
add_dirs = addDirs; add_dirs = addDirs;
auto_depth = autoDepth; auto_depth = autoDepth;
browse_files = helpers.mkRaw browseFiles; browse_files = browseFiles;
browse_folders = helpers.mkRaw browseFolders; browse_folders = browseFolders;
collapse_dirs = collapseDirs; collapse_dirs = collapseDirs;
cwd_to_path = cwdToPath; cwd_to_path = cwdToPath;
dir_icon = dirIcon; dir_icon = dirIcon;

View file

@ -69,7 +69,7 @@ in {
''; '';
condition = condition =
helpers.defaultNullOpts.mkStr helpers.defaultNullOpts.mkLuaFn
'' ''
function(buf) function(buf)
local fn = vim.fn local fn = vim.fn
@ -120,7 +120,7 @@ in {
cleaning_interval = cleaningInterval; cleaning_interval = cleaningInterval;
}; };
trigger_events = cfg.triggerEvents; trigger_events = cfg.triggerEvents;
condition = helpers.mkRaw cfg.condition; inherit (cfg) condition;
write_all_buffers = cfg.writeAllBuffers; write_all_buffers = cfg.writeAllBuffers;
debounce_delay = cfg.debounceDelay; debounce_delay = cfg.debounceDelay;
callbacks = with cfg.callbacks; callbacks = with cfg.callbacks;

View file

@ -81,12 +81,12 @@ in {
Restore session for upcoming cwd on cwd change. Restore session for upcoming cwd on cwd change.
''; '';
preCwdChangedHook = helpers.mkNullOrOption types.str '' preCwdChangedHook = helpers.defaultNullOpts.mkLuaFn "nil" ''
lua function hook. lua function hook.
This is called after auto_session code runs for the `DirChangedPre` autocmd. This is called after auto_session code runs for the `DirChangedPre` autocmd.
''; '';
postCwdChangedHook = helpers.mkNullOrOption types.str '' postCwdChangedHook = helpers.defaultNullOpts.mkLuaFn "nil" ''
lua function hook. lua function hook.
This is called after auto_session code runs for the `DirChanged` autocmd. This is called after auto_session code runs for the `DirChanged` autocmd.
''; '';
@ -160,8 +160,8 @@ in {
then then
with cfg.cwdChangeHandling; { with cfg.cwdChangeHandling; {
restore_upcoming_session = restoreUpcomingSession; restore_upcoming_session = restoreUpcomingSession;
pre_cwd_changed_hook = helpers.mkRaw preCwdChangedHook; pre_cwd_changed_hook = preCwdChangedHook;
post_cwd_changed_hook = helpers.mkRaw postCwdChangedHook; post_cwd_changed_hook = postCwdChangedHook;
} }
else cfg.cwdChangeHandling; else cfg.cwdChangeHandling;
bypass_session_save_file_types = cfg.bypassSessionSaveFileTypes; bypass_session_save_file_types = cfg.bypassSessionSaveFileTypes;

View file

@ -140,7 +140,7 @@ in {
"Fail text highlight group of the summary pop-up."; "Fail text highlight group of the summary pop-up.";
}; };
loadCoverageCb = helpers.mkNullOrOption types.str '' loadCoverageCb = helpers.defaultNullOpts.mkLuaFn "nil" ''
A lua function that will be called when a coverage file is loaded. A lua function that will be called when a coverage file is loaded.
Example: Example:
@ -278,7 +278,7 @@ in {
summary_pass = summaryPass; summary_pass = summaryPass;
summary_fail = summaryFail; summary_fail = summaryFail;
}; };
load_coverage_cb = helpers.mkRaw loadCoverageCb; load_coverage_cb = loadCoverageCb;
inherit signs; inherit signs;
sign_group = signGroup; sign_group = signGroup;
summary = with summary; { summary = with summary; {

View file

@ -155,7 +155,7 @@ in {
}; };
format = format =
helpers.defaultNullOpts.mkStr '' helpers.defaultNullOpts.mkLuaFn ''
format = function(opts) format = function(opts)
return { { opts.match.label, opts.hl_group } } return { { opts.match.label, opts.hl_group } }
end end
@ -186,7 +186,7 @@ in {
}; };
}; };
action = helpers.mkNullOrOption types.str '' action = helpers.defaultNullOpts.mkLuaFn "nil" ''
action to perform when picking a label. action to perform when picking a label.
defaults to the jumping logic depending on the mode. defaults to the jumping logic depending on the mode.
@type fun(match:Flash.Match, state:Flash.State) @type fun(match:Flash.Match, state:Flash.State)
@ -198,7 +198,7 @@ in {
When `true`, flash will try to continue the last search When `true`, flash will try to continue the last search
''; '';
config = helpers.mkNullOrOption types.str '' config = helpers.defaultNullOpts.mkLuaFn "nil" ''
Set config to a function to dynamically change the config Set config to a function to dynamically change the config
@type fun(opts:Flash.Config) @type fun(opts:Flash.Config)
''; '';
@ -298,7 +298,7 @@ in {
''; '';
charActions = charActions =
helpers.defaultNullOpts.mkStr '' helpers.defaultNullOpts.mkLuaFn ''
function(motion) function(motion)
return { return {
[";"] = "next", -- set to right to always go right [";"] = "next", -- set to right to always go right
@ -406,14 +406,12 @@ in {
rainbow = { rainbow = {
inherit (c.label.rainbow) enabled shade; inherit (c.label.rainbow) enabled shade;
}; };
format = helpers.mkRaw c.label.format; inherit (c.label) format;
}; };
highlight = { highlight = {
inherit (c.highlight) backdrop matches priority groups; inherit (c.highlight) backdrop matches priority groups;
}; };
action = helpers.mkRaw c.action; inherit (c) action pattern continue config;
inherit (c) pattern continue;
config = helpers.mkRaw c.config;
prompt = { prompt = {
inherit (c.prompt) enabled prefix; inherit (c.prompt) enabled prefix;
win_config = c.prompt.winConfig; win_config = c.prompt.winConfig;
@ -443,8 +441,7 @@ in {
inherit (c) enabled autohide; inherit (c) enabled autohide;
jump_labels = c.jumpLabels; jump_labels = c.jumpLabels;
multi_line = c.multiLine; multi_line = c.multiLine;
inherit (c) keys; inherit (c) keys charActions;
char_actions = helpers.mkRaw c.charActions;
}); });
treesitter = mkModeConfig cfg.modes.treesitter (c: {}); treesitter = mkModeConfig cfg.modes.treesitter (c: {});
treesitter_search = mkModeConfig cfg.modes.treesitterSearch (c: {}); treesitter_search = mkModeConfig cfg.modes.treesitterSearch (c: {});

View file

@ -71,11 +71,11 @@ in {
trace = ""; trace = "";
}; };
onOpen = helpers.mkNullOrOption types.str '' onOpen = helpers.defaultNullOpts.mkLuaFn "nil" ''
Function called when a new window is opened, use for changing win settings/config. Function called when a new window is opened, use for changing win settings/config.
''; '';
onClose = helpers.mkNullOrOption types.str '' onClose = helpers.defaultNullOpts.mkLuaFn "nil" ''
Function called when a new window is closed. Function called when a new window is closed.
''; '';
@ -130,8 +130,8 @@ in {
} }
) )
icons; icons;
on_open = helpers.mkRaw onOpen; on_open = onOpen;
on_close = helpers.mkRaw onClose; on_close = onClose;
inherit render; inherit render;
minimum_width = minimumWidth; minimum_width = minimumWidth;
inherit fps; inherit fps;

View file

@ -70,7 +70,7 @@ in {
Add label of current item buffer at the end of the item line. Add label of current item buffer at the end of the item line.
''; '';
shouldPreviewCb = helpers.mkNullOrOption types.str '' shouldPreviewCb = helpers.defaultNullOpts.mkLuaFn "nil" ''
A callback function to decide whether to preview while switching buffer, with A callback function to decide whether to preview while switching buffer, with
(bufnr: number, qwinid: number) parameters. (bufnr: number, qwinid: number) parameters.
''; '';
@ -135,7 +135,7 @@ in {
win_vheight = winVheight; win_vheight = winVheight;
inherit wrap; inherit wrap;
buf_label = bufLabel; buf_label = bufLabel;
should_preview_cb = helpers.mkRaw shouldPreviewCb; should_preview_cb = shouldPreviewCb;
}; };
func_map = cfg.funcMap; func_map = cfg.funcMap;
filter = { filter = {

View file

@ -20,7 +20,7 @@ in {
while opening the folded line, `0` value will disable the highlight while opening the folded line, `0` value will disable the highlight
''; '';
providerSelector = helpers.defaultNullOpts.mkStr "null" '' providerSelector = helpers.defaultNullOpts.mkLuaFn "null" ''
A lua function as a selector for fold providers. A lua function as a selector for fold providers.
''; '';
@ -31,7 +31,7 @@ in {
run `UfoInspect` for details if your provider has extended the kinds. run `UfoInspect` for details if your provider has extended the kinds.
''; '';
foldVirtTextHandler = helpers.defaultNullOpts.mkStr "null" "A lua function to customize fold virtual text"; foldVirtTextHandler = helpers.defaultNullOpts.mkLuaFn "null" "A lua function to customize fold virtual text";
enableGetFoldVirtText = helpers.defaultNullOpts.mkBool false '' enableGetFoldVirtText = helpers.defaultNullOpts.mkBool false ''
Enable a function with `lnum` as a parameter to capture the virtual text Enable a function with `lnum` as a parameter to capture the virtual text
@ -58,9 +58,9 @@ in {
options = with cfg; options = with cfg;
{ {
open_fold_hl_timeout = openFoldHlTimeout; open_fold_hl_timeout = openFoldHlTimeout;
provider_selector = helpers.mkRaw providerSelector; provider_selector = providerSelector;
close_fold_kinds = closeFoldKinds; close_fold_kinds = closeFoldKinds;
fold_virt_text_handler = helpers.mkRaw foldVirtTextHandler; fold_virt_text_handler = foldVirtTextHandler;
enable_get_fold_virt_text = enableGetFoldVirtText; enable_get_fold_virt_text = enableGetFoldVirtText;
preview = with preview; { preview = with preview; {

View file

@ -289,7 +289,7 @@ in {
''; '';
isHiddenFile = isHiddenFile =
helpers.defaultNullOpts.mkStr helpers.defaultNullOpts.mkLuaFn
'' ''
function(name, bufnr) function(name, bufnr)
return vim.startswith(name, ".") return vim.startswith(name, ".")
@ -298,7 +298,7 @@ in {
"This function defines what is considered a 'hidden' file."; "This function defines what is considered a 'hidden' file.";
isAlwaysHidden = isAlwaysHidden =
helpers.defaultNullOpts.mkStr helpers.defaultNullOpts.mkLuaFn
'' ''
function(name, bufnr) function(name, bufnr)
return false return false
@ -381,8 +381,8 @@ in {
use_default_keymaps = cfg.useDefaultKeymaps; use_default_keymaps = cfg.useDefaultKeymaps;
view_options = with cfg.viewOptions; { view_options = with cfg.viewOptions; {
show_hidden = showHidden; show_hidden = showHidden;
is_hidden_file = helpers.mkRaw isHiddenFile; is_hidden_file = isHiddenFile;
is_always_hidden = helpers.mkRaw isAlwaysHidden; is_always_hidden = isAlwaysHidden;
}; };
float = with cfg.float; { float = with cfg.float; {
inherit padding; inherit padding;

View file

@ -41,7 +41,7 @@ with lib; {
helpers.defaultNullOpts.mkNullable (with types; listOf (enum sessionOpts)) helpers.defaultNullOpts.mkNullable (with types; listOf (enum sessionOpts))
''["buffers" "curdir" "tabpages" "winsize" "skiprtp"]'' "sessionoptions used for saving"; ''["buffers" "curdir" "tabpages" "winsize" "skiprtp"]'' "sessionoptions used for saving";
preSave = helpers.mkNullOrOption types.str "a function to call before saving the session"; preSave = helpers.defaultNullOpts.mkLuaFn "nil" "a function to call before saving the session";
saveEmpty = helpers.defaultNullOpts.mkBool false '' saveEmpty = helpers.defaultNullOpts.mkBool false ''
don't save if there are no open file buffers don't save if there are no open file buffers
@ -57,7 +57,7 @@ with lib; {
extraConfigLua = let extraConfigLua = let
opts = { opts = {
inherit (cfg) dir options; inherit (cfg) dir options;
pre_save = helpers.mkRaw cfg.preSave; pre_save = cfg.preSave;
save_empty = cfg.saveEmpty; save_empty = cfg.saveEmpty;
}; };
in '' in ''

View file

@ -191,7 +191,7 @@ in {
- if > 1 numbers of column - if > 1 numbers of column
''; '';
after = helpers.mkNullOrOption types.str '' after = helpers.defaultNullOpts.mkLuaFn "nil" ''
A function that gets executed at the end. A function that gets executed at the end.
''; '';
@ -312,7 +312,7 @@ in {
{ {
mapping_keys = mappingKeys; mapping_keys = mappingKeys;
cursor_column = cursorColumn; cursor_column = cursorColumn;
after = helpers.mkRaw after; inherit after;
empty_lines_between_mappings = emptyLinesBetweenMappings; empty_lines_between_mappings = emptyLinesBetweenMappings;
disable_statuslines = disableStatuslines; disable_statuslines = disableStatuslines;
inherit paddings; inherit paddings;

View file

@ -39,27 +39,27 @@ in {
normal mode. normal mode.
''; '';
onCreate = helpers.mkNullOrOption types.str '' onCreate = helpers.defaultNullOpts.mkLuaFn "nil" ''
Function to run when the terminal is first created. Function to run when the terminal is first created.
''; '';
onOpen = helpers.mkNullOrOption types.str '' onOpen = helpers.defaultNullOpts.mkLuaFn "nil" ''
Function to run when the terminal opens. Function to run when the terminal opens.
''; '';
onClose = helpers.mkNullOrOption types.str '' onClose = helpers.defaultNullOpts.mkLuaFn "nil" ''
Function to run when the terminal closes. Function to run when the terminal closes.
''; '';
onStdout = helpers.mkNullOrOption types.str '' onStdout = helpers.defaultNullOpts.mkLuaFn "nil" ''
Callback for processing output on stdout. Callback for processing output on stdout.
''; '';
onStderr = helpers.mkNullOrOption types.str '' onStderr = helpers.defaultNullOpts.mkLuaFn "nil" ''
Callback for processing output on stderr. Callback for processing output on stderr.
''; '';
onExit = helpers.mkNullOrOption types.str '' onExit = helpers.defaultNullOpts.mkLuaFn "nil" ''
Function to run when terminal process exits. Function to run when terminal process exits.
''; '';
@ -160,7 +160,7 @@ in {
enabled = helpers.defaultNullOpts.mkBool false ""; enabled = helpers.defaultNullOpts.mkBool false "";
nameFormatter = nameFormatter =
helpers.defaultNullOpts.mkStr helpers.defaultNullOpts.mkLuaFn
'' ''
function(term) function(term)
return term.name return term.name
@ -177,12 +177,12 @@ in {
else helpers.mkRaw size else helpers.mkRaw size
); );
open_mapping = helpers.ifNonNull' openMapping (helpers.mkRaw "[[${openMapping}]]"); open_mapping = helpers.ifNonNull' openMapping (helpers.mkRaw "[[${openMapping}]]");
on_create = helpers.mkRaw onCreate; on_create = onCreate;
on_open = helpers.mkRaw onOpen; on_open = onOpen;
on_close = helpers.mkRaw onClose; on_close = onClose;
on_stdout = helpers.mkRaw onStdout; on_stdout = onStdout;
on_stderr = helpers.mkRaw onStderr; on_stderr = onStderr;
on_exit = helpers.mkRaw onExit; on_exit = onExit;
hide_numbers = hideNumbers; hide_numbers = hideNumbers;
shade_filetypes = shadeFiletypes; shade_filetypes = shadeFiletypes;
shade_terminals = shadeTerminals; shade_terminals = shadeTerminals;
@ -197,7 +197,7 @@ in {
float_opts = floatOpts; float_opts = floatOpts;
winbar = with winbar; { winbar = with winbar; {
inherit enabled; inherit enabled;
name_formatter = helpers.mkRaw nameFormatter; name_formatter = nameFormatter;
}; };
}; };
in in

View file

@ -175,7 +175,7 @@ in {
``` ```
''; '';
renderer = helpers.mkNullOrOption types.str '' renderer = helpers.defaultNullOpts.mkLuaFn "nil" ''
Sets the renderer to used to display the completions. Sets the renderer to used to display the completions.
See `|wilder-renderer|`. See `|wilder-renderer|`.
@ -190,7 +190,7 @@ in {
``` ```
''; '';
preHook = helpers.mkNullOrOption types.str '' preHook = helpers.defaultNullOpts.mkLuaFn "nil" ''
A function which takes a `ctx`. A function which takes a `ctx`.
This function is called when wilder starts, or when wilder becomes unhidden. This function is called when wilder starts, or when wilder becomes unhidden.
See `|wilder-hidden|`. See `|wilder-hidden|`.
@ -198,7 +198,7 @@ in {
`ctx` contains no keys. `ctx` contains no keys.
''; '';
postHook = helpers.mkNullOrOption types.str '' postHook = helpers.defaultNullOpts.mkLuaFn "nil" ''
A function which takes a `ctx`. A function which takes a `ctx`.
This function is called when wilder stops, or when wilder becomes hidden. This function is called when wilder stops, or when wilder becomes hidden.
See `|wilder-hidden|`. See `|wilder-hidden|`.
@ -237,9 +237,9 @@ in {
pipeline = pipeline =
helpers.ifNonNull' pipeline helpers.ifNonNull' pipeline
(map helpers.mkRaw pipeline); (map helpers.mkRaw pipeline);
renderer = helpers.mkRaw renderer; inherit renderer;
preHook = helpers.mkRaw preHook; pre_hook = preHook;
postHook = helpers.mkRaw postHook; post_hook = postHook;
} }
// cfg.extraOptions; // cfg.extraOptions;
in in