2025-04-07 10:42:07 +02:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
2025-04-28 17:32:11 +01:00
|
|
|
options,
|
2025-04-07 10:42:07 +02:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
2025-04-28 18:02:00 +01:00
|
|
|
inherit (lib) types;
|
2025-04-07 10:42:07 +02:00
|
|
|
inherit (lib.nixvim) toLuaObject;
|
|
|
|
|
|
|
|
cfg = config.lsp;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.lsp = {
|
|
|
|
luaConfig = lib.mkOption {
|
|
|
|
type = lib.types.pluginLuaConfig;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
Lua code configuring LSP.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
inlayHints = {
|
|
|
|
enable = lib.mkEnableOption "inlay hints globally";
|
|
|
|
};
|
|
|
|
|
2025-04-28 18:02:00 +01:00
|
|
|
servers = lib.mkOption {
|
|
|
|
type = types.attrsOf (types.submodule ./server.nix);
|
2025-04-07 10:42:07 +02:00
|
|
|
description = ''
|
|
|
|
LSP servers to enable and/or configure.
|
|
|
|
|
|
|
|
This option is implemented using neovim's `vim.lsp` lua API.
|
2025-04-28 17:32:11 +01:00
|
|
|
|
|
|
|
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`].
|
2025-04-07 10:42:07 +02:00
|
|
|
|
2025-04-28 17:32:11 +01:00
|
|
|
[nvim-lspconfig]: ${options.plugins.lspconfig.package.default.meta.homepage}
|
2025-04-28 14:24:52 +01:00
|
|
|
[`plugins.lspconfig`]: https://nix-community.github.io/nixvim/plugins/lspconfig/index.html
|
2025-04-07 10:42:07 +02:00
|
|
|
'';
|
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
"*".config = {
|
|
|
|
root_markers = [ ".git" ];
|
|
|
|
capabilities.textDocument.semanticTokens = {
|
|
|
|
multilineTokenSupport = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
luals.enable = true;
|
|
|
|
clangd = {
|
|
|
|
enable = true;
|
|
|
|
config = {
|
|
|
|
cmd = [
|
|
|
|
"clangd"
|
|
|
|
"--background-index"
|
|
|
|
];
|
|
|
|
root_markers = [
|
|
|
|
"compile_commands.json"
|
|
|
|
"compile_flags.txt"
|
|
|
|
];
|
|
|
|
filetypes = [
|
|
|
|
"c"
|
|
|
|
"cpp"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
2025-04-28 18:12:18 +01:00
|
|
|
enabledServers = lib.pipe cfg.servers [
|
2025-04-07 10:42:07 +02:00
|
|
|
builtins.attrValues
|
2025-04-28 18:12:18 +01:00
|
|
|
(builtins.filter (server: server.enable))
|
2025-04-07 10:42:07 +02:00
|
|
|
];
|
2025-04-28 18:12:18 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
extraPackages = builtins.catAttrs "package" enabledServers;
|
2025-04-07 10:42:07 +02:00
|
|
|
|
|
|
|
lsp.luaConfig.content =
|
|
|
|
let
|
|
|
|
mkServerConfig =
|
2025-04-28 18:12:18 +01:00
|
|
|
server:
|
2025-04-07 10:42:07 +02:00
|
|
|
let
|
2025-04-28 18:12:18 +01:00
|
|
|
luaName = toLuaObject server.name;
|
|
|
|
luaCfg = toLuaObject server.config;
|
2025-04-07 10:42:07 +02:00
|
|
|
in
|
|
|
|
''
|
2025-04-28 18:12:18 +01:00
|
|
|
vim.lsp.config(${luaName}, ${luaCfg})
|
2025-04-07 10:42:07 +02:00
|
|
|
''
|
2025-04-28 18:12:18 +01:00
|
|
|
+ lib.optionalString server.activate ''
|
2025-04-07 10:42:07 +02:00
|
|
|
vim.lsp.enable(${luaName})
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
lib.mkMerge (
|
|
|
|
lib.optional cfg.inlayHints.enable "vim.lsp.inlay_hint.enable(true)"
|
2025-04-28 18:12:18 +01:00
|
|
|
++ builtins.map mkServerConfig enabledServers
|
2025-04-07 10:42:07 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
extraConfigLua = lib.mkIf (cfg.luaConfig.content != "") ''
|
|
|
|
-- LSP {{{
|
|
|
|
do
|
|
|
|
${cfg.luaConfig.content}
|
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|