2021-02-01 15:54:53 +00:00
|
|
|
{
|
2023-11-06 15:04:08 +01:00
|
|
|
lib,
|
|
|
|
helpers,
|
2023-02-20 11:42:13 +01:00
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.plugins.lsp;
|
|
|
|
in {
|
2024-02-14 11:22:33 +01:00
|
|
|
imports =
|
|
|
|
[
|
|
|
|
./language-servers
|
|
|
|
]
|
|
|
|
# TODO: introduced 2024-02-14, remove on 2024-03-14
|
|
|
|
++ (
|
|
|
|
map
|
|
|
|
(
|
|
|
|
serverName:
|
|
|
|
mkRemovedOptionModule
|
|
|
|
["plugins" "lsp" "servers" serverName "installLanguageServer"]
|
2024-02-15 15:57:47 +08:00
|
|
|
"If you want to not install the language server package, set `plugins.lsp.servers.${serverName}.package` to `null`."
|
2024-02-14 11:22:33 +01:00
|
|
|
)
|
|
|
|
[
|
|
|
|
"astro"
|
|
|
|
"bashls"
|
|
|
|
"beancount"
|
|
|
|
"biome"
|
|
|
|
"ccls"
|
|
|
|
"clangd"
|
|
|
|
"clojure-lsp"
|
|
|
|
"cmake"
|
|
|
|
"csharp-ls"
|
|
|
|
"cssls"
|
|
|
|
"dagger"
|
|
|
|
"dartls"
|
|
|
|
"denols"
|
|
|
|
"dhall-lsp-server"
|
|
|
|
"digestif"
|
|
|
|
"dockerls"
|
|
|
|
"efm"
|
|
|
|
"elixirls"
|
|
|
|
"elmls"
|
|
|
|
"emmet_ls"
|
|
|
|
"eslint"
|
|
|
|
"fsautocomplete"
|
|
|
|
"futhark-lsp"
|
|
|
|
"gdscript"
|
|
|
|
"gleam"
|
|
|
|
"gopls"
|
|
|
|
"graphql"
|
|
|
|
"helm-ls"
|
|
|
|
"hls"
|
|
|
|
"html"
|
|
|
|
"htmx"
|
|
|
|
"intelephense"
|
|
|
|
"java-language-server"
|
|
|
|
"jsonls"
|
|
|
|
"julials"
|
|
|
|
"kotlin-language-server"
|
|
|
|
"leanls"
|
|
|
|
"lemminx"
|
|
|
|
"ltex"
|
|
|
|
"lua-ls"
|
|
|
|
"marksman"
|
|
|
|
"metals"
|
|
|
|
"nil_ls"
|
|
|
|
"nixd"
|
|
|
|
"nushell"
|
|
|
|
"ols"
|
|
|
|
"omnisharp"
|
|
|
|
"perlpls"
|
|
|
|
"pest_ls"
|
|
|
|
"phpactor"
|
|
|
|
"prismals"
|
|
|
|
"prolog-ls"
|
|
|
|
"purescriptls"
|
|
|
|
"pylsp"
|
|
|
|
"pylyzer"
|
|
|
|
"pyright"
|
|
|
|
"rnix-lsp"
|
|
|
|
"ruff-lsp"
|
|
|
|
"rust-analyzer"
|
|
|
|
"solargraph"
|
|
|
|
"sourcekit"
|
|
|
|
"svelte"
|
|
|
|
"tailwindcss"
|
|
|
|
"taplo"
|
|
|
|
"templ"
|
|
|
|
"terraformls"
|
|
|
|
"texlab"
|
|
|
|
"tsserver"
|
|
|
|
"typst-lsp"
|
|
|
|
"vala-ls"
|
|
|
|
"vls"
|
|
|
|
"volar"
|
|
|
|
"vuels"
|
|
|
|
"yamlls"
|
|
|
|
"zls"
|
|
|
|
]
|
|
|
|
);
|
2021-02-01 15:54:53 +00:00
|
|
|
|
|
|
|
options = {
|
2022-09-18 11:19:23 +01:00
|
|
|
plugins.lsp = {
|
2023-01-22 03:32:08 +00:00
|
|
|
enable = mkEnableOption "neovim's built-in LSP";
|
2021-02-01 15:54:53 +00:00
|
|
|
|
2023-03-14 15:22:56 +01:00
|
|
|
keymaps = {
|
|
|
|
silent = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = "Whether nvim-lsp keymaps should be silent";
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
diagnostic = mkOption {
|
2023-07-17 15:37:00 +02:00
|
|
|
type = with types; attrsOf (either str attrs);
|
2023-03-14 15:22:56 +01:00
|
|
|
description = "Mappings for `vim.diagnostic.<action>` functions.";
|
|
|
|
example = {
|
|
|
|
"<leader>k" = "goto_prev";
|
|
|
|
"<leader>j" = "goto_next";
|
|
|
|
};
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
lspBuf = mkOption {
|
2023-07-17 15:37:00 +02:00
|
|
|
type = with types; attrsOf (either str attrs);
|
2023-03-14 15:22:56 +01:00
|
|
|
description = "Mappings for `vim.lsp.buf.<action>` functions.";
|
|
|
|
example = {
|
|
|
|
"gd" = "definition";
|
|
|
|
"gD" = "references";
|
|
|
|
"gt" = "type_definition";
|
|
|
|
"gi" = "implementation";
|
|
|
|
"K" = "hover";
|
|
|
|
};
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-02-01 15:54:53 +00:00
|
|
|
enabledServers = mkOption {
|
2023-02-20 11:42:13 +01:00
|
|
|
type = with types;
|
|
|
|
listOf (oneOf [
|
|
|
|
str
|
|
|
|
(submodule {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "The server's name";
|
|
|
|
};
|
2021-02-01 15:54:53 +00:00
|
|
|
|
2024-03-06 12:50:14 -08:00
|
|
|
capabilities = mkOption {
|
|
|
|
type = types.nullOr (types.attrsOf types.bool);
|
|
|
|
description = "Control resolved capabilities for the language server.";
|
|
|
|
default = null;
|
|
|
|
example = {
|
|
|
|
documentFormattingProvider = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
extraOptions = mkOption {
|
|
|
|
type = attrs;
|
|
|
|
description = "Extra options for the server";
|
|
|
|
};
|
2022-09-18 11:19:23 +01:00
|
|
|
};
|
2023-02-20 11:42:13 +01:00
|
|
|
})
|
|
|
|
]);
|
2021-02-01 15:54:53 +00:00
|
|
|
description = "A list of enabled LSP servers. Don't use this directly.";
|
2023-02-20 11:42:13 +01:00
|
|
|
default = [];
|
2023-11-23 16:36:41 +01:00
|
|
|
internal = true;
|
|
|
|
visible = false;
|
2021-02-01 15:54:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
onAttach = mkOption {
|
|
|
|
type = types.lines;
|
2022-12-05 09:49:37 +07:00
|
|
|
description = "A lua function to be run when a new LSP buffer is attached. The argument `client` and `bufnr` is provided.";
|
2021-02-01 15:54:53 +00:00
|
|
|
default = "";
|
|
|
|
};
|
2021-11-23 15:39:57 +01:00
|
|
|
|
2023-02-20 17:32:05 +01:00
|
|
|
capabilities = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = "Lua code that modifies inplace the `capabilities` table.";
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
|
2022-01-09 23:00:19 +00:00
|
|
|
setupWrappers = mkOption {
|
|
|
|
type = with types; listOf (functionTo str);
|
|
|
|
description = "Code to be run to wrap the setup args. Takes in an argument containing the previous results, and returns a new string of code.";
|
2023-02-20 11:42:13 +01:00
|
|
|
default = [];
|
2022-01-09 23:00:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
preConfig = mkOption {
|
2021-11-23 15:39:57 +01:00
|
|
|
type = types.lines;
|
2022-01-09 23:00:19 +00:00
|
|
|
description = "Code to be run before loading the LSP. Useful for requiring plugins";
|
2021-11-23 15:39:57 +01:00
|
|
|
default = "";
|
|
|
|
};
|
2023-01-21 19:52:56 +01:00
|
|
|
|
|
|
|
postConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = "Code to be run after loading the LSP. This is an internal option";
|
|
|
|
default = "";
|
|
|
|
};
|
2021-02-01 15:54:53 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
config = let
|
|
|
|
runWrappers = wrappers: s:
|
|
|
|
if wrappers == []
|
|
|
|
then s
|
|
|
|
else (head wrappers) (runWrappers (tail wrappers) s);
|
2024-03-06 12:50:14 -08:00
|
|
|
updateCapabilities = let
|
|
|
|
servers =
|
|
|
|
builtins.filter
|
|
|
|
(server: server.capabilities != null && server.capabilities != {})
|
|
|
|
cfg.enabledServers;
|
|
|
|
in
|
|
|
|
lib.concatMapStringsSep "\n" (
|
|
|
|
server: let
|
|
|
|
updates =
|
|
|
|
lib.concatMapStringsSep "\n"
|
|
|
|
(name: ''
|
|
|
|
client.server_capabilities.${name} = ${helpers.toLuaObject server.capabilities.${name}}
|
|
|
|
'')
|
|
|
|
(builtins.attrNames server.capabilities);
|
|
|
|
in ''
|
|
|
|
if client.name == "${server.name}" then
|
|
|
|
${updates}
|
|
|
|
end
|
|
|
|
''
|
|
|
|
)
|
|
|
|
servers;
|
2023-02-20 11:42:13 +01:00
|
|
|
in
|
2022-09-18 11:19:23 +01:00
|
|
|
mkIf cfg.enable {
|
2023-02-20 11:42:13 +01:00
|
|
|
extraPlugins = [pkgs.vimPlugins.nvim-lspconfig];
|
2021-02-01 15:54:53 +00:00
|
|
|
|
2023-09-15 14:35:13 +02:00
|
|
|
keymaps = let
|
2023-07-17 15:37:00 +02:00
|
|
|
mkMaps = prefix:
|
2023-09-15 14:35:13 +02:00
|
|
|
mapAttrsToList
|
|
|
|
(
|
|
|
|
key: action: let
|
|
|
|
actionStr =
|
|
|
|
if isString action
|
|
|
|
then action
|
|
|
|
else action.action;
|
|
|
|
actionProps =
|
|
|
|
if isString action
|
|
|
|
then {}
|
|
|
|
else filterAttrs (n: v: n != "action") action;
|
|
|
|
in {
|
|
|
|
mode = "n";
|
|
|
|
inherit key;
|
2024-02-03 17:42:24 +01:00
|
|
|
action.__raw = prefix + actionStr;
|
2023-09-15 14:35:13 +02:00
|
|
|
|
|
|
|
options =
|
|
|
|
{
|
|
|
|
inherit (cfg.keymaps) silent;
|
|
|
|
}
|
|
|
|
// actionProps;
|
2023-07-17 15:37:00 +02:00
|
|
|
}
|
2023-09-15 14:35:13 +02:00
|
|
|
);
|
2023-03-14 15:22:56 +01:00
|
|
|
in
|
2023-09-15 14:35:13 +02:00
|
|
|
(mkMaps "vim.diagnostic." cfg.keymaps.diagnostic)
|
|
|
|
++ (mkMaps "vim.lsp.buf." cfg.keymaps.lspBuf);
|
2023-03-14 15:22:56 +01:00
|
|
|
|
2021-02-01 15:54:53 +00:00
|
|
|
# Enable all LSP servers
|
|
|
|
extraConfigLua = ''
|
|
|
|
-- LSP {{{
|
2022-01-09 23:00:19 +00:00
|
|
|
do
|
|
|
|
${cfg.preConfig}
|
2023-02-20 17:32:05 +01:00
|
|
|
|
2022-01-09 23:00:19 +00:00
|
|
|
local __lspServers = ${helpers.toLuaObject cfg.enabledServers}
|
2022-12-05 09:49:37 +07:00
|
|
|
local __lspOnAttach = function(client, bufnr)
|
2024-03-06 12:50:14 -08:00
|
|
|
${updateCapabilities}
|
|
|
|
|
2022-01-09 23:00:19 +00:00
|
|
|
${cfg.onAttach}
|
|
|
|
end
|
2023-02-20 17:32:05 +01:00
|
|
|
local __lspCapabilities = function()
|
|
|
|
capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
|
|
|
|
${cfg.capabilities}
|
|
|
|
|
|
|
|
return capabilities
|
|
|
|
end
|
2022-01-09 23:00:19 +00:00
|
|
|
|
|
|
|
local __setup = ${runWrappers cfg.setupWrappers "{
|
2023-02-20 17:32:05 +01:00
|
|
|
on_attach = __lspOnAttach,
|
|
|
|
capabilities = __lspCapabilities()
|
2022-01-09 23:00:19 +00:00
|
|
|
}"}
|
2021-02-01 15:54:53 +00:00
|
|
|
|
2022-01-09 23:00:19 +00:00
|
|
|
for i,server in ipairs(__lspServers) do
|
|
|
|
if type(server) == "string" then
|
|
|
|
require('lspconfig')[server].setup(__setup)
|
|
|
|
else
|
|
|
|
local options = ${runWrappers cfg.setupWrappers "server.extraOptions"}
|
2022-10-22 22:15:03 +01:00
|
|
|
|
|
|
|
if options == nil then
|
|
|
|
options = __setup
|
|
|
|
else
|
|
|
|
options = vim.tbl_extend("keep", options, __setup)
|
|
|
|
end
|
|
|
|
|
2022-01-09 23:00:19 +00:00
|
|
|
require('lspconfig')[server.name].setup(options)
|
|
|
|
end
|
2021-02-01 15:54:53 +00:00
|
|
|
end
|
2023-01-21 19:52:56 +01:00
|
|
|
|
|
|
|
${cfg.postConfig}
|
2021-02-01 15:54:53 +00:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|