plugins/lsp-format: migrate to mkNeovimPlugin

This commit is contained in:
Austin Horstman 2024-10-22 23:34:43 -05:00
parent fb1943a673
commit 32969847d3
No known key found for this signature in database
2 changed files with 75 additions and 81 deletions

View file

@ -1,53 +1,47 @@
{ {
lib, lib,
config, config,
pkgs,
... ...
}: }:
let lib.nixvim.neovim-plugin.mkNeovimPlugin {
cfg = config.plugins.lsp-format; name = "lsp-format";
in originalName = "lsp-format.nvim";
{ package = "lsp-format-nvim";
options.plugins.lsp-format = lib.nixvim.neovim-plugin.extraOptionsOptions // {
enable = lib.mkEnableOption "lsp-format.nvim";
package = lib.mkPackageOption pkgs "lsp-format.nvim" { maintainers = [ lib.maintainers.khaneliman ];
default = [
"vimPlugins" # TODO: added 10-22-2024 remove after 24.11
"lsp-format-nvim" deprecateExtraOptions = true;
imports = [
(lib.mkRenamedOptionModule
[
"plugins"
"lsp-format"
"setup"
]
[
"plugins"
"lsp-format"
"settings"
]
)
]; ];
};
setup = lib.mkOption { description = ''
type = ## Configuring a Language
with lib.types;
attrsOf (submodule {
# Allow the user to provide other options
freeformType = types.attrs;
options = { `lsp-format` uses a table defining which lsp servers to use for each language.
exclude = lib.nixvim.mkNullOrOption (listOf str) "List of client names to exclude from formatting.";
order = lib.nixvim.mkNullOrOption (listOf str) ''
List of client names. Formatting is requested from clients in the following - `exclude` is a table of LSP servers that should not format the buffer.
order: first all clients that are not in the `order` table, then the remaining - Alternatively, you can also just not call `on_attach` for the clients you don't want to use for
clients in the order as they occur in the `order` table. formatting.
(same logic as |vim.lsp.buf.formatting_seq_sync()|). - `order` is a table that determines the order formatting is requested from the LSP server.
- `sync` turns on synchronous formatting. The editor will block until the formatting is done.
- `force` will write the format result to the buffer, even if the buffer changed after the format request started.
''; '';
sync = lib.nixvim.defaultNullOpts.mkBool false '' settingsExample = {
Whether to turn on synchronous formatting.
The editor will block until formatting is done.
'';
force = lib.nixvim.defaultNullOpts.mkBool false ''
If true, the format result will always be written to the buffer, even if the
buffer changed.
'';
};
});
description = "The setup option maps |filetypes| to format options.";
example = {
go = { go = {
exclude = [ "gopls" ]; exclude = [ "gopls" ];
order = [ order = [
@ -57,10 +51,18 @@ in
sync = true; sync = true;
force = true; force = true;
}; };
typescript = {
tab_width.__raw = ''
function()
return vim.opt.shiftwidth:get()
end'';
};
yaml = {
tab_width = 2;
}; };
default = { };
}; };
extraOptions = {
lspServersToEnable = lib.mkOption { lspServersToEnable = lib.mkOption {
type = type =
with lib.types; with lib.types;
@ -87,35 +89,27 @@ in
}; };
}; };
config = extraConfig = cfg: {
let
setupOptions = cfg.setup // cfg.extraOptions;
in
lib.mkIf cfg.enable {
warnings = lib.mkIf (!config.plugins.lsp.enable) [ warnings = lib.mkIf (!config.plugins.lsp.enable) [
"You have enabled `plugins.lsp-format` but have `plugins.lsp` disabled." "You have enabled `plugins.lsp-format` but have `plugins.lsp` disabled."
]; ];
extraPlugins = [ cfg.package ];
plugins.lsp = { plugins.lsp = {
onAttach = lib.mkIf (cfg.lspServersToEnable == "all") '' onAttach =
lib.mkIf (cfg.lspServersToEnable == "all") # Lua
''
require("lsp-format").on_attach(client) require("lsp-format").on_attach(client)
''; '';
servers = servers = lib.optionalAttrs (lib.isList cfg.lspServersToEnable) (
if (lib.isList cfg.lspServersToEnable) then
lib.genAttrs cfg.lspServersToEnable (serverName: { lib.genAttrs cfg.lspServersToEnable (serverName: {
onAttach.function = '' onAttach.function = # Lua
''
require("lsp-format").on_attach(client) require("lsp-format").on_attach(client)
''; '';
}) })
else );
{ };
};
extraConfigLua = '' };
require("lsp-format").setup(${lib.nixvim.toLuaObject setupOptions})
'';
}; };
} }

View file

@ -20,7 +20,7 @@
lsp-format = { lsp-format = {
enable = true; enable = true;
setup = { settings = {
go = { go = {
exclude = [ "gopls" ]; exclude = [ "gopls" ];
order = [ order = [