nvim-config

Log | Files | Refs | Submodules | README

commit d29bc45ac04166a87af78712bcd142514a929432
parent f453b82d3880eabe241a4a323697a0ba52580c75
Author: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
Date:   Thu, 28 Jul 2022 20:56:14 +0200

feat: add nvim-dap and mappings

Diffstat:
Aafter/ftplugin/dap-repl.lua | 1+
Minit.lua | 5+++--
Alua/dap-config.lua | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mlua/lsp_config.lua | 13+------------
Mlua/plugins.lua | 15++++++++++++---
5 files changed, 78 insertions(+), 17 deletions(-)

diff --git a/after/ftplugin/dap-repl.lua b/after/ftplugin/dap-repl.lua @@ -0,0 +1 @@ +require('dap.ext.autocompl').attach() diff --git a/init.lua b/init.lua @@ -35,7 +35,8 @@ o.scrolloff = 5 o.winblend = 10 o.updatetime = 500 o.cursorline = false -o.mouse = "n" +o.mouse = "nvr" +o.mousemodel = 'extend' o.previewheight = 10 o.title = true o.cursorline = true @@ -77,7 +78,7 @@ o.shortmess:append "c" o.sessionoptions:remove "buffers" vim.g.mapleader = " " -vim.g.maplocalleader = "&" +vim.g.maplocalleader = "\\" vim.api.nvim_create_autocmd("TextYankPost", { callback = function() diff --git a/lua/dap-config.lua b/lua/dap-config.lua @@ -0,0 +1,61 @@ +local dap = require('dap') +dap.adapters.cppdbg = { + id = 'cppdbg', + type = 'executable', + command = 'OpenDebugAD7', +} + +dap.configurations.cpp = { + { + name = "Launch file", + type = "cppdbg", + request = "launch", + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + args = function() + local args_string = vim.fn.input('Arguments: ', "", "file") + return vim.split(args_string, " +") + end, + cwd = '${workspaceFolder}', + stopOnEntry = true, + }, +} + +-- If you want to use this for Rust and C, add something like this: + +dap.configurations.c = dap.configurations.cpp +dap.configurations.rust = dap.configurations.cpp + +dap.defaults.fallback.external_terminal = { + command = vim.fn.exepath "st"; + args = { '-e' }; +} +dap.defaults.fallback.force_external_terminal = true + +local widgets = require "dap.ui.widgets" + +local sbar = widgets.sidebar(widgets.frames) + +dap.listeners.after['event_initialized']['me'] = function() + sbar.open() +end + +dap.listeners.after['event_terminated']['me'] = function() + sbar.close() +end + +vim.keymap.set("n", "<LocalLeader>r", dap.continue) +vim.keymap.set("n", "<LocalLeader>n", dap.step_over) +vim.keymap.set("n", "<LocalLeader>s", dap.step_into) +vim.keymap.set("n", "<LocalLeader>o", dap.step_out) +vim.keymap.set("n", "<LocalLeader>b", dap.toggle_breakpoint) +vim.keymap.set({"n", "v"}, "<LocalLeader><LocalLeader>", widgets.hover) +vim.keymap.set("n", "<LocalLeader>ib", function() + dap.set_breakpoint(vim.fn.input('Breakpoint condition: ')) +end) +vim.keymap.set("n", "<LocalLeader>lb", function() + dap.set_breakpoint(nil, nil, vim.fn.input('Log point message: ')) +end) + +require("nvim-dap-virtual-text").setup() diff --git a/lua/lsp_config.lua b/lua/lsp_config.lua @@ -1,5 +1,3 @@ -require "mason".setup {} - vim.diagnostic.config { virtual_text = false, severity_sort = true, @@ -190,7 +188,6 @@ local function setup_lsp(name, filetypes, command, ucommands, config) if not cfg.root_dir then cfg.root_dir = find_root(cfg.root_markers or { ".git" }, args.file) end - cfg.cmd_cwd = cfg.root_dir vim.lsp.start(cfg) end }) @@ -213,38 +210,31 @@ local default_config = { capabilities = capabilities, on_attach = on_attach } local system_lsps = { hls = { filetypes = { "haskell" }, - cfg = default_config, }, ocamllsp = { filetypes = { "ocaml" }, - cfg = default_config, }, clangd = { filetypes = { "c", "cpp" }, root_markers = { "CMakeLists.txt", ".git" }, - cfg = default_config, }, pylsp = { filetypes = { "python" }, - cfg = default_config, }, rnix = { filetypes = { "nix" }, - cfg = default_config, }, ["vim-language-server"] = { filetypes = { "vim" }, - cfg = default_config, }, gopls = { filetypes = { "go" }, - cfg = default_config, }, -- Special cases @@ -262,7 +252,6 @@ local system_lsps = { filetypes = { "rust" }, root_markers = { "Cargo.toml", ".git" }, command = { "rustup", "run", "nightly", "rust-analyzer" }, - cfg = default_config, }, ["lua-language-server"] = (function() @@ -379,7 +368,7 @@ for lname, config in pairs(system_lsps) do if not config.filetypes then vim.notify(string.format("No filetypes defined for %s", lname)) else - setup_lsp(lname, config.filetypes, config.command or { lname }, config.ucommands or {}, config.cfg) + setup_lsp(lname, config.filetypes, config.command or { lname }, config.ucommands or {}, config.cfg or default_config) end end diff --git a/lua/plugins.lua b/lua/plugins.lua @@ -5,7 +5,8 @@ local fn = vim.fn local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' local packer_bootstrap = false if fn.empty(fn.glob(install_path)) > 0 then - packer_bootstrap = fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', + packer_bootstrap = fn.system({ 'git', 'clone', '--depth', '1', + 'https://github.com/wbthomason/packer.nvim', install_path }) end @@ -30,7 +31,8 @@ return packer.startup(function(use) -- Basic localuse { 'vigoux/complementree.nvim', - requires = { 'L3MON4D3/LuaSnip', 'nvim-treesitter/nvim-treesitter', { 'romgrk/fzy-lua-native', run = 'make' } } } + requires = { 'L3MON4D3/LuaSnip', 'nvim-treesitter/nvim-treesitter', + { 'romgrk/fzy-lua-native', run = 'make' } } } use { 'nvim-telescope/telescope.nvim', requires = { @@ -56,9 +58,16 @@ return packer.startup(function(use) require("lsp_lines").setup() end, } - use { "williamboman/mason.nvim" } + use { "williamboman/mason.nvim", config = function() + require "mason".setup {} + end } localuse { 'vigoux/ltex-ls.nvim' } + -- DAP related + use { 'mfussenegger/nvim-dap', requires = { 'theHamsta/nvim-dap-virtual-text' }, config = function() + require 'dap-config' + end } + -- Treesitter related localuse 'nvim-treesitter/nvim-treesitter' use { 'nvim-treesitter/playground', opt = true }