nvf/modules/plugins/languages/elixir.nix
diniamo f9789432f9
treewide: make the entire generated config lua based (#333)
* modules: switch to gerg's neovim-wrapper

* modules: use initViml instead of writing the file

* treewide: make the entire generated config lua based

* docs: remove mentions of configRC

* plugins/treesitter: remove vim.cmd hack

* treewide: move resolveDag to lib

* modules/wrapper(rc): fix typo

* treewide: migrate to pluginRC for correct DAG order

The "new" DAG order is as follows:
- (luaConfigPre)
- globalsScript
- basic
- theme
- pluginConfigs
- extraPluginConfigs
- mappings
- (luaConfigPost)

* plugins/theme: fix theme DAG place

* plugins/theme: fix fixed theme DAG place

* modules/wrapper(rc): add removed option module for configRC

* docs: add dag-entries chapter, add release note entry

* fix: formatting CI

* languages/nix: add missing `local`

* docs: fix page link

* docs: add mention of breaking changes at the start of the release notes

* plugins/neo-tree: convert to pluginRC

* modules/wrapper(rc): add back entryAnywhere

* modules/wrapper(rc): expose pluginRC

* apply raf patch

---------

Co-authored-by: NotAShelf <raf@notashelf.dev>
2024-07-20 08:30:48 +00:00

139 lines
3.6 KiB
Nix

{
config,
pkgs,
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) isList;
inherit (lib.types) enum either listOf package str;
inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.lua) expToLua;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.languages.elixir;
defaultServer = "elixirls";
servers = {
elixirls = {
package = pkgs.elixir-ls;
lspConfig = ''
-- elixirls setup
lspconfig.elixirls.setup {
capabilities = capabilities,
on_attach = default_on_attach,
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/elixir-ls"}''
}
}
'';
};
};
defaultFormat = "mix";
formats = {
mix = {
package = pkgs.elixir;
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.mix.with({
command = "${cfg.format.package}/bin/mix",
})
)
'';
};
};
in {
options.vim.languages.elixir = {
enable = mkEnableOption "Elixir language support";
treesitter = {
enable = mkEnableOption "Elixir treesitter" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "elixir";
};
lsp = {
enable = mkEnableOption "Elixir LSP support" // {default = config.vim.languages.enableLSP;};
server = mkOption {
description = "Elixir LSP server to use";
type = enum (attrNames servers);
default = defaultServer;
};
package = mkOption {
description = "Elixir LSP server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]'';
type = either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
};
format = {
enable = mkEnableOption "Elixir formatting" // {default = config.vim.languages.enableFormat;};
type = mkOption {
description = "Elixir formatter to use";
type = enum (attrNames formats);
default = defaultFormat;
};
package = mkOption {
description = "Elixir formatter package";
type = package;
default = formats.${cfg.format.type}.package;
};
};
elixir-tools = {
enable = mkEnableOption "Elixir tools";
};
};
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.elixir-lsp = servers.${cfg.lsp.server}.lspConfig;
})
(mkIf cfg.format.enable {
vim.lsp.null-ls.enable = true;
vim.lsp.null-ls.sources.elixir-format = formats.${cfg.format.type}.nullConfig;
})
(mkIf cfg.elixir-tools.enable {
vim.startPlugins = ["elixir-tools"];
vim.pluginRC.elixir-tools = entryAnywhere ''
local elixir-tools = require("elixir")
local elixirls = require("elixir-tools.elixirls")
-- disable imperative insstallations of various
-- elixir related tools installed by elixir-tools
elixir-tools.setup {
nextls = {
enable = false -- defaults to false
},
credo = {
enable = false -- defaults to true
},
elixirls = {
enable = false, -- defaults to true
}
}
'';
})
]);
}