From f30e09d3c8884185ad9eceae8699eb900f731b2c Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Tue, 5 Jul 2022 16:49:59 -0500 Subject: fix(nvim): only run codelldb check on rust lsp attach --- .../nvim/lua/tobyvin/plugins/rust-tools.lua | 41 +++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/rust-tools.lua b/nvim/.config/nvim/lua/tobyvin/plugins/rust-tools.lua index 3178e75..f78d360 100644 --- a/nvim/.config/nvim/lua/tobyvin/plugins/rust-tools.lua +++ b/nvim/.config/nvim/lua/tobyvin/plugins/rust-tools.lua @@ -1,22 +1,15 @@ -local M = {} +local lsp = require("tobyvin.lsp") +local M = { + codelldb = "/usr/lib/codelldb/adapter/codelldb", + liblldb = "/usr/lib/codelldb/lldb/lib/liblldb.so", +} -M._dap_adapter = function() - local ext_path = vim.env.HOME .. "/usr/lib/codelldb/" - local codelldb_path = ext_path .. "adapter/codelldb" - local liblldb_path = ext_path .. "lldb/lib/liblldb.so" - - if not require("tobyvin.utils").isdir(ext_path) then - vim.notify( - "[DAP] Failed to find codelldb, falling back to default DAP adapter.", - "warn", - { title = "[rust-tools] codelldb not found" } - ) - return {} +M.dap_adapter = function() + if vim.fn.executable(M.codelldb) ~= 0 then + return { + adapter = require("rust-tools.dap").get_codelldb_adapter(M.codelldb, M.liblldb), + } end - - return { - adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path), - } end M.setup = function() @@ -26,8 +19,6 @@ M.setup = function() return end - local lsp = require("tobyvin.lsp") - rust_tools.setup({ tools = { autoSetHints = true, @@ -52,8 +43,18 @@ M.setup = function() }, }, }, + on_attach = function(client, bufnr) + if vim.fn.executable(M.codelldb) == 0 then + vim.notify( + "[DAP] Failed to find codelldb, falling back to default DAP adapter.", + "warn", + { title = "[rust-tools] codelldb not found" } + ) + end + lsp.on_attach(client, bufnr) + end, }), - dap = M._dap_adapter(), + dap = M.dap_adapter(), }) end -- cgit v1.2.3-70-g09d2