From e96897f6b3e60183e81a04a45593f837f4e101d8 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 7 May 2024 00:52:33 +0300 Subject: [PATCH] languages/elixir: readd; format module options --- configuration.nix | 3 +- docs/release-notes/rl-0.7.md | 10 +- flake.lock | 17 +++ flake.nix | 19 ++- modules/extra/deprecations.nix | 5 - modules/plugins/languages/default.nix | 1 + modules/plugins/languages/elixir.nix | 138 ++++++++++++++++++ modules/plugins/languages/elixir/config.nix | 67 --------- modules/plugins/languages/elixir/default.nix | 6 - .../plugins/languages/elixir/elixir-tools.nix | 7 - 10 files changed, 175 insertions(+), 98 deletions(-) create mode 100644 modules/plugins/languages/elixir.nix delete mode 100644 modules/plugins/languages/elixir/config.nix delete mode 100644 modules/plugins/languages/elixir/default.nix delete mode 100644 modules/plugins/languages/elixir/elixir-tools.nix diff --git a/configuration.nix b/configuration.nix index 82f86cc..56e5d90 100644 --- a/configuration.nix +++ b/configuration.nix @@ -54,7 +54,6 @@ inputs: let enableTreesitter = true; enableExtraDiagnostics = true; - nim.enable = false; nix.enable = true; markdown.enable = true; @@ -65,12 +64,14 @@ inputs: let ts.enable = isMaximal; svelte.enable = isMaximal; go.enable = isMaximal; + elixir.enable = isMaximal; zig.enable = isMaximal; python.enable = isMaximal; dart.enable = isMaximal; bash.enable = isMaximal; tailwind.enable = isMaximal; typst.enable = isMaximal; + nim.enable = isMaximal; clang = { enable = isMaximal; lsp.server = "clangd"; diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index 8f61a89..0cf265f 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -24,9 +24,9 @@ Release notes for release 0.7 automatically if you have autoformatting enabled, but can be disabled manually if you choose to. -- Remove vim-tidal and friends +- Refactor `programs.languages.elixir` to use lspconfig and none-ls for LSP and + formatter setups respectively. Diagnostics support is considered, and may be + added once the [credo](https://github.com/rrrene/credo) linter has been added + to nixpkgs. A pull request is currently open. -- Remove unmaintained Elixir language module. This has been long broken, and was - unmaintained due to my disinterest in using Elixir. If you depend on Elixir - language support, please create an issue. Do keep in mind that elixirls **does - not exist in nixpkgs**. +- Remove vim-tidal and friends diff --git a/flake.lock b/flake.lock index cd2a3ee..c34ef94 100644 --- a/flake.lock +++ b/flake.lock @@ -546,6 +546,22 @@ "type": "github" } }, + "plugin-elixir-tools": { + "flake": false, + "locked": { + "lastModified": 1714657398, + "narHash": "sha256-U6db1n/RIpT7Dd54e9iI/PjO1BhDpMyNPfaph+dUk7k=", + "owner": "elixir-tools", + "repo": "elixir-tools.nvim", + "rev": "51eddb03a7a8c9f00d6415b356a4d3b75d8e75b6", + "type": "github" + }, + "original": { + "owner": "elixir-tools", + "repo": "elixir-tools.nvim", + "type": "github" + } + }, "plugin-fidget-nvim": { "flake": false, "locked": { @@ -1764,6 +1780,7 @@ "plugin-diffview-nvim": "plugin-diffview-nvim", "plugin-dracula": "plugin-dracula", "plugin-dressing-nvim": "plugin-dressing-nvim", + "plugin-elixir-tools": "plugin-elixir-tools", "plugin-fidget-nvim": "plugin-fidget-nvim", "plugin-flutter-tools": "plugin-flutter-tools", "plugin-gesture-nvim": "plugin-gesture-nvim", diff --git a/flake.nix b/flake.nix index d51617a..ae6885a 100644 --- a/flake.nix +++ b/flake.nix @@ -178,13 +178,8 @@ flake = false; }; - plugin-glow-nvim = { - url = "github:ellisonleao/glow.nvim"; - flake = false; - }; - - plugin-image-nvim = { - url = "github:3rd/image.nvim"; + plugin-elixir-tools = { + url = "github:elixir-tools/elixir-tools.nvim"; flake = false; }; @@ -487,6 +482,16 @@ flake = false; }; + plugin-glow-nvim = { + url = "github:ellisonleao/glow.nvim"; + flake = false; + }; + + plugin-image-nvim = { + url = "github:3rd/image.nvim"; + flake = false; + }; + # Note-taking plugin-obsidian-nvim = { url = "github:epwalsh/obsidian.nvim"; diff --git a/modules/extra/deprecations.nix b/modules/extra/deprecations.nix index b2bf522..cb06380 100644 --- a/modules/extra/deprecations.nix +++ b/modules/extra/deprecations.nix @@ -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. diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index 802dfe7..279d46b 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -6,6 +6,7 @@ in { ./dart.nix ./clang.nix ./css.nix + ./elixir.nix ./go.nix ./html.nix ./java.nix diff --git a/modules/plugins/languages/elixir.nix b/modules/plugins/languages/elixir.nix new file mode 100644 index 0000000..7f969ad --- /dev/null +++ b/modules/plugins/languages/elixir.nix @@ -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 + } + } + ''; + }) + ]); +} diff --git a/modules/plugins/languages/elixir/config.nix b/modules/plugins/languages/elixir/config.nix deleted file mode 100644 index eaf26ea..0000000 --- a/modules/plugins/languages/elixir/config.nix +++ /dev/null @@ -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", "r", vim.lsp.codelens.run, map_opts) - -- remove the pipe operator - vim.keymap.set("n", "fp", ":ElixirFromPipe", map_opts) - -- add the pipe operator - vim.keymap.set("n", "tp", ":ElixirToPipe", map_opts) - vim.keymap.set("v", "em", ":ElixirExpandMacro", map_opts) - - -- bindings for standard LSP functions. - vim.keymap.set("n", "df", "lua vim.lsp.buf.format()", map_opts) - vim.keymap.set("n", "gd", "lua vim.diagnostic.open_float()", map_opts) - vim.keymap.set("n", "dt", "lua vim.lsp.buf.definition()", map_opts) - vim.keymap.set("n", "K", "lua vim.lsp.buf.hover()", map_opts) - vim.keymap.set("n", "gD","lua vim.lsp.buf.implementation()", map_opts) - vim.keymap.set("n", "1gD","lua vim.lsp.buf.type_definition()", 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", "gr", ":References", map_opts) - vim.keymap.set("n", "g0", ":DocumentSymbols", map_opts) - vim.keymap.set("n", "gW", ":WorkspaceSymbols", map_opts) - vim.keymap.set("n", "d", ":Diagnostics", map_opts) - end - } - } - ''; - }; -} diff --git a/modules/plugins/languages/elixir/default.nix b/modules/plugins/languages/elixir/default.nix deleted file mode 100644 index c84acf0..0000000 --- a/modules/plugins/languages/elixir/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - imports = [ - ./config.nix - ./elixir-tools.nix - ]; -} diff --git a/modules/plugins/languages/elixir/elixir-tools.nix b/modules/plugins/languages/elixir/elixir-tools.nix deleted file mode 100644 index 0527359..0000000 --- a/modules/plugins/languages/elixir/elixir-tools.nix +++ /dev/null @@ -1,7 +0,0 @@ -{lib, ...}: let - inherit (lib.options) mkEnableOption; -in { - options.vim.languages.elixir = { - enable = mkEnableOption "Elixir language support"; - }; -}