From 56c7eedc37a5b8e028d66fa3ac538123a68fbe12 Mon Sep 17 00:00:00 2001 From: Ward Truyen Date: Sun, 4 May 2025 00:34:02 +0200 Subject: [PATCH] Chore: Update May2025 --- lua/ward/plugins/autocomplete.lua | 199 ++++++++++++++++++++++++++++++ lua/ward/plugins/bufferline.lua | 15 ++- lua/ward/plugins/catppucin.lua | 8 +- lua/ward/plugins/gitsigns.lua | 19 +++ lua/ward/plugins/lsp-config.lua | 147 ++++++++++++++++++++++ lua/ward/plugins/mason.lua | 10 +- lua/ward/plugins/statusline.lua | 16 +++ lua/ward/plugins/telescope.lua | 3 +- lua/ward/plugins/toggleterm.lua | 6 +- lua/ward/plugins/treesitter.lua | 2 +- lua/ward/plugins/which-key.lua | 3 +- lua/ward/setup.lua | 3 +- 12 files changed, 416 insertions(+), 15 deletions(-) create mode 100644 lua/ward/plugins/autocomplete.lua create mode 100644 lua/ward/plugins/gitsigns.lua create mode 100644 lua/ward/plugins/lsp-config.lua create mode 100644 lua/ward/plugins/statusline.lua diff --git a/lua/ward/plugins/autocomplete.lua b/lua/ward/plugins/autocomplete.lua new file mode 100644 index 0000000..6d5f4c3 --- /dev/null +++ b/lua/ward/plugins/autocomplete.lua @@ -0,0 +1,199 @@ +--$ autocomplete for C++ Rust and Lua +--$ URL: https://github.com/hrsh7th/nvim-cmp +--$ help: nvim-cmp +return { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + -- Snippet Engine & its associated nvim-cmp source + { + "L3MON4D3/LuaSnip", + build = (function() + -- Build Step is needed for regex support in snippets. + -- This step is not supported in many windows environments. + -- Remove the below condition to re-enable on windows. + if vim.fn.has("win32") == 1 or vim.fn.executable("make") == 0 then + return + end + return "make install_jsregexp" + end)(), + dependencies = { + -- `friendly-snippets` contains a variety of premade snippets. + { + "rafamadriz/friendly-snippets", + config = function() + require("luasnip.loaders.from_vscode").lazy_load() + end, + }, + }, + }, + + -- Adds other completion capabilities. + -- nvim-cmp does not ship with all sources by default. They are split + -- into multiple repos for maintenance purposes. + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-cmdline", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-path", + + { + -- This is the signature help plugin. Hints the parameters when using a function. + "ray-x/lsp_signature.nvim", + event = "VeryLazy", + config = function() + require("lsp_signature").setup({ + bind = true, -- This is mandatory, otherwise border config won't get registered. + handler_opts = { + border = "rounded", + }, + }) + end, + }, + }, + config = function() + local cmp = require("cmp") + local luasnip = require("luasnip") + + -- For jumping around snippets + vim.keymap.set({ "i", "s" }, "", function() + luasnip.jump(1) + end, { silent = true }) + vim.keymap.set({ "i", "s" }, "", function() + luasnip.jump(-1) + end, { silent = true }) + + -- Icons for completion window. + local cmp_kinds = { + Text = " ", + Method = " ", + Function = " ", + Constructor = " ", + Field = " ", + Variable = " ", + Class = " ", + Interface = " ", + Module = " ", + Property = " ", + Unit = " ", + Value = " ", + Enum = " ", + Keyword = " ", + Snippet = " ", + Color = " ", + File = " ", + Reference = " ", + Folder = " ", + EnumMember = " ", + Constant = " ", + Struct = " ", + Event = " ", + Operator = " ", + TypeParameter = " ", + } + luasnip.config.setup({}) + + -- For setting up max width of the window + local ELLIPSIS_CHAR = "…" + local MAX_LABEL_WIDTH = 30 + local MIN_LABEL_WIDTH = 20 + + cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + completion = { + completeopt = "menu,menuone,noinsert", + }, + + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + + formatting = { + -- Max/min width setup + format = function(_, vim_item) + vim_item.kind = (cmp_kinds[vim_item.kind] or "") .. vim_item.kind + + local label = vim_item.abbr + local truncated_label = vim.fn.strcharpart(label, 0, MAX_LABEL_WIDTH) + if truncated_label ~= label then + vim_item.abbr = truncated_label .. ELLIPSIS_CHAR + elseif string.len(label) < MIN_LABEL_WIDTH then + local padding = string.rep(" ", MIN_LABEL_WIDTH - string.len(label)) + vim_item.abbr = label .. padding + end + + vim_item.menu = "" + return vim_item + end, + }, + + -- gray + vim.api.nvim_set_hl(0, "CmpItemAbbrDeprecated", { bg = "NONE", strikethrough = true, fg = "#808080" }), + -- blue + vim.api.nvim_set_hl(0, "CmpItemAbbrMatch", { bg = "NONE", fg = "#569CD6" }), + vim.api.nvim_set_hl(0, "CmpItemAbbrMatchFuzzy", { link = "CmpIntemAbbrMatch" }), + -- light blue + vim.api.nvim_set_hl(0, "CmpItemKindVariable", { bg = "NONE", fg = "#9CDCFE" }), + vim.api.nvim_set_hl(0, "CmpItemKindInterface", { link = "CmpItemKindVariable" }), + vim.api.nvim_set_hl(0, "CmpItemKindText", { link = "CmpItemKindVariable" }), + -- pink + vim.api.nvim_set_hl(0, "CmpItemKindFunction", { bg = "NONE", fg = "#C586C0" }), + vim.api.nvim_set_hl(0, "CmpItemKindMethod", { link = "CmpItemKindFunction" }), + -- front + vim.api.nvim_set_hl(0, "CmpItemKindKeyword", { bg = "NONE", fg = "#D4D4D4" }), + vim.api.nvim_set_hl(0, "CmpItemKindProperty", { link = "CmpItemKindKeyword" }), + vim.api.nvim_set_hl(0, "CmpItemKindUnit", { link = "CmpItemKindKeyword" }), + + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.confirm({ select = true }), + [""] = function() + if cmp.visible() then + cmp.confirm({ select = true }) + else + cmp.complete({}) + end + end, + }), + sources = { + { name = "luasnip" }, + { name = "nvim_lsp" }, + { name = "path" }, + -- { name = "buffer" }, + }, + }) + + -- `/` cmdline setup. + cmp.setup.cmdline("/", { + mapping = cmp.mapping.preset.cmdline(), + opts = {}, + sources = { + { name = "buffer" }, + }, + }) + + -- `:` cmdline setup. + cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + opts = {}, + sources = cmp.config.sources({ + { name = "path" }, + }, { + { + name = "cmdline", + option = { + ignore_cmds = { "Man", "!" }, + }, + }, + }), + }) + end, +} diff --git a/lua/ward/plugins/bufferline.lua b/lua/ward/plugins/bufferline.lua index 3eb05e7..b5d6844 100644 --- a/lua/ward/plugins/bufferline.lua +++ b/lua/ward/plugins/bufferline.lua @@ -2,13 +2,13 @@ --$ URL: https://github.com/akinsho/bufferline.nvim --$ :help bufferline return { - 'akinsho/bufferline.nvim', - version = "*", + 'akinsho/bufferline.nvim', + version = "*", dependencies = 'nvim-tree/nvim-web-devicons', config = function() require("bufferline").setup({ - options = { + options = { buffer_close_icon = '󰅖', offsets = { { @@ -17,6 +17,15 @@ return { separator = true, }, }, + diagnostics = "nvim_lsp", + diagnostics_indicator = function(count, level, diagnostics_dict, context) + local s = " " + for e, n in pairs(diagnostics_dict) do + local sym = e == "error" and " " or (e == "warning" and " " or "") + s = s .. n .. sym + end + return s + end, } }) end, diff --git a/lua/ward/plugins/catppucin.lua b/lua/ward/plugins/catppucin.lua index 30a2d4e..c01cb9a 100644 --- a/lua/ward/plugins/catppucin.lua +++ b/lua/ward/plugins/catppucin.lua @@ -1,12 +1,12 @@ --$ Better coloring theme/colorscheme --$ URL: https://github.com/catppuccin/nvim -return { - "catppuccin/nvim", - name = "catppuccin", +return { + "catppuccin/nvim", + name = "catppuccin", priority = 1000, config = function() - require("catppuccin").setup({ }) + require("catppuccin").setup({}) vim.cmd.colorscheme("catppuccin") end, } diff --git a/lua/ward/plugins/gitsigns.lua b/lua/ward/plugins/gitsigns.lua new file mode 100644 index 0000000..0d6fcf4 --- /dev/null +++ b/lua/ward/plugins/gitsigns.lua @@ -0,0 +1,19 @@ +return { + "lewis6991/gitsigns.nvim", + -- event = "BufReadPre", + + config = function() + require("gitsigns").setup { + signs = { + -- add = { text = "│" }, + -- change = { text = "│" }, + delete = { text = "_", show_count = true }, + -- topdelete = { text = "‾" }, + -- changedelete = { text = "~" }, + -- untracked = { text = "┆" }, + }, + numhl = true, -- Toggle with `:Gitsigns toggle_numhl` + linehl = true, -- Toggle with `:Gitsigns toggle_linehl` + } + end, +} diff --git a/lua/ward/plugins/lsp-config.lua b/lua/ward/plugins/lsp-config.lua new file mode 100644 index 0000000..62c7bfe --- /dev/null +++ b/lua/ward/plugins/lsp-config.lua @@ -0,0 +1,147 @@ +return { + "neovim/nvim-lspconfig", + version = "*", + config = function() + local lspconfig = require("lspconfig") + + vim.cmd([[autocmd! ColorScheme * highlight NormalFloat guibg=#1f2335]]) + vim.cmd([[autocmd! ColorScheme * highlight FloatBorder guifg=white guibg=#1f2335]]) + + -- Beautiful borders around LSP stuff like hover/signature_help + local border = { + { "┌", "FloatBorder" }, + { "─", "FloatBorder" }, + { "┐", "FloatBorder" }, + { "│", "FloatBorder" }, + { "┘", "FloatBorder" }, + { "─", "FloatBorder" }, + { "└", "FloatBorder" }, + { "│", "FloatBorder" }, + } + + -- LSP settings (for overriding per client) + local handlers = { + ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border }), + ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = border }), + } + + lspconfig.clangd.setup({ + cmd = { + "clangd", + "--offset-encoding=utf-16", + }, + handlers = handlers, + }) + + lspconfig.glsl_analyzer.setup({ + filetypes = { "glsl", "vert", "tese", "frag", "geom", "comp", "vs", "fs" }, + handlers = handlers, + }) + + -- diagnostics border + local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview + function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) + -- I would love to retrieve the severity level just here in order to modify opts.border + opts = opts or {} + opts.border = opts.border or border + return orig_util_open_floating_preview(contents, syntax, opts, ...) + end + + -- adding filetypes to get glsl things + vim.filetype.add({ + extension = { + vert = "glsl", + tesc = "glsl", + tese = "glsl", + frag = "glsl", + geom = "glsl", + comp = "glsl", + vs = "glsl", + fs = "glsl", + }, + }) + + lspconfig.rust_analyzer.setup({ + settings = { + ["rust-analyzer"] = {}, + }, + handlers = handlers, + }) + + lspconfig.lua_ls.setup({ + handlers = handlers, + }) + + -- These lsp keybinds only load when an LSP is attatched to the buffer. + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("UserLspConfig", {}), + callback = function(event) + -- Enable completion triggered by + vim.bo[event.buf].omnifunc = "v:lua.vim.lsp.omnifunc" + + local map = function(keys, func, desc) + vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) + end + + -- Jump to the definition of the word under your cursor. + -- This is where a variable was first declared, or where a function is defined, etc. + -- To jump back, press . + map("gd", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition") + + -- Find references for the word under your cursor. + map("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences") + + -- Jump to the implementation of the word under your cursor. + -- Useful when your language has ways of declaring types without an actual implementation. + map("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation") + + -- Jump to the type of the word under your cursor. + -- Useful when you're not sure what type a variable is and you want to see + -- the definition of its *type*, not where it was *defined*. + map("ld", require("telescope.builtin").lsp_type_definitions, "Type [D]efinition") + + -- Fuzzy find all the symbols in your current document. + -- Symbols are things like variables, functions, types, etc. + map("ls", require("telescope.builtin").lsp_document_symbols, "document [S]ymbols") + + -- Format file + map("lf", vim.lsp.buf.format, "[F]ormat") + + -- Fuzzy find all the symbols in your current workspace. + -- Similar to document symbols, except searches over your entire project. + map( + "lw", + require("telescope.builtin").lsp_dynamic_workspace_symbols, + "[W]orkspace symbols" + ) + map("lp", vim.diagnostic.goto_prev, "Go to [P]revious diagnostic message") + + map("ln", vim.diagnostic.goto_next, "Go to [N]ext diagnostic message") + + map("le", vim.diagnostic.open_float, "Show diagnostic [E]rror messages") + vim.diagnostic.config({ virtual_text = false }) + + map("lq", vim.diagnostic.setloclist, "Open diagnostic [Q]uickfix list") + + -- Rename the variable under your cursor. + -- Most Language Servers support renaming across files, etc. + map("lr", vim.lsp.buf.rename, "[R]ename") + + -- Execute a code action, usually your cursor needs to be on top of an error + -- or a suggestion from your LSP for this to activate. + map("la", vim.lsp.buf.code_action, "code [A]ction") + + -- Opens a popup that displays documentation about the word under your cursor + -- See `:help K` for why this keymap. + + -- WARN: This is not Goto Definition, this is Goto Declaration. + -- For example, in C this would take you to the header. + map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") + + map("th", function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf })) + end, "[T]oggle Inlay [H]ints") + end, + }) + end, +} diff --git a/lua/ward/plugins/mason.lua b/lua/ward/plugins/mason.lua index 0097aa9..c63a676 100644 --- a/lua/ward/plugins/mason.lua +++ b/lua/ward/plugins/mason.lua @@ -1,10 +1,18 @@ --$ LSP manager --$ URL: https://github.com/williamboman/mason.nvim --$ :Mason -return{ +return { "williamboman/mason.nvim", config = function() require("mason").setup() end, + + opts = { + ensure_installed = { + "clangd", + "clang-format", + "codelldb", + }, + }, } diff --git a/lua/ward/plugins/statusline.lua b/lua/ward/plugins/statusline.lua new file mode 100644 index 0000000..02510c8 --- /dev/null +++ b/lua/ward/plugins/statusline.lua @@ -0,0 +1,16 @@ +return { + -- The bar at the bottom + "nvim-lualine/lualine.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, + + config = function() + require("lualine").setup({ + options = { + globalstatus = true, -- enable global statusline (have a single statusline + }, + sections = { + lualine_x = { "filetype" }, + }, + }) + end, +} diff --git a/lua/ward/plugins/telescope.lua b/lua/ward/plugins/telescope.lua index 4ddb548..bd41c2d 100644 --- a/lua/ward/plugins/telescope.lua +++ b/lua/ward/plugins/telescope.lua @@ -23,6 +23,7 @@ return { vim.keymap.set('n', 'ps', function() builtin.grep_string({ search = vim.fn.input("Grep > ") }) end) - vim.keymap.set('n', 'vh', builtin.help_tags, {}) + vim.keymap.set('n', 'vh', builtin.help_tags, {desc = "Search [H]elp"}) + vim.keymap.set('n', 'vk', builtin.keymaps, {desc = "Search [K]eymaps"}) end } diff --git a/lua/ward/plugins/toggleterm.lua b/lua/ward/plugins/toggleterm.lua index 64b90d5..6126ceb 100644 --- a/lua/ward/plugins/toggleterm.lua +++ b/lua/ward/plugins/toggleterm.lua @@ -16,8 +16,8 @@ return{ return 20 end, }) - vim.keymap.set('n', 'tt', ":ToggleTerm name=BottomTerm") - vim.keymap.set('n', 'tv', ":ToggleTerm direction=vertical name=VerticalTerm") - vim.keymap.set('n', 'tf', ":ToggleTerm direction=float name=FloatTerm") + vim.keymap.set('n', 't', ":ToggleTerm name=BottomTerm") + --vim.keymap.set('n', 'tv', ":ToggleTerm direction=vertical name=VerticalTerm") + --vim.keymap.set('n', 'tf', ":ToggleTerm direction=float name=FloatTerm") end, } diff --git a/lua/ward/plugins/treesitter.lua b/lua/ward/plugins/treesitter.lua index 24d1e32..d7c534b 100644 --- a/lua/ward/plugins/treesitter.lua +++ b/lua/ward/plugins/treesitter.lua @@ -10,7 +10,7 @@ return { configs.setup({ ensure_installed = { - "c", "lua", "vim", "vimdoc", "elixir", "javascript", "html", "python", "typescript" + "c", "lua", "vim", "vimdoc", "javascript", "html", "python", "typescript" }, sync_install = false, highlight = { enable = true }, diff --git a/lua/ward/plugins/which-key.lua b/lua/ward/plugins/which-key.lua index c0a3801..7ca2a0d 100644 --- a/lua/ward/plugins/which-key.lua +++ b/lua/ward/plugins/which-key.lua @@ -47,6 +47,7 @@ return { {"vm", "marks", desc = "Marks", }, {"vr", "registers", desc = "Registers" }, {"h", "nohlsearch", desc = "Stop Highlight" }, + {"l", group = "LSP"}, }) end, -} +} diff --git a/lua/ward/setup.lua b/lua/ward/setup.lua index 7f317ed..a8ebb17 100644 --- a/lua/ward/setup.lua +++ b/lua/ward/setup.lua @@ -1,4 +1,5 @@ - +vim.g.have_nerd_font = true -- use nerd_font + vim.opt.clipboard = 'unnamedplus' -- use system keyboard for yank vim.opt.nu = true -- set line numbers