From 51139ded5ca3158b2b2679f5af4a0d01d387cc9f Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 18 Aug 2022 16:12:37 +0200 Subject: [PATCH] feat: added early nvim-dap configuration still needs some work, it's a pretty weak configuration. It would also be very cool if language-specific configurations were loaded with ftplugin, rather than for each file. --- lua/colors.lua | 35 +++++++++++++++- lua/keybinds.lua | 23 ++++++++--- lua/plugins.lua | 102 ++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 134 insertions(+), 26 deletions(-) diff --git a/lua/colors.lua b/lua/colors.lua index c600b5b..46f2455 100644 --- a/lua/colors.lua +++ b/lua/colors.lua @@ -249,7 +249,7 @@ end function PALETTE:set_telescope_colors() -- FG BG ATTR vim.api.nvim_set_hl(0, "TelescopeBorder", HIGHLIGHT(self.black.bright, nil, nil)); - -- vim.api.nvim_set_hl(0, "TelescopePromptBorder", highlight(self.black.bright, nil, nil)); + -- vim.api.nvim_set_hl(0, "TelescopePromptBorder", highlight(self.black.bright, nil, nil)) -- vim.api.nvim_set_hl(0, "TelescopePromptNormal", highlight()); -- vim.api.nvim_set_hl(0, "TelescopePromptPrefix", highlight()); -- vim.api.nvim_set_hl(0, "TelescopeNormal", highlight()); @@ -260,6 +260,38 @@ function PALETTE:set_telescope_colors() -- vim.api.nvim_set_hl(0, "TelescopePreviewLine", highlight()); end +function PALETTE:set_dap_colors() + -- FG BG ATTR + vim.api.nvim_set_hl(0, "DapMarks", HIGHLIGHT(self.purple.normal, nil, {bold=true})) + vim.api.nvim_set_hl(0, "DapStep", HIGHLIGHT(nil, self.black.normal, nil)) + vim.api.nvim_set_hl(0, "DapStepNr", HIGHLIGHT(self.purple.normal, self.black.normal, {bold=true})) + -- DapUIVariable xxx links to Normal + -- DapUIScope xxx guifg=#00F1F5 + -- DapUIType xxx guifg=#D484FF + -- DapUIValue xxx links to Normal + -- DapUIModifiedValue xxx gui=bold guifg=#00F1F5 + -- DapUIDecoration xxx guifg=#00F1F5 + -- DapUIThread xxx guifg=#A9FF68 + -- DapUIStoppedThread xxx guifg=#00f1f5 + -- DapUIFrameName xxx links to Normal + -- DapUISource xxx guifg=#D484FF + -- DapUILineNumber xxx guifg=#00f1f5 + -- DapUIFloatBorder xxx guifg=#00F1F5 + -- DapUIWatchesEmpty xxx guifg=#F70067 + -- DapUIWatchesValue xxx guifg=#A9FF68 + -- DapUIWatchesError xxx guifg=#F70067 + -- DapUIBreakpointsPath xxx guifg=#00F1F5 + -- DapUIBreakpointsInfo xxx guifg=#A9FF68 + -- DapUIBreakpointsCurrentLine xxx gui=bold guifg=#A9FF68 + -- DapUIBreakpointsLine xxx links to DapUILineNumber + -- DapUIBreakpointsDisabledLine xxx guifg=#424242 + vim.fn.sign_define('DapBreakpoint', {text='⬤', texthl='DapMarks', linehl='', numhl=''}) + vim.fn.sign_define('DapBreakpointCondition', {text='◯', texthl='DapMarks', linehl='', numhl=''}) + vim.fn.sign_define('DapBreakpointRejected', {text='⦻', texthl='DapMarks', linehl='', numhl=''}) + vim.fn.sign_define('DapLogPoint', {text='□', texthl='DapMarks', linehl='', numhl=''}) + vim.fn.sign_define('DapStopped', {text='➤', texthl='DapStepNr', linehl='DapStep', numhl='DapStepNr'}) +end + --- set all theme highlight groups function PALETTE:set_colors() -- core @@ -273,6 +305,7 @@ function PALETTE:set_colors() self:set_treesitter_colors() self:set_gitsigns_colors() self:set_telescope_colors() + self:set_dap_colors() end return PALETTE diff --git a/lua/keybinds.lua b/lua/keybinds.lua index 03092f2..2c3e35a 100644 --- a/lua/keybinds.lua +++ b/lua/keybinds.lua @@ -28,12 +28,10 @@ local KEYBINDS = { --|| GLOBAL KEYBINDS function KEYBINDS:set_global_keys(opts) -- Quick settings - vim.keymap.set('n', '', ':set hls!', opts) - vim.keymap.set('n', '', ':set wrap!', opts) - vim.keymap.set('n', '', ':set list!', opts) - vim.keymap.set('n', '', ':set spell!', opts) - vim.keymap.set('n', '', ':Hexmode', opts) - vim.keymap.set('n', '', ':Telescope oldfiles', opts) + vim.keymap.set('n', '', ':set hls!', opts) + vim.keymap.set('n', '', ':set wrap!', opts) + vim.keymap.set('n', '', ':set list!', opts) + vim.keymap.set('n', '', ':set spell!', opts) -- Files navigation vim.keymap.set('n', '', ':tabnew', opts) vim.keymap.set('n', '', ':tabnew', opts) -- fallback for windows @@ -90,6 +88,7 @@ end function KEYBINDS:set_telescope_keys(opts) -- File navigation + vim.keymap.set('n', '', ':Telescope oldfiles', opts) vim.keymap.set('n', '', ':Telescope find_files', opts) vim.keymap.set('n', 'F', ':Telescope find_files', opts) -- fallback for windows vim.keymap.set('n', '', ':Telescope live_grep', opts) @@ -112,4 +111,16 @@ function KEYBINDS:set_telescope_keys(opts) vim.keymap.set('n', '', ':Telescope diagnostics bufnr=0', opts) end +function KEYBINDS:set_dap_keys(opts) + -- dapui + local dap = require('dap') + local dapui = require('dapui') + vim.keymap.set('n', '' , function() dapui.toggle({}) end, {}) + vim.keymap.set('n', '' , function() dap.toggle_breakpoint() end, {}) + vim.keymap.set('n', '' , function() dap.continue() end, {}) + vim.keymap.set('n', '', function() dap.step_over() end, {}) + vim.keymap.set('n', '', function() dap.step_into() end, {}) + vim.keymap.set('n', '', function() dap.step_out() end, {}) +end + return KEYBINDS diff --git a/lua/plugins.lua b/lua/plugins.lua index fc144b7..15c72e7 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -38,13 +38,68 @@ local init_fn = function(use) use 'neovim/nvim-lspconfig' -- import LSP configurations use 'simrat39/rust-tools.nvim' -- extra LSP defaults for rust - use 'hrsh7th/nvim-cmp' -- completion engine core - use 'hrsh7th/cmp-nvim-lsp' -- completions based on LSP - use 'hrsh7th/cmp-path' -- completions based on paths - use 'hrsh7th/cmp-buffer' -- completions based on buffer - use 'L3MON4D3/LuaSnip' -- snippet engine - use 'saadparwaiz1/cmp_luasnip' -- incorporate with completions + + use { + 'mfussenegger/nvim-dap', -- debugger adapter protocol + requires = { + 'rcarriga/nvim-dap-ui', --batteries-included debugger ui + }, + config = function() + local dap = require('dap') + dap.adapters.python = { + type = 'executable', + command = (vim.fn.environ()["VIRTUAL_ENV"] or "") .. "/bin/python", + args = { '-m', 'debugpy.adapter' }, + } + dap.configurations.python = { + { + name = "Launch file", + type = "python", + request = "launch", + program = vim.fn.expand('%'), + cwd = '${workspaceFolder}', + }, + } + dap.adapters.lldb = { + type = 'executable', + command = '/usr/bin/lldb-vscode', -- adjust as needed, must be absolute path + name = 'lldb' + } + dap.configurations.cpp = { + { + name = 'Launch', + type = 'lldb', + request = 'launch', + program = function() + local program = "" + for i in string.gmatch(vim.fn.getcwd(), "([^/]+)") do + program = i + end + return vim.fn.getcwd() .. "/target/debug/" .. program -- TODO can I put startup file somewhere? + end, + cwd = '${workspaceFolder}', + }, + } + dap.configurations.c = dap.configurations.cpp + dap.configurations.rust = dap.configurations.cpp + require('keybinds'):set_dap_keys({}) + require('dapui').setup() + end, + } + + use { + 'hrsh7th/nvim-cmp', -- completion engine core + requires = { + 'hrsh7th/cmp-nvim-lsp', -- complete with LSP + 'hrsh7th/cmp-nvim-lsp-signature-help', -- complete function signatures + 'hrsh7th/cmp-nvim-lsp-document-symbol', -- complete document symbols + 'hrsh7th/cmp-path', -- complete paths + 'hrsh7th/cmp-buffer', -- complete based on buffer + 'rcarriga/cmp-dap', -- complete in debugger + 'saadparwaiz1/cmp_luasnip', -- complete with snippets + }, + } use { 'norcalli/nvim-colorizer.lua', @@ -61,7 +116,7 @@ local init_fn = function(use) config = function() require('telescope').load_extension('fzf') require("telescope").load_extension("ui-select") - require('keybinds').set_telescope_keys({}) + require('keybinds'):set_telescope_keys({}) end } @@ -117,24 +172,33 @@ local init_fn = function(use) -- TODO this part is messy, can I make it cleaner? -- TODO can I put these setup steps inside their respective config callback? -- TODO can I make them also load their highlight groups? + local cmp = require('cmp') cmp.setup({ snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) end, }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = function(fallback) if cmp.visible() then cmp.select_next_item() else fallback() end end, - [''] = cmp.mapping.confirm({ select = true }), - }), + mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.confirm({ select = true }) }), sources = cmp.config.sources({ + { name = 'nvim_lsp_signature_help', max_item_count = 1 }, + { name = 'luasnip' }, { name = 'nvim_lsp' }, - }, { - { name = 'path' }, - }, { - { name = 'buffer' }, + { name = 'path', max_item_count = 3 }, + { name = 'buffer', keyword_length = 3, max_item_count = 3 }, + }), + }) + cmp.setup.filetype({ "dap-repl", "dapui_watches" }, { + mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.confirm({ select = true }) }), + sources = { + { name = 'dap' }, + }, + }) + cmp.setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'nvim_lsp_document_symbol' }, + { name = 'buffer', keyword_length = 3 }, }) }) @@ -156,7 +220,8 @@ local init_fn = function(use) server = { capabilities = capabilities, on_attach = set_lsp_binds, - } + }, + dap = { adapter = require('dap').adapters.lldb }, }) rust_tools.inlay_hints.enable() @@ -191,4 +256,3 @@ end return require('packer').startup(init_fn) -