-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support startDebugging
#38
Open
mxsdev
wants to merge
4
commits into
main
Choose a base branch
from
start-debugging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,51 @@ | ||
local M = {} | ||
local uv = vim.loop | ||
local js_session = require("dap-vscode-js.session") | ||
local utils = require("dap-vscode-js.utils") | ||
local logger = require("dap-vscode-js.log") | ||
-- local logger = require("dap-vscode-js.log") | ||
local dapjs_config = require("dap-vscode-js.config") | ||
local dap = require("dap") | ||
|
||
local function adapter_config(port, mode, proc, start_child) | ||
return { | ||
type = "server", | ||
host = "127.0.0.1", | ||
port = port, | ||
id = mode, | ||
reverse_request_handlers = { | ||
attachedChildSession = function(parent, request) | ||
logger.debug( | ||
string.format( | ||
"Got attachedChildSession request from port %d to start port %s", | ||
parent.adapter.port, | ||
request.arguments.config.__jsDebugChildServer | ||
) | ||
) | ||
logger.trace("attachedChildSession request, port " .. tostring(port) .. ": " .. vim.inspect(request)) | ||
|
||
start_child(request, mode, parent, proc) | ||
end, | ||
}, | ||
} | ||
end | ||
|
||
local function start_child_session(request, mode, parent, proc) | ||
local body = request.arguments | ||
local session = nil | ||
local child_port = tonumber(body.config.__jsDebugChildServer) | ||
|
||
session = require("dap.session"):connect( | ||
adapter_config(child_port, mode, proc, start_child_session), | ||
{}, | ||
function(err) | ||
if err then | ||
logger.log("DAP connection failed to start: " .. err, vim.log.levels.ERROR) | ||
else | ||
logger.debug("Initializing child session on port " .. tostring(child_port)) | ||
|
||
session:initialize(body.config) | ||
|
||
js_session.register_session(session, parent, proc) | ||
end | ||
end | ||
) | ||
end | ||
|
||
function M.generate_adapter(mode, config) | ||
config = config or dapjs_config | ||
|
||
return function(callback) | ||
local proc | ||
|
||
proc = utils.start_debugger(config, function(port, proc) | ||
logger.debug("Debugger process started on port " .. port) | ||
|
||
js_session.register_port(port) | ||
callback(adapter_config(port, mode, proc, start_child_session)) | ||
end, function(code, signal) | ||
if code and code ~= 0 then | ||
logger.error("JS Debugger exited with code " .. code .. "!") | ||
end | ||
end, function(err) | ||
logger.error("Error trying to launch JS debugger: " .. err) | ||
end, function(chunk) | ||
-- logger.log("JS Debugger stderr: " .. chunk, vim.log.levels.ERROR) | ||
logger.error("JS Debugger stderr: " .. chunk) | ||
end) | ||
end | ||
function M.generate_adapter(_, user_config) | ||
user_config = user_config or dapjs_config | ||
|
||
return function(on_config, config, parent) | ||
local target = config["__pendingTargetId"] | ||
if target and parent then | ||
local adapter = parent.adapter | ||
on_config({ | ||
type = "server", | ||
host = "localhost", | ||
port = adapter.port | ||
}) | ||
else | ||
local debug_executable = user_config.adapter_executable_config | ||
|
||
if not debug_executable then | ||
local debugger_path = user_config.debugger_executable | ||
|
||
if not utils.file_exists(debugger_path) then | ||
-- TODO: show user to README.md with directions | ||
error("Debugger entrypoint file '" .. debugger_path .. "' does not exist. Did it build properly?") | ||
end | ||
|
||
local debugger_cmd_args = { debugger_path, "${port}" } | ||
|
||
for _, arg in ipairs(user_config.debugger_args or {}) do | ||
table.insert(debugger_cmd_args, arg) | ||
end | ||
|
||
debug_executable = { | ||
command = user_config.node_path, | ||
args = debugger_cmd_args, | ||
} | ||
end | ||
|
||
on_config({ | ||
type = "server", | ||
host = "localhost", | ||
port = "${port}", | ||
executable = debug_executable | ||
}) | ||
end | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
local M = {} | ||
local uv = vim.loop | ||
local js_session = require("dap-vscode-js.legacy.session") | ||
local utils = require("dap-vscode-js.utils") | ||
local logger = require("dap-vscode-js.log") | ||
local dapjs_config = require("dap-vscode-js.config") | ||
local dap = require("dap") | ||
|
||
local function adapter_config(port, mode, proc, start_child) | ||
return { | ||
type = "server", | ||
host = "127.0.0.1", | ||
port = port, | ||
id = mode, | ||
reverse_request_handlers = { | ||
attachedChildSession = function(parent, request) | ||
logger.debug( | ||
string.format( | ||
"Got attachedChildSession request from port %d to start port %s", | ||
parent.adapter.port, | ||
request.arguments.config.__jsDebugChildServer | ||
) | ||
) | ||
logger.trace("attachedChildSession request, port " .. tostring(port) .. ": " .. vim.inspect(request)) | ||
|
||
start_child(request, mode, parent, proc) | ||
end, | ||
}, | ||
} | ||
end | ||
|
||
local function start_child_session(request, mode, parent, proc) | ||
local body = request.arguments | ||
local session = nil | ||
local child_port = tonumber(body.config.__jsDebugChildServer) | ||
|
||
session = require("dap.session"):connect( | ||
adapter_config(child_port, mode, proc, start_child_session), | ||
{}, | ||
function(err) | ||
if err then | ||
logger.log("DAP connection failed to start: " .. err, vim.log.levels.ERROR) | ||
else | ||
logger.debug("Initializing child session on port " .. tostring(child_port)) | ||
if parent.children then | ||
session.parent = parent | ||
parent.children[session.id] = session | ||
end | ||
session:initialize(body.config) | ||
js_session.register_session(session, parent, proc) | ||
end | ||
end | ||
) | ||
end | ||
|
||
function M.generate_adapter(mode, config) | ||
config = config or dapjs_config | ||
|
||
return function(callback) | ||
local proc | ||
|
||
proc = utils.start_debugger(config, function(port, proc) | ||
logger.debug("Debugger process started on port " .. port) | ||
|
||
js_session.register_port(port) | ||
callback(adapter_config(port, mode, proc, start_child_session)) | ||
end, function(code, signal) | ||
if code and code ~= 0 then | ||
logger.error("JS Debugger exited with code " .. code .. "!") | ||
end | ||
end, function(err) | ||
logger.error("Error trying to launch JS debugger: " .. err) | ||
end, function(chunk) | ||
logger.error("JS Debugger stderr: " .. chunk) | ||
end) | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
local js_adapter = require("dap-vscode-js.legacy.adapter") | ||
local js_session = require("dap-vscode-js.legacy.session") | ||
local js_dap = require("dap-vscode-js.dap") | ||
|
||
local M = {} | ||
|
||
--- Whether or not to use legacy module | ||
--- @param config Settings | ||
--- @return boolean | ||
function M.use_legacy(config) | ||
-- TODO: figure out if `startDebugging` is supported | ||
return config.legacy_flat_debugger | ||
end | ||
|
||
function M.setup(config) | ||
-- js_session.setup_hooks("dap-vscode-js", config) | ||
-- js_dap.attach_adapters(config, js_adapter.generate_adapter) | ||
end | ||
|
||
return M |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a further change in nvim-dap to automatically use the parent host+port if the
adapter
has both type server and an executable. See mfussenegger/nvim-dap#913. This should make it unnecessary to check fortarget
and parent, you can instead always return the same definition.