From 3071c6bb4be4cde5936cfec533c7a8b2fd3bd9cd Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 15 Apr 2023 22:51:13 +0300 Subject: [PATCH] feat: use elixir-tools.nvim for additional highlighting --- flake.lock | 17 ++++++++ flake.nix | 5 +++ lib/types/plugins.nix | 1 + modules/lsp/config.nix | 2 +- modules/lsp/default.nix | 5 ++- modules/lsp/elixir/config.nix | 67 +++++++++++++++++++++++++++++ modules/lsp/elixir/default.nix | 6 +++ modules/lsp/elixir/elixir-tools.nix | 10 +++++ modules/treesitter/treesitter.nix | 2 + 9 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 modules/lsp/elixir/config.nix create mode 100644 modules/lsp/elixir/default.nix create mode 100644 modules/lsp/elixir/elixir-tools.nix diff --git a/flake.lock b/flake.lock index 492f575..3680042 100644 --- a/flake.lock +++ b/flake.lock @@ -337,6 +337,22 @@ "type": "github" } }, + "elixir-tools": { + "flake": false, + "locked": { + "lastModified": 1681453321, + "narHash": "sha256-7QgWrdq4p5t8WVnFhL5P948JFPR0i2C06kisxl30D2U=", + "owner": "elixir-tools", + "repo": "elixir-tools.nvim", + "rev": "8ccb696c048eca667486ee005f4386c0db8c5e14", + "type": "github" + }, + "original": { + "owner": "elixir-tools", + "repo": "elixir-tools.nvim", + "type": "github" + } + }, "fidget-nvim": { "flake": false, "locked": { @@ -1336,6 +1352,7 @@ "diffview-nvim": "diffview-nvim", "dressing-nvim": "dressing-nvim", "elixir-ls": "elixir-ls", + "elixir-tools": "elixir-tools", "fidget-nvim": "fidget-nvim", "flake-parts": "flake-parts", "flake-utils": "flake-utils", diff --git a/flake.nix b/flake.nix index b19b16d..da89f51 100644 --- a/flake.nix +++ b/flake.nix @@ -153,6 +153,11 @@ flake = false; }; + elixir-tools = { + url = "github:elixir-tools/elixir-tools.nvim"; + flake = false; + }; + # Copying/Registers registers = { url = "github:tversteeg/registers.nvim"; diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 03a433a..2c1aaa9 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -80,6 +80,7 @@ with lib; let "smartcolumn" "project-nvim" "elixir-ls" + "elixir-tools" ]; # You can either use the name of the plugin or a package. pluginsType = with types; diff --git a/modules/lsp/config.nix b/modules/lsp/config.nix index c1cb706..6a6810c 100644 --- a/modules/lsp/config.nix +++ b/modules/lsp/config.nix @@ -344,7 +344,7 @@ in { ${writeIf cfg.elixir.enable '' lspconfig.elixirls.setup { - cmd = { "${pkgs.elixir-ls}/language_server.sh" }, + cmd = { "${lib.getExe pkgs.elixir-ls}" }, on_attach = on_attach } ''} diff --git a/modules/lsp/default.nix b/modules/lsp/default.nix index db4f027..cb88e3d 100644 --- a/modules/lsp/default.nix +++ b/modules/lsp/default.nix @@ -11,7 +11,8 @@ ./lsp-signature ./lightbulb - # flutter-tools - ./flutter-tools-nvim + # language specific modules + ./flutter-tools-nvim # dart & flutter + ./elixir # elixir ]; } diff --git a/modules/lsp/elixir/config.nix b/modules/lsp/elixir/config.nix new file mode 100644 index 0000000..1b1e2a5 --- /dev/null +++ b/modules/lsp/elixir/config.nix @@ -0,0 +1,67 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; +with builtins; let + cfg = config.vim.lsp.elixir; +in { + config = mkIf (cfg.enable) { + vim.startPlugins = [ + "elixir-tools" + "plenary-nvim" + ]; + + vim.luaConfigRC.elixir-tools = nvim.dag.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 = "${lib.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/lsp/elixir/default.nix b/modules/lsp/elixir/default.nix new file mode 100644 index 0000000..b8ea9be --- /dev/null +++ b/modules/lsp/elixir/default.nix @@ -0,0 +1,6 @@ +_: { + imports = [ + ./config.nix + ./elixir-tools.nix + ]; +} diff --git a/modules/lsp/elixir/elixir-tools.nix b/modules/lsp/elixir/elixir-tools.nix new file mode 100644 index 0000000..d3fe1ec --- /dev/null +++ b/modules/lsp/elixir/elixir-tools.nix @@ -0,0 +1,10 @@ +{ + config, + lib, + ... +}: +with lib; +with builtins; { + options.vim.lsp.elixir = { + }; +} diff --git a/modules/treesitter/treesitter.nix b/modules/treesitter/treesitter.nix index ab3cea6..550e7fe 100644 --- a/modules/treesitter/treesitter.nix +++ b/modules/treesitter/treesitter.nix @@ -45,6 +45,8 @@ with builtins; { graphql json zig + elixir + heex ] ++ (optional config.vim.notes.orgmode.enable org); # add orgmode grammar if enabled description = ''