feat(neovim): dynamically set the cwd for dap in dotnet debugging
This commit is contained in:
parent
62c04dfd25
commit
0596629c20
1 changed files with 22 additions and 13 deletions
|
@ -1,14 +1,24 @@
|
||||||
---@class CSFTPlugin.Project
|
---@class CSFTPlugin.Project
|
||||||
---@field dll_path string
|
---@field dll_path string
|
||||||
---@field name string
|
---@field name string
|
||||||
|
---@field project_path string
|
||||||
---@field target_framework string
|
---@field target_framework string
|
||||||
|
|
||||||
|
---@class CSFTPlugin.LaunchOptions: dap.Configuration
|
||||||
|
---@field cwd string
|
||||||
|
---@field program (fun(): thread)?
|
||||||
|
|
||||||
---@class CSFTPlugin
|
---@class CSFTPlugin
|
||||||
---@field dotnet_cmd string?
|
---@field dotnet_cmd string?
|
||||||
---@field projects CSFTPlugin.Project[]
|
---@field launch_options CSFTPlugin.LaunchOptions?
|
||||||
local M = {
|
local M = {
|
||||||
dotnet_cmd = vim.fn.exepath "dotnet",
|
dotnet_cmd = vim.fn.exepath "dotnet",
|
||||||
projects = {},
|
launch_options = {
|
||||||
|
cwd = "${env:CSPROJ_LOCATION}",
|
||||||
|
name = "Launch project DLL",
|
||||||
|
request = "launch",
|
||||||
|
type = "netcoredbg",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
---@param command string The shell command to execute
|
---@param command string The shell command to execute
|
||||||
|
@ -39,6 +49,7 @@ end
|
||||||
|
|
||||||
---@return CSFTPlugin.Project[]
|
---@return CSFTPlugin.Project[]
|
||||||
function M.find_projects()
|
function M.find_projects()
|
||||||
|
---@type CSFTPlugin.Project[]
|
||||||
local projects = {}
|
local projects = {}
|
||||||
|
|
||||||
local csproj_extension = ".csproj"
|
local csproj_extension = ".csproj"
|
||||||
|
@ -54,8 +65,9 @@ function M.find_projects()
|
||||||
local target_framework = M.cmd("rg -e 'TargetFramework>(.*)<' -r '$1' -o " .. file_path)[1]
|
local target_framework = M.cmd("rg -e 'TargetFramework>(.*)<' -r '$1' -o " .. file_path)[1]
|
||||||
|
|
||||||
projects[#projects + 1] = {
|
projects[#projects + 1] = {
|
||||||
dll_path = project_location .. "bin/Debug/" .. target_framework .. "/" .. project_name .. ".dll",
|
dll_path = "bin/Debug/" .. target_framework .. "/" .. project_name .. ".dll",
|
||||||
name = project_name,
|
name = project_name,
|
||||||
|
project_path = vim.fn.simplify(vim.fn.getcwd() .. "/" .. project_location),
|
||||||
target_framework = target_framework,
|
target_framework = target_framework,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -106,6 +118,8 @@ function M:choose_dll()
|
||||||
self:run "build"
|
self:run "build"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vim.fn.setenv("CSPROJ_LOCATION", item.project_path)
|
||||||
|
|
||||||
coroutine.resume(search_coroutine, path)
|
coroutine.resume(search_coroutine, path)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
@ -133,17 +147,12 @@ function M:start()
|
||||||
args = { "--interpreter=vscode" },
|
args = { "--interpreter=vscode" },
|
||||||
}
|
}
|
||||||
|
|
||||||
---@type dap.Configuration[]
|
self.launch_options.program = function()
|
||||||
dap.configurations.cs = {
|
|
||||||
{
|
|
||||||
type = "netcoredbg",
|
|
||||||
name = "Launch project DLL",
|
|
||||||
request = "launch",
|
|
||||||
program = function()
|
|
||||||
return self:choose_dll()
|
return self:choose_dll()
|
||||||
end,
|
end
|
||||||
},
|
|
||||||
}
|
---@type dap.Configuration[]
|
||||||
|
dap.configurations.cs = { self.launch_options }
|
||||||
|
|
||||||
vim.g.loaded_csftplugin = true
|
vim.g.loaded_csftplugin = true
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue