From 7f1268112b49a6c8a517b377722b040ef67840a4 Mon Sep 17 00:00:00 2001 From: Sean Dunn Date: Mon, 30 Oct 2023 21:59:27 -0400 Subject: [PATCH] nvim: Update rust config and add nvim dap --- dot_config/nvim/lua/atta/main/general.lua | 2 +- dot_config/nvim/lua/atta/plugins/lsp/init.lua | 34 ++++++++++++++++++- dot_config/nvim/lua/atta/plugins/lspsaga.lua | 2 +- dot_config/nvim/lua/atta/plugins/mason.lua | 1 + dot_config/nvim/lua/atta/plugins/nvim_dap.lua | 27 +++++++++++++++ dot_config/private_zsh/config/rust.zsh | 4 +++ dot_config/private_zsh/private_functions/c | 2 +- 7 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 dot_config/nvim/lua/atta/plugins/nvim_dap.lua create mode 100644 dot_config/private_zsh/config/rust.zsh diff --git a/dot_config/nvim/lua/atta/main/general.lua b/dot_config/nvim/lua/atta/main/general.lua index d9b1045..4a2b7e7 100644 --- a/dot_config/nvim/lua/atta/main/general.lua +++ b/dot_config/nvim/lua/atta/main/general.lua @@ -88,7 +88,7 @@ local function general_settings() opt.ttimeoutlen = 0 -- When switching buffers, prefer ones that are already open vs opening a new duplicate - opt.switchbuf = "useopen" + -- opt.switchbuf = "useopen" -- Automatically indent inside of blocks per the language rules opt.autoindent = true diff --git a/dot_config/nvim/lua/atta/plugins/lsp/init.lua b/dot_config/nvim/lua/atta/plugins/lsp/init.lua index 50b2ebd..ac5ad4e 100644 --- a/dot_config/nvim/lua/atta/plugins/lsp/init.lua +++ b/dot_config/nvim/lua/atta/plugins/lsp/init.lua @@ -117,7 +117,39 @@ function M.config() opts = vim.tbl_deep_extend("force", {}, options, opts or {}) if server == "rust_analyzer" then - rust_tools.setup(opts) + local mason_registry = require("mason-registry") + local rust_tools_dap = require("rust-tools.dap") + + local codelldb = mason_registry.get_package("codelldb") + local extension_path = codelldb:get_install_path() .. "/extension/" + local codelldb_path = extension_path .. "adapter/codelldb" + local liblldb_path = extension_path .. "lldb/lib/liblldb.dylib" + + rust_options = { + dap = { + adapter = rust_tools_dap.get_codelldb_adapter(codelldb_path, liblldb_path), + }, + server = vim.tbl_deep_extend("force", opts, { + on_attach = function(client, bufnr) + on_attach(client, bufnr) + + vim.keymap.set("n", "K", rust_tools.hover_actions.hover_actions, { buffer = bufnr }) + vim.keymap.set( + "n", + "a", + rust_tools.code_action_group.code_action_group, + { buffer = bufnr } + ) + end, + }), + tools = { + hover_actions = { + auto_focus = true, + }, + }, + } + + rust_tools.setup(rust_options) else lspconfig[server].setup(opts) end diff --git a/dot_config/nvim/lua/atta/plugins/lspsaga.lua b/dot_config/nvim/lua/atta/plugins/lspsaga.lua index 5a8f54b..4e71305 100644 --- a/dot_config/nvim/lua/atta/plugins/lspsaga.lua +++ b/dot_config/nvim/lua/atta/plugins/lspsaga.lua @@ -31,7 +31,7 @@ function M.config() utils.noremap("n", "K", "Lspsaga hover_doc", { silent = true }) -- code action - utils.noremap({ "n", "v" }, "ca", "Lspsaga code_action", { silent = true }) + utils.noremap({ "n", "v" }, "a", "Lspsaga code_action", { silent = true }) -- diagnostics utils.noremap("n", "cd", "Lspsaga show_line_diagnostics", { silent = true }) diff --git a/dot_config/nvim/lua/atta/plugins/mason.lua b/dot_config/nvim/lua/atta/plugins/mason.lua index ec85d84..e02dd50 100644 --- a/dot_config/nvim/lua/atta/plugins/mason.lua +++ b/dot_config/nvim/lua/atta/plugins/mason.lua @@ -21,6 +21,7 @@ local language_servers = { } local tools = { + "codelldb", "eslint_d", "black", "rubocop", diff --git a/dot_config/nvim/lua/atta/plugins/nvim_dap.lua b/dot_config/nvim/lua/atta/plugins/nvim_dap.lua new file mode 100644 index 0000000..16a7e2f --- /dev/null +++ b/dot_config/nvim/lua/atta/plugins/nvim_dap.lua @@ -0,0 +1,27 @@ +local M = { + "mfussenegger/nvim-dap", + "rcarriga/nvim-dap-ui", +} + +function M.config() + local dap = require("dap") + local dapui = require("dapui") + + dapui.setup() + + dap.listeners.after.event_initialized["dapui_config"] = function() + dapui.open() + end + dap.listeners.after.event_terminated["dapui_config"] = function() + dapui.close() + end + dap.listeners.after.event_exited["dapui_config"] = function() + dapui.close() + end + + vim.keymap.set("n", "dt", ":DapToggleBreakpoint") + vim.keymap.set("n", "dx", ":DapTerminate") + vim.keymap.set("n", "do", ":DapStepOver") +end + +return M diff --git a/dot_config/private_zsh/config/rust.zsh b/dot_config/private_zsh/config/rust.zsh new file mode 100644 index 0000000..62f49eb --- /dev/null +++ b/dot_config/private_zsh/config/rust.zsh @@ -0,0 +1,4 @@ +if [[ -d "$HOME/.cargo" ]] +then + source "$HOME/.cargo/env" +fi diff --git a/dot_config/private_zsh/private_functions/c b/dot_config/private_zsh/private_functions/c index 21cfff9..f9906e4 100644 --- a/dot_config/private_zsh/private_functions/c +++ b/dot_config/private_zsh/private_functions/c @@ -1 +1 @@ -z $PROJECTS/$1; +cd $PROJECTS/$1;