-
Notifications
You must be signed in to change notification settings - Fork 0
Debugging
Oleksii Lisikh edited this page Feb 27, 2026
·
3 revisions
neotest-scala supports debugging tests with nvim-dap and nvim-metals.
| Requirement | Purpose |
|---|---|
| nvim-dap | Debug Adapter Protocol client for Neovim |
| nvim-metals | Scala LSP with debug capabilities |
| Java Debug Server | Metals handles this automatically |
-- lazy.nvim
{
'mfussenegger/nvim-dap',
dependencies = {
'rcarriga/nvim-dap-ui', -- Optional: nice UI for debugging
},
}local metals_config = require('metals').bare_config()
-- Auto-attach Metals
vim.api.nvim_create_autocmd("FileType", {
pattern = { "scala", "sbt" },
callback = function()
require("metals").initialize_or_attach(metals_config)
require("metals").setup_dap()
end,
group = vim.api.nvim_create_augroup("nvim-metals", { clear = true }),
})local dap = require('dap')
-- Scala/Java debug configuration
dap.configurations.scala = {
{
type = "scala",
request = "launch",
name = "Run or Test Target",
metals = {
runType = "runOrTestFile",
},
},
}-- Debug nearest test
require('neotest').run.run({ strategy = 'dap' })
-- Debug all tests in file
require('neotest').run.run({ vim.fn.expand('%'), strategy = 'dap' })vim.keymap.set('n', '<leader>td', function()
require('neotest').run.run({ strategy = 'dap' })
end, { desc = "Debug nearest test" }):lua require('neotest').run.run({strategy = 'dap'})DAP support prioritizes reliable session startup:
-
Nearest test runs at file scope
- Test-node debug requests launch
runType = "testFile".
- Test-node debug requests launch
-
Per-test DAP selectors are disabled
- This applies to all frameworks, including ScalaTest, munit, specs2, utest, and zio-test.
-
No-suite runs are failed
-
No test suites were run.is reported as a failed run, including DAP.
-
-
Metals controls backend execution
- neotest-scala cannot force Metals DAP to pick sbt/bloop at debug-launch time.
When you run a test with the dap strategy, neotest-scala:
-
Queries Metals for build target information
-
Builds a debug configuration appropriate for the test type:
-
File: Uses
runType = "testFile" -
Namespace/Class: Uses
testClassparameter -
Individual Test: Uses file-level debug (
runType = "testFile")
-
File: Uses
-
Starts the debugger via nvim-dap
{
type = "scala",
request = "launch",
name = "Run Test",
metals = {
runType = "testFile",
path = "file:///path/to/TestFile.scala",
},
}{
type = "scala",
request = "launch",
name = "from_lens",
metals = {
testClass = "com.example.MyTestSuite",
},
}{
type = "scala",
request = "launch",
name = "Run Test",
metals = {
runType = "testFile",
path = "file:///path/to/TestFile.scala",
},
}{
type = "scala",
request = "launch",
name = "Run Test",
metals = {
runType = "testFile",
path = "file:///path/to/TestFile.scala",
},
}| Library | Single Test Debug | Class Debug | Notes |
|---|---|---|---|
| ScalaTest | ❌ | ✅ | Nearest-test debug runs file scope |
| munit | ❌ | ✅ | Nearest-test debug runs file scope |
| specs2 | ❌ | ✅ | Nearest-test debug runs file scope |
| utest | ❌ | ✅ | Nearest-test debug runs file scope |
| zio-test | ❌ | ✅ | Nearest-test debug runs file scope |
Individual test debugging is intentionally disabled in DAP mode. You can:
- Debug the entire test suite
- Temporarily isolate the test you want to debug
- Add breakpoints that catch the right test
For a better debugging experience:
require("dapui").setup()
-- Auto-open UI on debug
vim.api.nvim_create_autocmd("FileType", {
pattern = "scala",
callback = function()
local dap = require('dap')
local dapui = require('dapui')
dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close()
end
end,
})Ensure Metals is running and has initialized:
:LspInfo
" Should show metals attachedThe test may not have compiled. Run tests normally first:
:Neotest run- Ensure the code is compiled with debug symbols (default in sbt)
- Check that the breakpoint is in the correct file
- Try setting the breakpoint after the debug session starts
This is a known limitation. Debug at the suite level instead.
- Troubleshooting — General issues
- Configuration — Configuration options
- Supported Test Libraries — Library support matrix