dap and leap
This commit is contained in:
parent
4916c4eca2
commit
9055e4e876
249
lua/plugins/dap.lua
Normal file
249
lua/plugins/dap.lua
Normal file
@ -0,0 +1,249 @@
|
||||
return {
|
||||
'mfussenegger/nvim-dap',
|
||||
dependencies = {
|
||||
'mfussenegger/nvim-dap-python',
|
||||
'theHamsta/nvim-dap-virtual-text',
|
||||
{
|
||||
'nvim-telescope/telescope-dap.nvim',
|
||||
dependencies = 'telescope.nvim',
|
||||
},
|
||||
'rcarriga/nvim-dap-ui',
|
||||
'rcarriga/cmp-dap',
|
||||
},
|
||||
keys = {
|
||||
{
|
||||
'<F5>',
|
||||
function()
|
||||
require('dap').continue()
|
||||
end,
|
||||
desc = 'DAP continue'
|
||||
},
|
||||
{
|
||||
'<F6>',
|
||||
function()
|
||||
loadConfigs()
|
||||
end,
|
||||
desc = 'DAP configs'
|
||||
},
|
||||
{
|
||||
'<F7>',
|
||||
function()
|
||||
require('dap').goto_()
|
||||
end,
|
||||
desc = 'DAP goto'
|
||||
},
|
||||
{
|
||||
'<F8>',
|
||||
function()
|
||||
require('dap.ui.widgets').hover()
|
||||
end,
|
||||
desc = 'DAP Hover'
|
||||
},
|
||||
{
|
||||
'<F9>',
|
||||
function()
|
||||
require('dap').toggle_breakpoint()
|
||||
end,
|
||||
desc = 'DAP breakpoint'
|
||||
},
|
||||
{
|
||||
'<F10>',
|
||||
function()
|
||||
require('dap').step_over()
|
||||
end,
|
||||
desc = 'DAP step_over'
|
||||
},
|
||||
{
|
||||
'<F11>',
|
||||
function()
|
||||
require('dap').step_into()
|
||||
end,
|
||||
desc = 'DAP step_into'
|
||||
},
|
||||
{
|
||||
'<S-F11>',
|
||||
function()
|
||||
require('dap').step_out()
|
||||
end,
|
||||
desc = 'DAP step_out'
|
||||
},
|
||||
},
|
||||
config = function()
|
||||
local dap = require('dap')
|
||||
|
||||
require("cmp_dap").is_dap_buffer()
|
||||
|
||||
|
||||
-- make sure we can exit the terminal with esc
|
||||
vim.api.nvim_create_autocmd({ "TermOpen" }, {
|
||||
pattern = { '*dap-terminal*' },
|
||||
callback = function()
|
||||
local opts = { noremap = true }
|
||||
vim.api.nvim_buf_set_keymap(0, 't', '<esc>', [[<C-\><C-n>]], opts)
|
||||
end
|
||||
})
|
||||
|
||||
local function getVenvSuffix()
|
||||
if vim.loop.os_uname().sysname == 'Linux' then
|
||||
return 'bin/python'
|
||||
elseif vim.loop.os_uname().sysname == 'Windows_NT' then
|
||||
return 'Scripts/python.exe'
|
||||
end
|
||||
end
|
||||
|
||||
local function getPythonEnv()
|
||||
local venv = os.getenv("VIRTUAL_ENV")
|
||||
if venv ~= nil then
|
||||
return string.format("%s/%s", venv, getVenvSuffix())
|
||||
end
|
||||
local conda = os.getenv("CONDA_PREFIX")
|
||||
if conda ~= nil then
|
||||
return string.format("%s/%s", conda, 'python.exe')
|
||||
end
|
||||
|
||||
local cwd = vim.fn.getcwd()
|
||||
if vim.fn.executable(cwd .. '/venv/' .. getVenvSuffix()) == 1 then
|
||||
return cwd .. '/venv/' .. getVenvSuffix()
|
||||
elseif vim.fn.executable(cwd .. '/.venv/' .. getVenvSuffix()) == 1 then
|
||||
return cwd .. '/.venv/' .. getVenvSuffix()
|
||||
else
|
||||
if vim.loop.os_uname().sysname == 'Linux' then
|
||||
return '/usr/bin/python'
|
||||
elseif vim.loop.os_uname().sysname == 'Windows_NT' then
|
||||
return os.getenv('SCOOP') .. '/apps/python/current/python.exe'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function loadConfigs()
|
||||
require('dap.ext.vscode').load_launchjs()
|
||||
-- Make sure we use the correct python env even for the configs from launch.json
|
||||
for nr, config in pairs(dap.configurations.python) do
|
||||
config.pythonPath = getPythonEnv()
|
||||
config.cwd = vim.fn.getcwd()
|
||||
end
|
||||
require 'telescope'.extensions.dap.configurations {}
|
||||
end
|
||||
|
||||
local initDir = vim.api.nvim_list_runtime_paths()[1]
|
||||
local masonpath = vim.fn.stdpath('data') .. '/mason'
|
||||
|
||||
-- PYTHON
|
||||
dap.adapters.python = {
|
||||
type = 'executable';
|
||||
command = masonpath .. '/packages/debugpy/venv/' .. getVenvSuffix();
|
||||
args = { '-m', 'debugpy.adapter' };
|
||||
options = {
|
||||
detached = true;
|
||||
};
|
||||
}
|
||||
|
||||
local dap = require("dap")
|
||||
local dapui = require("dapui")
|
||||
dapui.setup()
|
||||
dap.listeners.after.event_initialized["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.configurations.python = {
|
||||
{
|
||||
type = 'python';
|
||||
request = 'launch';
|
||||
name = "Launch file with venv";
|
||||
justMyCode = false;
|
||||
program = "${file}";
|
||||
cwd = vim.fn.getcwd();
|
||||
pythonPath = getPythonEnv
|
||||
},
|
||||
}
|
||||
|
||||
-- require('dap-python').setup('C:\\Users\\oli\\AppData\\Local\\nvim\\venv_debugpy\\Scripts\\python')
|
||||
-- table.insert(require('dap').configurations.python, {
|
||||
-- -- type = 'python',
|
||||
-- -- request = 'launch',
|
||||
-- -- name = 'My custom launch configuration',
|
||||
-- -- program = '${file}',
|
||||
-- justMyCode = false
|
||||
-- -- ... more options, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings
|
||||
-- })
|
||||
-- require('dap-python').setup('C:/Users/oli/AppData/Local/nvim-data/mason/packages/debugpy/venv/Scripts/python.exe')
|
||||
|
||||
-- CPP
|
||||
dap.adapters.codelldb = {
|
||||
type = 'server',
|
||||
port = "${port}",
|
||||
executable = {
|
||||
-- CHANGE THIS to your path!
|
||||
command = masonpath .. '/bin/codelldb.cmd',
|
||||
args = { '--port', '${port}' },
|
||||
|
||||
-- On windows you may have to uncomment this:
|
||||
detached = false,
|
||||
}
|
||||
}
|
||||
|
||||
dap.adapters.lldb = {
|
||||
type = 'executable',
|
||||
command = function()
|
||||
if vim.loop.os_uname().sysname == 'Linux' then
|
||||
return 'lldb-vscode'
|
||||
else
|
||||
return os.getenv('SCOOP') .. '/apps/llvm/current/bin/lldb-vscode.exe'
|
||||
end
|
||||
end,
|
||||
name = 'lldb'
|
||||
}
|
||||
|
||||
dap.configurations.cpp = {
|
||||
{
|
||||
name = "Launch codelldb",
|
||||
type = "codelldb",
|
||||
request = "launch",
|
||||
program = function()
|
||||
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/build_nvim/', 'file')
|
||||
end,
|
||||
cwd = '${workspaceFolder}',
|
||||
stopOnEntry = true,
|
||||
},
|
||||
}
|
||||
|
||||
dap.configurations.cpp = {
|
||||
{
|
||||
name = 'Launch lldb',
|
||||
type = 'lldb',
|
||||
request = 'launch',
|
||||
program = function()
|
||||
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/build_nvim', 'file')
|
||||
end,
|
||||
cwd = '${workspaceFolder}',
|
||||
stopOnEntry = false,
|
||||
args = {},
|
||||
|
||||
-- 💀
|
||||
-- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
|
||||
--
|
||||
-- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
|
||||
--
|
||||
-- Otherwise you might get the following error:
|
||||
--
|
||||
-- Error on launch: Failed to attach to the target process
|
||||
--
|
||||
-- But you should be aware of the implications:
|
||||
-- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
|
||||
-- runInTerminal = false,
|
||||
},
|
||||
}
|
||||
|
||||
-- EXTENSIONS
|
||||
|
||||
require('nvim-dap-virtual-text').setup()
|
||||
require('telescope').load_extension('dap')
|
||||
|
||||
end,
|
||||
}
|
@ -29,40 +29,6 @@ return {
|
||||
require('setup/my_gruvbox_flat')
|
||||
end
|
||||
},
|
||||
{
|
||||
'ggandor/leap.nvim',
|
||||
dependencies = { 'tpope/vim-repeat' },
|
||||
config = function()
|
||||
require('setup/my_leap')
|
||||
end,
|
||||
event = 'VeryLazy'
|
||||
},
|
||||
{
|
||||
'mfussenegger/nvim-dap',
|
||||
dependencies = {
|
||||
'mfussenegger/nvim-dap-python',
|
||||
'theHamsta/nvim-dap-virtual-text',
|
||||
{
|
||||
'nvim-telescope/telescope-dap.nvim',
|
||||
dependencies = 'telescope.nvim',
|
||||
},
|
||||
'rcarriga/nvim-dap-ui',
|
||||
'rcarriga/cmp-dap',
|
||||
},
|
||||
keys = {
|
||||
{ '<F5>' },
|
||||
{ '<F6>' },
|
||||
{ '<F7>' },
|
||||
{ '<F8>' },
|
||||
{ '<F9>' },
|
||||
{ '<F10>' },
|
||||
{ '<F11>' },
|
||||
{ '<S-F11>' }
|
||||
},
|
||||
config = function()
|
||||
require('setup/my_dap')
|
||||
end,
|
||||
},
|
||||
{
|
||||
'sindrets/diffview.nvim',
|
||||
dependencies = 'nvim-lua/plenary.nvim',
|
||||
|
8
lua/plugins/leap.lua
Normal file
8
lua/plugins/leap.lua
Normal file
@ -0,0 +1,8 @@
|
||||
return {
|
||||
'ggandor/leap.nvim',
|
||||
dependencies = { 'tpope/vim-repeat' },
|
||||
config = function()
|
||||
require('leap').set_default_keymaps()
|
||||
end,
|
||||
event = 'VeryLazy'
|
||||
}
|
@ -1,185 +0,0 @@
|
||||
dap = require('dap')
|
||||
|
||||
require("cmp_dap").is_dap_buffer()
|
||||
|
||||
|
||||
-- make sure we can exit the terminal with esc
|
||||
vim.api.nvim_create_autocmd({ "TermOpen" }, {
|
||||
pattern = { '*dap-terminal*' },
|
||||
callback = function()
|
||||
local opts = { noremap = true }
|
||||
vim.api.nvim_buf_set_keymap(0, 't', '<esc>', [[<C-\><C-n>]], opts)
|
||||
end
|
||||
})
|
||||
|
||||
local function getVenvSuffix()
|
||||
if vim.loop.os_uname().sysname == 'Linux' then
|
||||
return 'bin/python'
|
||||
elseif vim.loop.os_uname().sysname == 'Windows_NT' then
|
||||
return 'Scripts/python.exe'
|
||||
end
|
||||
end
|
||||
|
||||
local function getPythonEnv()
|
||||
local venv = os.getenv("VIRTUAL_ENV")
|
||||
if venv ~= nil then
|
||||
return string.format("%s/%s", venv, getVenvSuffix())
|
||||
end
|
||||
local conda = os.getenv("CONDA_PREFIX")
|
||||
if conda ~= nil then
|
||||
return string.format("%s/%s", conda, 'python.exe')
|
||||
end
|
||||
|
||||
local cwd = vim.fn.getcwd()
|
||||
if vim.fn.executable(cwd .. '/venv/' .. getVenvSuffix()) == 1 then
|
||||
return cwd .. '/venv/' .. getVenvSuffix()
|
||||
elseif vim.fn.executable(cwd .. '/.venv/' .. getVenvSuffix()) == 1 then
|
||||
return cwd .. '/.venv/' .. getVenvSuffix()
|
||||
else
|
||||
if vim.loop.os_uname().sysname == 'Linux' then
|
||||
return '/usr/bin/python'
|
||||
elseif vim.loop.os_uname().sysname == 'Windows_NT' then
|
||||
return os.getenv('SCOOP') .. '/apps/python/current/python.exe'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function loadConfigs ()
|
||||
require('dap.ext.vscode').load_launchjs()
|
||||
-- Make sure we use the correct python env even for the configs from launch.json
|
||||
for nr,config in pairs(dap.configurations.python) do
|
||||
config.pythonPath = getPythonEnv()
|
||||
config.cwd = vim.fn.getcwd()
|
||||
end
|
||||
require'telescope'.extensions.dap.configurations{}
|
||||
end
|
||||
local opts = { noremap = true, silent = false }
|
||||
vim.keymap.set('n', '<F5>', dap.continue, opts)
|
||||
vim.keymap.set('n', '<F6>', loadConfigs, opts)
|
||||
vim.keymap.set('n', '<F7>', dap.goto_, opts)
|
||||
vim.keymap.set('n', '<F8>', require('dap.ui.widgets').hover, opts)
|
||||
vim.keymap.set('n', '<F9>', dap.toggle_breakpoint, opts)
|
||||
vim.keymap.set('n', '<F10>', dap.step_over, opts)
|
||||
vim.keymap.set('n', '<F11>', dap.step_into, opts)
|
||||
vim.keymap.set('n', '<S-F11>', dap.step_out, opts)
|
||||
|
||||
local initDir = vim.api.nvim_list_runtime_paths()[1]
|
||||
local masonpath = vim.fn.stdpath('data') .. '/mason'
|
||||
|
||||
-- PYTHON
|
||||
dap.adapters.python = {
|
||||
type = 'executable';
|
||||
command = masonpath .. '/packages/debugpy/venv/' .. getVenvSuffix();
|
||||
args = { '-m', 'debugpy.adapter' };
|
||||
options = {
|
||||
detached = true;
|
||||
};
|
||||
}
|
||||
|
||||
local dap= require("dap")
|
||||
local dapui = require("dapui")
|
||||
dapui.setup()
|
||||
dap.listeners.after.event_initialized["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.configurations.python = {
|
||||
{
|
||||
type = 'python';
|
||||
request = 'launch';
|
||||
name = "Launch file with venv";
|
||||
justMyCode = false;
|
||||
program = "${file}";
|
||||
cwd = vim.fn.getcwd();
|
||||
pythonPath = getPythonEnv
|
||||
},
|
||||
}
|
||||
|
||||
-- require('dap-python').setup('C:\\Users\\oli\\AppData\\Local\\nvim\\venv_debugpy\\Scripts\\python')
|
||||
-- table.insert(require('dap').configurations.python, {
|
||||
-- -- type = 'python',
|
||||
-- -- request = 'launch',
|
||||
-- -- name = 'My custom launch configuration',
|
||||
-- -- program = '${file}',
|
||||
-- justMyCode = false
|
||||
-- -- ... more options, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings
|
||||
-- })
|
||||
-- require('dap-python').setup('C:/Users/oli/AppData/Local/nvim-data/mason/packages/debugpy/venv/Scripts/python.exe')
|
||||
|
||||
-- CPP
|
||||
dap.adapters.codelldb = {
|
||||
type = 'server',
|
||||
port = "${port}",
|
||||
executable = {
|
||||
-- CHANGE THIS to your path!
|
||||
command = masonpath .. '/bin/codelldb.cmd',
|
||||
args = { '--port', '${port}' },
|
||||
|
||||
-- On windows you may have to uncomment this:
|
||||
detached = false,
|
||||
}
|
||||
}
|
||||
|
||||
dap.adapters.lldb = {
|
||||
type = 'executable',
|
||||
command = function()
|
||||
if vim.loop.os_uname().sysname == 'Linux' then
|
||||
return 'lldb-vscode'
|
||||
else
|
||||
return os.getenv('SCOOP') .. '/apps/llvm/current/bin/lldb-vscode.exe'
|
||||
end
|
||||
end,
|
||||
name = 'lldb'
|
||||
}
|
||||
|
||||
dap.configurations.cpp = {
|
||||
{
|
||||
name = "Launch codelldb",
|
||||
type = "codelldb",
|
||||
request = "launch",
|
||||
program = function()
|
||||
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/build_nvim/', 'file')
|
||||
end,
|
||||
cwd = '${workspaceFolder}',
|
||||
stopOnEntry = true,
|
||||
},
|
||||
}
|
||||
|
||||
dap.configurations.cpp = {
|
||||
{
|
||||
name = 'Launch lldb',
|
||||
type = 'lldb',
|
||||
request = 'launch',
|
||||
program = function()
|
||||
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/build_nvim', 'file')
|
||||
end,
|
||||
cwd = '${workspaceFolder}',
|
||||
stopOnEntry = false,
|
||||
args = {},
|
||||
|
||||
-- 💀
|
||||
-- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
|
||||
--
|
||||
-- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
|
||||
--
|
||||
-- Otherwise you might get the following error:
|
||||
--
|
||||
-- Error on launch: Failed to attach to the target process
|
||||
--
|
||||
-- But you should be aware of the implications:
|
||||
-- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
|
||||
-- runInTerminal = false,
|
||||
},
|
||||
}
|
||||
|
||||
-- EXTENSIONS
|
||||
|
||||
require('nvim-dap-virtual-text').setup()
|
||||
require('telescope').load_extension('dap')
|
||||
|
@ -1 +0,0 @@
|
||||
require('leap').set_default_keymaps()
|
Loading…
x
Reference in New Issue
Block a user