From 6c292874c8964712c1718a6370652f323cfbd630 Mon Sep 17 00:00:00 2001 From: jxl Date: Thu, 17 Oct 2024 17:18:26 +0800 Subject: [PATCH] use fnamemodify to get parent path instead of writing our own function --- lua/dap-go.lua | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/lua/dap-go.lua b/lua/dap-go.lua index 1f0ad2c..caaee92 100644 --- a/lua/dap-go.lua +++ b/lua/dap-go.lua @@ -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) @@ -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