plugins/nvim-lsp: add per-server onAttach option (#341)

This commit is contained in:
Gaétan Lepage 2023-04-19 14:30:02 +02:00 committed by GitHub
parent 838f616f0a
commit bc468178ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 3 deletions

View file

@ -1,5 +1,8 @@
# This file was generated by nvfetcher, please do not modify it manually.
{ fetchgit, fetchurl, fetchFromGitHub, dockerTools }:
{
fetchgit,
fetchurl,
fetchFromGitHub,
dockerTools,
}: {
}

View file

@ -57,6 +57,24 @@
`:LspStart` (|lspconfig-commands|).
'';
onAttach =
helpers.mkCompositeOption "Server specific on_attach behavior."
{
override = mkOption {
type = types.bool;
default = false;
description = "Override the global `plugins.lsp.onAttach` function.";
};
function = mkOption {
type = types.str;
description = ''
Body of the on_attach function.
The argument `client` and `bufnr` is provided.
'';
};
};
settings = settingsOptions;
extraSettings = mkOption {
@ -82,6 +100,16 @@
name = serverName;
extraOptions = {
inherit (cfg) cmd filetypes autostart;
on_attach =
helpers.ifNonNull' cfg.onAttach
(
helpers.mkRaw ''
function(client, bufnr)
${optionalString (!cfg.onAttach.override) config.plugins.lsp.onAttach}
${cfg.onAttach.function}
end
''
);
settings = (settings cfg.settings) // cfg.extraSettings;
};
}

View file

@ -25,7 +25,12 @@
servers = {
bashls.enable = true;
clangd.enable = true;
clangd = {
enable = true;
onAttach.function = ''
print('The clangd language server has been attached !')
'';
};
nil_ls.enable = true;
rust-analyzer.enable = true;
pylsp = {