@@ -315,6 +315,176 @@ require("dap-python").setup("python", {
315315 include_configs = true ,
316316})
317317
318+ dap .adapters .lldb = {
319+ type = " executable" ,
320+ command = " /usr/bin/lldb-vscode-12" ,
321+ name = " lldb" ,
322+ }
323+
324+ local extension_path = vim .fn .expand " ~/.vscode/extensions/vadimcn.vscode-lldb-1.6.10/"
325+ local codelldb_path = extension_path .. " adapter/codelldb"
326+ local liblldb_path = extension_path .. " lldb/lib/liblldb.so"
327+
328+ -- dap.adapters.rt_lldb = {
329+ -- type = "executable",
330+ -- command = codelldb_path,
331+ -- name = "rt_lldb",
332+ -- }
333+
334+ dap .adapters .rt_lldb = function (callback , _ )
335+ local stdout = vim .loop .new_pipe (false )
336+ local stderr = vim .loop .new_pipe (false )
337+ local handle
338+ local pid_or_err
339+ local port
340+ local error_message = " "
341+
342+ local opts = {
343+ stdio = { nil , stdout , stderr },
344+ args = { " --liblldb" , liblldb_path },
345+ detached = true ,
346+ }
347+
348+ handle , pid_or_err = vim .loop .spawn (codelldb_path , opts , function (code )
349+ stdout :close ()
350+ stderr :close ()
351+ handle :close ()
352+ if code ~= 0 then
353+ print (" codelldb exited with code" , code )
354+ print (" error message" , error_message )
355+ end
356+ end )
357+
358+ assert (handle , " Error running codelldb: " .. tostring (pid_or_err ))
359+
360+ stdout :read_start (function (err , chunk )
361+ assert (not err , err )
362+ if chunk then
363+ if not port then
364+ local chunks = {}
365+ for substring in chunk :gmatch " %S+" do
366+ table.insert (chunks , substring )
367+ end
368+ port = tonumber (chunks [# chunks ])
369+ vim .schedule (function ()
370+ callback {
371+ type = " server" ,
372+ host = " 127.0.0.1" ,
373+ port = port ,
374+ }
375+ end )
376+ else
377+ vim .schedule (function ()
378+ require (" dap.repl" ).append (chunk )
379+ end )
380+ end
381+ end
382+ end )
383+ stderr :read_start (function (_ , chunk )
384+ if chunk then
385+ error_message = error_message .. chunk
386+
387+ vim .schedule (function ()
388+ require (" dap.repl" ).append (chunk )
389+ end )
390+ end
391+ end )
392+ end
393+
394+ -- function M.setup_adapter()
395+ -- local dap = require("dap")
396+ -- dap.adapters.rt_lldb = config.options.dap.adapter
397+ -- end
398+
399+ function StartRustServer (args )
400+ args = args or {}
401+
402+ if not pcall (require , " dap" ) then
403+ vim .notify " nvim-dap not found."
404+ return
405+ end
406+
407+ if not pcall (require , " plenary.job" ) then
408+ vim .notify " plenary not found."
409+ return
410+ end
411+
412+ local Job = require " plenary.job"
413+
414+ -- local cargo_args = get_cargo_args_from_runnables_args(args)
415+
416+ vim .notify " Compiling a debug build for debugging. This might take some time..."
417+
418+ Job
419+ :new ({
420+ command = " cargo" ,
421+ args = { " build" , " --message-format=json" },
422+ cwd = nil ,
423+ on_exit = function (j , code )
424+ if code and code > 0 then
425+ vim .notify " An error occured while compiling. Please fix all compilation issues and try again."
426+ end
427+ vim .schedule (function ()
428+ for _ , value in pairs (j :result ()) do
429+ local json = vim .fn .json_decode (value )
430+ if type (json ) == " table" and json .executable ~= vim .NIL and json .executable ~= nil then
431+ local dap_config = {
432+ name = " Rust tools debug" ,
433+ type = " rt_lldb" ,
434+ request = " launch" ,
435+ program = json .executable ,
436+ args = args .executableArgs or { " lsif" , " /home/tjdevries/build/rmpv/" },
437+ cwd = args .workspaceRoot ,
438+ stopOnEntry = false ,
439+ runInTerminal = false ,
440+ }
441+ dap .run (dap_config )
442+
443+ break
444+ end
445+ end
446+ end )
447+ end ,
448+ })
449+ :start ()
450+ end
451+
452+ dap .configurations .rust = {
453+ {
454+ name = " Launch" ,
455+ type = " lldb" ,
456+ request = " launch" ,
457+ program = function ()
458+ return vim .fn .input (" Path to executable: " , vim .fn .getcwd () .. " /" , " file" )
459+ end ,
460+ cwd = " ${workspaceFolder}" ,
461+ stopOnEntry = false ,
462+ args = {},
463+
464+ -- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
465+ --
466+ -- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
467+ --
468+ -- Otherwise you might get the following error:
469+ --
470+ -- Error on launch: Failed to attach to the target process
471+ --
472+ -- But you should be aware of the implications:
473+ -- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
474+ runInTerminal = false ,
475+ },
476+ {
477+ name = " Launch rust-analyzer lsif" ,
478+ type = " lldb" ,
479+ request = " launch" ,
480+ program = " /home/tjdevries/sourcegraph/rust-analyzer.git/monikers-1/target/debug/rust-analyzer" ,
481+ args = { " lsif" , " /home/tjdevries/build/rmpv/" },
482+ cwd = " /home/tjdevries/sourcegraph/rust-analyzer.git/monikers-1/" ,
483+ stopOnEntry = false ,
484+ runInTerminal = false ,
485+ },
486+ }
487+
318488vim .cmd [[ nnoremap <silent> <F5> :lua require'dap'.continue()<CR>]]
319489vim .cmd [[ nnoremap <silent> <F1> :lua require'dap'.step_into()<CR>]]
320490vim .cmd [[ nnoremap <silent> <F10> :lua require'dap'.step_over()<CR>]]
0 commit comments