From 07d3bcb177585ed4b357b7a5341a0a5bd7db7a29 Mon Sep 17 00:00:00 2001 From: Ruslan Rakhmanov Date: Sat, 19 Apr 2025 09:47:01 +0200 Subject: [PATCH] JS Debug using obsolete vscode-chrome-debug lib --- init.lua | 8 +++-- lua/kickstart/plugins/debug.lua | 54 +++++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/init.lua b/init.lua index 409d9706..fc505201 100644 --- a/init.lua +++ b/init.lua @@ -651,7 +651,9 @@ require('lazy').setup({ capabilities = lsp_capabilities, filetypes = { 'typescript', 'html', 'angular', 'htmlangular' }, root_dir = function(fname) - return require('lspconfig.util').root_pattern('angular.json', 'workspace.json', 'nx.json', 'package.json', 'tsconfig.base.json')(fname) + return require('lspconfig.util').root_pattern('angular.json', 'workspace.json', 'nx.json', 'package.json', 'tsconfig.base.json', 'project.json')( + fname + ) end, on_new_config = function(new_config, new_root_dir) new_config.cmd = { @@ -913,7 +915,7 @@ require('lazy').setup({ priority = 1000, -- Make sure to load this before all the other start plugins. config = function() require('everforest').setup { - background = 'medium', + background = 'hard', ui_contrast = 'low', } @@ -1034,7 +1036,7 @@ require('lazy').setup({ -- Here are some example plugins that I've included in the Kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- - -- require 'kickstart.plugins.debug', + require 'kickstart.plugins.debug', -- require 'kickstart.plugins.indent_line', -- require 'kickstart.plugins.lint', require 'kickstart.plugins.autopairs', diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 753cb0ce..0e313381 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -23,37 +23,52 @@ return { -- Add your own debuggers here 'leoluz/nvim-dap-go', + + -- Web + { + 'microsoft/vscode-chrome-debug', + version = '1.x', + build = 'npm i && npm run build', + }, }, keys = { -- Basic debugging keymaps, feel free to change to your liking! { - '', + '', function() require('dap').continue() end, desc = 'Debug: Start/Continue', }, { - '', + '', function() require('dap').step_into() end, desc = 'Debug: Step Into', }, { - '', + '', function() require('dap').step_over() end, desc = 'Debug: Step Over', }, { - '', + '', function() require('dap').step_out() end, desc = 'Debug: Step Out', }, + -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. + { + '', + function() + require('dapui').toggle() + end, + desc = 'Debug: See last session result.', + }, { 'b', function() @@ -68,14 +83,6 @@ return { end, desc = 'Debug: Set Breakpoint', }, - -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. - { - '', - function() - require('dapui').toggle() - end, - desc = 'Debug: See last session result.', - }, }, config = function() local dap = require 'dap' @@ -136,6 +143,29 @@ return { dap.listeners.before.event_terminated['dapui_config'] = dapui.close dap.listeners.before.event_exited['dapui_config'] = dapui.close + dap.adapters.chrome = { + type = 'executable', + command = 'node', + args = { vim.fn.stdpath 'data' .. '/lazy/vscode-chrome-debug/out/src/chromeDebug.js' }, -- TODO adjust + } + + -- TODO: Figure out how to launch chrome automatically + -- TODO: Figure out why I have two additional configurations when starting debugger: "Launch Chrome Debugger", "Debug App Two" + -- now I have to do "open -a "Google Chrome" --args --remote-debugging-port=9222" + dap.configurations.typescript = { + { + name = 'Attach to Chrome', + type = 'chrome', + request = 'attach', + program = '${file}', + cwd = vim.fn.getcwd(), + sourceMaps = true, + protocol = 'inspector', + port = 9222, + webRoot = '${workspaceFolder}', + }, + } + -- Install golang specific config require('dap-go').setup { delve = {