.config/nvim/after/ftplugin/elixir.lua

Thu, 16 May 2024 14:37:26 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Thu, 16 May 2024 14:37:26 -0500
changeset 1166
34bf03fa07e4
parent 1165
840f0fde07e2
child 1169
db64f7947671
permissions
-rw-r--r--

normalize config.util.autocmd

1165
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
1 -- elixir-tools installs elixir-ls in directories by version and otp version in
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
2 -- order to match up the right version with your app. it doesn't expose what
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
3 -- path is in use except for how it launches elixir-ls, so we can scrape it out
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
4 -- of there. it's not clear to me how nvim-dap would handle an adapter's
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
5 -- definition changing, so i wouldn't expect this to work well with more than
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
6 -- one version in the same nvim session.
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
7
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
8 local function find_elixir_lsp_dap_cmd(bufnr)
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
9 local elixir_lsp = vim.lsp.get_active_clients({
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
10 idname = "ElixirLS",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11 bufnr = bufnr or vim.api.nvim_get_current_buf(),
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12 })[1]
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
14 if elixir_lsp then
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
15 local elixir_lsp_cmd = elixir_lsp.config.cmd[1]
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
16 local dap_cmd = elixir_lsp_cmd:gsub("language_server.", "debug_adapter.")
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
17
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
18 return dap_cmd
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
19 end
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
20 end
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
21
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
22 local dap = require("dap")
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
23
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
24 dap.adapters.mix_task = function(callback, _)
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
25 local dap_cmd = find_elixir_lsp_dap_cmd()
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
26
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
27 if dap_cmd then
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
28 callback({
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
29 type = 'executable',
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
30 command = find_elixir_lsp_dap_cmd(),
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
31 args = {},
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
32 })
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
33 end
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
34 end
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
35
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
36 dap.configurations.elixir = {
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
37 {
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
38 type = "mix_task",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
39 name = "mix test",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
40 task = 'test',
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
41 taskArgs = { "--trace" },
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
42 request = "launch",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
43 startApps = true,
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
44 projectDir = "${workspaceFolder}",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
45 requireFiles = {
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
46 "test/**/test_helper.exs",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
47 "test/**/*_test.exs"
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
48 }
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
49 },
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
50 {
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
51 type = "mix_task",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
52 name = "phx.server",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
53 request = "launch",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
54 task = "phx.server",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
55 projectDir = "${workspaceFolder}"
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
56 },
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
57 }

mercurial