mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-06 02:11:33 +00:00
languages/elixir: readd; format module options
This commit is contained in:
parent
e0790f2bdb
commit
e96897f6b3
10 changed files with 175 additions and 98 deletions
|
@ -3,11 +3,6 @@
|
|||
in {
|
||||
imports = [
|
||||
# 2024-06-06
|
||||
(mkRemovedOptionModule ["vim" "languages" "elixir"] ''
|
||||
Elixir language support has been removed as of 2024-06-06 as it was long unmaintained. If
|
||||
you dependend on this language support, please consider contributing to its maintenance.
|
||||
'')
|
||||
|
||||
(mkRemovedOptionModule ["vim" "tidal"] ''
|
||||
Tidalcycles language support has been removed as of 2024-06-06 as it was long unmaintained. If
|
||||
you depended on this functionality, please open an issue.
|
||||
|
|
|
@ -6,6 +6,7 @@ in {
|
|||
./dart.nix
|
||||
./clang.nix
|
||||
./css.nix
|
||||
./elixir.nix
|
||||
./go.nix
|
||||
./html.nix
|
||||
./java.nix
|
||||
|
|
138
modules/plugins/languages/elixir.nix
Normal file
138
modules/plugins/languages/elixir.nix
Normal file
|
@ -0,0 +1,138 @@
|
|||
{
|
||||
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.luaConfigRC.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
|
||||
}
|
||||
}
|
||||
'';
|
||||
})
|
||||
]);
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.meta) getExe;
|
||||
inherit (lib.nvim.dag) entryAnywhere;
|
||||
|
||||
cfg = config.vim.languages.elixir;
|
||||
in {
|
||||
config = mkIf (cfg.enable) {
|
||||
vim.startPlugins = [
|
||||
"elixir-tools"
|
||||
];
|
||||
|
||||
vim.luaConfigRC.elixir-tools = entryAnywhere ''
|
||||
local elixir = require("elixir")
|
||||
local elixirls = require("elixir.elixirls")
|
||||
|
||||
elixir.setup {
|
||||
elixirls = {
|
||||
-- alternatively, point to an existing elixir-ls installation (optional)
|
||||
-- not currently supported by elixirls, but can be a table if you wish to pass other args `{"path/to/elixirls", "--foo"}`
|
||||
cmd = "${getExe pkgs.elixir-ls}",
|
||||
|
||||
-- default settings, use the `settings` function to override settings
|
||||
settings = elixirls.settings {
|
||||
dialyzerEnabled = true,
|
||||
fetchDeps = false,
|
||||
enableTestLenses = false,
|
||||
suggestSpecs = false,
|
||||
},
|
||||
|
||||
on_attach = function(client, bufnr)
|
||||
local map_opts = { buffer = true, noremap = true}
|
||||
|
||||
-- run the codelens under the cursor
|
||||
vim.keymap.set("n", "<space>r", vim.lsp.codelens.run, map_opts)
|
||||
-- remove the pipe operator
|
||||
vim.keymap.set("n", "<space>fp", ":ElixirFromPipe<cr>", map_opts)
|
||||
-- add the pipe operator
|
||||
vim.keymap.set("n", "<space>tp", ":ElixirToPipe<cr>", map_opts)
|
||||
vim.keymap.set("v", "<space>em", ":ElixirExpandMacro<cr>", map_opts)
|
||||
|
||||
-- bindings for standard LSP functions.
|
||||
vim.keymap.set("n", "<space>df", "<cmd>lua vim.lsp.buf.format()<cr>", map_opts)
|
||||
vim.keymap.set("n", "<space>gd", "<cmd>lua vim.diagnostic.open_float()<cr>", map_opts)
|
||||
vim.keymap.set("n", "<space>dt", "<cmd>lua vim.lsp.buf.definition()<cr>", map_opts)
|
||||
vim.keymap.set("n", "<space>K", "<cmd>lua vim.lsp.buf.hover()<cr>", map_opts)
|
||||
vim.keymap.set("n", "<space>gD","<cmd>lua vim.lsp.buf.implementation()<cr>", map_opts)
|
||||
vim.keymap.set("n", "<space>1gD","<cmd>lua vim.lsp.buf.type_definition()<cr>", map_opts)
|
||||
|
||||
-- keybinds for fzf-lsp.nvim: https://github.com/gfanto/fzf-lsp.nvim
|
||||
-- you could also use telescope.nvim: https://github.com/nvim-telescope/telescope.nvim
|
||||
-- there are also core vim.lsp functions that put the same data in the loclist
|
||||
vim.keymap.set("n", "<space>gr", ":References<cr>", map_opts)
|
||||
vim.keymap.set("n", "<space>g0", ":DocumentSymbols<cr>", map_opts)
|
||||
vim.keymap.set("n", "<space>gW", ":WorkspaceSymbols<cr>", map_opts)
|
||||
vim.keymap.set("n", "<leader>d", ":Diagnostics<cr>", map_opts)
|
||||
end
|
||||
}
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
imports = [
|
||||
./config.nix
|
||||
./elixir-tools.nix
|
||||
];
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib.options) mkEnableOption;
|
||||
in {
|
||||
options.vim.languages.elixir = {
|
||||
enable = mkEnableOption "Elixir language support";
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue