From 9efae9f0f4db2d86354a926c174860681830987f Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Thu, 11 May 2023 17:30:35 +0300 Subject: [PATCH] setup dap debugger --- lua/config/dap.lua | 36 ++++++++++++++++++++++++++++++++++++ lua/config/lspinstaller.lua | 33 ++++++++++++++------------------- lua/plugins.lua | 13 +++++++++++-- 3 files changed, 61 insertions(+), 21 deletions(-) create mode 100644 lua/config/dap.lua diff --git a/lua/config/dap.lua b/lua/config/dap.lua new file mode 100644 index 0000000..4b23707 --- /dev/null +++ b/lua/config/dap.lua @@ -0,0 +1,36 @@ +local dap = require('dap') +dap.adapters.lldb = { + type = 'executable', + command = '/usr/bin/lldb-vscode', + name = 'lldb' +} + +dap.configurations.cpp = { + { + name = 'Launch', + type = 'lldb', + request = 'launch', + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', '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, + }, +} + +dap.configurations.c = dap.configurations.cpp +dap.configurations.rust = dap.configurations.cpp diff --git a/lua/config/lspinstaller.lua b/lua/config/lspinstaller.lua index aa40e63..e6bb58e 100644 --- a/lua/config/lspinstaller.lua +++ b/lua/config/lspinstaller.lua @@ -1,5 +1,5 @@ local lspconfig_config = require 'config.lspconfig' -local lsp_instller = require 'nvim-lsp-installer' +local lsp_installer = require 'nvim-lsp-installer' local lsp_installer_servers = require'nvim-lsp-installer.servers' local M = {} @@ -14,12 +14,8 @@ end local capabilities = lspconfig_config.get_capabilities() -lsp_instller.on_server_ready(function(server) - - -- print(server.name) - -- print(vim.inspect(lspconfig_config.get_server_settings(server.name))) - - server:setup{ +for _, server in ipairs(lsp_installer.get_installed_servers()) do + local opts = { root_dir = function() return vim.fn.getcwd() end, @@ -30,18 +26,17 @@ lsp_instller.on_server_ready(function(server) capabilities = capabilities, settings = lspconfig_config.get_server_settings(server.name) } -end) -require("lspconfig").gdscript.setup{ - root_dir = function() - return vim.fn.getcwd() - end, - init_options = lspconfig_config.get_server_init_options("godot"), - on_attach = lspconfig_config.on_attach, - on_init = lspconfig_config.on_init, - flags = lspconfig_config.flags, - capabilities = capabilities, - settings = lspconfig_config.get_server_settings("godot") -} + if server.name == "rust_analyzer" then + local has_rust_tools, rust_tools = pcall(require, "rust-tools") + if has_rust_tools then + rust_tools.setup({ server = opts }) + goto continue + end + end + + server:setup(opts) + ::continue:: +end return M diff --git a/lua/plugins.lua b/lua/plugins.lua index e37347a..77cf4f6 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -3,9 +3,18 @@ ---@diagnostic disable-next-line: unused-local local function usePlugins(use, use_rocks) + -- Toggle terminal + use {'akinsho/toggleterm.nvim', tag = '*', config=[[require('toggleterm').setup()]]} + -- Debugger - use { 'puremourning/vimspector', config = [[require 'config.vimspector']] } - use 'puuuuh/vimspector-rust' + use { 'mfussenegger/nvim-dap', config=[[require('config.dap')]]} + use { "rcarriga/nvim-dap-ui", requires = "mfussenegger/nvim-dap", config=[[require('dapui').setup()]] } + use 'simrat39/rust-tools.nvim' + use { + 'theHamsta/nvim-dap-virtual-text', + requires = {"mfussenegger/nvim-dap", "nvim-treesitter/nvim-treesitter"}, + config=[[require('nvim-dap-virtual-text')]] + } -- Seemless pane switching betwen tmux and vim use 'christoomey/vim-tmux-navigator'