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

@ -61,7 +61,7 @@
`: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
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.
@ -110,7 +110,7 @@
extraOptions =
{
inherit (cfg) cmd filetypes autostart;
root_dir = helpers.mkRaw cfg.rootDir;
root_dir = cfg.rootDir;
on_attach =
helpers.ifNonNull' cfg.onAttach
(

View file

@ -30,7 +30,7 @@ with lib; {
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
'';
};
@ -43,7 +43,7 @@ with lib; {
preview_empty_name = cfg.previewEmptyName;
show_message = cfg.showMessage;
input_buffer_type = cfg.inputBufferType;
post_hook = helpers.mkRaw cfg.postHook;
post_hook = cfg.postHook;
};
in
mkIf cfg.enable {

View file

@ -72,9 +72,9 @@ in {
"Default search engine.";
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" ''
@ -96,8 +96,8 @@ in {
additional_instructions = additionalInstructions;
search_engine = searchEngine;
hooks = {
request_started = helpers.mkRaw hooks.requestStarted;
request_finished = helpers.mkRaw hooks.requestFinished;
request_started = hooks.requestStarted;
request_finished = hooks.requestFinished;
};
inherit winhighlight;
}