mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
plugins/lsp-format: migrate to mkNeovimPlugin
This commit is contained in:
parent
fb1943a673
commit
32969847d3
2 changed files with 75 additions and 81 deletions
|
@ -1,66 +1,68 @@
|
||||||
{
|
{
|
||||||
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"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
description = ''
|
||||||
|
## Configuring a Language
|
||||||
|
|
||||||
|
`lsp-format` uses a table defining which lsp servers to use for each language.
|
||||||
|
|
||||||
|
|
||||||
|
- `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 = {
|
||||||
setup = lib.mkOption {
|
tab_width.__raw = ''
|
||||||
type =
|
function()
|
||||||
with lib.types;
|
return vim.opt.shiftwidth:get()
|
||||||
attrsOf (submodule {
|
end'';
|
||||||
# Allow the user to provide other options
|
|
||||||
freeformType = types.attrs;
|
|
||||||
|
|
||||||
options = {
|
|
||||||
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
|
|
||||||
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()|).
|
|
||||||
'';
|
|
||||||
|
|
||||||
sync = lib.nixvim.defaultNullOpts.mkBool false ''
|
|
||||||
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 = {
|
|
||||||
exclude = [ "gopls" ];
|
|
||||||
order = [
|
|
||||||
"gopls"
|
|
||||||
"efm"
|
|
||||||
];
|
|
||||||
sync = true;
|
|
||||||
force = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
default = { };
|
|
||||||
};
|
};
|
||||||
|
yaml = {
|
||||||
|
tab_width = 2;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
extraOptions = {
|
||||||
lspServersToEnable = lib.mkOption {
|
lspServersToEnable = lib.mkOption {
|
||||||
type =
|
type =
|
||||||
with lib.types;
|
with lib.types;
|
||||||
|
@ -87,35 +89,27 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config =
|
extraConfig = cfg: {
|
||||||
let
|
warnings = lib.mkIf (!config.plugins.lsp.enable) [
|
||||||
setupOptions = cfg.setup // cfg.extraOptions;
|
"You have enabled `plugins.lsp-format` but have `plugins.lsp` disabled."
|
||||||
in
|
];
|
||||||
lib.mkIf cfg.enable {
|
|
||||||
warnings = lib.mkIf (!config.plugins.lsp.enable) [
|
|
||||||
"You have enabled `plugins.lsp-format` but have `plugins.lsp` disabled."
|
|
||||||
];
|
|
||||||
|
|
||||||
extraPlugins = [ cfg.package ];
|
plugins.lsp = {
|
||||||
|
onAttach =
|
||||||
|
lib.mkIf (cfg.lspServersToEnable == "all") # Lua
|
||||||
|
''
|
||||||
|
require("lsp-format").on_attach(client)
|
||||||
|
'';
|
||||||
|
|
||||||
plugins.lsp = {
|
servers = lib.optionalAttrs (lib.isList cfg.lspServersToEnable) (
|
||||||
onAttach = lib.mkIf (cfg.lspServersToEnable == "all") ''
|
lib.genAttrs cfg.lspServersToEnable (serverName: {
|
||||||
require("lsp-format").on_attach(client)
|
onAttach.function = # Lua
|
||||||
'';
|
''
|
||||||
|
require("lsp-format").on_attach(client)
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
servers =
|
|
||||||
if (lib.isList cfg.lspServersToEnable) then
|
|
||||||
lib.genAttrs cfg.lspServersToEnable (serverName: {
|
|
||||||
onAttach.function = ''
|
|
||||||
require("lsp-format").on_attach(client)
|
|
||||||
'';
|
|
||||||
})
|
|
||||||
else
|
|
||||||
{ };
|
|
||||||
};
|
|
||||||
|
|
||||||
extraConfigLua = ''
|
|
||||||
require("lsp-format").setup(${lib.nixvim.toLuaObject setupOptions})
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
lsp-format = {
|
lsp-format = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
setup = {
|
settings = {
|
||||||
go = {
|
go = {
|
||||||
exclude = [ "gopls" ];
|
exclude = [ "gopls" ];
|
||||||
order = [
|
order = [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue