mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-11-12 16:35:30 +00:00
Add toggleFormatOnSave capability to conform
This commit is contained in:
parent
80ac1cbc7b
commit
c688311e37
2 changed files with 67 additions and 38 deletions
|
|
@ -1,11 +1,9 @@
|
||||||
{
|
{lib, ...}: let
|
||||||
config,
|
inherit (lib.generators) mkLuaInline;
|
||||||
lib,
|
|
||||||
...
|
|
||||||
}: let
|
|
||||||
inherit (lib.options) mkOption mkEnableOption;
|
inherit (lib.options) mkOption mkEnableOption;
|
||||||
inherit (lib.types) attrs nullOr;
|
inherit (lib.types) attrs either nullOr;
|
||||||
inherit (lib.nvim.types) mkPluginSetupOption;
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
|
inherit (lib.nvim.types) luaInline mkPluginSetupOption;
|
||||||
in {
|
in {
|
||||||
options.vim.formatter.conform-nvim = {
|
options.vim.formatter.conform-nvim = {
|
||||||
enable = mkEnableOption "lightweight yet powerful formatter plugin for Neovim [conform-nvim]";
|
enable = mkEnableOption "lightweight yet powerful formatter plugin for Neovim [conform-nvim]";
|
||||||
|
|
@ -29,33 +27,68 @@ in {
|
||||||
description = "Default values when calling `conform.format()`";
|
description = "Default values when calling `conform.format()`";
|
||||||
};
|
};
|
||||||
|
|
||||||
format_on_save = mkOption {
|
format_on_save = let
|
||||||
type = nullOr attrs;
|
defaultFormatOnSaveOpts = {
|
||||||
default =
|
lsp_format = "fallback";
|
||||||
if config.vim.lsp.formatOnSave
|
timeout_ms = 500;
|
||||||
then {
|
};
|
||||||
lsp_format = "fallback";
|
in
|
||||||
timeout_ms = 500;
|
mkOption {
|
||||||
}
|
type = nullOr (either attrs luaInline);
|
||||||
else null;
|
default =
|
||||||
description = ''
|
mkLuaInline
|
||||||
Table that will be passed to `conform.format()`. If this
|
# lua
|
||||||
is set, Conform will run the formatter on save.
|
''
|
||||||
'';
|
function()
|
||||||
};
|
if (not vim.g.formatsave) or (vim.b.disableFormatSave) then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
return ${toLuaObject defaultFormatOnSaveOpts}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Table or function(lualinline) that will be passed to `conform.format()`. If this
|
||||||
|
is set, Conform will run the formatter on save.
|
||||||
|
|
||||||
format_after_save = mkOption {
|
Note:
|
||||||
type = nullOr attrs;
|
- When config.vim.lsp.formatOnSave is set to true, internally
|
||||||
default =
|
vim.g.formatsave is set to true.
|
||||||
if config.vim.lsp.formatOnSave
|
- vim.b.disableFormatSave initally equals !config.vim.lsp.formatOnSave.
|
||||||
then {lsp_format = "fallback";}
|
- vim.b.disableFormatSave is toggled using the
|
||||||
else null;
|
mapping from config.vim.lsp.mappings.toggleFormatOnSave.
|
||||||
description = ''
|
'';
|
||||||
Table that will be passed to `conform.format()`. If this
|
};
|
||||||
is set, Conform will run the formatter asynchronously after
|
|
||||||
save.
|
format_after_save = let
|
||||||
'';
|
defaultFormatAfterSaveOpts = {lsp_format = "fallback";};
|
||||||
};
|
in
|
||||||
|
mkOption {
|
||||||
|
type = nullOr (either attrs luaInline);
|
||||||
|
default =
|
||||||
|
mkLuaInline
|
||||||
|
# lua
|
||||||
|
''
|
||||||
|
function()
|
||||||
|
if (not vim.g.formatsave) or (vim.b.disableFormatSave) then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
return ${toLuaObject defaultFormatAfterSaveOpts}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Table or function(luainline) that will be passed to `conform.format()`. If this
|
||||||
|
is set, Conform will run the formatter asynchronously after save.
|
||||||
|
|
||||||
|
Note:
|
||||||
|
- When config.vim.lsp.formatOnSave is set to true, internally
|
||||||
|
vim.g.formatsave is set to true.
|
||||||
|
- vim.b.disableFormatSave initally equals !config.vim.lsp.formatOnSave.
|
||||||
|
- vim.b.disableFormatSave is toggled using the
|
||||||
|
mapping from config.vim.lsp.mappings.toggleFormatOnSave.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,11 +93,7 @@ in {
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
''
|
''
|
||||||
else "
|
else ""
|
||||||
vim.lsp.buf.format({
|
|
||||||
bufnr = bufnr,
|
|
||||||
})
|
|
||||||
"
|
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue