diff options
| author | Elvis Claros Castro <elvis@claros.ar> | 2024-07-12 11:18:14 -0300 |
|---|---|---|
| committer | Elvis Claros Castro <elvis@claros.ar> | 2024-07-12 11:18:14 -0300 |
| commit | ea0f4bf8ffade657b1d45152dbc183d4679e75c4 (patch) | |
| tree | cc1fb023bc308e019ddce33a4b0aed39f56805dc /lua/pi/dap | |
| parent | 1fd0af14d592d612c2aaab7717c04c8806ba3daa (diff) | |
| download | nvim-conf-ea0f4bf8ffade657b1d45152dbc183d4679e75c4.tar.gz nvim-conf-ea0f4bf8ffade657b1d45152dbc183d4679e75c4.zip | |
Feat: PI
Diffstat (limited to 'lua/pi/dap')
| -rw-r--r-- | lua/pi/dap/configs/dart.lua | 32 | ||||
| -rw-r--r-- | lua/pi/dap/configs/elixir.lua | 52 | ||||
| -rw-r--r-- | lua/pi/dap/configs/golang.lua | 1 | ||||
| -rw-r--r-- | lua/pi/dap/configs/javascript.lua | 62 | ||||
| -rw-r--r-- | lua/pi/dap/configs/kotlin.lua | 18 | ||||
| -rw-r--r-- | lua/pi/dap/configs/php.lua | 27 | ||||
| -rw-r--r-- | lua/pi/dap/configs/rust.lua | 57 | ||||
| -rw-r--r-- | lua/pi/dap/init.lua | 108 |
8 files changed, 357 insertions, 0 deletions
diff --git a/lua/pi/dap/configs/dart.lua b/lua/pi/dap/configs/dart.lua new file mode 100644 index 0000000..a23c118 --- /dev/null +++ b/lua/pi/dap/configs/dart.lua @@ -0,0 +1,32 @@ +local dap = require('dap') + +dap.adapters.dart = { + type = "executable", + -- As of this writing, this functionality is open for review in https://github.com/flutter/flutter/pull/91802 + command = "flutter", + args = {"debug_adapter"} +} +dap.configurations.dart = { + { + name = "Launch Flutter Program Linux", + type = "dart", + request = "launch", + -- The nvim-dap plugin populates this variable with the filename of the current buffer + program = "${file}", + -- The nvim-dap plugin populates this variable with the editor's current working directory + cwd = "${workspaceFolder}", + -- This gets forwarded to the Flutter CLI tool, substitute `linux` for whatever device you wish to launch + toolArgs = {"-d", "linux"} + }, + { + name = "Launch Flutter Program Motorola", + type = "dart", + request = "launch", + -- The nvim-dap plugin populates this variable with the filename of the current buffer + program = "${file}", + -- The nvim-dap plugin populates this variable with the editor's current working directory + cwd = "${workspaceFolder}", + -- This gets forwarded to the Flutter CLI tool, substitute `linux` for whatever device you wish to launch + toolArgs = {"-d", "192.168.0.33:5555"} + } +} diff --git a/lua/pi/dap/configs/elixir.lua b/lua/pi/dap/configs/elixir.lua new file mode 100644 index 0000000..bf732ce --- /dev/null +++ b/lua/pi/dap/configs/elixir.lua @@ -0,0 +1,52 @@ +local dap = require('dap') + +dap.adapters.mix_task = { + type = 'executable', + command = 'elixir-ls-debugger', -- El comando 'elixir-ls' está en $PATH + args = {} +} + +dap.configurations.elixir = { + { + type = "mix_task", + name = "mix (Default task)", + request = "launch", + projectDir = "${workspaceRoot}" + }, + { + type = "mix_task", + name = "mix test", + request = "launch", + task = 'test', + env = { + MIX_ENV = "test", + MIX_TARGET = "host", + HEX_UNSAFE_HTTPS = 1 + }, + taskArgs = {"--trace"}, + startApps = true, -- for Phoenix projects + projectDir = "${workspaceFolder}", + requireFiles = { + "test/**/test_helper.exs", + "test/**/*_test.exs" + } + }, + { + type = "mix_task", + name = "phx server", + request = "launch", + stackTraceMode = "all", + task = 'phx.server', + debugAutoInterpretAllModules = true, + noDebug = false, + exitAfterTaskReturns = false, + env = { + MIX_ENV = "dev", + MIX_TARGET = "host", + HEX_UNSAFE_HTTPS = 1 + }, + startApps = false, -- for Phoenix projects + taskArgs = {"--no-halt", "--open"}, + projectDir = "${workspaceFolder}", + }, +} diff --git a/lua/pi/dap/configs/golang.lua b/lua/pi/dap/configs/golang.lua new file mode 100644 index 0000000..1ec449a --- /dev/null +++ b/lua/pi/dap/configs/golang.lua @@ -0,0 +1 @@ +require("dap-go").setup() diff --git a/lua/pi/dap/configs/javascript.lua b/lua/pi/dap/configs/javascript.lua new file mode 100644 index 0000000..03173ba --- /dev/null +++ b/lua/pi/dap/configs/javascript.lua @@ -0,0 +1,62 @@ +local dap = require('dap') +dap.adapters.firefox = { + type = 'executable', + command = 'firefox-debug-adapter', +} + +dap.configurations.typescript = { + { + name = 'Debug with Firefox', + type = 'firefox', + request = 'launch', + reAttach = true, + url = 'http://localhost:3010', + webRoot = '${workspaceFolder}', + firefoxExecutable = '/home/elvis/.local/bin/firefox' + }, +} +-- require("dap-vscode-js").setup { +-- debugger_cmd = { "js-debug-adapter" }, +-- adapters = { "pwa-node", "pwa-chrome", "node-terminal" }, +-- } +-- +-- for _, language in ipairs { "typescript", "javascript" } do +-- require("dap").configurations[language] = { +-- { +-- type = "pwa-node", +-- request = "launch", +-- name = "Launch file", +-- program = "${file}", +-- cwd = "${workspaceFolder}", +-- }, +-- { +-- type = "pwa-node", +-- request = "attach", +-- name = "Attach", +-- processId = require("dap.utils").pick_process, +-- cwd = "${workspaceFolder}", +-- }, +-- } +-- end +-- +-- for _, language in ipairs { "typescriptreact", "javascriptreact" } do +-- require("dap").configurations[language] = { +-- { +-- type = "pwa-chrome", +-- name = "Attach - Remote Debugging", +-- request = "attach", +-- program = "${file}", +-- cwd = vim.fn.getcwd(), +-- sourceMaps = true, +-- protocol = "inspector", +-- port = 9222, +-- webRoot = "${workspaceFolder}", +-- }, +-- { +-- type = "pwa-chrome", +-- name = "Launch Chrome", +-- request = "launch", +-- url = "http://localhost:3000", +-- }, +-- } +-- end diff --git a/lua/pi/dap/configs/kotlin.lua b/lua/pi/dap/configs/kotlin.lua new file mode 100644 index 0000000..aa486db --- /dev/null +++ b/lua/pi/dap/configs/kotlin.lua @@ -0,0 +1,18 @@ +local dap = require('dap') + +dap.adapters.kotlin = { + type = 'executable'; + command = "kotlin-debug-adapter"; +} + +dap.configurations.kotlin = { + { + type = 'kotlin', + request = 'launch', + program = "${file}", + name = 'Launch kotlin program', + projectRoot = "${workspaceFolder}/app", + mainClass = "AppKt", + } +} +dap.defaults.kotlin.auto_continue_if_many_stopped = false diff --git a/lua/pi/dap/configs/php.lua b/lua/pi/dap/configs/php.lua new file mode 100644 index 0000000..968bb9d --- /dev/null +++ b/lua/pi/dap/configs/php.lua @@ -0,0 +1,27 @@ +local dap = require("dap") + +dap.adapters.php = { + type = "executable", + command = "php-debug-adapter", +} + +dap.configurations.php = { + { + type = "php", + request = "launch", + name = "Laravel", + port = 9003, + pathMappings = { + ["/var/www/html"] = "${workspaceFolder}", + }, + }, + { + type = "php", + request = "launch", + name = "Symfony", + port = 9003, + pathMappings = { + ["/app"] = "${workspaceFolder}", + }, + }, +} diff --git a/lua/pi/dap/configs/rust.lua b/lua/pi/dap/configs/rust.lua new file mode 100644 index 0000000..9ca976f --- /dev/null +++ b/lua/pi/dap/configs/rust.lua @@ -0,0 +1,57 @@ +local dap = require("dap") + +local rust_adapter = nil +local rust_adapters = { "lldb-vscode", "codelldb" } +for _, adapter in pairs(rust_adapters) do + if vim.fn.executable(adapter) then + rust_adapter = adapter + end +end + +if rust_adapter ~= nil then + dap.adapters.lldb = { + type = "executable", + command = rust_adapter, + name = "lldb", + } + + dap.configurations.rust = { + { + name = "launch", + type = "lldb", + request = "launch", + program = function() + local dir = vim.fn.getcwd() + return dir .. "/target/debug/" .. vim.fs.basename(dir) + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + args = function() + local resp = vim.fn.input "Arguments: " + if resp == "" then + return {} + end + + return vim.fn.split(resp, " ") + end, + }, + { + name = "custom", + type = "lldb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + args = function() + local resp = vim.fn.input "Arguments: " + if resp == "" then + return {} + end + + return vim.fn.split(resp, " ") + end, + }, + } +end diff --git a/lua/pi/dap/init.lua b/lua/pi/dap/init.lua new file mode 100644 index 0000000..327dedf --- /dev/null +++ b/lua/pi/dap/init.lua @@ -0,0 +1,108 @@ +local dap, dapui, hydra = require "dap", require "dapui", require "hydra" + +dap.set_log_level('TRACE') + +-- Setup Virtual Text +require("nvim-dap-virtual-text").setup {} + +for _, ft_path in ipairs(vim.api.nvim_get_runtime_file("lua/pi/dap/configs/*.lua", true)) do + loadfile(ft_path)() +end + +-- Signs +vim.fn.sign_define("DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapStopped", { text = "▶", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapBreakpointRejected", { text = "🚫", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapBreakpointCondition", { text = "❓", texthl = "", linehl = "", numhl = "" }) +vim.fn.sign_define("DapLogPoint", { text = "💬", texthl = "", linehl = "", numhl = "" }) + +-- UI structure +dapui.setup { + icons = { expanded = "▾", collapsed = "▸" }, + layouts = { + { + elements = { + "scopes", + "breakpoints", + "stacks", + "watches", + }, + size = 50, + position = "right", + }, + { + elements = { + "repl", + "console", + }, + size = 7, + position = "bottom", + }, + }, +} + +-- Events Listeners +dap.listeners.after.event_initialized["dapui_config"] = function() + dapui.open {} +end + +local hint = [[ + Nvim DAP + _d_: Start/Continue _j_: StepOver _k_: StepOut _l_: StepInto ^ + _bp_: Toogle Breakpoint _bc_: Conditional Breakpoint ^ + _?_: log point ^ + _c_: Run To Cursor ^ + _h_: Show information of the variable under the cursor ^ + _x_: Stop Debbuging ^ + ^^ _<Esc>_ +]] + +hydra { + name = "dap", + hint = hint, + mode = "n", + config = { + color = "blue", + invoke_on_body = true, + hint = { + border = "rounded", + position = "bottom", + }, + }, + body = "<leader>d", + heads = { + { "d", dap.continue }, + { "bp", dap.toggle_breakpoint }, + { "l", dap.step_into }, + { "j", dap.step_over }, + { "k", dap.step_out }, + { "h", dapui.eval }, + { "c", dap.run_to_cursor }, + { + "bc", + function() + vim.ui.input({ prompt = "Condition: " }, function(condition) + dap.set_breakpoint(condition) + end) + end, + }, + { + "?", + function() + vim.ui.input({ prompt = "Log: " }, function(log) + dap.set_breakpoint(nil, nil, log) + end) + end, + }, + { + "x", + function() + dap.terminate() + dapui.close {} + dap.clear_breakpoints() + end, + }, + + { "<Esc>", nil, { exit = true } }, + }, +} |