mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
fix(dap): parse quoted strings as single argument
This commit is contained in:
parent
90a92312ae
commit
f87c5312ce
1 changed files with 40 additions and 1 deletions
|
|
@ -4,8 +4,47 @@ local function get_args(config)
|
||||||
config = vim.deepcopy(config)
|
config = vim.deepcopy(config)
|
||||||
---@cast args string[]
|
---@cast args string[]
|
||||||
config.args = function()
|
config.args = function()
|
||||||
|
-- Prompt the user with the current arguments as a default input
|
||||||
local new_args = vim.fn.input("Run with args: ", table.concat(args, " ")) --[[@as string]]
|
local new_args = vim.fn.input("Run with args: ", table.concat(args, " ")) --[[@as string]]
|
||||||
return vim.split(vim.fn.expand(new_args) --[[@as string]], " ")
|
local expanded_args = vim.fn.expand(new_args) -- Expand any environment variables, wildcards, etc.
|
||||||
|
|
||||||
|
-- Initialize result table to collect parsed arguments
|
||||||
|
local result = {}
|
||||||
|
|
||||||
|
-- Pattern to match quoted strings or non-space sequences
|
||||||
|
local i = 1
|
||||||
|
while i <= #expanded_args do
|
||||||
|
local character = expanded_args:sub(i, i)
|
||||||
|
if character == " " then
|
||||||
|
i = i + 1
|
||||||
|
elseif character == '"' then
|
||||||
|
-- Handle quoted string
|
||||||
|
local end_quote = expanded_args:find('"', i + 1)
|
||||||
|
if end_quote then
|
||||||
|
local arg = expanded_args:sub(i + 1, end_quote - 1)
|
||||||
|
table.insert(result, arg)
|
||||||
|
i = end_quote + 1
|
||||||
|
else
|
||||||
|
-- If no closing quote found, take the rest of the string
|
||||||
|
table.insert(result, expanded_args:sub(i + 1))
|
||||||
|
break
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- Handle unquoted argument
|
||||||
|
local next_space = expanded_args:find(" ", i)
|
||||||
|
if next_space then
|
||||||
|
local arg = expanded_args:sub(i, next_space - 1)
|
||||||
|
table.insert(result, arg)
|
||||||
|
i = next_space + 1
|
||||||
|
else
|
||||||
|
-- Take the rest of the string
|
||||||
|
table.insert(result, expanded_args:sub(i))
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
return config
|
return config
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue