Skip to content

Commit

Permalink
Support attaching to remote debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
jabrouwer82 committed Oct 3, 2024
1 parent c2aed75 commit b90bb40
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 15 additions & 2 deletions doc/metals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ metals configuration with the following `on_attach` function. >

This will ensure that the correct |dap-adapter| is configured for Scala.

From here, there are 2 main ways you can interact with `nvim-dap`. The first
From here, there are 3 main ways you can interact with `nvim-dap`. The first
requires no further setup and relies on code lenses. You'll notice that you
will have `run` and `debug` code lenses on your main methods and `test` and
`testDebug` code lenses on your test classes. By triggering these behind the
Expand All @@ -1289,6 +1289,10 @@ the metals table are as follows: >
}
<

The final option is to attach to a remote debugger, here the expected
configuration should match the vscode configuration, requiring a
hostName, port, buildTarget, and setting request to "attach".

NOTE: Keep in mind that if you are defining these configurations you'll want
to trigger them with your dap mappings, not the code lenses.

Expand All @@ -1308,7 +1312,8 @@ The following run types are valid for Metals.
run it or if there are tests in the file, run those)

Below you can see an example of configurations, one for running or testing the
current file and the other for testing the entire target. >
current file, one for testing the entire target, and one for attaching to
an existing remote debugger. >
local dap = require("dap")
Expand All @@ -1329,6 +1334,14 @@ current file and the other for testing the entire target. >
runType = "testTarget",
},
},
{
type = "scala",
request = "attach",
name = "Attach to Localhost",
hostName = "localhost",
port = 5005,
buildTarget = "root",
}
}
<
You may also want to use the `Select Test Suite` and `Select Test Case`
Expand Down
8 changes: 7 additions & 1 deletion lua/metals/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ local function setup_dap(execute_command)

dap.adapters.scala = function(callback, config)
local arguments = {}
if config.name == "from_lens" or config.name == "Run Test" then
if config.request == "attach" then
arguments = {
hostName = assert(config.hostName, "`hostName` is required for a scala `attach` configuration."),
port = assert(config.port, "`port` is required for a scala `attach` configuration."),
buildTarget = config.buildTarget,
}
elseif config.name == "from_lens" or config.name == "Run Test" then
arguments = config.metals
else
local metals_dap_settings = config.metals or {}
Expand Down

0 comments on commit b90bb40

Please sign in to comment.