mason_path, use js dap with mason

This commit is contained in:
Amanda Graven 2023-11-12 09:52:29 +01:00
parent 4990d80291
commit 5a8f49e2ca
Signed by: amanda
GPG key ID: F747582C5608F4CB

132
init.lua
View file

@ -236,6 +236,10 @@ if fn.empty(fn.glob(packer_path)) > 0 then
vim.notify('Downloading plugin manager with git') vim.notify('Downloading plugin manager with git')
packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', packer_path}) packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', packer_path})
end end
--- @param package string
function mason_path(package)
return vim.fn.stdpath('data') .. '/mason/packages/' .. package
end
require'packer'.startup(function(use) require'packer'.startup(function(use)
use 'wbthomason/packer.nvim' use 'wbthomason/packer.nvim'
@ -356,15 +360,30 @@ require'packer'.startup(function(use)
vim.fn.sign_define('DapBreakpoint', {text='', texthl='DiagnosticError'}) vim.fn.sign_define('DapBreakpoint', {text='', texthl='DiagnosticError'})
dap.adapters.codelldb = { dap.adapters.codelldb = {
type = 'server', type = 'server',
host = 'localhost',
port = '${port}', port = '${port}',
executable = { executable = {
command = vim.fn.stdpath('data') .. '/mason/packages/codelldb/extension/adapter/codelldb', --command = mason_path('codelldb') .. '/extension/adapter/codelldb',
--args = {'--liblldb', mason_path('codelldb') .. '/extension/lldb/lib/liblldb.so', '--port', '${port}'},
command = 'lldb',
args = {'--port', '${port}'}, args = {'--port', '${port}'},
}, },
} }
dap.adapters.sh = { dap.adapters.sh = {
type = 'executable', type = 'executable',
command = vim.fn.stdpath('data') .. '/mason/packages/bash-debug-adapter/bash-debug-adapter' command = mason_path('bash-debug-adapter') .. '/bash-debug-adapter'
}
dap.adapters['pwa-node'] = {
type = 'server',
host = 'localhost',
port = '${port}',
executable = {
command = 'node',
args = {
mason_path('js-debug-adapter') .. '/js-debug/src/dapDebugServer.js',
'${port}'
},
},
} }
dap.configurations.cpp = { dap.configurations.cpp = {
{ {
@ -387,8 +406,8 @@ require'packer'.startup(function(use)
request = 'launch', request = 'launch',
program = '${file}', program = '${file}',
cwd = '${fileDirname}', cwd = '${fileDirname}',
pathBashdb = vim.fn.stdpath('data') .. '/mason/packages/bash-debug-adapter/extension/bashdb_dir/bashdb', pathBashdb = mason_path('bash-debug-adapter') .. '/extension/bashdb_dir/bashdb',
pathBashdbLib = vim.fn.stdpath('data') .. '/mason/packages/bash-debug-adapter/extension/bashdb_dir', pathBashdbLib = mason_path('bash-debug-adapter') .. '/extension/bashdb_dir',
pathBash = 'bash', pathBash = 'bash',
pathCat = 'cat', pathCat = 'cat',
pathMkfifo = 'mkfifo', pathMkfifo = 'mkfifo',
@ -399,6 +418,47 @@ require'packer'.startup(function(use)
end, end,
}, },
} }
dap.configurations.javascript = {
{
type = 'pwa-node',
request = 'launch',
name = 'Launch current file',
program = '${file}',
cwd = '${workspaceFolder}',
},
{
type = 'pwa-node',
request = 'launch',
name = 'Launch file',
program = function()
return vim.fn.input('Path to file: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
},
{
type = 'pwa-node',
request = 'attach',
name = 'Attach',
processId = require'dap.utils'.pick_process,
cwd = '${workspaceFolder}',
},
{
type = 'pwa-node',
request = 'launch',
name = 'Debug Mocha Tests',
-- trace = true, -- include debugger info
runtimeExecutable = 'node',
runtimeArgs = {
'./node_modules/mocha/bin/mocha',
},
rootPath = '${workspaceFolder}',
cwd = '${workspaceFolder}',
console = 'integratedTerminal',
internalConsoleOptions = 'neverOpen',
}
}
dap.configurations.typescript = dap.configurations.javascript
local function conditional_breakpoint() local function conditional_breakpoint()
vim.ui.input({prompt = 'Breakpoint condition'}, function(condition) vim.ui.input({prompt = 'Breakpoint condition'}, function(condition)
if not condition then return end if not condition then return end
@ -444,57 +504,6 @@ require'packer'.startup(function(use)
clear_on_continue = true, clear_on_continue = true,
} }
end} end}
use {'mxsdev/nvim-dap-vscode-js', requires = {'mfussenegger/nvim-dap'}, config = function()
require'dap-vscode-js'.setup {
adapters = {'pwa-node', 'node-terminal'},
}
for _, language in ipairs({'javascript', 'typescript'}) do
require'dap'.configurations[language] = {
{
type = 'pwa-node',
request = 'launch',
name = 'Launch current file',
program = '${file}',
cwd = '${workspaceFolder}',
},
{
type = 'pwa-node',
request = 'launch',
name = 'Launch file',
program = function()
return vim.fn.input('Path to file: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
},
{
type = 'pwa-node',
request = 'attach',
name = 'Attach',
processId = require'dap.utils'.pick_process,
cwd = '${workspaceFolder}',
},
{
type = 'pwa-node',
request = 'launch',
name = 'Debug Mocha Tests',
-- trace = true, -- include debugger info
runtimeExecutable = 'node',
runtimeArgs = {
'./node_modules/mocha/bin/mocha',
},
rootPath = '${workspaceFolder}',
cwd = '${workspaceFolder}',
console = 'integratedTerminal',
internalConsoleOptions = 'neverOpen',
}
}
end
end}
use {
'microsoft/vscode-js-debug',
opt = true,
run = 'npm install --legacy-peer-deps && npm run compile'
}
use {'sindrets/diffview.nvim', config = function() use {'sindrets/diffview.nvim', config = function()
require'diffview'.setup { require'diffview'.setup {
-- Use nicer highlighting for diffs -- Use nicer highlighting for diffs
@ -918,7 +927,6 @@ capabilities.textDocument.foldingRange = {
--- @param bufnr number --- @param bufnr number
--- @diagnostic disable-next-line: unused-local --- @diagnostic disable-next-line: unused-local
local function on_attach(client, bufnr) local function on_attach(client, bufnr)
require'which-key'.register({ require'which-key'.register({
['<Leader>l'] = { ['<Leader>l'] = {
D = {vim.lsp.buf.declaration, 'Declaration'}, D = {vim.lsp.buf.declaration, 'Declaration'},
@ -1005,7 +1013,6 @@ au('FileType', {
jdtls.dap = require'jdtls.dap' jdtls.dap = require'jdtls.dap'
_G.jdt = jdtls _G.jdt = jdtls
local path = vim.fn.stdpath('data') .. '/mason/packages/jdtls'
local root_dir = jdtls.setup.find_root({'.git', 'mvnw', 'gradlew'}) local root_dir = jdtls.setup.find_root({'.git', 'mvnw', 'gradlew'})
local config = { local config = {
@ -1016,7 +1023,7 @@ au('FileType', {
'--jvm-arg=-Dlog.level=ALL', '--jvm-arg=-Dlog.level=ALL',
'--jvm-arg=-Dlog.protocol=true', '--jvm-arg=-Dlog.protocol=true',
-- Enable lombok -- Enable lombok
'--jvm-arg=-javaagent:' .. path .. '/lombok.jar', '--jvm-arg=-javaagent:' .. mason_path('jdtls') .. '/lombok.jar',
-- store workpace data in ~/.local/share/eclipse/<project-name> -- store workpace data in ~/.local/share/eclipse/<project-name>
'-data', vim.fn.expand('~/.local/share/eclipse/') .. vim.fn.fnamemodify(root_dir, ':p:h:t') '-data', vim.fn.expand('~/.local/share/eclipse/') .. vim.fn.fnamemodify(root_dir, ':p:h:t')
}, },
@ -1032,11 +1039,11 @@ au('FileType', {
bundles = (function () bundles = (function ()
-- add java-debug-adapter -- add java-debug-adapter
local bundles = { local bundles = {
vim.fn.glob(vim.fn.stdpath('data') .. '/mason/packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar', true) vim.fn.glob(mason_path'java-debug-adapter' .. '/extension/server/com.microsoft.java.debug.plugin-*.jar', true)
} }
-- add java-test -- add java-test
vim.list_extend(bundles, vim.split( vim.list_extend(bundles, vim.split(
vim.fn.glob(vim.fn.stdpath'data' .. '/mason/packages/java-test/extension/server/*.jar', true), vim.fn.glob(mason_path'java-test' .. '/extension/server/*.jar', true),
'\n' '\n'
)) ))
@ -1151,10 +1158,7 @@ require'rust-tools'.setup {
}, },
}, },
dap = { dap = {
adapter = require'rust-tools.dap'.get_codelldb_adapter( adapter = require'dap'.adapters.codelldb,
vim.fn.stdpath('data') .. '/mason/packages/codelldb/extension/adapter/codelldb',
vim.fn.stdpath('data') .. '/mason/packages/codelldb/extension/lldb/lib/liblldb.so'
)
}, },
} }