plugins.lsp: alias onAttach to new lsp.onAttach

This simplifies the impl by doing global on-attach logic in a
`LspAttach` autocmd instead of adding lua lines to each server's
individual `on_attach` callback.

This is effectively a `mkAliasOptionModule` alias, other than the alias
only being applied when `plugins.lsp.enable`.
This commit is contained in:
Matt Sturgeon 2025-05-07 14:13:13 +01:00
parent c26f5c2e31
commit 5c52e8f9e4
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
5 changed files with 53 additions and 53 deletions

View file

@ -53,43 +53,30 @@ lib.nixvim.plugins.mkNeovimPlugin {
callSetup = false;
hasLuaConfig = false;
extraConfig =
cfg:
mkMerge [
{
globals.rustaceanvim = cfg.settings;
extraConfig = cfg: {
globals.rustaceanvim = cfg.settings;
assertions = lib.nixvim.mkAssertions "plugins.rustaceanvim" {
assertion = cfg.enable -> !config.plugins.lsp.servers.rust_analyzer.enable;
message = ''
Both `plugins.rustaceanvim.enable` and `plugins.lsp.servers.rust_analyzer.enable` are true.
Disable one of them otherwise you will have multiple clients attached to each buffer.
'';
};
assertions = lib.nixvim.mkAssertions "plugins.rustaceanvim" {
assertion = cfg.enable -> !config.plugins.lsp.servers.rust_analyzer.enable;
message = ''
Both `plugins.rustaceanvim.enable` and `plugins.lsp.servers.rust_analyzer.enable` are true.
Disable one of them otherwise you will have multiple clients attached to each buffer.
'';
};
# TODO: remove after 24.11
warnings = lib.nixvim.mkWarnings "plugins.rustaceanvim" {
when = hasAttrByPath [
"settings"
"server"
"settings"
] cfg;
message = ''
The `settings.server.settings' option has been renamed to `settings.server.default_settings'.
# TODO: remove after 24.11
warnings = lib.nixvim.mkWarnings "plugins.rustaceanvim" {
when = hasAttrByPath [
"settings"
"server"
"settings"
] cfg;
message = ''
The `settings.server.settings' option has been renamed to `settings.server.default_settings'.
Note that if you supplied an attrset and not a function you need to set this attr set in:
`settings.server.default_settings.rust-analyzer'.
'';
};
}
# If nvim-lspconfig is enabled:
(mkIf config.plugins.lsp.enable {
# Use the same `on_attach` callback as for the other LSP servers
plugins.rustaceanvim.settings.server.on_attach = mkDefault ''
function(client, bufnr)
return _M.lspOnAttach(client, bufnr)
end
'';
})
];
Note that if you supplied an attrset and not a function you need to set this attr set in:
`settings.server.default_settings.rust-analyzer'.
'';
};
};
}