From 079c385b9bd40a73ebafae6d847f62c2bed5126c Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Mon, 20 May 2024 17:08:02 +0100 Subject: [nvim] Rewrite config motivated by nvim 0.10 --- home/.config/nvim/after/plugin/mappings.lua | 4 - home/.config/nvim/init.lua | 12 +- home/.config/nvim/lua/cfg/lsp.lua | 107 +- home/.config/nvim/lua/cfg/options.lua | 16 +- home/.config/nvim/lua/cfg/utils.lua | 21 +- .../.config/nvim/lua/custom/plugins/completion.lua | 112 ++ home/.config/nvim/lua/custom/plugins/debug.lua | 237 +++++ home/.config/nvim/lua/custom/plugins/ft.lua | 7 + home/.config/nvim/lua/custom/plugins/git.lua | 116 +++ home/.config/nvim/lua/custom/plugins/init.lua | 1076 +------------------- home/.config/nvim/lua/custom/plugins/lsp.lua | 210 ++++ home/.config/nvim/lua/custom/plugins/telescope.lua | 139 +++ home/.config/nvim/lua/custom/plugins/ts.lua | 148 +++ home/.config/nvim/lua/custom/plugins/ui.lua | 81 ++ 14 files changed, 1120 insertions(+), 1166 deletions(-) create mode 100644 home/.config/nvim/lua/custom/plugins/completion.lua create mode 100644 home/.config/nvim/lua/custom/plugins/debug.lua create mode 100644 home/.config/nvim/lua/custom/plugins/ft.lua create mode 100644 home/.config/nvim/lua/custom/plugins/git.lua create mode 100644 home/.config/nvim/lua/custom/plugins/lsp.lua create mode 100644 home/.config/nvim/lua/custom/plugins/telescope.lua create mode 100644 home/.config/nvim/lua/custom/plugins/ts.lua create mode 100644 home/.config/nvim/lua/custom/plugins/ui.lua (limited to 'home') diff --git a/home/.config/nvim/after/plugin/mappings.lua b/home/.config/nvim/after/plugin/mappings.lua index 7fd0f03..f16c720 100644 --- a/home/.config/nvim/after/plugin/mappings.lua +++ b/home/.config/nvim/after/plugin/mappings.lua @@ -46,10 +46,6 @@ map.ncmd("x", "update") map.t("", "", { silent = true, noremap = true, expr = true }) -map.n("gw", vim.diagnostic.open_float) -map.n("gW", vim.diagnostic.setloclist) -map.n("[w", vim.diagnostic.goto_prev) -map.n("]w", vim.diagnostic.goto_next) map.n("[e", function() vim.diagnostic.goto_prev({ severity = vim.diagnostic.severity.ERROR }) end) diff --git a/home/.config/nvim/init.lua b/home/.config/nvim/init.lua index 8326c43..e71c054 100644 --- a/home/.config/nvim/init.lua +++ b/home/.config/nvim/init.lua @@ -1,10 +1,6 @@ vim.loader.enable() -function docfg(name) - dofile(vim.fn.stdpath("config") .. "/lua/cfg/" .. name .. ".lua") -end - -docfg("options") +dofile(vim.fn.stdpath("config") .. "/lua/cfg/options.lua") function P(v) print(vim.inspect(v)) @@ -23,4 +19,8 @@ if not vim.loop.fs_stat(lazypath) then }) end vim.opt.rtp:prepend(lazypath) -require("lazy").setup("custom.plugins") +require("lazy").setup({ import = "custom/plugins" }, { + change_detection = { + notify = false, + }, +}) diff --git a/home/.config/nvim/lua/cfg/lsp.lua b/home/.config/nvim/lua/cfg/lsp.lua index 5767ff6..894b578 100644 --- a/home/.config/nvim/lua/cfg/lsp.lua +++ b/home/.config/nvim/lua/cfg/lsp.lua @@ -1,64 +1,53 @@ -return { - on_attach_wrapper = function(client, bufnr, opts) - local map = require("mapper") - local autocmd = vim.api.nvim_create_autocmd +local M = {} +local map = require("mapper") +local lspconfig = require("lspconfig") - opts = vim.tbl_extend("force", { auto_format = false }, opts or {}) +function M.on_attach_wrapper(client, bufnr, opts) + local autocmd = vim.api.nvim_create_autocmd - if client.supports_method("textDocument/codeLens") then - require("virtualtypes").on_attach(client, bufnr) - autocmd( - { "CursorHold", "CursorHoldI", "InsertLeave" }, - { buffer = bufnr, callback = vim.lsp.codelens.refresh } - ) - map.n("gl", vim.lsp.codelens.run, { buffer = bufnr }) - end - - if client.supports_method("textDocument/definition") then - map.n("", vim.lsp.buf.definition, { buffer = bufnr }) - end - if client.supports_method("textDocument/declaration") then - map.n("gD", vim.lsp.buf.declaration, { buffer = bufnr }) - end - if client.supports_method("textDocument/signatureHelp") then - require("lsp_signature").on_attach(client, bufnr) - map.n("gs", vim.lsp.buf.signature_help, { buffer = bufnr }) - end - if client.supports_method("textDocument/rename") then - map.n("gR", vim.lsp.buf.rename, { buffer = bufnr }) - end - if client.supports_method("textDocument/codeAction") then - map.n("ga", vim.lsp.buf.code_action, { buffer = bufnr }) - map.v("ga", vim.lsp.buf.code_action, { buffer = bufnr }) - end - - local buf_async_format = function() - vim.lsp.buf.format( - { bufnr = bufnr, async = true, id = client.id }) - end - local buf_sync_format = function() - vim.lsp.buf.format( - { bufnr = bufnr, async = false, id = client.id }) - end - local buf_async_format_hunks = function() - require("cfg.utils").format_hunks( - { bufnr = bufnr, async = true, id = client.id }) - end + if client.supports_method("textDocument/codeLens") then + autocmd( + { "CursorHold", "CursorHoldI", "InsertLeave" }, + { buffer = bufnr, callback = vim.lsp.codelens.refresh } + ) + map.n("gl", vim.lsp.codelens.run, { buffer = bufnr }) + end - if client.supports_method("textDocument/formatting") then - map.n("f", buf_async_format, { buffer = bufnr }) - if opts.auto_format then - autocmd( - "BufWritePre", - { buffer = bufnr, callback = buf_sync_format } - ) - end - end - if client.supports_method("textDocument/rangeFormatting") then - map.v("f", buf_async_format, { buffer = bufnr }) - map.n("hf", buf_async_format_hunks, { buffer = bufnr }) - end + map.n("", vim.lsp.buf.definition, { buffer = bufnr }) + map.n("gD", vim.lsp.buf.declaration, { buffer = bufnr }) + map.n("gR", vim.lsp.buf.rename, { buffer = bufnr }) + map.n("ga", vim.lsp.buf.code_action, { buffer = bufnr }) + map.v("ga", vim.lsp.buf.code_action, { buffer = bufnr }) +end - require("lsp-inlayhints").on_attach(client, bufnr, false) +function M.switch_source_header_splitcmd(bufnr, splitcmd) + bufnr = lspconfig.util.validate_bufnr(bufnr) + local clangd_client = lspconfig.util.get_active_client_by_name( + bufnr, + "clangd" + ) + local params = { uri = vim.uri_from_bufnr(bufnr) } + if clangd_client then + clangd_client.request( + "textDocument/switchSourceHeader", + params, + function(err, result) + if err then + error(tostring(err)) + end + if not result then + print("Corresponding file cannot be determined") + return + end + vim.api.nvim_command(splitcmd .. " " .. vim.uri_to_fname(result)) + end, + bufnr + ) + else + print( + "method textDocument/switchSourceHeader is not supported by any servers active on the current buffer" + ) end -} +end + +return M diff --git a/home/.config/nvim/lua/cfg/options.lua b/home/.config/nvim/lua/cfg/options.lua index cce808a..ee957a2 100644 --- a/home/.config/nvim/lua/cfg/options.lua +++ b/home/.config/nvim/lua/cfg/options.lua @@ -2,16 +2,11 @@ local opt = vim.opt opt.undofile = true opt.swapfile = false -vim.opt.shadafile = "NONE" -vim.g.ts_highlight_lua = true -vim.g.ts_highlight_c = true -vim.g.ts_highlight_vim = true +opt.shadafile = "NONE" -opt.showmode = true opt.number = true opt.cursorline = true opt.signcolumn = "auto:2" -opt.showtabline = 2 opt.showmatch = true opt.expandtab = true @@ -20,8 +15,6 @@ opt.shiftwidth = 0 opt.softtabstop = -1 opt.tabstop = 4 -opt.foldenable = false - opt.splitbelow = true opt.splitright = true @@ -32,7 +25,6 @@ opt.colorcolumn = "+1" opt.formatoptions:remove("t") opt.cmdheight = 2 -opt.updatetime = 300 opt.shortmess:append({ a = true }) @@ -106,7 +98,6 @@ opt.foldmethod = "expr" opt.foldexpr = "nvim_treesitter#foldexpr()" opt.foldenable = false -opt.laststatus = 2 vim.g.mapleader = " " vim.g.maplocalleader = "," @@ -114,8 +105,5 @@ vim.diagnostic.config({ virtual_text = { source = "if_many", severity = vim.diagnostic.severity.ERROR, - }, - signs = true, - underline = true, - update_in_insert = false, + } }) diff --git a/home/.config/nvim/lua/cfg/utils.lua b/home/.config/nvim/lua/cfg/utils.lua index abda35d..7cd172a 100644 --- a/home/.config/nvim/lua/cfg/utils.lua +++ b/home/.config/nvim/lua/cfg/utils.lua @@ -1,22 +1,21 @@ local M = {} local gitsigns = require("gitsigns") +local conform = require("conform") function M.format_hunks(options) - local hunks = require("gitsigns").get_hunks() + local hunks = gitsigns.get_hunks() if not hunks or vim.tbl_isempty(hunks) then return end for _, hunk in ipairs(hunks) do - local added = hunk.added - if added then - local start_line = added.start - local count = added.count - if start_line and count and start_line > 0 and count > 0 then - local end_line = start_line + added.count - 1 - local range = { start = { start_line, 0 }, ["end"] = { end_line, 0 } } - options = vim.tbl_extend("force", { range = range }, options or {}) - vim.lsp.buf.format(options) - end + if hunk and hunk.added then + local start = hunk.added.start + local last = start + hunk.added.count + -- nvim_buf_get_lines uses zero-based indexing -> subtract from last + local last_hunk_line = vim.api.nvim_buf_get_lines(0, last - 2, last - 1, true)[1] + local range = { start = { start, 0 }, ["end"] = { last - 1, last_hunk_line:len() } } + options = vim.tbl_extend("force", { range = range, lsp_fallback = true, quiet = true }, options or {}) + conform.format(options) end end end diff --git a/home/.config/nvim/lua/custom/plugins/completion.lua b/home/.config/nvim/lua/custom/plugins/completion.lua new file mode 100644 index 0000000..e122857 --- /dev/null +++ b/home/.config/nvim/lua/custom/plugins/completion.lua @@ -0,0 +1,112 @@ +return { + { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + config = function() + local cmp = require("cmp") + + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 + and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1] + :sub(col, col) + :match("%s") + == nil + end + + local luasnip = require("luasnip") + + cmp.setup({ + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = { + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { + "i", + "s", + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { + "i", + "s", + }), + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + }, + formatting = { + format = function(entry, vim_item) + -- set a name for each source + vim_item.menu = ({ + path = "[Path]", + nvim_lsp = "[LSP]", + luasnip = "[LuaSnip]", + dap = "[dap]", + })[entry.source.name] + return vim_item + end, + }, + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "path" }, + { name = "nvim_lsp_signature_help" }, + }, + }) + + require "cmp".setup.filetype( + { "dap-repl", "dapui_watches", "dapui_hover" }, { + sources = { + { name = "dap" }, + }, + }) + end, + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-path", + "hrsh7th/cmp-nvim-lsp-signature-help", + "rcarriga/cmp-dap", + { + "saadparwaiz1/cmp_luasnip", + dependencies = { + { + "L3MON4D3/LuaSnip", + event = "InsertCharPre", + keys = { + { "", function() require "luasnip".jump(1) end, mode = "i" }, + { "", function() require "luasnip".jump(-1) end, mode = "i" }, + }, + config = function() + require("luasnip/loaders/from_vscode").lazy_load() + end, + dependencies = { + "kitagry/vs-snippets", + "rafamadriz/friendly-snippets", + "kkonghao/snippet-dog", + }, + } + }, + }, + }, + }, +} diff --git a/home/.config/nvim/lua/custom/plugins/debug.lua b/home/.config/nvim/lua/custom/plugins/debug.lua new file mode 100644 index 0000000..82de07d --- /dev/null +++ b/home/.config/nvim/lua/custom/plugins/debug.lua @@ -0,0 +1,237 @@ +local map = require("mapper") + +return { + { + "mfussenegger/nvim-dap", + config = function() + local dap = require("dap") + + dap.defaults.fallback.force_external_terminal = true + dap.defaults.fallback.external_terminal = { + command = "/usr/bin/st", + args = { "-e" }, + } + + dap.defaults.fallback.terminal_win_cmd = "50vsplit new" + + local function get_env_vars() + local variables = {} + for k, v in pairs(vim.fn.environ()) do + table.insert(variables, string.format("%s=%s", k, v)) + end + return variables + end + + dap.adapters.lldb = { + type = "executable", + command = "/usr/bin/lldb-vscode", + name = "lldb", + } + + local function str_split(inputstr, sep) + sep = sep or "%s" + local t = {} + for str in inputstr:gmatch("([^" .. sep .. "]+)") do + table.insert(t, str) + end + return t + end + + local _cmd = nil + + local function get_cmd() + if _cmd then + return _cmd + end + local clipboard_cmd = vim.fn.getreg("+") + _cmd = vim.fn.input({ + prompt = "Command to execute: ", + default = clipboard_cmd + }) + return _cmd + end + + local function get_program() + return str_split(get_cmd())[1] + end + + local function get_args() + local argv = str_split(get_cmd()) + local args = {} + + if #argv < 2 then + return {} + end + + for i = 2, #argv do + args[#args + 1] = argv[i] + end + + return args + end + + dap.configurations.cpp = { + { + name = "Launch", + type = "lldb", + request = "launch", + cwd = "${workspaceFolder}", + program = get_program, + stopOnEntry = true, + args = get_args, + env = get_env_vars, + runInTerminal = true, + }, + { + -- If you get an "Operation not permitted" error using this, try disabling YAMA: + -- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope + name = "Attach to process", + type = "lldb", + request = "attach", + pid = require('dap.utils').pick_process, + }, + } + + dap.configurations.c = dap.configurations.cpp + dap.configurations.rust = dap.configurations.cpp + + local get_python_path = function() + local venv_path = os.getenv("VIRTUAL_ENV") + if venv_path then + return venv_path .. "/bin/python" + end + return "/usr/bin/python" + end + + require("dap-python").setup(get_python_path()) + + dap.adapters.nlua = function(callback, config) + callback({ type = "server", host = config.host, port = config.port }) + end + + dap.configurations.lua = { + { + type = "nlua", + request = "attach", + name = "Attach to running Neovim instance", + host = function() + local value = vim.fn.input("Host [127.0.0.1]: ") + if value ~= "" then + return value + end + return "127.0.0.1" + end, + port = function() + local val = tonumber(vim.fn.input("Port: ")) + assert(val, "Please provide a port number") + return val + end, + }, + } + + dap.repl.commands = vim.tbl_extend("force", dap.repl.commands, { + continue = { "continue", "c" }, + next_ = { "next", "n" }, + back = { "back", "b" }, + reverse_continue = { "reverse-continue", "rc" }, + into = { "into" }, + into_target = { "into_target" }, + out = { "out" }, + scopes = { "scopes" }, + threads = { "threads" }, + frames = { "frames" }, + exit = { "exit", "quit", "q" }, + up = { "up" }, + down = { "down" }, + goto_ = { "goto" }, + capabilities = { "capabilities", "cap" }, + -- add your own commands + custom_commands = { + ["echo"] = function(text) + dap.repl.append(text) + end, + }, + }) + + map.n("", dap.close) + map.n("", dap.continue) + map.n("", dap.step_over) + map.n("", dap.step_into) + map.n("", dap.step_out) + map.n("b", dap.toggle_breakpoint) + map.n("B", function() + dap.set_breakpoint(vim.fn.input("Breakpoint condition: ")) + end) + map.n("lp", function() + dap.set_breakpoint(nil, nil, vim.fn.input("Log point message: ")) + end) + map.n("dr", dap.repl.open) + map.n("dl", dap.run_last) + map.n("", dap.list_breakpoints) + + local dapui = require("dapui") + dap.listeners.after.event_initialized["dapui_config"] = function() + dapui.open() + end + dap.listeners.before.event_terminated["dapui_config"] = function() + dapui.close() + end + dap.listeners.before.event_exited["dapui_config"] = function() + dapui.close() + end + map.n("du", dapui.toggle) + map.v("de", dapui.eval) + end, + dependencies = { + { + "rcarriga/nvim-dap-ui", + dependencies = "nvim-neotest/nvim-nio", + opts = { + icons = { expanded = "-", collapsed = "+", current_frame = "*" }, + controls = { enabled = false }, + layouts = { + { + elements = { + -- Elements can be strings or table with id and size keys. + "scopes", + "breakpoints", + "stacks", + "watches", + }, + size = 40, + position = "left", + }, + { + elements = { + "repl", + }, + size = 0.25, -- 25% of total lines + position = "bottom", + }, + }, + }, + }, + { + "mfussenegger/nvim-dap-python", + keys = { + { "gm", function() + require("dap-python").test_method() + end }, + { + "g", + function() + require("dap-python").debug_selection() + end, + mode = "v" + }, + }, + }, + "jbyuki/one-small-step-for-vimkind", + { + "theHamsta/nvim-dap-virtual-text", + config = true, + dependencies = { "nvim-treesitter/nvim-treesitter" } + } + }, + }, +} diff --git a/home/.config/nvim/lua/custom/plugins/ft.lua b/home/.config/nvim/lua/custom/plugins/ft.lua new file mode 100644 index 0000000..769db86 --- /dev/null +++ b/home/.config/nvim/lua/custom/plugins/ft.lua @@ -0,0 +1,7 @@ +return { + "kovetskiy/sxhkd-vim", + "tmux-plugins/vim-tmux", + "martinda/Jenkinsfile-vim-syntax", + "rhysd/vim-llvm", + "wgwoods/vim-systemd-syntax", +} diff --git a/home/.config/nvim/lua/custom/plugins/git.lua b/home/.config/nvim/lua/custom/plugins/git.lua new file mode 100644 index 0000000..adc584c --- /dev/null +++ b/home/.config/nvim/lua/custom/plugins/git.lua @@ -0,0 +1,116 @@ +local map = require("mapper") + +return { + { 'akinsho/git-conflict.nvim', config = true }, + { + "NeogitOrg/neogit", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-telescope/telescope.nvim", + }, + config = function() + local neogit = require("neogit") + neogit.setup({ + disable_commit_confirmation = true, + kind = "split", + console_timeout = 5000, + auto_show_console = false, + }) + map.n("ng", neogit.open) + end, + }, + { + "ruifm/gitlinker.nvim", + keys = { + { "gy", function() require 'gitlinker'.get_buf_range_url("n") end }, + { + "gy", + function() + require 'gitlinker'.get_buf_range_url("v") + end, + mode = "v" + }, + }, + dependencies = { + "nvim-lua/plenary.nvim", + }, + config = function() + require "gitlinker".setup({ + callbacks = { + ["personal"] = function(url_data) + url_data.host = "github.com" + return require "gitlinker.hosts".get_github_type_url(url_data) + end, + ["work"] = function(url_data) + url_data.host = "github.com" + return require "gitlinker.hosts".get_github_type_url(url_data) + end, + ["git.strisemarx.com"] = function(url_data) + local url = require "gitlinker.hosts".get_base_https_url(url_data) + url = url .. "/tree/" .. url_data.file .. "?id=" .. url_data.rev + if url_data.lstart then + url = url .. "#n" .. url_data.lstart + end + return url + end + }, + }) + end, + }, + { + "lewis6991/gitsigns.nvim", + event = "BufRead", + opts = { + signs = { + change = { show_count = true }, + delete = { show_count = true }, + topdelete = { show_count = true }, + changedelete = { show_count = true }, + }, + numhl = true, + _extmark_signs = true, + _threaded_diff = true, + _signs_staged_enable = true, + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + + -- Navigation + map.n(']c', function() + if vim.wo.diff then return ']c' end + vim.schedule(function() gs.next_hunk() end) + return '' + end, { expr = true }, bufnr) + + map.n('[c', function() + if vim.wo.diff then return '[c' end + vim.schedule(function() gs.prev_hunk() end) + return '' + end, { expr = true }, bufnr) + + -- Actions + map.nvcmd('hs', "Gitsigns stage_hunk", nil, bufnr) + map.nvcmd('hr', "Gitsigns reset_hunk", nil, bufnr) + map.n('hS', gs.stage_buffer, nil, bufnr) + map.n('hu', gs.undo_stage_hunk, nil, bufnr) + map.n('hR', gs.reset_buffer, nil, bufnr) + map.n('hp', gs.preview_hunk, nil, bufnr) + map.n('hb', function() gs.blame_line { full = true } end, nil, + bufnr) + map.n('tb', gs.toggle_current_line_blame, nil, bufnr) + map.n('hd', gs.diffthis, nil, bufnr) + map.n('hD', function() gs.diffthis('~') end, nil, bufnr) + map.n('hc', gs.change_base, nil, bufnr) + map.n('hC', function() gs.change_base('~') end, nil, bufnr) + map.n('td', gs.toggle_deleted, nil, bufnr) + map.n('tw', gs.toggle_word_diff, nil, bufnr) + map.n('tl', gs.toggle_linehl, nil, bufnr) + + -- Text object + map.map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', nil, bufnr) + end + }, + dependencies = { + "nvim-lua/plenary.nvim", + }, + }, +} diff --git a/home/.config/nvim/lua/custom/plugins/init.lua b/home/.config/nvim/lua/custom/plugins/init.lua index 8c979e4..cfd6b24 100644 --- a/home/.config/nvim/lua/custom/plugins/init.lua +++ b/home/.config/nvim/lua/custom/plugins/init.lua @@ -5,33 +5,13 @@ return { { "tpope/vim-repeat", event = "VeryLazy" }, 'tpope/vim-sleuth', { - "numToStr/Comment.nvim", - config = true, - }, - { - "tpope/vim-unimpaired", + 'tummetott/unimpaired.nvim', keys = { "]", "[", "yo" }, + opts = { + -- add options here if you wish to override the default settings + }, }, - { "folke/which-key.nvim", lazy = true }, { "kylechui/nvim-surround", config = true }, - { - "dstein64/vim-startuptime", - cmd = "StartupTime", - }, - "xiyaowong/nvim-cursorword", - { - "sainnhe/gruvbox-material", - priority = 1000, - config = function() - vim.g.gruvbox_material_background = "hard" - vim.g.gruvbox_material_enable_bold = 1 - vim.g.gruvbox_material_enable_italic = 1 - vim.g.gruvbox_material_better_performance = 1 - vim.g.gruvbox_material_palette = "original" - - vim.cmd([[ colorscheme gruvbox-material]]) - end - }, { "aserowy/tmux.nvim", config = true, @@ -40,62 +20,6 @@ return { "Julian/vim-textobj-variable-segment", dependencies = { "kana/vim-textobj-user" }, }, - { - "norcalli/nvim-colorizer.lua", - event = "BufRead", - config = true - }, - { - "lewis6991/hover.nvim", - config = function() - require("hover").setup { - init = function() - require("hover.providers.lsp") - require('hover.providers.gh') - require('hover.providers.man') - -- require('hover.providers.dictionary') - end, - } - - vim.keymap.set("n", "K", require("hover").hover, { desc = "hover.nvim" }) - vim.keymap.set("n", "gh", require("hover").hover, { desc = "hover.nvim" }) - vim.keymap.set("n", "gK", require("hover").hover_select, - { desc = "hover.nvim (select)" }) - end - }, - { 'akinsho/git-conflict.nvim', config = true }, - { - "lukas-reineke/indent-blankline.nvim", - config = function() - local highlight = { - "RainbowRed", - "RainbowYellow", - "RainbowBlue", - "RainbowOrange", - "RainbowGreen", - "RainbowViolet", - "RainbowCyan", - } - local hooks = require "ibl.hooks" - -- create the highlight groups in the highlight setup hook, so they are reset - -- every time the colorscheme changes - hooks.register(hooks.type.HIGHLIGHT_SETUP, function() - vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" }) - vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" }) - vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" }) - vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" }) - vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" }) - vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" }) - vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" }) - end) - - vim.g.rainbow_delimiters = { highlight = highlight } - require("ibl").setup { scope = { highlight = highlight } } - - hooks.register(hooks.type.SCOPE_HIGHLIGHT, - hooks.builtin.scope_highlight_from_extmark) - end - }, { "monaqa/dial.nvim", config = function() @@ -111,1000 +35,8 @@ return { build = "cd app && yarn install", ft = { "markdown" }, }, - "gpanders/editorconfig.nvim", { "kwkarlwang/bufresize.nvim", config = true }, - "kovetskiy/sxhkd-vim", - "tmux-plugins/vim-tmux", - "chrisbra/csv.vim", - "martinda/Jenkinsfile-vim-syntax", - "rhysd/vim-llvm", - "MTDL9/vim-log-highlighting", - "raimon49/requirements.txt.vim", - "wgwoods/vim-systemd-syntax", - { - "NeogitOrg/neogit", - dependencies = { - "nvim-lua/plenary.nvim", - "nvim-telescope/telescope.nvim", - }, - config = function() - local neogit = require("neogit") - neogit.setup({ - disable_commit_confirmation = true, - kind = "split", - console_timeout = 5000, - auto_show_console = false, - }) - map.n("ng", neogit.open) - end, - }, - { - "ruifm/gitlinker.nvim", - keys = { - { "gy", function() require 'gitlinker'.get_buf_range_url("n") end }, - { - "gy", - function() - require 'gitlinker'.get_buf_range_url("v") - end, - mode = "v" - }, - }, - dependencies = { - "nvim-lua/plenary.nvim", - }, - config = function() - require "gitlinker".setup({ - callbacks = { - ["personal"] = function(url_data) - url_data.host = "github.com" - return require "gitlinker.hosts".get_github_type_url(url_data) - end, - ["work"] = function(url_data) - url_data.host = "github.com" - return require "gitlinker.hosts".get_github_type_url(url_data) - end, - ["git.strisemarx.com"] = function(url_data) - local url = require "gitlinker.hosts".get_base_https_url(url_data) - url = url .. "/tree/" .. url_data.file .. "?id=" .. url_data.rev - if url_data.lstart then - url = url .. "#n" .. url_data.lstart - end - return url - end - }, - }) - end, - }, - { - "lewis6991/gitsigns.nvim", - event = "BufRead", - opts = { - signs = { - change = { show_count = true }, - delete = { show_count = true }, - topdelete = { show_count = true }, - changedelete = { show_count = true }, - }, - numhl = true, - _extmark_signs = true, - _threaded_diff = true, - _signs_staged_enable = true, - on_attach = function(bufnr) - local gs = package.loaded.gitsigns - - -- Navigation - map.n(']c', function() - if vim.wo.diff then return ']c' end - vim.schedule(function() gs.next_hunk() end) - return '' - end, { expr = true }, bufnr) - - map.n('[c', function() - if vim.wo.diff then return '[c' end - vim.schedule(function() gs.prev_hunk() end) - return '' - end, { expr = true }, bufnr) - - -- Actions - map.nvcmd('hs', "Gitsigns stage_hunk", nil, bufnr) - map.nvcmd('hr', "Gitsigns reset_hunk", nil, bufnr) - map.n('hS', gs.stage_buffer, nil, bufnr) - map.n('hu', gs.undo_stage_hunk, nil, bufnr) - map.n('hR', gs.reset_buffer, nil, bufnr) - map.n('hp', gs.preview_hunk, nil, bufnr) - map.n('hb', function() gs.blame_line { full = true } end, nil, - bufnr) - map.n('tb', gs.toggle_current_line_blame, nil, bufnr) - map.n('hd', gs.diffthis, nil, bufnr) - map.n('hD', function() gs.diffthis('~') end, nil, bufnr) - map.n('hc', gs.change_base, nil, bufnr) - map.n('hC', function() gs.change_base('~') end, nil, bufnr) - map.n('td', gs.toggle_deleted, nil, bufnr) - map.n('tw', gs.toggle_word_diff, nil, bufnr) - map.n('tl', gs.toggle_linehl, nil, bufnr) - - -- Text object - map.map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', nil, bufnr) - end - }, - dependencies = { - "nvim-lua/plenary.nvim", - }, - }, - { - "nvim-telescope/telescope.nvim", - config = function() - local actions = require("telescope.actions") - require("telescope").setup({ - defaults = { - sorting_strategy = "ascending", - layout_config = { - prompt_position = "top", - }, - scroll_strategy = "cycle", - selection_strategy = "follow", - color_devicons = false, - mappings = { - i = { - [""] = actions.move_selection_next, - [""] = actions.move_selection_previous, - }, - }, - extensions = { - fzf = { - fuzzy = true, -- false will only do exact matching - override_generic_sorter = true, -- override the generic sorter - override_file_sorter = true, -- override the file sorter - case_mode = "smart_case", -- or "ignore_case" or "respect_case" - }, - ["ui-select"] = { - require("telescope.themes").get_dropdown({ - -- even more opts - }), - }, - }, - }, - }) - require("telescope").load_extension("fzf") - require("telescope").load_extension("ui-select") - - local b = require("telescope.builtin") - - map.n("p", b.planets) - map.n("B", b.builtin) - map.n("/", b.live_grep) - map.n("?", b.grep_string) - map.n("f", function() - b.find_files({ - find_command = { - "fd", - "--type", - "file", - "--follow", - "--hidden", - "--exclude", - ".git", - }, - }) - end) - map.n("b", function() - b.buffers({ sort_lastused = true, initial_mode = "normal" }) - end) - - map.n("t", b.treesitter) - - map.n("c", b.commands) - map.n("h", b.help_tags) - map.n("m", b.man_pages) - map.n("k", b.keymaps) - map.n("Q", function() - b.quickfix({ initial_mode = "normal" }) - end) - map.n("L", function() - b.loclist({ initial_mode = "normal" }) - end) - map.n("R", function() - b.registers({ initial_mode = "normal" }) - end) - map.n("A", b.autocommands) - - map.n("gd", function() - b.lsp_definitions({ initial_mode = "normal" }) - end) - map.n("gvd", function() - b.lsp_definitions({ initial_mode = "normal", jump_type = "vsplit" }) - end) - map.n("gxd", function() - b.lsp_definitions({ initial_mode = "normal", jump_type = "split" }) - end) - map.n("gtd", function() - b.lsp_definitions({ initial_mode = "normal", jump_type = "tab" }) - end) - map.n("gi", function() - b.lsp_implementations({ initial_mode = "normal" }) - end) - map.n("gvi", function() - b.lsp_implementations({ initial_mode = "normal", jump_type = "vsplit" }) - end) - map.n("gxi", function() - b.lsp_implementations({ initial_mode = "normal", jump_type = "split" }) - end) - map.n("gti", function() - b.lsp_implementations({ initial_mode = "normal", jump_type = "tab" }) - end) - map.n("go", b.lsp_document_symbols) - map.n("gS", b.lsp_dynamic_workspace_symbols) - map.n("ge", function() - b.lsp_document_diagnostics({ initial_mode = "normal" }) - end) - map.n("gE", function() - b.lsp_workspace_diagnostics({ initial_mode = "normal" }) - end) - map.n("gr", function() - b.lsp_references({ initial_mode = "normal" }) - end) - map.n("gic", function() - b.lsp_incoming_calls({ initial_mode = "normal" }) - end) - map.n("goc", function() - b.lsp_outgoing_calls({ initial_mode = "normal" }) - end) - end, - dependencies = { - "nvim-lua/plenary.nvim", - { - "nvim-telescope/telescope-fzf-native.nvim", - build = "make", - }, - "nvim-telescope/telescope-ui-select.nvim", - }, - }, - { - "mfussenegger/nvim-dap", - config = function() - local dap = require("dap") - - dap.defaults.fallback.force_external_terminal = true - dap.defaults.fallback.external_terminal = { - command = "/usr/bin/st", - args = { "-e" }, - } - - dap.defaults.fallback.terminal_win_cmd = "50vsplit new" - - local function get_env_vars() - local variables = {} - for k, v in pairs(vim.fn.environ()) do - table.insert(variables, string.format("%s=%s", k, v)) - end - return variables - end - - dap.adapters.lldb = { - type = "executable", - command = "/usr/bin/lldb-vscode", - name = "lldb", - } - - local function str_split(inputstr, sep) - sep = sep or "%s" - local t = {} - for str in inputstr:gmatch("([^" .. sep .. "]+)") do - table.insert(t, str) - end - return t - end - - local _cmd = nil - - local function get_cmd() - if _cmd then - return _cmd - end - local clipboard_cmd = vim.fn.getreg("+") - _cmd = vim.fn.input({ - prompt = "Command to execute: ", - default = clipboard_cmd - }) - return _cmd - end - - local function get_program() - return str_split(get_cmd())[1] - end - - local function get_args() - local argv = str_split(get_cmd()) - local args = {} - - if #argv < 2 then - return {} - end - - for i = 2, #argv do - args[#args + 1] = argv[i] - end - - return args - end - - dap.configurations.cpp = { - { - name = "Launch", - type = "lldb", - request = "launch", - cwd = "${workspaceFolder}", - program = get_program, - stopOnEntry = true, - args = get_args, - env = get_env_vars, - runInTerminal = true, - }, - { - -- If you get an "Operation not permitted" error using this, try disabling YAMA: - -- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope - name = "Attach to process", - type = "lldb", - request = "attach", - pid = require('dap.utils').pick_process, - }, - } - - dap.configurations.c = dap.configurations.cpp - dap.configurations.rust = dap.configurations.cpp - - local get_python_path = function() - local venv_path = os.getenv("VIRTUAL_ENV") - if venv_path then - return venv_path .. "/bin/python" - end - return "/usr/bin/python" - end - - require("dap-python").setup(get_python_path()) - - dap.adapters.nlua = function(callback, config) - callback({ type = "server", host = config.host, port = config.port }) - end - - dap.configurations.lua = { - { - type = "nlua", - request = "attach", - name = "Attach to running Neovim instance", - host = function() - local value = vim.fn.input("Host [127.0.0.1]: ") - if value ~= "" then - return value - end - return "127.0.0.1" - end, - port = function() - local val = tonumber(vim.fn.input("Port: ")) - assert(val, "Please provide a port number") - return val - end, - }, - } - - dap.repl.commands = vim.tbl_extend("force", dap.repl.commands, { - continue = { "continue", "c" }, - next_ = { "next", "n" }, - back = { "back", "b" }, - reverse_continue = { "reverse-continue", "rc" }, - into = { "into" }, - into_target = { "into_target" }, - out = { "out" }, - scopes = { "scopes" }, - threads = { "threads" }, - frames = { "frames" }, - exit = { "exit", "quit", "q" }, - up = { "up" }, - down = { "down" }, - goto_ = { "goto" }, - capabilities = { "capabilities", "cap" }, - -- add your own commands - custom_commands = { - ["echo"] = function(text) - dap.repl.append(text) - end, - }, - }) - - map.n("", dap.close) - map.n("", dap.continue) - map.n("", dap.step_over) - map.n("", dap.step_into) - map.n("", dap.step_out) - map.n("b", dap.toggle_breakpoint) - map.n("B", function() - dap.set_breakpoint(vim.fn.input("Breakpoint condition: ")) - end) - map.n("lp", function() - dap.set_breakpoint(nil, nil, vim.fn.input("Log point message: ")) - end) - map.n("dr", dap.repl.open) - map.n("dl", dap.run_last) - map.n("", dap.list_breakpoints) - - local dapui = require("dapui") - dap.listeners.after.event_initialized["dapui_config"] = function() - dapui.open() - end - dap.listeners.before.event_terminated["dapui_config"] = function() - dapui.close() - end - dap.listeners.before.event_exited["dapui_config"] = function() - dapui.close() - end - map.n("du", dapui.toggle) - map.v("de", dapui.eval) - end, - dependencies = { - { - "rcarriga/nvim-dap-ui", - dependencies = "nvim-neotest/nvim-nio", - opts = { - icons = { expanded = "-", collapsed = "+", current_frame = "*" }, - controls = { enabled = false }, - layouts = { - { - elements = { - -- Elements can be strings or table with id and size keys. - "scopes", - "breakpoints", - "stacks", - "watches", - }, - size = 40, - position = "left", - }, - { - elements = { - "repl", - }, - size = 0.25, -- 25% of total lines - position = "bottom", - }, - }, - }, - }, - { - "mfussenegger/nvim-dap-python", - keys = { - { "gm", function() - require("dap-python").test_method() - end }, - { - "g", - function() - require("dap-python").debug_selection() - end, - mode = "v" - }, - }, - }, - "jbyuki/one-small-step-for-vimkind", - { - "theHamsta/nvim-dap-virtual-text", - config = true, - dependencies = { "nvim-treesitter/nvim-treesitter" } - } - }, - }, - { - 'nvim-treesitter/nvim-treesitter', - dependencies = { - 'nvim-treesitter/nvim-treesitter-textobjects', - "nvim-treesitter/nvim-treesitter-refactor", - "RRethy/nvim-treesitter-textsubjects", - "theHamsta/nvim-treesitter-pairs", - "RRethy/nvim-treesitter-endwise", - }, - build = ":TSUpdate", - config = function() - require("nvim-treesitter.configs").setup({ - ensure_installed = { - "bash", - "c", - "cmake", - "comment", - "cpp", - "css", - "cuda", - "diff", - "dockerfile", - "fortran", - "git_rebase", - "gitattributes", - "gitcommit", - "gitignore", - "go", - "html", - "javascript", - "jsdoc", - "json", - "llvm", - "lua", - "make", - "markdown", - "markdown_inline", - "ninja", - "python", - "regex", - "rust", - "sql", - "todotxt", - "toml", - "typescript", - "vim", - "vimdoc", - "yaml" - }, - -- ignore_install = { "phpdoc" }, - highlight = { - enable = true, -- false will disable the whole extension - additional_vim_regex_highlighting = false, - }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = "gnn", - node_incremental = "grn", - scope_incremental = "grc", - node_decremental = "grm", - }, - }, - indent = { enable = true }, - refactor = { - highlight_definitions = { enable = true }, - highlight_current_scope = { enable = true }, - smart_rename = { enable = true, keymaps = { smart_rename = "grr" } }, - navigation = { - enable = true, - keymaps = { - goto_definition = "gnd", - list_definitions = "gnD", - list_definitions_toc = "gO", - goto_next_usage = "", - goto_previous_usage = "", - }, - }, - }, - textobjects = { - select = { - enable = true, - -- Automatically jump forward to textobj, similar to targets.vim - lookahead = true, - keymaps = { - -- You can use the capture groups defined in textobjects.scm - ["af"] = "@function.outer", - ["if"] = "@function.inner", - ["ac"] = "@class.outer", - ["ic"] = "@class.inner", - }, - }, - swap = { - enable = true, - swap_next = { ["a"] = "@parameter.inner" }, - swap_previous = { ["A"] = "@parameter.inner" }, - }, - move = { - enable = true, - set_jumps = true, -- whether to set jumps in the jumplist - goto_next_start = { - ["]m"] = "@function.outer", - ["]]"] = "@class.outer", - }, - goto_next_end = { - ["]M"] = "@function.outer", - ["]["] = "@class.outer", - }, - goto_previous_start = { - ["[m"] = "@function.outer", - ["[["] = "@class.outer", - }, - goto_previous_end = { - ["[M"] = "@function.outer", - ["[]"] = "@class.outer", - }, - }, - lsp_interop = { - enable = true, - peek_definition_code = { - ["df"] = "@function.outer", - ["dF"] = "@class.outer", - }, - }, - }, - matchup = { - enable = true, - }, - pairs = { - enable = true, - goto_right_end = false, - keymaps = { goto_partner = "%" }, - }, - textsubjects = { - enable = true, - keymaps = { ["."] = "textsubjects-smart", [";"] = "textsubjects-big" }, - }, - tree_docs = { - enable = true, - }, - endwise = { - enable = true, - }, - }) - end - }, - { - "hrsh7th/nvim-cmp", - event = "InsertEnter", - config = function() - local cmp = require("cmp") - - local has_words_before = function() - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 - and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1] - :sub(col, col) - :match("%s") - == nil - end - - local luasnip = require("luasnip") - - cmp.setup({ - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - mapping = { - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { - "i", - "s", - }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { - "i", - "s", - }), - [""] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }), - }, - formatting = { - format = function(entry, vim_item) - -- set a name for each source - vim_item.menu = ({ - path = "[Path]", - nvim_lsp = "[LSP]", - luasnip = "[LuaSnip]", - dap = "[dap]", - })[entry.source.name] - return vim_item - end, - }, - sources = { - { name = "nvim_lsp" }, - { name = "luasnip" }, - { name = "path" }, - { name = "nvim_lsp_signature_help" }, - }, - }) - - require "cmp".setup.filetype( - { "dap-repl", "dapui_watches", "dapui_hover" }, { - sources = { - { name = "dap" }, - }, - }) - end, - dependencies = { - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-path", - "hrsh7th/cmp-nvim-lsp-signature-help", - "rcarriga/cmp-dap", - { - "saadparwaiz1/cmp_luasnip", - dependencies = { - { - "L3MON4D3/LuaSnip", - event = "InsertCharPre", - keys = { - { "", function() require "luasnip".jump(1) end, mode = "i" }, - { "", function() require "luasnip".jump(-1) end, mode = "i" }, - }, - config = function() - require("luasnip/loaders/from_vscode").lazy_load() - end, - dependencies = { - "kitagry/vs-snippets", - "rafamadriz/friendly-snippets", - "kkonghao/snippet-dog", - }, - } - }, - }, - }, - }, - { - 'neovim/nvim-lspconfig', - config = function() - local lspconfig = require("lspconfig") - -- Enable (broadcasting) snippet capability for completion - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities.textDocument.completion.completionItem.snippetSupport = true - capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = true - capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) - - lspconfig.util.default_config = vim.tbl_extend( - "force", - lspconfig.util.default_config, - { - on_attach = require "cfg.lsp".on_attach_wrapper, - capabilities = capabilities, - flags = { - debounce_text_changes = 150, - }, - } - ) - - local function switch_source_header_splitcmd(bufnr, splitcmd) - bufnr = lspconfig.util.validate_bufnr(bufnr) - local clangd_client = lspconfig.util.get_active_client_by_name( - bufnr, - "clangd" - ) - local params = { uri = vim.uri_from_bufnr(bufnr) } - if clangd_client then - clangd_client.request( - "textDocument/switchSourceHeader", - params, - function(err, result) - if err then - error(tostring(err)) - end - if not result then - print("Corresponding file cannot be determined") - return - end - vim.api.nvim_command(splitcmd .. " " .. vim.uri_to_fname(result)) - end, - bufnr - ) - else - print( - "method textDocument/switchSourceHeader is not supported by any servers active on the current buffer" - ) - end - end - - local servers = { - bashls = {}, - dockerls = {}, - fortls = {}, - lua_ls = { - on_attach = function(client, bufnr) - require("cfg.lsp").on_attach_wrapper( - client, - bufnr, - { auto_format = true } - ) - end, - settings = { - Lua = { - completion = { - callSnippet = "Both", - displayContext = 1, - }, - hint = { - enable = true, - } - } - }, - }, - ruff_lsp = {}, - pyright = {}, - clangd = { - cmd = { - "clangd", - "--enable-config", - "--completion-parse=auto", - "--completion-style=bundled", - "--header-insertion=iwyu", - "--header-insertion-decorators", - "--inlay-hints", - "--suggest-missing-includes", - "--folding-ranges", - "--function-arg-placeholders", - "--pch-storage=memory", - }, - commands = { - ClangdSwitchSourceHeader = { - function() - switch_source_header_splitcmd(0, "edit") - end, - description = "Open source/header in current buffer", - }, - ClangdSwitchSourceHeaderVSplit = { - function() - switch_source_header_splitcmd(0, "vsplit") - end, - description = "Open source/header in a new vsplit", - }, - ClangdSwitchSourceHeaderSplit = { - function() - switch_source_header_splitcmd(0, "split") - end, - description = "Open source/header in a new split", - }, - ClangdSwitchSourceHeaderTab = { - function() - switch_source_header_splitcmd(0, "tabedit") - end, - description = "Open source/header in a new tab", - }, - }, - on_attach = function(client, bufnr) - require("cfg.lsp").on_attach_wrapper(client, bufnr) - local cmpconfig = require("cmp.config") - local compare = require("cmp.config.compare") - cmpconfig.set_buffer({ - sorting = { - comparators = { - compare.offset, - compare.exact, - -- compare.scopes, - require("clangd_extensions.cmp_scores"), - compare.recently_used, - compare.locality, - compare.kind, - compare.sort_text, - compare.length, - compare.order, - }, - }, - }, bufnr) - vim.api.nvim_create_augroup("clang-format", {}) - vim.api.nvim_create_autocmd("BufWritePre", { - group = "clang-format", - buffer = bufnr, - callback = function() - if vim.fn.expand('%:p:h'):find("test") then - return - end - require("cfg.utils").format_hunks({ - bufnr = bufnr, - async = false, - id = client.id - }) - end, - }) - map.ncmd("gH", "ClangdSwitchSourceHeader") - map.ncmd("gvH", "ClangdSwitchSourceHeaderVSplit") - map.ncmd("gxH", "ClangdSwitchSourceHeaderSplit") - map.ncmd("gtH", "ClangdSwitchSourceHeaderSplit") - - require("clangd_extensions.inlay_hints").setup_autocmd() - require("clangd_extensions.inlay_hints").set_inlay_hints() - end, - init_options = { - usePlaceholders = true, - completeUnimported = true, - clangdFileStatus = true, - }, - }, - } - - for server, config in pairs(servers) do - local default_config = lspconfig[server].default_config or - lspconfig[server].document_config.default_config - local cmd = config.cmd or default_config.cmd - if vim.fn.executable(cmd[1]) == 1 then lspconfig[server].setup(config) end - end - end, - dependencies = { - "hrsh7th/cmp-nvim-lsp", - "ray-x/lsp_signature.nvim", - "jubnzv/virtual-types.nvim", - { 'folke/neodev.nvim', opts = {} }, - { "lvimuser/lsp-inlayhints.nvim", config = true }, - { - "p00f/clangd_extensions.nvim", - config = function() - require("clangd_extensions").setup({ - }) - end - }, - }, - }, - { - 'mrcjkb/rustaceanvim', - config = function() - vim.g.rustaceanvim = { - server = { - on_attach = function(client, bufnr) - require("cfg.lsp").on_attach_wrapper( - client, - bufnr, - { auto_format = true } - ) - end, - }, - } - end, - ft = { 'rust' }, - }, - { - 'nvim-lualine/lualine.nvim', - opts = { - options = { - icons_enabled = false, - theme = 'gruvbox_dark', - component_separators = '', - section_separators = '|', - }, - sections = { - lualine_a = { 'filetype', { 'filename', path = 1 } }, - lualine_b = { '%l/%L:%c:%o' }, - lualine_c = { 'diff' }, - lualine_x = { 'searchcount, selectioncount' }, - lualine_y = {}, - lualine_z = { 'diagnostics' } - }, - inactive_sections = { - lualine_a = { 'filename' }, - lualine_b = {}, - lualine_c = {}, - lualine_x = {}, - lualine_y = {}, - lualine_z = {} - }, - }, - }, - { - "nvimtools/none-ls.nvim", - config = function() - local nls = require("null-ls") - nls.setup({ - on_attach = function(client, bufnr) - require("cfg.lsp").on_attach_wrapper( - client, - bufnr, - { auto_format = true } - ) - end, - sources = { - nls.builtins.formatting.black, - nls.builtins.diagnostics.hadolint, - } - }) - end, - }, - "https://gitlab.com/HiPhish/rainbow-delimiters.nvim", } diff --git a/home/.config/nvim/lua/custom/plugins/lsp.lua b/home/.config/nvim/lua/custom/plugins/lsp.lua new file mode 100644 index 0000000..9faa259 --- /dev/null +++ b/home/.config/nvim/lua/custom/plugins/lsp.lua @@ -0,0 +1,210 @@ +local map = require("mapper") + +return { + { + "lewis6991/hover.nvim", + config = function() + require("hover").setup { + init = function() + require("hover.providers.lsp") + require('hover.providers.gh') + require('hover.providers.man') + -- require('hover.providers.dictionary') + end, + } + + vim.keymap.set("n", "K", require("hover").hover, { desc = "hover.nvim" }) + vim.keymap.set("n", "gh", require("hover").hover, { desc = "hover.nvim" }) + vim.keymap.set("n", "gK", require("hover").hover_select, + { desc = "hover.nvim (select)" }) + end + }, + { + 'neovim/nvim-lspconfig', + config = function() + local lspconfig = require("lspconfig") + local cfg_lsp = require "cfg.lsp" + -- Enable (broadcasting) snippet capability for completion + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities.textDocument.completion.completionItem.snippetSupport = true + capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = true + if pcall(require, "cmp_nvim_lsp") then + capabilities = require("cmp_nvim_lsp").default_capabilities() + end + + lspconfig.util.default_config = vim.tbl_extend( + "force", + lspconfig.util.default_config, + { + capabilities = capabilities, + } + ) + + local servers = { + bashls = {}, + dockerls = {}, + fortls = {}, + lua_ls = {}, + ruff_lsp = {}, + pyright = {}, + clangd = { + cmd = { + "clangd", + "--enable-config", + "--completion-parse=auto", + "--completion-style=bundled", + "--header-insertion=iwyu", + "--header-insertion-decorators", + "--inlay-hints", + "--suggest-missing-includes", + "--folding-ranges", + "--function-arg-placeholders", + "--pch-storage=memory", + }, + commands = { + ClangdSwitchSourceHeader = { + function() + cfg_lsp.switch_source_header_splitcmd(0, "edit") + end, + description = "Open source/header in current buffer", + }, + ClangdSwitchSourceHeaderVSplit = { + function() + cfg_lsp.switch_source_header_splitcmd(0, "vsplit") + end, + description = "Open source/header in a new vsplit", + }, + ClangdSwitchSourceHeaderSplit = { + function() + cfg_lsp.lsp.switch_source_header_splitcmd(0, "split") + end, + description = "Open source/header in a new split", + }, + ClangdSwitchSourceHeaderTab = { + function() + cfg_lsp.lsp.switch_source_header_splitcmd(0, "tabedit") + end, + description = "Open source/header in a new tab", + }, + }, + on_attach = function(_, bufnr) + map.ncmd("gH", "ClangdSwitchSourceHeader", { buffer = bufnr }) + map.ncmd("gvH", "ClangdSwitchSourceHeaderVSplit", { buffer = bufnr }) + map.ncmd("gxH", "ClangdSwitchSourceHeaderSplit", { buffer = bufnr }) + map.ncmd("gtH", "ClangdSwitchSourceHeaderSplit", { buffer = bufnr }) + + require("clangd_extensions.inlay_hints").setup_autocmd() + require("clangd_extensions.inlay_hints").set_inlay_hints() + end, + init_options = { + usePlaceholders = true, + completeUnimported = true, + clangdFileStatus = true, + }, + }, + } + + for server, config in pairs(servers) do + local default_config = lspconfig[server].default_config or + lspconfig[server].document_config.default_config + local cmd = config.cmd or default_config.cmd + if vim.fn.executable(cmd[1]) == 1 then lspconfig[server].setup(config) end + end + + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local bufnr = args.buf + local client = vim.lsp.get_client_by_id(args.data.client_id) + cfg_lsp.on_attach_wrapper(client, bufnr) + end, + }) + end, + dependencies = { + { 'folke/neodev.nvim', opts = {} }, + { + "p00f/clangd_extensions.nvim", + config = function() + require("clangd_extensions").setup({ + }) + end + }, + }, + }, + { + "ray-x/lsp_signature.nvim", + event = "VeryLazy", + config = function() + local lsp_signature = require "lsp_signature" + lsp_signature.setup({}) + + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local bufnr = args.buf + local client = assert(vim.lsp.get_client_by_id(args.data.client_id)) + if client.supports_method("textDocument/signatureHelp") then + require("lsp_signature").on_attach({}, bufnr) + map.n("gs", vim.lsp.buf.signature_help, { buffer = bufnr }) + end + end, + }) + end + }, + { + "stevearc/conform.nvim", + event = { "BufWritePre" }, + cmd = { "ConformInfo" }, + keys = { + { + "f", + function() + require("conform").format({ async = true, lsp_fallback = true }) + end, + mode = "", + desc = "Format buffer", + }, + }, + opts = { + formatters_by_ft = { + python = { "ruff_format" }, + c = { "clang-format" }, + cpp = { "clang-format" }, + cmake = { "cmake_format" }, + json = { "jq" }, + rust = { "rustfmt" }, + sh = { "shfmt" }, + bash = { "shfmt" }, + zsh = { "shfmt" }, + }, + formatters = { + shfmt = { + prepend_args = { "-i", "2" }, + }, + }, + }, + init = function() + vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" + vim.api.nvim_create_autocmd("BufWritePre", { + callback = require "cfg.utils".format_hunks, + }) + end, + }, + { + 'mrcjkb/rustaceanvim', + lazy = false, + }, + { + "mfussenegger/nvim-lint", + event = { 'BufReadPre', 'BufNewFile' }, + config = function() + local lint = require('lint') + lint.linters_by_ft = { + dockerfile = { "hadolint" }, + } + vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost", "InsertLeave" }, { + callback = function() + lint.try_lint() + end + }) + end + }, +} diff --git a/home/.config/nvim/lua/custom/plugins/telescope.lua b/home/.config/nvim/lua/custom/plugins/telescope.lua new file mode 100644 index 0000000..d2e97d7 --- /dev/null +++ b/home/.config/nvim/lua/custom/plugins/telescope.lua @@ -0,0 +1,139 @@ +local map = require("mapper") + +return { + { + "nvim-telescope/telescope.nvim", + config = function() + local actions = require("telescope.actions") + require("telescope").setup({ + defaults = { + sorting_strategy = "ascending", + layout_config = { + prompt_position = "top", + }, + scroll_strategy = "cycle", + selection_strategy = "follow", + color_devicons = false, + mappings = { + i = { + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + }, + }, + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, -- override the generic sorter + override_file_sorter = true, -- override the file sorter + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + }, + ["ui-select"] = { + require("telescope.themes").get_dropdown({ + -- even more opts + }), + }, + }, + }, + }) + require("telescope").load_extension("fzf") + require("telescope").load_extension("ui-select") + + local b = require("telescope.builtin") + + map.n("B", b.builtin) + map.n("/", b.live_grep) + map.n("?", b.grep_string) + map.n("f", function() + b.find_files({ + find_command = { + "fd", + "--type", + "file", + "--follow", + "--hidden", + "--exclude", + ".git", + }, + }) + end) + map.n("b", function() + b.buffers({ sort_lastused = true, initial_mode = "normal" }) + end) + + map.n("t", b.treesitter) + + map.n("c", b.commands) + map.n("h", b.help_tags) + map.n("m", b.man_pages) + map.n("k", b.keymaps) + map.n("Q", function() + b.quickfix({ initial_mode = "normal" }) + end) + map.n("L", function() + b.loclist({ initial_mode = "normal" }) + end) + map.n("R", function() + b.registers({ initial_mode = "normal" }) + end) + map.n("A", b.autocommands) + + + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(event) + local bnmap = function(keys, func) + map.n(keys, func, { buffer = event.buf }) + end + bnmap("gd", function() + b.lsp_definitions({ initial_mode = "normal" }) + end) + bnmap("gvd", function() + b.lsp_definitions({ initial_mode = "normal", jump_type = "vsplit" }) + end) + bnmap("gxd", function() + b.lsp_definitions({ initial_mode = "normal", jump_type = "split" }) + end) + bnmap("gtd", function() + b.lsp_definitions({ initial_mode = "normal", jump_type = "tab" }) + end) + bnmap("gi", function() + b.lsp_implementations({ initial_mode = "normal" }) + end) + bnmap("gvi", function() + b.lsp_implementations({ initial_mode = "normal", jump_type = "vsplit" }) + end) + bnmap("gxi", function() + b.lsp_implementations({ initial_mode = "normal", jump_type = "split" }) + end) + bnmap("gti", function() + b.lsp_implementations({ initial_mode = "normal", jump_type = "tab" }) + end) + bnmap("go", b.lsp_document_symbols) + bnmap("gS", b.lsp_dynamic_workspace_symbols) + bnmap("ge", function() + b.lsp_document_diagnostics({ initial_mode = "normal" }) + end) + bnmap("gE", function() + b.lsp_workspace_diagnostics({ initial_mode = "normal" }) + end) + bnmap("gr", function() + b.lsp_references({ initial_mode = "normal" }) + end) + bnmap("gic", function() + b.lsp_incoming_calls({ initial_mode = "normal" }) + end) + bnmap("goc", function() + b.lsp_outgoing_calls({ initial_mode = "normal" }) + end) + end, + }) + end, + dependencies = { + "nvim-lua/plenary.nvim", + { + "nvim-telescope/telescope-fzf-native.nvim", + build = "make", + }, + "nvim-telescope/telescope-ui-select.nvim", + }, + }, +} diff --git a/home/.config/nvim/lua/custom/plugins/ts.lua b/home/.config/nvim/lua/custom/plugins/ts.lua new file mode 100644 index 0000000..33c6ca8 --- /dev/null +++ b/home/.config/nvim/lua/custom/plugins/ts.lua @@ -0,0 +1,148 @@ +return { + { + 'nvim-treesitter/nvim-treesitter', + dependencies = { + 'nvim-treesitter/nvim-treesitter-textobjects', + "nvim-treesitter/nvim-treesitter-refactor", + "RRethy/nvim-treesitter-textsubjects", + "theHamsta/nvim-treesitter-pairs", + "RRethy/nvim-treesitter-endwise", + }, + build = ":TSUpdate", + config = function() + require("nvim-treesitter.configs").setup({ + ensure_installed = { + "bash", + "c", + "cmake", + "comment", + "cpp", + "css", + "cuda", + "diff", + "dockerfile", + "fortran", + "git_rebase", + "gitattributes", + "gitcommit", + "gitignore", + "go", + "html", + "javascript", + "jsdoc", + "json", + "llvm", + "lua", + "make", + "markdown", + "markdown_inline", + "ninja", + "python", + "regex", + "rust", + "sql", + "todotxt", + "toml", + "typescript", + "vim", + "vimdoc", + "yaml" + }, + -- ignore_install = { "phpdoc" }, + highlight = { + enable = true, -- false will disable the whole extension + additional_vim_regex_highlighting = false, + }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "gnn", + node_incremental = "grn", + scope_incremental = "grc", + node_decremental = "grm", + }, + }, + indent = { enable = true }, + refactor = { + highlight_definitions = { enable = true }, + highlight_current_scope = { enable = true }, + smart_rename = { enable = true, keymaps = { smart_rename = "grr" } }, + navigation = { + enable = true, + keymaps = { + goto_definition = "gnd", + list_definitions = "gnD", + list_definitions_toc = "gO", + goto_next_usage = "", + goto_previous_usage = "", + }, + }, + }, + textobjects = { + select = { + enable = true, + -- Automatically jump forward to textobj, similar to targets.vim + lookahead = true, + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + ["ic"] = "@class.inner", + }, + }, + swap = { + enable = true, + swap_next = { ["a"] = "@parameter.inner" }, + swap_previous = { ["A"] = "@parameter.inner" }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + ["]m"] = "@function.outer", + ["]]"] = "@class.outer", + }, + goto_next_end = { + ["]M"] = "@function.outer", + ["]["] = "@class.outer", + }, + goto_previous_start = { + ["[m"] = "@function.outer", + ["[["] = "@class.outer", + }, + goto_previous_end = { + ["[M"] = "@function.outer", + ["[]"] = "@class.outer", + }, + }, + lsp_interop = { + enable = true, + peek_definition_code = { + ["df"] = "@function.outer", + ["dF"] = "@class.outer", + }, + }, + }, + matchup = { + enable = true, + }, + pairs = { + enable = true, + goto_right_end = false, + keymaps = { goto_partner = "%" }, + }, + textsubjects = { + enable = true, + keymaps = { ["."] = "textsubjects-smart", [";"] = "textsubjects-big" }, + }, + tree_docs = { + enable = true, + }, + endwise = { + enable = true, + }, + }) + end + }, +} diff --git a/home/.config/nvim/lua/custom/plugins/ui.lua b/home/.config/nvim/lua/custom/plugins/ui.lua new file mode 100644 index 0000000..79f447f --- /dev/null +++ b/home/.config/nvim/lua/custom/plugins/ui.lua @@ -0,0 +1,81 @@ +return { + "xiyaowong/nvim-cursorword", + { + "sainnhe/gruvbox-material", + priority = 1000, + config = function() + vim.g.gruvbox_material_background = "hard" + vim.g.gruvbox_material_enable_bold = 1 + vim.g.gruvbox_material_enable_italic = 1 + vim.g.gruvbox_material_better_performance = 1 + vim.g.gruvbox_material_palette = "original" + + vim.cmd([[ colorscheme gruvbox-material]]) + end + }, + { + "norcalli/nvim-colorizer.lua", + event = "BufRead", + config = true + }, + { + "lukas-reineke/indent-blankline.nvim", + config = function() + local highlight = { + "RainbowRed", + "RainbowYellow", + "RainbowBlue", + "RainbowOrange", + "RainbowGreen", + "RainbowViolet", + "RainbowCyan", + } + local hooks = require "ibl.hooks" + -- create the highlight groups in the highlight setup hook, so they are reset + -- every time the colorscheme changes + hooks.register(hooks.type.HIGHLIGHT_SETUP, function() + vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" }) + vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" }) + vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" }) + vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" }) + vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" }) + vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" }) + vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" }) + end) + + vim.g.rainbow_delimiters = { highlight = highlight } + require("ibl").setup { scope = { highlight = highlight } } + + hooks.register(hooks.type.SCOPE_HIGHLIGHT, + hooks.builtin.scope_highlight_from_extmark) + end + }, + { + 'nvim-lualine/lualine.nvim', + opts = { + options = { + icons_enabled = false, + theme = 'gruvbox_dark', + component_separators = '', + section_separators = '|', + }, + sections = { + lualine_a = { 'filetype', { 'filename', path = 1 } }, + lualine_b = { '%l/%L:%c:%o' }, + lualine_c = { 'diff' }, + lualine_x = { 'searchcount, selectioncount' }, + lualine_y = {}, + lualine_z = { 'diagnostics' } + }, + inactive_sections = { + lualine_a = { 'filename' }, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {} + }, + }, + }, + "https://gitlab.com/HiPhish/rainbow-delimiters.nvim", +} -- cgit v1.2.3-70-g09d2