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. 105
      lua/conf/langs/completion.lua
  3. 24
      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" },
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")

105
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)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
-- Add tab support
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<Tab>'] = cmp.mapping.select_next_item(),
['<C-S-f>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
mapping = cmp.mapping.preset.insert({
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-n>"] = cmp.mapping.select_next_item(),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = 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,
}),
["<Tab>"] = 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("<Plug>(vsnip-jump-next)", true, true, true),
""
)
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 = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
formatting = {
fields = {'menu', 'abbr', 'kind'},
fields = { "abbr", "kind", "menu" },
format = function(entry, item)
local menu_icon = {
nvim_lsp = 'λ',
vsnip = '',
buffer = 'Ω',
path = '',
nvim_lsp = "λ",
vsnip = "",
buffer = "Ω",
path = "",
}
item.menu = menu_icon[entry.source.name]
item.menu = menu_icon[entry.source.name] or entry.source.name
return item
end,
},
-- This will let enter work like expected and tab can be used to pick a suggestion.
preselect = cmp.PreselectMode.None
preselect = cmp.PreselectMode.None,
completion = {
completeopt = "menu,menuone,noinsert,noselect",
},
})
-- This also prevents enter from selecting the first suggestion.
vim.o.completeopt = "menuone,noselect,preview"
vim.o.completeopt = "menu,menuone,noinsert,noselect"

24
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", "<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,
vim.lsp.config("rust_analyzer", {
settings = {
['rust-analyzer'] = {
checkOnSave = {
command = "clippy"
}
}
}
["rust-analyzer"] = {
check = {
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-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')

Loading…
Cancel
Save