Browse Source

Address signature file weirdness and update to the new LSP standard

master
Taylor Bockman 6 days ago
parent
commit
fce3441a6b
  1. 30
      lua/conf/langs/c.lua
  2. 121
      lua/conf/langs/completion.lua
  3. 26
      lua/conf/langs/rust.lua
  4. 13
      lua/conf/plugins.lua

30
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" }, 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")

121
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({ cmp.setup({
-- Enable LSP snippets
snippet = { snippet = {
expand = function(args) expand = function(args)
vim.fn["vsnip#anonymous"](args.body) vim.fn["vsnip#anonymous"](args.body)
end, end,
}, },
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(), mapping = cmp.mapping.preset.insert({
['<C-n>'] = cmp.mapping.select_next_item(), ["<C-p>"] = cmp.mapping.select_prev_item(),
-- Add tab support ["<C-n>"] = cmp.mapping.select_next_item(),
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<Tab>'] = cmp.mapping.select_next_item(), ["<C-f>"] = cmp.mapping.scroll_docs(4),
['<C-S-f>'] = cmp.mapping.scroll_docs(-4), ["<C-b>"] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(), ["<C-Space>"] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(), ["<C-e>"] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert, behavior = cmp.ConfirmBehavior.Insert,
select = true, select = false,
}) }),
},
-- Installed sources: ["<Tab>"] = cmp.mapping(function(fallback)
sources = { if cmp.visible() then
{ name = 'path' }, -- file paths cmp.select_next_item()
{ name = 'nvim_lsp', keyword_length = 3 }, -- from language server elseif vim.fn == 1 then
{ name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized vim.fn.feedkeys(
{ name = 'nvim_lua', keyword_length = 2}, -- complete neovim's Lua runtime API such vim.lsp.* vim.api.nvim_replace_termcodes("<Plug>(vsnip-jump-next)", true, true, true),
{ 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 else
}, fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = 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("<Plug>(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 = { window = {
completion = cmp.config.window.bordered(), completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(),
}, },
formatting = { formatting = {
fields = {'menu', 'abbr', 'kind'}, fields = { "abbr", "kind", "menu" },
format = function(entry, item) format = function(entry, item)
local menu_icon ={ local menu_icon = {
nvim_lsp = 'λ', nvim_lsp = "λ",
vsnip = '', vsnip = "",
buffer = 'Ω', buffer = "Ω",
path = '', path = "",
} }
item.menu = menu_icon[entry.source.name]
return item item.menu = menu_icon[entry.source.name] or entry.source.name
end, 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 = "menu,menuone,noinsert,noselect"
vim.o.completeopt = "menuone,noselect,preview"

26
lua/conf/langs/rust.lua

@ -1,19 +1,11 @@
local rt = require("rust-tools") vim.lsp.config("rust_analyzer", {
settings = {
rt.setup({ ["rust-analyzer"] = {
server = { check = {
on_attach = function(_, bufnr) command = "clippy",
-- Hover actions },
vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr }) },
-- Code action groups
vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
end,
settings = {
['rust-analyzer'] = {
checkOnSave = {
command = "clippy"
}
}
}
}, },
}) })
vim.lsp.enable("rust_analyzer")

13
lua/conf/plugins.lua

@ -23,7 +23,7 @@ Plug 'arcticicestudio/nord-vim'
Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes' Plug 'vim-airline/vim-airline-themes'
Plug 'ryanoasis/vim-devicons' Plug 'ryanoasis/vim-devicons'
Plug('nvim-treesitter/nvim-treesitter', {['do'] = vim.fn[':TSUpdate']}) Plug('nvim-treesitter/nvim-treesitter', { ['do'] = ':TSUpdate' })
-- General Editing -- General Editing
Plug 'tpope/vim-surround' Plug 'tpope/vim-surround'
@ -32,14 +32,14 @@ Plug 'tpope/vim-commentary'
-- Search -- Search
Plug 'kien/ctrlp.vim' Plug 'kien/ctrlp.vim'
Plug 'nvim-lua/plenary.nvim' 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' }) Plug('nvim-telescope/telescope-fzf-native.nvim', {['do'] = 'make' })
-- Git -- Git
Plug 'tpope/vim-fugitive' Plug 'tpope/vim-fugitive'
-- LSP -- LSP
Plug('williamboman/mason.nvim', {['do'] = vim.fn[':MasonUpdate']}) Plug('williamboman/mason.nvim', { ['do'] = ':MasonUpdate' })
Plug('williamboman/mason-lspconfig.nvim') Plug('williamboman/mason-lspconfig.nvim')
Plug('neovim/nvim-lspconfig') Plug('neovim/nvim-lspconfig')
@ -47,12 +47,15 @@ Plug('neovim/nvim-lspconfig')
Plug 'hrsh7th/nvim-cmp' Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp' Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-nvim-lua' Plug 'hrsh7th/cmp-nvim-lua'
Plug 'hrsh7th/cmp-nvim-lsp-signature-help'
Plug 'hrsh7th/cmp-vsnip' Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/cmp-path' Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-buffer' Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/vim-vsnip' 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 -- Tmux Helper
Plug 'preservim/vimux' Plug 'preservim/vimux'
Plug 'christoomey/vim-tmux-navigator' Plug 'christoomey/vim-tmux-navigator'
@ -78,7 +81,5 @@ Plug 'puremourning/vimspector'
-- Python -- Python
------------------------- -------------------------
-- Rust
Plug 'simrat39/rust-tools.nvim'
vim.call('plug#end') vim.call('plug#end')

Loading…
Cancel
Save