2023-05-12 11:01:10 +02:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
2023-11-06 15:04:08 +01:00
|
|
|
pkgs,
|
2023-05-12 11:01:10 +02:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.plugins.lsp-format;
|
|
|
|
in
|
|
|
|
{
|
2024-10-22 23:11:37 -05:00
|
|
|
options.plugins.lsp-format = lib.nixvim.neovim-plugin.extraOptionsOptions // {
|
|
|
|
enable = lib.mkEnableOption "lsp-format.nvim";
|
2023-05-12 11:01:10 +02:00
|
|
|
|
2024-09-04 22:00:43 +01:00
|
|
|
package = lib.mkPackageOption pkgs "lsp-format.nvim" {
|
|
|
|
default = [
|
|
|
|
"vimPlugins"
|
|
|
|
"lsp-format-nvim"
|
|
|
|
];
|
|
|
|
};
|
2023-05-12 11:01:10 +02:00
|
|
|
|
2024-10-22 23:11:37 -05:00
|
|
|
setup = lib.mkOption {
|
2023-05-12 11:01:10 +02:00
|
|
|
type =
|
2024-10-22 23:11:37 -05:00
|
|
|
with lib.types;
|
2023-05-12 11:01:10 +02:00
|
|
|
attrsOf (submodule {
|
|
|
|
# Allow the user to provide other options
|
|
|
|
freeformType = types.attrs;
|
|
|
|
|
|
|
|
options = {
|
2024-10-22 23:11:37 -05:00
|
|
|
exclude = lib.nixvim.mkNullOrOption (listOf str) "List of client names to exclude from formatting.";
|
2023-05-12 11:01:10 +02:00
|
|
|
|
2024-10-22 23:11:37 -05:00
|
|
|
order = lib.nixvim.mkNullOrOption (listOf str) ''
|
2023-05-12 11:01:10 +02:00
|
|
|
List of client names. Formatting is requested from clients in the following
|
|
|
|
order: first all clients that are not in the `order` table, then the remaining
|
|
|
|
clients in the order as they occur in the `order` table.
|
|
|
|
(same logic as |vim.lsp.buf.formatting_seq_sync()|).
|
|
|
|
'';
|
|
|
|
|
2024-10-22 23:11:37 -05:00
|
|
|
sync = lib.nixvim.defaultNullOpts.mkBool false ''
|
2023-05-12 11:01:10 +02:00
|
|
|
Whether to turn on synchronous formatting.
|
|
|
|
The editor will block until formatting is done.
|
|
|
|
'';
|
|
|
|
|
2024-10-22 23:11:37 -05:00
|
|
|
force = lib.nixvim.defaultNullOpts.mkBool false ''
|
2023-05-12 11:01:10 +02:00
|
|
|
If true, the format result will always be written to the buffer, even if the
|
|
|
|
buffer changed.
|
|
|
|
'';
|
|
|
|
};
|
2024-05-05 19:39:35 +02:00
|
|
|
});
|
2023-05-12 11:01:10 +02:00
|
|
|
description = "The setup option maps |filetypes| to format options.";
|
|
|
|
example = {
|
2024-05-19 18:33:14 +02:00
|
|
|
go = {
|
2023-05-12 11:01:10 +02:00
|
|
|
exclude = [ "gopls" ];
|
2024-05-05 19:39:35 +02:00
|
|
|
order = [
|
|
|
|
"gopls"
|
|
|
|
"efm"
|
|
|
|
];
|
2023-05-12 11:01:10 +02:00
|
|
|
sync = true;
|
|
|
|
force = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
default = { };
|
2024-05-05 19:39:35 +02:00
|
|
|
};
|
2023-05-12 11:01:10 +02:00
|
|
|
|
2024-10-22 23:11:37 -05:00
|
|
|
lspServersToEnable = lib.mkOption {
|
2023-05-12 11:01:10 +02:00
|
|
|
type =
|
2024-10-22 23:11:37 -05:00
|
|
|
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
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
|
|
|
setupOptions = cfg.setup // cfg.extraOptions;
|
|
|
|
in
|
2024-10-22 23:11:37 -05:00
|
|
|
lib.mkIf cfg.enable {
|
|
|
|
warnings = lib.mkIf (!config.plugins.lsp.enable) [
|
2023-05-12 11:01:10 +02:00
|
|
|
"You have enabled `plugins.lsp-format` but have `plugins.lsp` disabled."
|
|
|
|
];
|
|
|
|
|
|
|
|
extraPlugins = [ cfg.package ];
|
|
|
|
|
|
|
|
plugins.lsp = {
|
2024-10-22 23:11:37 -05:00
|
|
|
onAttach = lib.mkIf (cfg.lspServersToEnable == "all") ''
|
2023-05-12 11:01:10 +02:00
|
|
|
require("lsp-format").on_attach(client)
|
|
|
|
'';
|
|
|
|
|
|
|
|
servers =
|
2024-10-22 23:11:37 -05:00
|
|
|
if (lib.isList cfg.lspServersToEnable) then
|
|
|
|
lib.genAttrs cfg.lspServersToEnable (serverName: {
|
2023-05-12 11:01:10 +02:00
|
|
|
onAttach.function = ''
|
|
|
|
require("lsp-format").on_attach(client)
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
else
|
|
|
|
{ };
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfigLua = ''
|
2024-10-22 23:11:37 -05:00
|
|
|
require("lsp-format").setup(${lib.nixvim.toLuaObject setupOptions})
|
2023-05-12 11:01:10 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|