2023-10-22 17:10:28 +02:00
|
|
|
# From home-manager: https://github.com/nix-community/home-manager/blob/master/modules/lib/booleans.nix
|
2024-03-24 01:14:39 +01:00
|
|
|
{lib}: let
|
|
|
|
inherit (builtins) isString getAttr;
|
|
|
|
inherit (lib.options) mkOption;
|
|
|
|
inherit (lib.types) bool;
|
2024-10-16 04:01:09 +02:00
|
|
|
inherit (lib.meta) getExe;
|
|
|
|
inherit (lib.lists) isList optionals;
|
|
|
|
inherit (lib.generators) mkLuaInline;
|
2024-10-09 19:50:34 +02:00
|
|
|
inherit (lib.nvim.attrsets) mapListToAttrs;
|
2024-10-16 04:01:09 +02:00
|
|
|
inherit (lib.nvim.lua) toLuaObject;
|
2024-03-24 01:14:39 +01:00
|
|
|
in {
|
2024-07-04 16:36:07 +02:00
|
|
|
# A wrapper around `mkOption` to create a boolean option that is
|
|
|
|
# used for Language Server modules.
|
|
|
|
mkEnable = desc:
|
|
|
|
mkOption {
|
|
|
|
description = "Turn on ${desc} for enabled languages by default";
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
2023-10-22 17:10:28 +02:00
|
|
|
# Converts a boolean to a yes/no string. This is used in lots of
|
|
|
|
# configuration formats.
|
2023-04-17 22:27:27 +02:00
|
|
|
diagnosticsToLua = {
|
|
|
|
lang,
|
|
|
|
config,
|
2024-03-24 01:14:39 +01:00
|
|
|
diagnosticsProviders,
|
2023-04-17 22:27:27 +02:00
|
|
|
}:
|
2024-10-09 19:50:34 +02:00
|
|
|
mapListToAttrs
|
|
|
|
(v: let
|
|
|
|
type =
|
|
|
|
if isString v
|
|
|
|
then v
|
|
|
|
else getAttr v.type;
|
|
|
|
package =
|
|
|
|
if isString v
|
|
|
|
then diagnosticsProviders.${type}.package
|
|
|
|
else v.package;
|
|
|
|
in {
|
|
|
|
name = "${lang}-diagnostics-${type}";
|
|
|
|
value = diagnosticsProviders.${type}.nullConfig package;
|
|
|
|
})
|
|
|
|
config;
|
2024-10-16 04:01:09 +02:00
|
|
|
|
|
|
|
# `mkLspConfig` is a helper function that generates a LspConfig configuration
|
|
|
|
# from at least a name and a package, optionally also `capabilities`, and
|
|
|
|
# `on_attach`.
|
|
|
|
# TODO: nixpkgs-like doc comments from that one RFC
|
|
|
|
mkLspConfig = {
|
|
|
|
name,
|
|
|
|
package,
|
|
|
|
args ? [],
|
|
|
|
cmd ? [(getExe package)] ++ lib.optionals (args != []) args,
|
|
|
|
capabilities ? "capabilities",
|
|
|
|
on_attach ? "on_attach",
|
|
|
|
}: let
|
|
|
|
generatedConfig = {
|
|
|
|
inherit cmd;
|
|
|
|
capabilities = mkLuaInline capabilities;
|
|
|
|
on_attach = mkLuaInline on_attach;
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
inherit package;
|
|
|
|
lspConfig = ''
|
|
|
|
lspconfig.${name}.setup(${toLuaObject generatedConfig})
|
|
|
|
'';
|
|
|
|
};
|
2023-04-17 22:27:27 +02:00
|
|
|
}
|