nvf/lib/languages.nix

40 lines
1 KiB
Nix
Raw Normal View History

2023-10-22 15:10:28 +00:00
# From home-manager: https://github.com/nix-community/home-manager/blob/master/modules/lib/booleans.nix
2024-03-24 00:14:39 +00:00
{lib}: let
inherit (builtins) isString getAttr;
inherit (lib.options) mkOption;
inherit (lib.types) bool;
inherit (lib.nvim.attrsets) mapListToAttrs;
2024-03-24 00:14:39 +00:00
in {
# 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 15:10:28 +00:00
# Converts a boolean to a yes/no string. This is used in lots of
# configuration formats.
diagnosticsToLua = {
lang,
config,
2024-03-24 00:14:39 +00:00
diagnosticsProviders,
}:
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;
}