-
-
Notifications
You must be signed in to change notification settings - Fork 192
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 string input for args
field in launch.json
#1267
Comments
This is out of scope for nvim-dap as it aims to remain agnostic to debug adapter specific properties. If one debug adapter required a string You can use |
It seems that in the context of python, using a string as "args" is not supported, I'm having this error |
I'd love to request/contribute a fix for that but I'm not sure where is the best place to do this @mfussenegger. How can I have a client with |
As much as I would want this upstream, I've implemented the suggestion by @mfussenegger for now. Improvement suggestions welcome 🙏 -- string parser with quote escaping capabilities
-- inspired by http://lua-users.org/wiki/LpegRecipes
--- @param input string
--- @return table
local function split(input)
local lpeg = vim.lpeg
local P, S, C, Cc, Ct = lpeg.P, lpeg.S, lpeg.C, lpeg.Cc, lpeg.Ct
--- @param id string
--- @param patt vim.lpeg.Capture
--- @return vim.lpeg.Pattern
local function token(id, patt)
return Ct(Cc(id) * C(patt))
end
local single_quoted = P("'") * ((1 - S("'\r\n\f\\")) + (P("\\") * 1)) ^ 0 * "'"
local double_quoted = P('"') * ((1 - S('"\r\n\f\\')) + (P("\\") * 1)) ^ 0 * '"'
local whitespace = token("whitespace", S("\r\n\f\t ") ^ 1)
local word = token("word", (1 - S("' \r\n\f\t\"")) ^ 1)
local string = token("string", single_quoted + double_quoted)
local pattern = Ct((string + whitespace + word) ^ 0)
local t = {}
local tokens = lpeg.match(pattern, input)
-- somehow, this did not work out
if tokens == nil or type(tokens) == "integer" then
return t
end
for _, tok in ipairs(tokens) do
if tok[1] ~= "whitespace" then
if tok[1] == "string" then
-- cut off quotes and replace escaped quotes
local v, _ = tok[2]:sub(2, -2):gsub("\\(['\"])", "%1")
table.insert(t, v)
else
table.insert(t, tok[2])
end
end
end
return t
end
-- add debugpy capability to specify args as string
dap.listeners.on_config["debugpy"] = function(config)
-- copy the config and split the args if it is a string
local c = {}
for k, v in pairs(vim.deepcopy(config)) do
if k == "args" and type(v) == "string" then
c[k] = split(v)
else
c[k] = v
end
end
return c
end
end, |
I'd accept a PR that adds just the split function to |
There you go |
Problem Statement
The
args
field inlaunch.json
doesn't accept a string value when using the${input:programArgs}
variable with thecodelldb
adapter. This behavior differs from VS Code's handling of theargs
field with other debug adapters, where a string input is typically split by whitespace into multiple arguments.While not explicitly documented, VS Code generally supports both an array of strings and a single string (to be tokenized) for the
args
field with most debug adapters. However, when using thecodelldb
adapter, attempting to use a string input results in an error:This inconsistency prevents passing multiple arguments to the debugging program using a single input variable when using
codelldb
, which is especially useful for dynamic argument input. The behavior doesn't match the functionality available with other debug adapters in VS Code.My
launch.json
configuration:Click to expand launch.json
References
Possible Solutions
A potential solution to this issue involves modifying the
vscode.lua
file in the DAP (Debug Adapter Protocol) extension. Here's the proposed change:This solution adds a check specifically for the
args
key in the configuration. When theargs
value is a string, it splits the string into an array using whitespace as the delimiter. This approach aims to handle cases whereargs
is provided as a string, converting it to the array format expected by thecodelldb
adapter.I have personally verified that this solution works for my specific use case with the
codelldb
adapter.Limitations and Considerations
While this solution addresses the immediate issue, it's important to note that it may not cover all scenarios. Some potential limitations include:
A more robust solution might involve:
Further testing and refinement would be necessary to ensure this solution works correctly across various use cases and debug adapters.
Considered Alternatives
No response
Claim
This problem description and proposed solution have been refined with the assistance of an AI language model. As the original author is not a native English speaker, the AI has helped to improve clarity and expression while maintaining the original intent and technical accuracy of the content. The possible solutions, including the code modification and discussion of its limitations, are based on the author's original ideas and implementation. The AI has assisted in organizing and articulating these ideas more clearly, but the technical content and verification of the solution's effectiveness come from the author's own experience and testing.
The text was updated successfully, but these errors were encountered: