nix-community.nixvim/plugins/by-name/lsp-format/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
2.8 KiB
Nix
Raw Normal View History

2023-05-12 11:01:10 +02:00
{
lib,
config,
...
}:
2024-12-22 09:58:27 +00:00
lib.nixvim.plugins.mkNeovimPlugin {
name = "lsp-format";
packPathName = "lsp-format.nvim";
package = "lsp-format-nvim";
2023-05-12 11:01:10 +02:00
maintainers = [ lib.maintainers.khaneliman ];
2023-05-12 11:01:10 +02:00
# TODO: added 10-22-2024 remove after 24.11
deprecateExtraOptions = true;
imports = [
(lib.mkRenamedOptionModule
[
"plugins"
"lsp-format"
"setup"
]
[
"plugins"
"lsp-format"
"settings"
]
)
];
2023-05-12 11:01:10 +02:00
description = ''
## Configuring a Language
2023-05-12 11:01:10 +02:00
`lsp-format` uses a table defining which lsp servers to use for each language.
2023-05-12 11:01:10 +02:00
- `exclude` is a table of LSP servers that should not format the buffer.
- Alternatively, you can also just not call `on_attach` for the clients you don't want to use for
formatting.
- `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.
'';
settingsExample = {
go = {
exclude = [ "gopls" ];
order = [
"gopls"
"efm"
];
sync = true;
force = true;
};
typescript = {
tab_width.__raw = ''
function()
return vim.opt.shiftwidth:get()
end'';
2024-05-05 19:39:35 +02:00
};
yaml = {
tab_width = 2;
};
};
2023-05-12 11:01:10 +02:00
extraOptions = {
lspServersToEnable = lib.mkOption {
2023-05-12 11:01:10 +02:00
type =
with lib.types;
2023-05-12 11:01:10 +02:00
either (enum [
"none"
"all"
]) (listOf str);
default = "all";
description = ''
Choose the LSP servers for which lsp-format should be enabled.
Possible values:
- "all" (default): Enable formatting for all language servers
- "none": Do not enable formatting on any language server.
You might choose this if for some reason you want to manually call
`require("lsp-format").on_attach(client)` in the `onAttach` function of your language
servers.
- list of LS names: Manually choose the servers by name
'';
example = [
"efm"
"gopls"
];
};
2024-05-05 19:39:35 +02:00
};
2023-05-12 11:01:10 +02:00
extraConfig = cfg: {
warnings = lib.mkIf (!config.plugins.lsp.enable) [
"You have enabled `plugins.lsp-format` but have `plugins.lsp` disabled."
];
2023-05-12 11:01:10 +02:00
plugins.lsp = {
onAttach =
lib.mkIf (cfg.lspServersToEnable == "all") # Lua
''
require("lsp-format").on_attach(client)
'';
2023-05-12 11:01:10 +02:00
servers = lib.optionalAttrs (lib.isList cfg.lspServersToEnable) (
lib.genAttrs cfg.lspServersToEnable (serverName: {
onAttach.function = # Lua
''
require("lsp-format").on_attach(client)
'';
})
);
2023-05-12 11:01:10 +02:00
};
};
2023-05-12 11:01:10 +02:00
}