jfpedroza / neotest-elixir

Neotest adapter for Elixir
MIT License
42 stars 11 forks source link

How to debug tests? #27

Closed NonlinearFruit closed 1 year ago

NonlinearFruit commented 1 year ago

:world_map: Background

I just setup elixir in neovim. Running tests with neotest works but debugging isn't working yet. I have test debugging working for C# but I'm guessing my dap setup could be bad? Or maybe it isn't what neotest-elixir expects?

I'm using the Gilded Rose to learn Elixir (source)

:bug: Problem

lua require('neotest').run.run({strategy = 'dap'}) errors with:

Adapter doesn't support chosen strategy.
neotest-elixir: ...are/nvim/site/pack/packer/start/neotest/lua/nio/init.lua:105: The coroutine failed with this message:
...ker/start/neotest/lua/neotest/client/strategies/init.lua:55: attempt to index local 'instance' (a nil value)
stack traceback:
        ...ker/start/neotest/lua/neotest/client/strategies/init.lua: in function 'run'
        .../pack/packer/start/neotest/lua/neotest/client/runner.lua:129: in function '_run_spec'
        .../pack/packer/start/neotest/lua/neotest/client/runner.lua:89: in function <.../pack/packer/start/neotest/lua/neotest/client/runner.lua:88>
Press ENTER or type command to continue

This neotest issue seems to suggest that this problem involved the neotest adapter (source)

:building_construction: Configs

I use packer to install the plugin ```lua use({ "nvim-neotest/neotest", requires = { { "jfpedroza/neotest-elixir", }, } }) ```
I installed `elixirls` with mason. Here is how I setup the debug adapter. ```lua dap.adapters.mix_task = { type = 'executable', command = require("mason-core.package"):get_install_path()..'/bin/elixir-ls-debugger', args = {} } dap.configurations.elixir = { { type = "mix_task", name = "mix test", task = 'test', taskArgs = {"--trace"}, request = "launch", startApps = true, -- for Phoenix projects projectDir = "${workspaceFolder}", requireFiles = { "test/**/test_helper.exs", "test/**/*_test.exs" } }, } ```
Here is my neotest setup. The keymap for running the nearest test is working ```lua local neotest_ok, neotest = pcall(require, 'neotest') if not neotest_ok then return end local function keymap(key, cmd, description) vim.keymap.set({"n", "v"}, key, ""..cmd.."", { desc = description }) end keymap("tcr", "lua require('neotest').run.run(vim.fn.expand('%'))", "[t]est [c]lass [r]un") keymap("tcd", "lua require('neotest').run.run({vim.fn.expand('%'), strategy = 'dap'})", "[t]est [c]lass [d]ebug") keymap("tr", "lua require('neotest').run.run()", "[t]est [r]un") keymap("td", "lua require('neotest').run.run({strategy = 'dap'})", "[t]est [d]ebug") keymap("tsr", "lua require('neotest').run.run({suite = true})", "[t]est [s]uite [r]un") keymap("tsd", "lua require('neotest').run.run({suite = true, strategy = 'dap'})", "[t]est [s]uite [d]ebug") keymap("tw", "lua require('neotest').summary.toggle()", "[t]est [w]indow") local adapters = {} if packer_plugins["neotest-dotnet"] and packer_plugins["neotest-dotnet"].loaded then table.insert(adapters, require("neotest-dotnet")) end if packer_plugins["neotest-elixir"] and packer_plugins["neotest-elixir"].loaded then table.insert(adapters, require("neotest-elixir")) end neotest.setup({ adapters = adapters, diagnostic = { enabled = true } }) ```
jfpedroza commented 1 year ago

Hi.

The adapter doesn't support debugging. I haven't really worked with the Elixir debugger, so I haven't explored how it would integrate with the adapter.

NonlinearFruit commented 1 year ago

Ahhh, ok. That would explain it! Thanks for the swift response