@@ -65,3 +65,44 @@ _G._toggle_lazygit = function()
6565 vim .notify (" Command [lazygit] not found!" , vim .log .levels .ERROR , { title = " toggleterm.nvim" })
6666 end
6767end
68+
69+ _G .async_compile_and_debug = function ()
70+ local file_ext = vim .fn .expand (" %:e" )
71+ local file_path = vim .fn .expand (" %:p" )
72+ local out_name = vim .fn .expand (" %:p:h" ) .. " /" .. vim .fn .expand (" %:t:r" ) .. " .out"
73+ local compile_cmd
74+ if file_ext == " cpp" or file_ext == " cc" then
75+ compile_cmd = string.format (" g++ -g %s -o %s" , file_path , out_name )
76+ elseif file_ext == " c" then
77+ compile_cmd = string.format (" gcc -g %s -o %s" , file_path , out_name )
78+ elseif file_ext == " go" then
79+ compile_cmd = string.format (" go build -o %s %s" , out_name , file_path )
80+ elseif file_ext == " java" then
81+ compile_cmd = string.format (" javac %s" , file_path )
82+ elseif file_ext == " rs" then
83+ compile_cmd = string.format (" rustc %s -o %s" , file_path , out_name )
84+ else
85+ require (" dap" ).continue ()
86+ return
87+ end
88+ local notify_title = " Debug Pre-compile"
89+ vim .fn .jobstart (compile_cmd , {
90+ on_exit = function (_ , exit_code , _ )
91+ if exit_code == 0 then
92+ vim .notify (
93+ " Compilation succeeded! Executable: " .. out_name ,
94+ vim .log .levels .INFO ,
95+ { title = notify_title }
96+ )
97+ require (" dap" ).continue ()
98+ return
99+ else
100+ vim .notify (
101+ " Compilation failed with exit code: " .. exit_code ,
102+ vim .log .levels .ERROR ,
103+ { title = notify_title }
104+ )
105+ end
106+ end ,
107+ })
108+ end
0 commit comments