Trying to get debugging going for JS/TS

This commit is contained in:
Adam Cooper 2024-01-01 11:27:24 -05:00
parent 938ff36c6b
commit 9d71ab4be4
2 changed files with 117 additions and 27 deletions

78
neovim/init-dap.lua Normal file
View File

@ -0,0 +1,78 @@
-- Minimal init.lua to test out nvim-dap (for Node.js, really NestJS)
-- lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
"mfussenegger/nvim-dap",
{ "rcarriga/nvim-dap-ui", requires = "mfussenegger/nvim-dap" },
{ "mxsdev/nvim-dap-vscode-js", requires = "mfussenegger/nvim-dap" },
{
"microsoft/vscode-js-debug",
opt = true,
run = "npm install --legacy-peer-deps && npx gulp dapDebugServerBundle && mv dist out",
},
"leoluz/nvim-dap-go",
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
})
--[[ mason
Mason manages external editor plugins such as LSP servers, DAP servers,
linters, and formatters. There are further recommended plugins for better
integration.
--]]
require('mason').setup()
require('mason-lspconfig').setup()
-- setup adapters
require('dap-vscode-js').setup({
node_path = 'node',
debugger_path = vim.fn.stdpath('data') .. '/mason/packages/js-debug-adapter',
debugger_cmd = { 'js-debug-adapter' },
adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' },
log_file_path = vim.fn.stdpath('cache') .. '/dap_vscode_js.log',
log_file_level = 1,
log_console_level = vim.log.levels.TRACE,
})
local dap = require('dap')
for _, language in ipairs({ "typescript", "javascript" }) do
dap.configurations[language] = {
{
type = "pwa-node",
request = "launch",
name = "Launch file",
program = "${file}",
cwd = "${workspaceFolder}",
},
--[[
{
type = "pwa-node",
request = "launch",
name = "Debug Nest Framework",
args = { "${workspaceFolder}/src/main.ts" },
runtimeArgs = { "--nolazy", "-r", "ts-node/register" },
sourceMaps = true,
cwd = "${workspaceRoot}",
protocol = "inspector",
}
--]]
}
end
require('dap-go').setup()
require('dapui').setup()

View File

@ -263,27 +263,27 @@ cmp.setup.cmdline(':', {
-- Setup language servers.
local lua_ls_setup = {
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false,
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false,
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
},
},
}
local capabilities = require('cmp_nvim_lsp').default_capabilities()
@ -428,10 +428,10 @@ require('gitsigns').setup({
-- LSPSaga : provides a diverse basket of utilities
--]]
require('lspsaga').setup({
beacon = {
enable = true,
frequency = 7,
}
beacon = {
enable = true,
frequency = 7,
}
})
vim.keymap.set('n', '<leader>si', '<cmd>Lspsaga incoming_calls<CR>')
vim.keymap.set('n', '<leader>so', '<cmd>Lspsaga outgoing_calls<CR>')
@ -457,14 +457,26 @@ require('dap-vscode-js').setup({
adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' },
log_file_path = vim.fn.stdpath('cache') .. '/dap_vscode_js.log',
log_file_level = 1,
log_console_level = vim.log.levels.ERROR,
log_console_level = vim.log.levels.TRACE,
})
--[[
local dap = require('dap')
for _, language in ipairs({ "typescript", "javascript" }) do
dap.configurations[language] = {
{
type = "pwa-node",
request = "launch",
name = "Debug Nest Framework",
args = { "${workspaceFolder}/src/main.ts" },
runtimeArgs = { "--nolazy", "-r", "ts-node/register" },
sourceMaps = true,
cwd = "${workspaceRoot}",
protocol = "inspector",
}
}
end
--[[
{
type = "pwa-node",
request = "launch",
@ -493,13 +505,13 @@ for _, language in ipairs({ "typescript", "javascript" }) do
console = "integratedTerminal",
internalConsoleOptions = "neverOpen",
},
}
end
--]]
--[[
local types_to_filetypes_table = {}
types_to_filetypes_table['pwa-node'] = { 'javascript', 'typescript' }
require('dap.ext.vscode').load_launchjs(nil, types_to_filetypes_table)
--]]
-- Tweak GitSigns blame color
-- This differentiates the cursorline from the git blame text