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

Mon, 20 May 2024 12:53:43 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 20 May 2024 12:53:43 -0500
changeset 1170
915a78d501d5
parent 1169
db64f7947671
child 1172
e9fe1489c0a6
permissions
-rw-r--r--

Bump nvim-treesitter to more recent commit

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)
1169
db64f7947671 Note get_active_clients deprecation
Meredith Howard <mhoward@roomag.org>
parents: 1165
diff changeset
9 -- deprecated 0.10.0: s/get_active_clients/get_clients/; s/idname/name/
1165
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
10 local elixir_lsp = vim.lsp.get_active_clients({
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11 idname = "ElixirLS",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12 bufnr = bufnr or vim.api.nvim_get_current_buf(),
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13 })[1]
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
14
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
15 if elixir_lsp then
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
16 local elixir_lsp_cmd = elixir_lsp.config.cmd[1]
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
17 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
18
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
19 return dap_cmd
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 end
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
22
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
23 local dap = require("dap")
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
24
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
25 dap.adapters.mix_task = function(callback, _)
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
26 local dap_cmd = find_elixir_lsp_dap_cmd()
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
27
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
28 if dap_cmd then
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
29 callback({
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
30 type = 'executable',
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
31 command = find_elixir_lsp_dap_cmd(),
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
32 args = {},
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
33 })
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 end
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
36
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
37 dap.configurations.elixir = {
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
38 {
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
39 type = "mix_task",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
40 name = "mix test",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
41 task = 'test',
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
42 taskArgs = { "--trace" },
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
43 request = "launch",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
44 startApps = true,
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
45 projectDir = "${workspaceFolder}",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
46 requireFiles = {
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
47 "test/**/test_helper.exs",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
48 "test/**/*_test.exs"
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 {
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
52 type = "mix_task",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
53 name = "phx.server",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
54 request = "launch",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
55 task = "phx.server",
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
56 projectDir = "${workspaceFolder}"
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
57 },
840f0fde07e2 set up nvim-dap etc
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
58 }

mercurial