modules/languages: add nu

This commit is contained in:
diniamo 2024-09-13 21:21:53 +02:00
parent b9dcbec29c
commit f196d2d620
2 changed files with 124 additions and 0 deletions

View file

@ -25,6 +25,7 @@ in {
./ts.nix ./ts.nix
./typst.nix ./typst.nix
./zig.nix ./zig.nix
./nu.nix
]; ];
options.vim.languages = { options.vim.languages = {

View file

@ -0,0 +1,123 @@
{
lib,
pkgs,
config,
...
}: let
inherit (lib.options) mkEnableOption mkOption mkPackageOption;
inherit (lib.types) str either package listOf enum;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.lua) expToLua;
inherit (pkgs) fetchFromGitHub;
inherit (builtins) attrNames isList;
defaultServer = "nushell";
servers = {
nushell = {
package = pkgs.nushell;
lspConfig = ''
lspconfig.nushell.setup{
capabilities = capabilities,
on_attach = default_on_attach,
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/nu", "--no-config-file", "--lsp"}''
}
}
'';
};
};
# FIX: uncomment formatting parts, once https://github.com/NixOS/nixpkgs/pull/341647 makes it into nixos-unstable
# defaultFormat = "nufmt";
# formats = {
# nufmt = {
# package = pkgs.nufmt.overrideAttrs {
# src = fetchFromGitHub {
# owner = "nushell";
# repo = "nufmt";
# rev = "63549df4406216cce7e744576b1ee8fcaba9a30a";
# hash = "sha256-Y7LvsCuirhYPjuQSF0w7me8vYrV39i4OhVvyI3XskpE=";
# };
# };
# nullConfig = ''
# table.insert(
# ls_sources,
# {
# name = "nufmt",
# method = null_methods.internal.FORMATTING,
# filetypes = { "nu" },
# generator_opts = {
# command = "${cfg.format.package}/bin/nufmt",
# args = { "--stdin" },
# to_stdin = true
# },
# factory = null_helpers.formatter_factory
# }
# )
# '';
# };
# };
cfg = config.vim.languages.nu;
in {
options.vim.languages.nu = {
enable = mkEnableOption "Nu language support";
treesitter = {
enable = mkEnableOption "Nu treesitter" // {default = config.vim.languages.enableTreesitter;};
package = mkPackageOption pkgs ["nu treesitter"] {
default = ["tree-sitter-grammars" "tree-sitter-nu"];
};
};
lsp = {
enable = mkEnableOption "Nu LSP support" // {default = config.vim.languages.enableLSP;};
server = mkOption {
description = "Nu LSP server to use";
type = str;
default = defaultServer;
};
package = mkOption {
description = "Nu LSP server package, or the command to run as a list of strings";
example = ''[(lib.getExe pkgs.nushell) "--lsp"]'';
type = either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
};
# format = {
# enable = mkEnableOption "Nu formatting" // {default = config.vim.languages.enableFormat;};
#
# type = mkOption {
# description = "Nu formatter to use";
# type = enum (attrNames formats);
# default = defaultFormat;
# };
# package = mkOption {
# description = "Nu formatter package";
# type = package;
# default = formats.${cfg.format.type}.package;
# };
# };
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
})
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.nu-lsp = servers.${cfg.lsp.server}.lspConfig;
})
# (mkIf cfg.format.enable {
# vim.lsp.null-ls.enable = true;
# vim.lsp.null-ls.sources.nu-format = formats.${cfg.format.type}.nullConfig;
# })
]);
}