From 9aba78a4a338c9feb20122711c16de9f263d55dc Mon Sep 17 00:00:00 2001 From: Fabio Lenherr / DashieTM Date: Wed, 7 Dec 2022 08:34:22 +0100 Subject: [PATCH] feat: add codelldb --- nvim/lua/settings/.prettierrc | 4 +- nvim/lua/settings/dap.lua | 230 +++++++++++++++++----------------- nvim/lua/settings/keymaps.lua | 9 +- nvim/lua/settings/lsp.lua | 96 +++----------- nvim/lua/settings/options.lua | 2 +- nvim/lua/settings/plugins.lua | 6 +- 6 files changed, 140 insertions(+), 207 deletions(-) diff --git a/nvim/lua/settings/.prettierrc b/nvim/lua/settings/.prettierrc index b9a0244..e524ddd 100644 --- a/nvim/lua/settings/.prettierrc +++ b/nvim/lua/settings/.prettierrc @@ -1,6 +1,6 @@ { "trailingComma": "all", - "tabWidth": 2, + "tabWidth": 4, "semi": true, - "singleQuote": false + "singleQuote": true } diff --git a/nvim/lua/settings/dap.lua b/nvim/lua/settings/dap.lua index 1a26926..bc43988 100644 --- a/nvim/lua/settings/dap.lua +++ b/nvim/lua/settings/dap.lua @@ -1,126 +1,124 @@ -local dap = require('dap') -dap.adapters.cppdbg = { - id = 'cppdbg', - type = 'executable', - command = '/home/dashie/.config/nvim/plugged/cpptools/extension/debugAdapters/bin/OpenDebugAD7', +local dap = require("dap") +dap.adapters.codelldb = { + type = "server", + port = "${port}", + executable = { + -- CHANGE THIS to your path! + command = "/home/dashie/.local/share/nvim/mason/packages/codelldb/extension/adapter/codelldb", + args = { "--port", "${port}" }, + }, +} + +local rust_dap = vim.fn.getcwd() +local filename = "" +for w in rust_dap:gmatch("([^/]+)") do filename = w end + +dap.configurations.rust = { + { + type = "codelldb", + request = "launch", + program = function() + return rust_dap .. "/target/debug/" .. filename + end, + --program = '${fileDirname}/${fileBasenameNoExtension}', + cwd = "${workspaceFolder}", + stopOnEntry = true, + terminal = "integrated", + }, } dap.configurations.cpp = { - { - name = "Launch file", - type = "cppdbg", - request = "launch", - program = function() - return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/build/', 'file') - end, - cwd = '${workspaceFolder}', - stopAtEntry = true, - }, - { - name = "Launch file --gui", - type = "cppdbg", - request = "launch", - program = function() - return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/build/', 'file') - end, - args = {'--gui'}, - cwd = '${workspaceFolder}', - stopAtEntry = true, - }, - { - name = 'Attach to gdbserver :1234', - type = 'cppdbg', - request = 'launch', - MIMode = 'gdb', - miDebuggerServerAddress = 'localhost:1234', - miDebuggerPath = '/usr/bin/gdb', - cwd = '${workspaceFolder}', - program = function() - return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/build/', 'file') - end, - }, + { + type = "codelldb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/build/", "file") + end, + --program = '${fileDirname}/${fileBasenameNoExtension}', + cwd = "${workspaceFolder}", + terminal = "integrated", + }, } - dap.configurations.c = dap.configurations.cpp -dap.configurations.rust = dap.configurations.cpp require("dapui").setup({ - icons = { expanded = "▾", collapsed = "▸", current_frame = "▸" }, - mappings = { - -- Use a table to apply multiple mappings - expand = { "", "<2-LeftMouse>" }, - open = "o", - remove = "d", - edit = "e", - repl = "r", - toggle = "t", - }, - -- Expand lines larger than the window - -- Requires >= 0.7 - expand_lines = vim.fn.has("nvim-0.7") == 1, - -- Layouts define sections of the screen to place windows. - -- The position can be "left", "right", "top" or "bottom". - -- The size specifies the height/width depending on position. It can be an Int - -- or a Float. Integer specifies height/width directly (i.e. 20 lines/columns) while - -- Float value specifies percentage (i.e. 0.3 - 30% of available lines/columns) - -- Elements are the elements shown in the layout (in order). - -- Layouts are opened in order so that earlier layouts take priority in window sizing. - layouts = { - { - elements = { - -- Elements can be strings or table with id and size keys. - { id = "scopes", size = 0.25 }, - "breakpoints", - "stacks", - "watches", - }, - size = 40, -- 40 columns - position = "left", - }, - { - elements = { - "repl", - "console", - }, - size = 0.25, -- 25% of total lines - position = "bottom", - }, - }, - controls = { - -- Requires Neovim nightly (or 0.8 when released) - enabled = true, - -- Display controls in this element - element = "repl", - icons = { - pause = "", - play = "", - step_into = "", - step_over = "", - step_out = "", - step_back = "", - run_last = "↻", - terminate = "□", - }, - }, - floating = { - max_height = nil, -- These can be integers or a float between 0 and 1. - max_width = nil, -- Floats will be treated as percentage of your screen. - border = "single", -- Border style. Can be "single", "double" or "rounded" - mappings = { - close = { "q", "" }, - }, - }, - windows = { indent = 1 }, - render = { - max_type_length = nil, -- Can be integer or nil. - max_value_lines = 100, -- Can be integer or nil. - } + icons = { expanded = "▾", collapsed = "▸", current_frame = "▸" }, + mappings = { + -- Use a table to apply multiple mappings + expand = { "", "<2-LeftMouse>" }, + open = "o", + remove = "d", + edit = "e", + repl = "r", + toggle = "t", + }, + -- Expand lines larger than the window + -- Requires >= 0.7 + expand_lines = vim.fn.has("nvim-0.7") == 1, + -- Layouts define sections of the screen to place windows. + -- The position can be "left", "right", "top" or "bottom". + -- The size specifies the height/width depending on position. It can be an Int + -- or a Float. Integer specifies height/width directly (i.e. 20 lines/columns) while + -- Float value specifies percentage (i.e. 0.3 - 30% of available lines/columns) + -- Elements are the elements shown in the layout (in order). + -- Layouts are opened in order so that earlier layouts take priority in window sizing. + layouts = { + { + elements = { + -- Elements can be strings or table with id and size keys. + { id = "scopes", size = 0.25 }, + "breakpoints", + "stacks", + "watches", + }, + size = 40, -- 40 columns + position = "left", + }, + { + elements = { + "repl", + "console", + }, + size = 0.25, -- 25% of total lines + position = "bottom", + }, + }, + controls = { + -- Requires Neovim nightly (or 0.8 when released) + enabled = true, + -- Display controls in this element + element = "repl", + icons = { + pause = "", + play = "", + step_into = "", + step_over = "", + step_out = "", + step_back = "", + run_last = "↻", + terminate = "□", + }, + }, + floating = { + max_height = nil, -- These can be integers or a float between 0 and 1. + max_width = nil, -- Floats will be treated as percentage of your screen. + border = "single", -- Border style. Can be "single", "double" or "rounded" + mappings = { + close = { "q", "" }, + }, + }, + windows = { indent = 1 }, + render = { + max_type_length = nil, -- Can be integer or nil. + max_value_lines = 100, -- Can be integer or nil. + }, }) require("mason-nvim-dap").setup({ - ensure_installed = { "cpptools", - "bash-debug-adapter", - "firefox-debug-adapter", - "js-debug-adapter", - "node-debug2-adapter" - } + ensure_installed = { + "codelldb", + "bash-debug-adapter", + "firefox-debug-adapter", + "js-debug-adapter", + "node-debug2-adapter", + }, }) diff --git a/nvim/lua/settings/keymaps.lua b/nvim/lua/settings/keymaps.lua index 5cd2487..b9e12a2 100644 --- a/nvim/lua/settings/keymaps.lua +++ b/nvim/lua/settings/keymaps.lua @@ -7,16 +7,15 @@ local keymap = vim.api.nvim_set_keymap --vim.lsp.handlers["textDocument/codeAction"] = require'lspactions'.codeaction --vim.cmd [[ nnoremap af :lua require'lspactions'.code_action() ]] -keymap("n", "", ":CodeActionMenu", opts) +-- keymap("n", "", ":CodeActionMenu", opts) keymap("n", "", "TroubleToggle", term_opts) -keymap("n", "", ':lua require("vgit").buffer_hunk_preview()', opts) --keymap("n", "", ':lua require("vgit").buffer_stage()', opts) keymap("n", "", ':lua require("dap").toggle_breakpoint()', opts) keymap("n", "", ':lua require("dap").step_over()', opts) keymap("n", "", ':lua require("dap").step_into()', opts) -keymap("n", "", ':lua require("dap").continue()', opts) -keymap("n", "", ':lua require("dap").close() :lua require("dapui").toggle()', opts) -keymap("n", "", ':lua require("dap").continue() :lua require("dapui").toggle()', opts) +keymap("n", "", ':lua require("dap").continue() :lua require("dapui").toggle()', opts) +keymap("n", "", ':lua require("dap").continue()', opts) +keymap("n", "", ':lua require("dap").close() :lua require("dapui").toggle()', opts) keymap("n", "t", ':lua require("nvim-tree").toggle()', opts) keymap("n", "f", ':lua require("nvim-tree").focus()', opts) diff --git a/nvim/lua/settings/lsp.lua b/nvim/lua/settings/lsp.lua index e03abc9..f122c03 100644 --- a/nvim/lua/settings/lsp.lua +++ b/nvim/lua/settings/lsp.lua @@ -17,9 +17,8 @@ require("mason-lspconfig").setup({ ensure_installed = { "cssls", -- css "html", -- html - "eslint", -- latex "clangd", -- cpp / c - --"tsserver", -- python + "tsserver", -- python "texlab", -- latex "sumneko_lua", -- lua "pyright", -- python @@ -28,86 +27,27 @@ require("mason-lspconfig").setup({ "cmake", -- cmake "bashls", -- shell "ansiblels", -- ansible - "csharp_ls", -- dotnot + "omnisharp", -- dotnot "hls", -- haskel }, automatic_installation = true, }) -local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) +local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) -require("lspconfig")["cssls"].setup({ - capabilities = capabilities, - --on_attach = on_attach, +local on_attach = function(client, bufnr) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") + local opts = { noremap = true, silent = true, buffer=bufnr } + vim.keymap.set("n", "", "lua vim.lsp.buf.hover()", opts) + vim.keymap.set("n", "", "lua vim.lsp.buf.code_action", opts) +end + +require("mason-lspconfig").setup_handlers({ + function(server_name) -- default handler (optional) + require("lspconfig")[server_name].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + end, }) - -require("lspconfig")["html"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - -require("lspconfig")["eslint"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - -require("lspconfig")["clangd"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - ---require("lspconfig")["tsserver"].setup({ --- capabilities = capabilities, - --on_attach = on_attach, ---}) - -require("lspconfig")["texlab"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - -require("lspconfig")["sumneko_lua"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - -require("lspconfig")["pyright"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - -require("lspconfig")["rust_analyzer"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - -require("lspconfig")["jdtls"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - -require("lspconfig")["cmake"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - -require("lspconfig")["bashls"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - -require("lspconfig")["ansiblels"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - -require("lspconfig")["csharp_ls"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - -require("lspconfig")["hls"].setup({ - capabilities = capabilities, - --on_attach = on_attach, -}) - diff --git a/nvim/lua/settings/options.lua b/nvim/lua/settings/options.lua index 2297bb1..71a4c39 100644 --- a/nvim/lua/settings/options.lua +++ b/nvim/lua/settings/options.lua @@ -1,6 +1,6 @@ local options = { clipboard = "unnamedplus", - mouse = "a", + mouse = "n", fileencoding = "utf-8", relativenumber = true, cursorline = false, diff --git a/nvim/lua/settings/plugins.lua b/nvim/lua/settings/plugins.lua index 2f4c6e4..54d42ef 100644 --- a/nvim/lua/settings/plugins.lua +++ b/nvim/lua/settings/plugins.lua @@ -17,7 +17,7 @@ Plug("mfussenegger/nvim-dap") -- debugging capabilities Plug("rcarriga/nvim-dap-ui") -- debug ui Plug("theHamsta/nvim-dap-virtual-text") -- more debug ui Plug("jayp0521/mason-nvim-dap.nvim") -- debug mason bridge -Plug("nvim-treesitter/nvim-treesitter", +Plug("nvim-treesitter/nvim-treesitter", { ["do"] = vim.fn[":TSUpdate"] }) -- syntax colors Plug("hrsh7th/nvim-cmp") -- completions Plug("hrsh7th/cmp-nvim-lsp") -- lsp integration with completions @@ -44,9 +44,5 @@ Plug("nvim-telescope/telescope-ui-select.nvim") -- telescope ui Plug("nvim-telescope/telescope-file-browser.nvim") -- telescope file browser Plug("nvim-telescope/telescope-fzy-native.nvim") -- telescope fuzzy search Plug 'folke/trouble.nvim' -- provides warning/error explanation tab ---Plug("folke/twilight.nvim") --twilight dims code not being edited right now ? useless ? ---Plug("lambdalisue/fern.vim") -- likely not needed? ---Plug("MarcWeber/vim-addon-mw-utils") -- wtf? ---Plug("tomtom/tlib_vim") --wtf2? vim.call("plug#end")