From 35637ecca0c38f1b99ab4179db6c2f56651a6e5c Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Thu, 30 Jan 2025 00:12:12 -0600 Subject: [PATCH] fix: use coroutine to get URL --- lazy-lock.json | 1 - lua/plugins/debugging.lua | 485 +++++++++++++++++++------------------- 2 files changed, 246 insertions(+), 240 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index 3f720a9..ff9d5ab 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -29,7 +29,6 @@ "nvim-cmp": { "branch": "main", "commit": "12509903a5723a876abd65953109f926f4634c30" }, "nvim-dap": { "branch": "master", "commit": "1fdfe74661170ce58d37dc46259448987ffe706c" }, "nvim-dap-ui": { "branch": "master", "commit": "bc81f8d3440aede116f821114547a476b082b319" }, - "nvim-dap-vscode-js": { "branch": "main", "commit": "03bd29672d7fab5e515fc8469b7d07cc5994bbf6" }, "nvim-lspconfig": { "branch": "master", "commit": "637293ce23c6a965d2f11dfbf92f604bb1978052" }, "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, "nvim-treesitter": { "branch": "master", "commit": "2206739829518c9ea59dbdb9003e0147fdaf2d1c" }, diff --git a/lua/plugins/debugging.lua b/lua/plugins/debugging.lua index 79828f0..451afed 100644 --- a/lua/plugins/debugging.lua +++ b/lua/plugins/debugging.lua @@ -1,268 +1,275 @@ return { - "mfussenegger/nvim-dap", - dependencies = { - "rcarriga/nvim-dap-ui", - "nvim-neotest/nvim-nio", - }, - config = function() - local dap = require("dap") - local dapui = require("dapui") + "mfussenegger/nvim-dap", + dependencies = { + "rcarriga/nvim-dap-ui", + "nvim-neotest/nvim-nio", + }, + config = function() + local dap = require("dap") + local dapui = require("dapui") - dap.defaults.fallback.exception_breakpoints = { "uncaught" } + dap.defaults.fallback.exception_breakpoints = { "uncaught" } - dapui.setup({ - controls = { - element = "repl", - enabled = true, - icons = { - disconnect = "", - pause = "", - play = "", - run_last = "", - step_back = "", - step_into = "", - step_out = "", - step_over = "", - terminate = "", - }, - }, - element_mappings = {}, - expand_lines = true, - floating = { - border = "rounded", - mappings = { - close = { "q", "" }, - }, - }, - force_buffers = true, - icons = { - collapsed = "", - current_frame = "", - expanded = "", - }, - layouts = { - { - elements = { - { - id = "scopes", - size = 0.25, - }, - { - id = "breakpoints", - size = 0.25, - }, - { - id = "stacks", - size = 0.25, - }, - { - id = "watches", - size = 0.25, - }, - }, - position = "right", - size = 50, - }, - { - elements = { - { - id = "repl", - size = 0.5, - }, - { - id = "console", - size = 0.5, - }, - }, - position = "bottom", - size = 10, - }, - }, - mappings = { - edit = "e", - expand = { "", "<2-LeftMouse>" }, - open = "o", - remove = "d", - repl = "r", - toggle = "t", - }, - render = { - indent = 1, - max_value_lines = 100, - }, - }) + dapui.setup({ + controls = { + element = "repl", + enabled = true, + icons = { + disconnect = "", + pause = "", + play = "", + run_last = "", + step_back = "", + step_into = "", + step_out = "", + step_over = "", + terminate = "", + }, + }, + element_mappings = {}, + expand_lines = true, + floating = { + border = "rounded", + mappings = { + close = { "q", "" }, + }, + }, + force_buffers = true, + icons = { + collapsed = "", + current_frame = "", + expanded = "", + }, + layouts = { + { + elements = { + { + id = "scopes", + size = 0.25, + }, + { + id = "breakpoints", + size = 0.25, + }, + { + id = "stacks", + size = 0.25, + }, + { + id = "watches", + size = 0.25, + }, + }, + position = "right", + size = 50, + }, + { + elements = { + { + id = "repl", + size = 0.5, + }, + { + id = "console", + size = 0.5, + }, + }, + position = "bottom", + size = 10, + }, + }, + mappings = { + edit = "e", + expand = { "", "<2-LeftMouse>" }, + open = "o", + remove = "d", + repl = "r", + toggle = "t", + }, + render = { + indent = 1, + max_value_lines = 100, + }, + }) - for _, adapterType in ipairs({ "node", "chrome", "msedge" }) do - local pwaType = "pwa-" .. adapterType + for _, adapterType in ipairs({ "node", "chrome", "msedge" }) do + local pwaType = "pwa-" .. adapterType - dap.adapters[pwaType] = { - type = "server", - host = "localhost", - port = "${port}", - executable = { - command = "node", - args = { - vim.fn.stdpath("data") .. "/mason/packages/js-debug-adapter/js-debug/src/dapDebugServer.js", - "${port}", - }, - }, - } + dap.adapters[pwaType] = { + type = "server", + host = "localhost", + port = "${port}", + executable = { + command = "node", + args = { + vim.fn.stdpath("data") .. "/mason/packages/js-debug-adapter/js-debug/src/dapDebugServer.js", + "${port}", + }, + }, + } - -- this allow us to handle launch.json configurations - -- which specify type as "node" or "chrome" or "msedge" - dap.adapters[adapterType] = function(cb, config) - local nativeAdapter = dap.adapters[pwaType] + -- this allow us to handle launch.json configurations + -- which specify type as "node" or "chrome" or "msedge" + dap.adapters[adapterType] = function(cb, config) + local nativeAdapter = dap.adapters[pwaType] - config.type = pwaType + config.type = pwaType - if type(nativeAdapter) == "function" then - nativeAdapter(cb, config) - else - cb(nativeAdapter) - end - end - end + if type(nativeAdapter) == "function" then + nativeAdapter(cb, config) + else + cb(nativeAdapter) + end + end + end - local enter_launch_url = function() - local url = vim.fn.input("URL to launch: ", "http://localhost:") - vim.cmd('echo ""') - return url - end + local enter_launch_url = function() + local co = coroutine.running() + return coroutine.create(function() + vim.ui.input({ prompt = "Enter URL: ", default = "http://localhost:" }, function(url) + if url == nil or url == "" then + return + else + coroutine.resume(co, url) + end + end) + end) + end - for _, language in ipairs({ "typescript", "javascript", "typescriptreact", "javascriptreact", "vue" }) do - dap.configurations[language] = { - { - type = "pwa-node", - request = "launch", - name = "Launch file using Node.js (nvim-dap)", - program = "${file}", - cwd = "${workspaceFolder}", - }, - { - type = "pwa-node", - request = "attach", - name = "Attach to process using Node.js (nvim-dap)", - processId = require("dap.utils").pick_process, - cwd = "${workspaceFolder}", - }, - -- requires ts-node to be installed globally or locally - { - type = "pwa-node", - request = "launch", - name = "Launch file using Node.js with ts-node/register (nvim-dap)", - program = "${file}", - cwd = "${workspaceFolder}", - runtimeArgs = { "-r", "ts-node/register" }, - }, - { - type = "pwa-chrome", - request = "launch", - name = "Launch Chrome (nvim-dap)", - url = enter_launch_url, - webRoot = "${workspaceFolder}", - sourceMaps = true, - }, - { - type = "pwa-msedge", - request = "launch", - name = "Launch Edge (nvim-dap)", - url = enter_launch_url, - webRoot = "${workspaceFolder}", - sourceMaps = true, - }, - } - end + for _, language in ipairs({ "typescript", "javascript", "typescriptreact", "javascriptreact", "vue" }) do + dap.configurations[language] = { + { + type = "pwa-node", + request = "launch", + name = "Launch file using Node.js (nvim-dap)", + program = "${file}", + cwd = "${workspaceFolder}", + }, + { + type = "pwa-node", + request = "attach", + name = "Attach to process using Node.js (nvim-dap)", + processId = require("dap.utils").pick_process, + cwd = "${workspaceFolder}", + }, + -- requires ts-node to be installed globally or locally + { + type = "pwa-node", + request = "launch", + name = "Launch file using Node.js with ts-node/register (nvim-dap)", + program = "${file}", + cwd = "${workspaceFolder}", + runtimeArgs = { "-r", "ts-node/register" }, + }, + { + type = "pwa-chrome", + request = "launch", + name = "Launch Chrome (nvim-dap)", + url = enter_launch_url, + webRoot = "${workspaceFolder}", + sourceMaps = true, + }, + { + type = "pwa-msedge", + request = "launch", + name = "Launch Edge (nvim-dap)", + url = enter_launch_url, + webRoot = "${workspaceFolder}", + sourceMaps = true, + }, + } + end - dap.adapters.coreclr = { - type = "executable", - command = "C:/Users/sfree/AppData/Local/nvim-data/mason/packages/netcoredbg/netcoredbg/netcoredbg.exe", - args = { "--interpreter=vscode" }, - } + dap.adapters.coreclr = { + type = "executable", + command = "C:/Users/sfree/AppData/Local/nvim-data/mason/packages/netcoredbg/netcoredbg/netcoredbg.exe", + args = { "--interpreter=vscode" }, + } - local dotnet_build_project = function() - local default_path = vim.fn.getcwd() .. "/" + local dotnet_build_project = function() + local default_path = vim.fn.getcwd() .. "/" - if vim.g["dotnet_last_proj_path"] ~= nil then - default_path = vim.g["dotnet_last_proj_path"] - end + if vim.g["dotnet_last_proj_path"] ~= nil then + default_path = vim.g["dotnet_last_proj_path"] + end - local path = vim.fn.input("Path to your *proj file", default_path, "file") + local path = vim.fn.input("Path to your *proj file", default_path, "file") - vim.g["dotnet_last_proj_path"] = path + vim.g["dotnet_last_proj_path"] = path - local cmd = "dotnet build -c Debug " .. path .. " > /dev/null" + local cmd = "dotnet build -c Debug " .. path .. " > /dev/null" - print("") - print("Cmd to execute: " .. cmd) + print("") + print("Cmd to execute: " .. cmd) - local f = os.execute(cmd) + local f = os.execute(cmd) - if f == 0 then - print("\nBuild: ✔️ ") - else - print("\nBuild: ❌ (code: " .. f .. ")") - end - end + if f == 0 then + print("\nBuild: ✔️ ") + else + print("\nBuild: ❌ (code: " .. f .. ")") + end + end - local dotnet_get_dll_path = function() - local request = function() - return vim.fn.input("Path to dll to debug: ", vim.fn.getcwd() .. "/bin/Debug/", "file") - end + local dotnet_get_dll_path = function() + local request = function() + return vim.fn.input("Path to dll to debug: ", vim.fn.getcwd() .. "/bin/Debug/", "file") + end - if vim.g["dotnet_last_dll_path"] == nil then - vim.g["dotnet_last_dll_path"] = request() - else - if - vim.fn.confirm("Change the path to dll?\n" .. vim.g["dotnet_last_dll_path"], "&yes\n&no", 2) == 1 - then - vim.g["dotnet_last_dll_path"] = request() - end - end + if vim.g["dotnet_last_dll_path"] == nil then + vim.g["dotnet_last_dll_path"] = request() + else + if + vim.fn.confirm("Change the path to dll?\n" .. vim.g["dotnet_last_dll_path"], "&yes\n&no", 2) == 1 + then + vim.g["dotnet_last_dll_path"] = request() + end + end - return vim.g["dotnet_last_dll_path"] - end + return vim.g["dotnet_last_dll_path"] + end - dap.configurations.cs = { - { - type = "coreclr", - name = "Launch - coreclr (nvim-dap)", - request = "launch", - program = function() - if vim.fn.confirm("Rebuild first?", "&yes\n&no", 2) == 1 then - dotnet_build_project() - end + dap.configurations.cs = { + { + type = "coreclr", + name = "Launch - coreclr (nvim-dap)", + request = "launch", + program = function() + if vim.fn.confirm("Rebuild first?", "&yes\n&no", 2) == 1 then + dotnet_build_project() + end - return dotnet_get_dll_path() - end, - }, - } + return dotnet_get_dll_path() + end, + }, + } - dap.listeners.before.attach.dapui_config = function() - dapui.open() - end - dap.listeners.before.launch.dapui_config = function() - dapui.open() - end - dap.listeners.before.event_terminated.dapui_config = function() - dapui.close() - end - dap.listeners.before.event_exited.dapui_config = function() - dapui.close() - end + dap.listeners.before.attach.dapui_config = function() + dapui.open() + end + dap.listeners.before.launch.dapui_config = function() + dapui.open() + end + dap.listeners.before.event_terminated.dapui_config = function() + dapui.close() + end + dap.listeners.before.event_exited.dapui_config = function() + dapui.close() + end - vim.keymap.set("n", "dt", dap.toggle_breakpoint, { desc = "Toggle breakpoint" }) - vim.keymap.set("n", "dbc", dap.clear_breakpoints, { desc = "Clear all breakpoints" }) - vim.keymap.set("n", "dbl", dap.list_breakpoints, { desc = "Clear all breakpoints" }) + vim.keymap.set("n", "dt", dap.toggle_breakpoint, { desc = "Toggle breakpoint" }) + vim.keymap.set("n", "dbc", dap.clear_breakpoints, { desc = "Clear all breakpoints" }) + vim.keymap.set("n", "dbl", dap.list_breakpoints, { desc = "Clear all breakpoints" }) - local continue = function() - -- support for vscode launch.json is partial. - -- not all configuration options and features supported - if vim.fn.filereadable(".vscode/launch.json") then - require("dap.ext.vscode").load_launchjs() - end - dap.continue() - end + local continue = function() + -- support for vscode launch.json is partial. + -- not all configuration options and features supported + if vim.fn.filereadable(".vscode/launch.json") then + require("dap.ext.vscode").load_launchjs() + end + dap.continue() + end - vim.keymap.set("n", "dc", continue, { desc = "Continue" }) - end, + vim.keymap.set("n", "dc", continue, { desc = "Continue" }) + end, }