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

Wed, 22 May 2024 21:14:12 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Wed, 22 May 2024 21:14:12 -0500
changeset 1173
79c1553aa040
parent 1172
e9fe1489c0a6
permissions
-rw-r--r--

Change tab completion/snippet maps

-- elixir-tools installs elixir-ls in directories by version and otp version in
-- order to match up the right version with your app.  it doesn't expose what
-- path is in use except for how it launches elixir-ls, so we can scrape it out
-- of there.  it's not clear to me how nvim-dap would handle an adapter's
-- definition changing, so i wouldn't expect this to work well with more than
-- one version in the same nvim session.

local function find_elixir_lsp_dap_cmd(bufnr)
  local elixir_lsp = vim.lsp.get_clients({
    name = "ElixirLS",
    bufnr = bufnr or vim.api.nvim_get_current_buf(),
  })[1]

  if elixir_lsp then
    local elixir_lsp_cmd = elixir_lsp.config.cmd[1]
    local dap_cmd = elixir_lsp_cmd:gsub("language_server.", "debug_adapter.")

    return dap_cmd
  end
end

local dap = require("dap")

dap.adapters.mix_task = function(callback, _)
  local dap_cmd = find_elixir_lsp_dap_cmd()

  if dap_cmd then
    callback({
      type = 'executable',
      command = find_elixir_lsp_dap_cmd(),
      args = {},
    })
  end
end

dap.configurations.elixir = {
  {
    type = "mix_task",
    name = "mix test",
    task = 'test',
    taskArgs = { "--trace" },
    request = "launch",
    startApps = true,
    projectDir = "${workspaceFolder}",
    requireFiles = {
      "test/**/test_helper.exs",
      "test/**/*_test.exs"
    }
  },
  {
    type = "mix_task",
    name = "phx.server",
    request = "launch",
    task = "phx.server",
    projectDir = "${workspaceFolder}"
  },
}

mercurial