diff --git a/lua/conf/langs/c.lua b/lua/conf/langs/c.lua index 103561a..7d92667 100644 --- a/lua/conf/langs/c.lua +++ b/lua/conf/langs/c.lua @@ -1,6 +1,30 @@ -local lspconfig = require("lspconfig") +vim.lsp.config("clangd", { + cmd = { + vim.fn.stdpath("data") .. "/mason/bin/clangd", + "--background-index", + "--clang-tidy", + }, -lspconfig.clangd.setup({ - cmd = { "clangd", "--background-index", "--clang-tidy" }, filetypes = { "c", "cpp", "objc", "objcpp" }, + + root_markers = { + "compile_commands.json", + "compile_flags.txt", + "CMakeLists.txt", + "meson.build", + ".git", + }, + + on_attach = function(client, bufnr) + require("lsp_signature").on_attach({ + bind = true, + floating_window = true, + hint_enable = true, + handler_opts = { + border = "rounded", + }, + }, bufnr) + end, }) + +vim.lsp.enable("clangd") diff --git a/lua/conf/langs/completion.lua b/lua/conf/langs/completion.lua index c0dbae3..d211f1e 100644 --- a/lua/conf/langs/completion.lua +++ b/lua/conf/langs/completion.lua @@ -1,59 +1,88 @@ --- Credit to https://rsdlt.github.io/ for this code. - -local cmp = require'cmp' +local cmp = require("cmp") cmp.setup({ - -- Enable LSP snippets snippet = { expand = function(args) - vim.fn["vsnip#anonymous"](args.body) + vim.fn["vsnip#anonymous"](args.body) end, }, - mapping = { - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), - -- Add tab support - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.close(), - [''] = cmp.mapping.confirm({ + + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.scroll_docs(-4), + + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.abort(), + + [""] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, - select = true, - }) - }, - -- Installed sources: - sources = { - { name = 'path' }, -- file paths - { name = 'nvim_lsp', keyword_length = 3 }, -- from language server - { name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized - { name = 'nvim_lua', keyword_length = 2}, -- complete neovim's Lua runtime API such vim.lsp.* - { name = 'buffer', keyword_length = 2 }, -- source current buffer - { name = 'vsnip', keyword_length = 2 }, -- nvim-cmp source for vim-vsnip - { name = 'calc'}, -- source for math calculation - }, + select = false, + }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn == 1 then + vim.fn.feedkeys( + vim.api.nvim_replace_termcodes("(vsnip-jump-next)", true, true, true), + "" + ) + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + vim.fn.feedkeys( + vim.api.nvim_replace_termcodes("(vsnip-jump-prev)", true, true, true), + "" + ) + else + fallback() + end + end, { "i", "s" }), + }), + + sources = cmp.config.sources({ + { name = "nvim_lsp", keyword_length = 2 }, + { name = "path" }, + { name = "vsnip", keyword_length = 2 }, + }, { + { name = "buffer", keyword_length = 5 }, + }), + window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), }, + formatting = { - fields = {'menu', 'abbr', 'kind'}, - format = function(entry, item) - local menu_icon ={ - nvim_lsp = 'λ', - vsnip = '⋗', - buffer = 'Ω', - path = '•', - } - item.menu = menu_icon[entry.source.name] - return item - end, + fields = { "abbr", "kind", "menu" }, + format = function(entry, item) + local menu_icon = { + nvim_lsp = "λ", + vsnip = "⋗", + buffer = "Ω", + path = "•", + } + + item.menu = menu_icon[entry.source.name] or entry.source.name + return item + end, + }, + + preselect = cmp.PreselectMode.None, + + completion = { + completeopt = "menu,menuone,noinsert,noselect", }, - -- This will let enter work like expected and tab can be used to pick a suggestion. - preselect = cmp.PreselectMode.None }) --- This also prevents enter from selecting the first suggestion. -vim.o.completeopt = "menuone,noselect,preview" +vim.o.completeopt = "menu,menuone,noinsert,noselect" + diff --git a/lua/conf/langs/rust.lua b/lua/conf/langs/rust.lua index 10ee9d5..78fad1c 100644 --- a/lua/conf/langs/rust.lua +++ b/lua/conf/langs/rust.lua @@ -1,19 +1,11 @@ -local rt = require("rust-tools") - -rt.setup({ - server = { - on_attach = function(_, bufnr) - -- Hover actions - vim.keymap.set("n", "", rt.hover_actions.hover_actions, { buffer = bufnr }) - -- Code action groups - vim.keymap.set("n", "a", rt.code_action_group.code_action_group, { buffer = bufnr }) - end, - settings = { - ['rust-analyzer'] = { - checkOnSave = { - command = "clippy" - } - } - } +vim.lsp.config("rust_analyzer", { + settings = { + ["rust-analyzer"] = { + check = { + command = "clippy", + }, + }, }, }) + +vim.lsp.enable("rust_analyzer") diff --git a/lua/conf/plugins.lua b/lua/conf/plugins.lua index f695de8..99ebd61 100644 --- a/lua/conf/plugins.lua +++ b/lua/conf/plugins.lua @@ -23,7 +23,7 @@ Plug 'arcticicestudio/nord-vim' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' Plug 'ryanoasis/vim-devicons' -Plug('nvim-treesitter/nvim-treesitter', {['do'] = vim.fn[':TSUpdate']}) +Plug('nvim-treesitter/nvim-treesitter', { ['do'] = ':TSUpdate' }) -- General Editing Plug 'tpope/vim-surround' @@ -32,14 +32,14 @@ Plug 'tpope/vim-commentary' -- Search Plug 'kien/ctrlp.vim' Plug 'nvim-lua/plenary.nvim' -Plug('nvim-telescope/telescope.nvim', { tag = '0.1.2' }) +Plug 'nvim-telescope/telescope.nvim' Plug('nvim-telescope/telescope-fzf-native.nvim', {['do'] = 'make' }) -- Git Plug 'tpope/vim-fugitive' -- LSP -Plug('williamboman/mason.nvim', {['do'] = vim.fn[':MasonUpdate']}) +Plug('williamboman/mason.nvim', { ['do'] = ':MasonUpdate' }) Plug('williamboman/mason-lspconfig.nvim') Plug('neovim/nvim-lspconfig') @@ -47,12 +47,15 @@ Plug('neovim/nvim-lspconfig') Plug 'hrsh7th/nvim-cmp' Plug 'hrsh7th/cmp-nvim-lsp' Plug 'hrsh7th/cmp-nvim-lua' -Plug 'hrsh7th/cmp-nvim-lsp-signature-help' Plug 'hrsh7th/cmp-vsnip' Plug 'hrsh7th/cmp-path' Plug 'hrsh7th/cmp-buffer' Plug 'hrsh7th/vim-vsnip' +-- This is currently pinned as of 4/28/26 to work around a bug +-- that crashes the LSP signature plugin when opening a file. +Plug('ray-x/lsp_signature.nvim', { ['commit'] = 'a381eb4' }) + -- Tmux Helper Plug 'preservim/vimux' Plug 'christoomey/vim-tmux-navigator' @@ -78,7 +81,5 @@ Plug 'puremourning/vimspector' -- Python ------------------------- --- Rust -Plug 'simrat39/rust-tools.nvim' vim.call('plug#end')