Add DAP support, and some refactoring, nothing fancy for the DAPs yet, but good enough to use.
This commit is contained in:
parent
905e873d31
commit
0bec36b390
1 changed files with 99 additions and 36 deletions
|
|
@ -1,10 +1,101 @@
|
||||||
|
local function setup_lsp(server_names)
|
||||||
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||||
|
local lspconfig = require("lspconfig")
|
||||||
|
for _, server_name in ipairs(server_names) do
|
||||||
|
local server = lspconfig[server_name]
|
||||||
|
if server then
|
||||||
|
local server_table = require("language_servers/" .. server_name)
|
||||||
|
server_table.capabilities = capabilities
|
||||||
|
server_table.on_attach = function(client, bufnr)
|
||||||
|
vim.lsp.inlay_hint.enable(bufnr, true)
|
||||||
|
|
||||||
|
if client.server_capabilities.documentFormattingProvider then
|
||||||
|
vim.api.nvim_buf_create_user_command(bufnr, "Format", vim.lsp.buf.format, { nargs = 0 })
|
||||||
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
|
buffer = bufnr,
|
||||||
|
callback = function()
|
||||||
|
vim.lsp.buf.format()
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
server.setup(server_table)
|
||||||
|
|
||||||
|
-- Run the post_setup function if it exists
|
||||||
|
if server_table.post_setup then
|
||||||
|
server_table.post_setup()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
error("LSP server not found: " .. server_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function setup_dap()
|
||||||
|
local dap = require("dap")
|
||||||
|
local dapui = require("dapui")
|
||||||
|
dapui.setup()
|
||||||
|
|
||||||
|
local dap_signs = {
|
||||||
|
{ "DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" } },
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, sign in ipairs(dap_signs) do
|
||||||
|
vim.fn.sign_define(sign[1], sign[2])
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
require("mason-nvim-dap").setup({
|
||||||
|
handlers = {}
|
||||||
|
})
|
||||||
|
require("nvim-dap-repl-highlights").setup()
|
||||||
|
|
||||||
|
require("utils").add_keymaps({
|
||||||
|
n = {
|
||||||
|
["<leader>dr"] = { cmd = ":lua require(\"dap\").continue()<CR>" },
|
||||||
|
["<leader>db"] = { cmd = ":lua require(\"dap\").toggle_breakpoint()<CR>" },
|
||||||
|
["<leader>ds"] = {
|
||||||
|
cmd = function()
|
||||||
|
dap.disconnect({ terminateDebuggee = true })
|
||||||
|
dap.close()
|
||||||
|
dapui.close()
|
||||||
|
end
|
||||||
|
},
|
||||||
|
["<F10>"] = { cmd = ":lua require(\"dap\").step_over()<CR>" },
|
||||||
|
["<F11>"] = { cmd = ":lua require(\"dap\").step_into()<CR>" },
|
||||||
|
["<F12>"] = { cmd = ":lua require(\"dap\").step_out()<CR>" },
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"williamboman/mason.nvim",
|
"williamboman/mason.nvim",
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"williamboman/mason-lspconfig.nvim",
|
-- Mason plugins
|
||||||
"neovim/nvim-lspconfig",
|
|
||||||
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
||||||
"RubixDev/mason-update-all",
|
"RubixDev/mason-update-all",
|
||||||
|
|
||||||
|
-- LSP config
|
||||||
|
"neovim/nvim-lspconfig",
|
||||||
|
"williamboman/mason-lspconfig.nvim",
|
||||||
|
|
||||||
|
-- DAP
|
||||||
|
"folke/neodev.nvim",
|
||||||
|
"jay-babu/mason-nvim-dap.nvim",
|
||||||
|
"rcarriga/nvim-dap-ui",
|
||||||
|
"mfussenegger/nvim-dap",
|
||||||
|
"nvim-neotest/nvim-nio",
|
||||||
|
"LiadOz/nvim-dap-repl-highlights"
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- Find all files in lua/language_servers and require them
|
-- Find all files in lua/language_servers and require them
|
||||||
|
|
@ -25,7 +116,8 @@ return {
|
||||||
local mason_installs = vim.list_extend({
|
local mason_installs = vim.list_extend({
|
||||||
"clang-format",
|
"clang-format",
|
||||||
"cmakelang",
|
"cmakelang",
|
||||||
-- "luaformater",
|
"codelldb",
|
||||||
|
"netcoredbg",
|
||||||
}, server_names)
|
}, server_names)
|
||||||
|
|
||||||
require("mason").setup()
|
require("mason").setup()
|
||||||
|
|
@ -33,39 +125,10 @@ return {
|
||||||
require("mason-tool-installer").setup({
|
require("mason-tool-installer").setup({
|
||||||
ensure_installed = mason_installs,
|
ensure_installed = mason_installs,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setup_lsp(server_names)
|
||||||
|
setup_dap()
|
||||||
|
|
||||||
require("mason-update-all").setup()
|
require("mason-update-all").setup()
|
||||||
|
|
||||||
-- Iterate each server and setup
|
|
||||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
||||||
local lspconfig = require("lspconfig")
|
|
||||||
for _, server_name in ipairs(server_names) do
|
|
||||||
local server = lspconfig[server_name]
|
|
||||||
if server then
|
|
||||||
local server_table = require("language_servers/" .. server_name)
|
|
||||||
server_table.capabilities = capabilities
|
|
||||||
server_table.on_attach = function(client, bufnr)
|
|
||||||
vim.lsp.inlay_hint.enable(bufnr, true)
|
|
||||||
|
|
||||||
if client.server_capabilities.documentFormattingProvider then
|
|
||||||
vim.api.nvim_buf_create_user_command(bufnr, "Format", vim.lsp.buf.format, { nargs = 0 })
|
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
||||||
buffer = bufnr,
|
|
||||||
callback = function()
|
|
||||||
vim.lsp.buf.format()
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
server.setup(server_table)
|
|
||||||
|
|
||||||
-- Run the post_setup function if it exists
|
|
||||||
if server_table.post_setup then
|
|
||||||
server_table.post_setup()
|
|
||||||
end
|
|
||||||
else
|
|
||||||
error("LSP server not found: " .. server_name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue