Skip to content

Commit 1313a98

Browse files
Marc TalcottMarc Talcott
authored andcommitted
fixed Dap Debug for .net
1 parent 6108707 commit 1313a98

File tree

2 files changed

+135
-6
lines changed

2 files changed

+135
-6
lines changed

lua/plugins/debug.lua

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,42 @@ return {
88
'nvim-neotest/nvim-nio',
99

1010
-- Installs the debug adapters for you
11-
'williamboman/mason.nvim',
11+
-- 'williamboman/mason.nvim',
1212
'jay-babu/mason-nvim-dap.nvim',
1313

1414
-- Add your own debuggers here
1515
'leoluz/nvim-dap-go',
16+
'dotnet/vscode-csharp',
17+
18+
-- virtual Text
19+
'theHamsta/nvim-dap-virtual-text',
1620
},
1721
config = function()
1822
require('dapui').setup()
1923
require('dap-go').setup()
20-
24+
require('nvim-dap-virtual-text').setup()
25+
require('lspconfig').omnisharp.setup {}
26+
require('dap.ext.vscode').load_launchjs(nil, {})
2127
local dap, dapui = require 'dap', require 'dapui'
28+
local ph_status, dotnet_ph = pcall(require, 'utilities.path_finder')
29+
dap.adapters.coreclr = {
30+
type = 'executable',
31+
command = 'netcoredbg',
32+
args = { '--interpreter=vscode' },
33+
}
34+
35+
dap.configurations.cs = {
36+
{
37+
type = 'coreclr',
38+
name = 'launch - netcoredbg',
39+
request = 'launch',
40+
program = function()
41+
-- return vim.fn.input('Path to dll:', '/Users/marctalcott/Documents/Projects/DotNetProjects/HelloWorld/bin/Debug/net8.0/', 'file')
42+
return vim.fn.input('Path to dll: ', vim.fn.getcwd() .. '/bin/Debug/net8.0/', 'file')
43+
end,
44+
console = 'integratedTerminal',
45+
},
46+
}
2247

2348
dap.listeners.before.attach.dapui_config = function()
2449
dapui.open()
@@ -33,9 +58,25 @@ return {
3358
dapui.close()
3459
end
3560

36-
vim.keymap.set('n', '<Leader>db', ':DapToggleBreakpoint<CR>')
37-
vim.keymap.set('n', '<Leader>dc', ':DapContinue<CR>')
38-
vim.keymap.set('n', '<Leader>dx', ':DapTerminate<CR>')
39-
vim.keymap.set('n', '<Leader>do', ':DapStepOver<CR>')
61+
-- Keymaps for all
62+
vim.fn.sign_define('DapBreakpoint', { text = '🔴', texthl = 'DapBreakpoint', linehl = 'DapBreakpoint', numhl = 'DapBreakpoint' })
63+
64+
vim.keymap.set('n', '<Leader>db', dap.toggle_breakpoint, { desc = '[d]ebug toggle [b]reakpoint' })
65+
vim.keymap.set('n', '<Leader>dc', dap.continue, { desc = '[d]ebug [c]continue' })
66+
vim.keymap.set('n', '<Leader>dC', dap.close, { desc = '[d]ebug [C]lose' })
67+
vim.keymap.set('n', '<F5>', dap.continue, { desc = 'Debug Continue' })
68+
69+
vim.keymap.set('n', '<F8>', dap.step_over, { desc = 'Step Over' })
70+
vim.keymap.set('n', '<F9>', dap.step_out, { desc = 'Step Out' })
71+
vim.keymap.set('n', '<F10>', dap.step_into, { desc = 'Step Into' })
72+
vim.keymap.set('n', '<F12>', dap.terminate, { desc = 'Terminate' })
73+
vim.keymap.set('n', '<Leader>dx', dap.terminate, { desc = 'Terminate' })
74+
vim.keymap.set('n', '<Leader>do', dap.step_over, { desc = 'Step over' })
75+
vim.keymap.set('n', '<Leader>dr', dap.restart, { desc = 'Restart' })
76+
vim.api.nvim_set_keymap('n', '<leader>dR', ":lua require('dapui').open({reset = true})<CR>", { noremap = true })
77+
vim.api.nvim_set_keymap('n', '<leader>ht', ":lua require('harpoon.ui').toggle_quick_menu()<CR>", { noremap = true })
78+
vim.keymap.set('n', '<Leader>?', function()
79+
require('dapui').eval(nil, { enter = true })
80+
end, { desc = 'Restart' })
4081
end,
4182
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
-- Check to see if path is a part of the config.projects, if so set last_proj_path and last_dll_path
2+
function M.GetProjConfig(path, config)
3+
local result = {}
4+
if config == nil then
5+
return result
6+
end
7+
local projects = config.projects
8+
9+
if projects == nil then
10+
return result
11+
end
12+
for _, project in ipairs(projects) do
13+
if project.base_path and string.find(path, project.base_path) then
14+
-- TODO: nil check, if even needed.
15+
-- TODO: these names make no sense
16+
result.dotnet_last_proj_path = project.dotnet_proj_file
17+
result.dotnet_last_dll_path = project.dotnet_dll_path
18+
result.dotnet_debug_cwd = project.dotnet_debug_cwd
19+
result.project_found = true
20+
return result
21+
end
22+
end
23+
result.project_found = false
24+
return result
25+
end
26+
27+
function M.search_up_path(project_root, path, pattern_func)
28+
local parent = vim.fn.fnamemodify(path, ':h')
29+
-- the parent of 'C:/' is 'C:/'
30+
if parent == path then
31+
return project_root
32+
end
33+
local parent_root = pattern_func(parent)
34+
-- returns nil when no root is found
35+
if parent_root == nil then
36+
return project_root
37+
end
38+
return M.search_up_path(parent_root, parent, pattern_func)
39+
end
40+
41+
function M.dotnet_get_dll_path(path, proj_found)
42+
local request = function()
43+
return vim.fn.input('Path to dll ', vim.fn.getcwd() .. '/bin/Debug/', 'file')
44+
end
45+
46+
if path == nil then
47+
path = request()
48+
print('Dll path: ' .. path)
49+
else
50+
if proj_found == false and vim.fn.confirm('Do you want to change the path to dll?\n' .. path, '&yes\n&no', 2) == 1 then
51+
path = request()
52+
print('Dll path: ' .. path)
53+
end
54+
end
55+
56+
return path
57+
end
58+
59+
function M.dotnet_build_project(last_path, config)
60+
local default_path = vim.fn.getcwd() .. '/'
61+
if last_path ~= nil then
62+
default_path = last_path
63+
end
64+
local result = nil
65+
66+
-- If project was found in config, use it
67+
if config.dotnet_last_proj_path ~= nil then
68+
print('Found project in config. Project file path is ' .. config.dotnet_last_proj_path)
69+
result = config.dotnet_last_proj_path
70+
else
71+
-- If the project was not found, always ask for it, but fill in the last path
72+
result = vim.fn.input('Path to your *proj file', default_path, 'file')
73+
end
74+
75+
local cmd = 'dotnet build -c Debug ' .. result
76+
print ''
77+
print('Cmd to execute: ' .. cmd)
78+
-- TODO: This should be done in async way
79+
local f = os.execute(cmd)
80+
if f == 0 then
81+
print '\nBuild: ✔️ '
82+
else
83+
print('\nBuild: ❌ (code: ' .. f .. ')')
84+
end
85+
return result
86+
end
87+
88+
return M

0 commit comments

Comments
 (0)