Unescaped source path in JSON body of DAP output event causes errors in nvim-dap
tbrauredev opened this issue · 2 comments
Description
I'm trying to use netcoredbg from neovim through nvim-dap and I get the following errors when debuging a simple ASP.NET Core Web API template project on Windows:
Error executing vim.schedule lua callback: ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: Expected value but found invalid escape code at character 209
stack traceback:
[C]: in function 'json_decode'
...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: in function 'handle_body'
...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1479: in function 'fn'
vim/_editor.lua:351: in function <vim/_editor.lua:350>
Error executing vim.schedule lua callback: ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: Expected value but found invalid escape code at character 217
stack traceback:
[C]: in function 'json_decode'
...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: in function 'handle_body'
...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1479: in function 'fn'
vim/_editor.lua:351: in function <vim/_editor.lua:350>
Error executing vim.schedule lua callback: ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: Expected value but found invalid escape code at character 201
stack traceback:
[C]: in function 'json_decode'
...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: in function 'handle_body'
...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1479: in function 'fn'
vim/_editor.lua:351: in function <vim/_editor.lua:350>
Error executing vim.schedule lua callback: ...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: Expected value but found invalid escape code at character 212
stack traceback:
[C]: in function 'json_decode'
...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:983: in function 'handle_body'
...ppData/Local/nvim-data/lazy/nvim-dap/lua/dap/session.lua:1479: in function 'fn'
vim/_editor.lua:351: in function <vim/_editor.lua:350>
I added a few traces in nvim-dap's session.lua and found the problematic JSON body:
{
"seq": 111,
"event": "output",
"type": "event",
"body": {
"category": "stdout",
"output"...r\n",
"source": {
"name": "Program.cs",
"path": "C:\Dev\csharp-project\WebApi1\Program.cs"
}
}
}
Note the unescaped backslashes in the path of the source file. Looking at the code of netcoredgb, it seems that it could easily be fixed by wrapping source.path
in an EscapedString<JSON_escape_rules>
within serialize_output
in src/protocol/vscodeprotocol.cpp.
I have tested this fix on my side and it works, I can submit a PR if needed.
Just for the record, here is my nvim-dap configuration:
local dap = require("dap")
dap.adapters["coreclr"] = {
type = "executable",
command = vim.fn.exepath("netcoredbg"),
args = { "--interpreter=vscode" },
options = {
detached = false,
},
}
dap.configurations["cs"] = {
{
type = "coreclr",
name = "Debug C# App",
request = "launch",
program = function()
return vim.fn.input("Path to dll", vim.fn.getcwd() .. "/bin/Debug/", "file")
end,
},
}
And I created my C# App using dotnet new webapi -o WebApi1
.
I have tested this fix on my side and it works, I can submit a PR if needed.
Sure, please, submit PR, we will take a look and test it in our internal CI.
This should be fixed in latest release. Feel free to reopen if you see any more related issues.