mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
modules/lsp/servers: move to dedicated file/dir
Move the code related to the `lsp.servers` option into a dedicated module, cleaning up `modules/lsp/default.nix`.
This commit is contained in:
parent
64cd675ece
commit
5308425718
5 changed files with 175 additions and 166 deletions
|
@ -1,64 +1,6 @@
|
||||||
{
|
{ lib, config, ... }:
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
options,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
let
|
||||||
inherit (lib) types;
|
|
||||||
inherit (lib.nixvim) toLuaObject;
|
|
||||||
|
|
||||||
cfg = config.lsp;
|
cfg = config.lsp;
|
||||||
|
|
||||||
# Import `server.nix` and apply args
|
|
||||||
# For convenience, we set a default here for args.pkgs
|
|
||||||
mkServerModule = args: lib.modules.importApply ./server.nix ({ inherit pkgs; } // args);
|
|
||||||
|
|
||||||
# Create a submodule type from `server.nix`
|
|
||||||
# Used as the type for both the freeform `lsp.servers.<name>`
|
|
||||||
# and the explicitly declared `lsp.servers.*` options
|
|
||||||
mkServerType = args: types.submodule (mkServerModule args);
|
|
||||||
|
|
||||||
# Create a server option
|
|
||||||
# Used below for the `lsp.servers.*` options
|
|
||||||
mkServerOption =
|
|
||||||
name: args:
|
|
||||||
let
|
|
||||||
homepage = lib.pipe options.lsp.servers [
|
|
||||||
# Get suboptions of `lsp.servers`
|
|
||||||
(opt: opt.type.getSubOptions opt.loc)
|
|
||||||
# Get suboptions of `lsp.servers.<name>`
|
|
||||||
(opts: opts.${name}.type.getSubOptions opts.${name}.loc)
|
|
||||||
# Get package option's homepage
|
|
||||||
(opts: opts.package.default.meta.homepage or null)
|
|
||||||
];
|
|
||||||
|
|
||||||
# If there's a known homepage for this language server,
|
|
||||||
# we'll link to it in the option description
|
|
||||||
nameLink = if homepage == null then name else "[${name}](${homepage})";
|
|
||||||
in
|
|
||||||
lib.mkOption {
|
|
||||||
type = mkServerType args;
|
|
||||||
description = ''
|
|
||||||
The ${nameLink} language server.
|
|
||||||
'';
|
|
||||||
default = { };
|
|
||||||
};
|
|
||||||
|
|
||||||
# Combine `packages` and `customCmd` sets from `lsp-packages.nix`
|
|
||||||
# We use this set to generate the package-option defaults
|
|
||||||
serverPackages =
|
|
||||||
let
|
|
||||||
inherit (import ../../plugins/lsp/lsp-packages.nix)
|
|
||||||
packages
|
|
||||||
customCmd
|
|
||||||
;
|
|
||||||
in
|
|
||||||
builtins.mapAttrs (name: v: {
|
|
||||||
inherit name;
|
|
||||||
package = v.package or v;
|
|
||||||
}) (packages // customCmd);
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.lsp = {
|
options.lsp = {
|
||||||
|
@ -73,108 +15,15 @@ in
|
||||||
inlayHints = {
|
inlayHints = {
|
||||||
enable = lib.mkEnableOption "inlay hints globally";
|
enable = lib.mkEnableOption "inlay hints globally";
|
||||||
};
|
};
|
||||||
|
|
||||||
servers = lib.mkOption {
|
|
||||||
type = types.submodule [
|
|
||||||
{
|
|
||||||
freeformType = types.attrsOf (mkServerType { });
|
|
||||||
}
|
|
||||||
{
|
|
||||||
options = builtins.mapAttrs mkServerOption serverPackages;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# `*` is effectively a meta server, where shared config & defaults can be set.
|
|
||||||
# It shouldn't have options like `activate` or `package` which relate to "real" servers.
|
|
||||||
# Therefore, we use a bespoke `global-server.nix`, which is inspired by the full `server.nix` module.
|
|
||||||
options."*" = lib.mkOption {
|
|
||||||
description = ''
|
|
||||||
Global configuration applied to all language servers.
|
|
||||||
'';
|
|
||||||
type = types.submodule ./global-server.nix;
|
|
||||||
default = { };
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
description = ''
|
|
||||||
LSP servers to enable and/or configure.
|
|
||||||
|
|
||||||
This option is implemented using neovim's `vim.lsp` lua API.
|
|
||||||
|
|
||||||
You may also want to use [nvim-lspconfig] to install _default configs_ for many language servers.
|
|
||||||
This can be installed using [`${options.plugins.lspconfig.enable}`][`plugins.lspconfig`].
|
|
||||||
|
|
||||||
[nvim-lspconfig]: ${options.plugins.lspconfig.package.default.meta.homepage}
|
|
||||||
[`plugins.lspconfig`]: ../../plugins/lspconfig/index.md
|
|
||||||
'';
|
|
||||||
default = { };
|
|
||||||
example = {
|
|
||||||
"*".settings = {
|
|
||||||
root_markers = [ ".git" ];
|
|
||||||
capabilities.textDocument.semanticTokens = {
|
|
||||||
multilineTokenSupport = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
luals.enable = true;
|
|
||||||
clangd = {
|
|
||||||
enable = true;
|
|
||||||
settings = {
|
|
||||||
cmd = [
|
|
||||||
"clangd"
|
|
||||||
"--background-index"
|
|
||||||
];
|
|
||||||
root_markers = [
|
|
||||||
"compile_commands.json"
|
|
||||||
"compile_flags.txt"
|
|
||||||
];
|
|
||||||
filetypes = [
|
|
||||||
"c"
|
|
||||||
"cpp"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
|
./servers
|
||||||
./keymaps.nix
|
./keymaps.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
config =
|
config = {
|
||||||
let
|
lsp.luaConfig.content = lib.mkIf cfg.inlayHints.enable "vim.lsp.inlay_hint.enable(true)";
|
||||||
enabledServers = lib.pipe cfg.servers [
|
|
||||||
builtins.attrValues
|
|
||||||
(builtins.filter (server: server.enable))
|
|
||||||
];
|
|
||||||
|
|
||||||
# Collect per-server warnings
|
|
||||||
serverWarnings = lib.pipe cfg.servers [
|
|
||||||
builtins.attrValues
|
|
||||||
(builtins.catAttrs "warnings")
|
|
||||||
builtins.concatLists
|
|
||||||
];
|
|
||||||
in
|
|
||||||
{
|
|
||||||
extraPackages = builtins.catAttrs "package" enabledServers;
|
|
||||||
|
|
||||||
lsp.luaConfig.content =
|
|
||||||
let
|
|
||||||
mkServerConfig =
|
|
||||||
server:
|
|
||||||
let
|
|
||||||
luaName = toLuaObject server.name;
|
|
||||||
luaSettings = toLuaObject server.settings;
|
|
||||||
in
|
|
||||||
[
|
|
||||||
(lib.mkIf (server.settings != { }) "vim.lsp.config(${luaName}, ${luaSettings})")
|
|
||||||
(lib.mkIf (server.activate or false) "vim.lsp.enable(${luaName})")
|
|
||||||
];
|
|
||||||
in
|
|
||||||
lib.mkMerge (
|
|
||||||
lib.optional cfg.inlayHints.enable "vim.lsp.inlay_hint.enable(true)"
|
|
||||||
++ builtins.concatMap mkServerConfig enabledServers
|
|
||||||
);
|
|
||||||
|
|
||||||
extraConfigLua = lib.mkIf (cfg.luaConfig.content != "") ''
|
extraConfigLua = lib.mkIf (cfg.luaConfig.content != "") ''
|
||||||
-- LSP {{{
|
-- LSP {{{
|
||||||
|
@ -183,8 +32,5 @@ in
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Propagate per-server warnings
|
|
||||||
warnings = lib.mkIf (serverWarnings != [ ]) serverWarnings;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
163
modules/lsp/servers/default.nix
Normal file
163
modules/lsp/servers/default.nix
Normal file
|
@ -0,0 +1,163 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
options,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (lib) types;
|
||||||
|
inherit (lib.nixvim) toLuaObject;
|
||||||
|
|
||||||
|
cfg = config.lsp;
|
||||||
|
|
||||||
|
# Import `server.nix` and apply args
|
||||||
|
# For convenience, we set a default here for args.pkgs
|
||||||
|
mkServerModule = args: lib.modules.importApply ./server.nix ({ inherit pkgs; } // args);
|
||||||
|
|
||||||
|
# Create a submodule type from `server.nix`
|
||||||
|
# Used as the type for both the freeform `lsp.servers.<name>`
|
||||||
|
# and the explicitly declared `lsp.servers.*` options
|
||||||
|
mkServerType = args: types.submodule (mkServerModule args);
|
||||||
|
|
||||||
|
# Create a server option
|
||||||
|
# Used below for the `lsp.servers.*` options
|
||||||
|
mkServerOption =
|
||||||
|
name: args:
|
||||||
|
let
|
||||||
|
homepage = lib.pipe options.lsp.servers [
|
||||||
|
# Get suboptions of `lsp.servers`
|
||||||
|
(opt: opt.type.getSubOptions opt.loc)
|
||||||
|
# Get suboptions of `lsp.servers.<name>`
|
||||||
|
(opts: opts.${name}.type.getSubOptions opts.${name}.loc)
|
||||||
|
# Get package option's homepage
|
||||||
|
(opts: opts.package.default.meta.homepage or null)
|
||||||
|
];
|
||||||
|
|
||||||
|
# If there's a known homepage for this language server,
|
||||||
|
# we'll link to it in the option description
|
||||||
|
nameLink = if homepage == null then name else "[${name}](${homepage})";
|
||||||
|
in
|
||||||
|
lib.mkOption {
|
||||||
|
type = mkServerType args;
|
||||||
|
description = ''
|
||||||
|
The ${nameLink} language server.
|
||||||
|
'';
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
|
||||||
|
# Combine `packages` and `customCmd` sets from `lsp-packages.nix`
|
||||||
|
# We use this set to generate the package-option defaults
|
||||||
|
serverPackages =
|
||||||
|
let
|
||||||
|
inherit (import ../../../plugins/lsp/lsp-packages.nix)
|
||||||
|
packages
|
||||||
|
customCmd
|
||||||
|
;
|
||||||
|
in
|
||||||
|
builtins.mapAttrs (name: v: {
|
||||||
|
inherit name;
|
||||||
|
package = v.package or v;
|
||||||
|
}) (packages // customCmd);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.lsp = {
|
||||||
|
servers = lib.mkOption {
|
||||||
|
type = types.submodule [
|
||||||
|
{
|
||||||
|
freeformType = types.attrsOf (mkServerType { });
|
||||||
|
}
|
||||||
|
{
|
||||||
|
options = builtins.mapAttrs mkServerOption serverPackages;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# `*` is effectively a meta server, where shared config & defaults can be set.
|
||||||
|
# It shouldn't have options like `activate` or `package` which relate to "real" servers.
|
||||||
|
# Therefore, we use a bespoke `global-server.nix`, which is inspired by the full `server.nix` module.
|
||||||
|
options."*" = lib.mkOption {
|
||||||
|
description = ''
|
||||||
|
Global configuration applied to all language servers.
|
||||||
|
'';
|
||||||
|
type = types.submodule ./global-server.nix;
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
description = ''
|
||||||
|
LSP servers to enable and/or configure.
|
||||||
|
|
||||||
|
This option is implemented using neovim's `vim.lsp` lua API.
|
||||||
|
|
||||||
|
You may also want to use [nvim-lspconfig] to install _default configs_ for many language servers.
|
||||||
|
This can be installed using [`${options.plugins.lspconfig.enable}`][`plugins.lspconfig`].
|
||||||
|
|
||||||
|
[nvim-lspconfig]: ${options.plugins.lspconfig.package.default.meta.homepage}
|
||||||
|
[`plugins.lspconfig`]: ../../plugins/lspconfig/index.md
|
||||||
|
'';
|
||||||
|
default = { };
|
||||||
|
example = {
|
||||||
|
"*".settings = {
|
||||||
|
root_markers = [ ".git" ];
|
||||||
|
capabilities.textDocument.semanticTokens = {
|
||||||
|
multilineTokenSupport = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
luals.enable = true;
|
||||||
|
clangd = {
|
||||||
|
enable = true;
|
||||||
|
settings = {
|
||||||
|
cmd = [
|
||||||
|
"clangd"
|
||||||
|
"--background-index"
|
||||||
|
];
|
||||||
|
root_markers = [
|
||||||
|
"compile_commands.json"
|
||||||
|
"compile_flags.txt"
|
||||||
|
];
|
||||||
|
filetypes = [
|
||||||
|
"c"
|
||||||
|
"cpp"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config =
|
||||||
|
let
|
||||||
|
enabledServers = lib.pipe cfg.servers [
|
||||||
|
builtins.attrValues
|
||||||
|
(builtins.filter (server: server.enable))
|
||||||
|
];
|
||||||
|
|
||||||
|
# Collect per-server warnings
|
||||||
|
serverWarnings = lib.pipe cfg.servers [
|
||||||
|
builtins.attrValues
|
||||||
|
(builtins.catAttrs "warnings")
|
||||||
|
builtins.concatLists
|
||||||
|
];
|
||||||
|
in
|
||||||
|
{
|
||||||
|
extraPackages = builtins.catAttrs "package" enabledServers;
|
||||||
|
|
||||||
|
lsp.luaConfig.content =
|
||||||
|
let
|
||||||
|
mkServerConfig =
|
||||||
|
server:
|
||||||
|
let
|
||||||
|
luaName = toLuaObject server.name;
|
||||||
|
luaSettings = toLuaObject server.settings;
|
||||||
|
in
|
||||||
|
[
|
||||||
|
(lib.mkIf (server.settings != { }) "vim.lsp.config(${luaName}, ${luaSettings})")
|
||||||
|
(lib.mkIf (server.activate or false) "vim.lsp.enable(${luaName})")
|
||||||
|
];
|
||||||
|
in
|
||||||
|
lib.mkMerge (builtins.concatMap mkServerConfig enabledServers);
|
||||||
|
|
||||||
|
# Propagate per-server warnings
|
||||||
|
warnings = lib.mkIf (serverWarnings != [ ]) serverWarnings;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue