Skip to content

Commit

Permalink
use fnamemodify to get parent path instead of writing our own function
Browse files Browse the repository at this point in the history
  • Loading branch information
jxl committed Oct 17, 2024
1 parent b49e81a commit 6c29287
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions lua/dap-go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,6 @@ local function filtered_pick_process()
return require("dap.utils").pick_process(opts)
end

local get_parent = (function()
local sep = "\\"

local os = string.lower(jit.os)
if os ~= "windows" then
sep = "/"
end

local pattern = string.format("^(.+)%s[^%s]+", sep, sep)

return function(abs_path)
local parent = abs_path:match(pattern)
if parent ~= nil and not parent:find(sep) then
return parent .. sep
end
return parent
end
end)()

local function setup_delve_adapter(dap, config)
local args = { "dap", "-l", "127.0.0.1:" .. config.delve.port }
vim.list_extend(args, config.delve.args)
Expand Down Expand Up @@ -109,8 +90,8 @@ local function setup_delve_adapter(dap, config)
local is_dir = vim.loop.fs_stat(program_absolute).type == "directory"
if is_dir then
delve_config.executable.cwd = program_absolute
elseif program_absolute:sub(-3) == ".go" then -- file extension is '.go'
local parent = get_parent(program_absolute)
elseif vim.fn.fnamemodify(program_absolute, ":e") == ".go" then -- file extension is '.go'
local parent = vim.fn.fnamemodify(program_absolute, ":p:h")
if parent ~= nil then
delve_config.executable.cwd = parent
end
Expand Down

0 comments on commit 6c29287

Please sign in to comment.