kitchen sink now don't support any version lower than 0.11.0 for lsp
- dap now works for java and c
This commit is contained in:
@ -1,50 +1,98 @@
|
||||
local misc = require("core.misc")
|
||||
local map = misc.map
|
||||
|
||||
--- select a program to execute
|
||||
---@return thread coroutine containing the picker
|
||||
local function select_program()
|
||||
return coroutine.create(function(coro)
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
local entries = vim.fn.readdir(".", [[v:val !~ '^\.']])
|
||||
vim.ui.select(entries, { prompt = "Select the executable to run:" },
|
||||
function(choice)
|
||||
coroutine.resume(coro, choice)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
local keymap_restore = {}
|
||||
--- make the default hover binding work for nvim-dap instead of lsp
|
||||
local function set_hover_bind()
|
||||
for _, buf in pairs(vim.api.nvim_list_bufs()) do
|
||||
local keymaps = vim.api.nvim_buf_get_keymap(buf, 'n')
|
||||
for _, keymap in pairs(keymaps) do
|
||||
if keymap.lhs == "K" then
|
||||
table.insert(keymap_restore, keymap)
|
||||
vim.api.nvim_buf_del_keymap(buf, 'n', 'K')
|
||||
end
|
||||
end
|
||||
end
|
||||
vim.keymap.set('n', 'K', require("dap.ui.widgets").hover,
|
||||
{ silent = true })
|
||||
end
|
||||
|
||||
--- revert the hover bind back to whatever it was
|
||||
local function unset_hover_bind()
|
||||
for _, keymap in pairs(keymap_restore) do
|
||||
if keymap.rhs then
|
||||
vim.api.nvim_buf_set_keymap(keymap.buffer, keymap.mode, keymap.lhs,
|
||||
keymap.rhs, { silent = keymap.silent == 1 })
|
||||
elseif keymap.callback then
|
||||
vim.keymap.set(keymap.mode, keymap.lhs, keymap.callback,
|
||||
{ buffer = keymap.buffer, silent = keymap.silent == 1 })
|
||||
end
|
||||
end
|
||||
keymap_restore = {}
|
||||
end
|
||||
|
||||
return { "mfussenegger/nvim-dap",
|
||||
requires = {
|
||||
"williamboman/mason.nvim",
|
||||
"nvim-telescope/telescope.nvim",
|
||||
"mason-org/mason.nvim",
|
||||
"nvim-telescope/telescope.nvim"
|
||||
},
|
||||
disable = not vim.fn.has("nvim-0.8.0"),
|
||||
branch = "0.8.0",
|
||||
disable = not vim.fn.has("nvim-0.9.5"),
|
||||
branch = "0.10.0",
|
||||
function()
|
||||
|
||||
local dap = require("dap")
|
||||
|
||||
local codelldb_port = 13000
|
||||
-- define codelldb
|
||||
dap.adapters.codelldb = {
|
||||
type = "server",
|
||||
host = "127.0.0.1",
|
||||
port = codelldb_port,
|
||||
executable = {
|
||||
command = require("mason-registry").get_package("codelldb"):get_install_path().."/codelldb",
|
||||
args = { "--port", codelldb_port }
|
||||
}
|
||||
type = "executable",
|
||||
command = "codelldb",
|
||||
}
|
||||
|
||||
-- define the c configuration for codelldb
|
||||
dap.configurations.c = {
|
||||
{
|
||||
name = "LLDB: Launch",
|
||||
name = "Launch file",
|
||||
type = "codelldb",
|
||||
request = "launch",
|
||||
program = function()
|
||||
return vim.fn.input("Path to executable: ", vim.fn.getcwd().."/", "file")
|
||||
end,
|
||||
program = select_program,
|
||||
|
||||
cwd = "${workspaceFolder}",
|
||||
stopOnEntry = false,
|
||||
args = {},
|
||||
console = "integratedTerminal"
|
||||
stopOnEntry = false
|
||||
}
|
||||
}
|
||||
|
||||
-- and define them for cpp, zig, and rust
|
||||
dap.configurations.cpp = dap.configurations.c
|
||||
dap.configurations.zig = dap.configurations.c
|
||||
dap.configurations.rust = dap.configurations.c
|
||||
|
||||
-- keybinds
|
||||
map("n", "<Leader>ec", dap.continue, { desc = "dap continue " })
|
||||
map("n", "<Leader>el", dap.run_last, { desc = "dap run last" })
|
||||
map("n", "<Leader>et", dap.terminate, { desc = "dap terminate " })
|
||||
map("n", "<Leader>et", function()
|
||||
dap.terminate()
|
||||
unset_hover_bind()
|
||||
end, { desc = "dap terminate " })
|
||||
map("n", "<Leader>eb", require("dap.breakpoints").toggle, { desc = "dap toggle breakpoint" })
|
||||
map("n", "<Leader>e]", dap.step_over, { desc = "dap step over" })
|
||||
map("n", "<Leader>e[", dap.step_back, { desc = "dap step back" })
|
||||
map("n", "<Leader>er", dap.repl.toggle, { desc = "dap repl toggle" })
|
||||
map("n", "<Leader>eR", dap.restart, { desc = "dap restart" })
|
||||
|
||||
-- events
|
||||
dap.listeners.after['event_initialized']['me'] = set_hover_bind
|
||||
dap.listeners.after['event_terminated']['me'] = unset_hover_bind
|
||||
end
|
||||
}
|
||||
|
Reference in New Issue
Block a user