123 lines
3.3 KiB
Lua
123 lines
3.3 KiB
Lua
return {
|
|
-- LSP installer
|
|
{ "williamboman/mason.nvim", config = true },
|
|
{ "williamboman/mason-lspconfig.nvim", config = true },
|
|
|
|
-- LSP configuration
|
|
{
|
|
"neovim/nvim-lspconfig",
|
|
config = function()
|
|
-- Initialize Mason
|
|
require("mason").setup()
|
|
require("mason-lspconfig").setup()
|
|
|
|
-- Lua for vim
|
|
vim.lsp.config("lua_ls", {
|
|
settings = {
|
|
Lua = {
|
|
diagnostics = {
|
|
globals = { "vim" }, -- recognize 'vim' as a global
|
|
},
|
|
workspace = {
|
|
library = vim.api.nvim_get_runtime_file("", true), -- includes Neovim runtime files
|
|
checkThirdParty = false, -- optional, avoids prompts about unknown libraries
|
|
},
|
|
telemetry = { enable = false }, -- optional, disable telemetry
|
|
},
|
|
},
|
|
})
|
|
vim.lsp.enable("lua_ls")
|
|
|
|
-- C/C++
|
|
vim.lsp.config("clangd", {})
|
|
vim.lsp.enable("clangd")
|
|
|
|
-- Rust
|
|
vim.lsp.config("rust_analyzer", {})
|
|
vim.lsp.enable("rust_analyzer")
|
|
|
|
-- Auto format
|
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
pattern = "*.rs",
|
|
callback = function()
|
|
vim.lsp.buf.format({ async = false })
|
|
end,
|
|
})
|
|
|
|
-- Floating diagnostic on hover
|
|
vim.api.nvim_create_autocmd("CursorHold", {
|
|
callback = function()
|
|
vim.diagnostic.open_float(nil, { focusable = false })
|
|
end,
|
|
})
|
|
|
|
-- Enable virtual text and signs
|
|
vim.diagnostic.config({
|
|
virtual_text = false,
|
|
signs = true,
|
|
underline = true,
|
|
update_in_insert = false,
|
|
severity_sort = true,
|
|
})
|
|
|
|
|
|
-- Optional: add keymaps
|
|
local keymap = vim.keymap
|
|
keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Go to definition" })
|
|
keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Hover documentation" })
|
|
keymap.set("n", "gr", vim.lsp.buf.references, { desc = "References" })
|
|
end,
|
|
},
|
|
|
|
-- Completion
|
|
{
|
|
"hrsh7th/nvim-cmp",
|
|
dependencies = {
|
|
"hrsh7th/cmp-nvim-lsp",
|
|
"L3MON4D3/LuaSnip",
|
|
},
|
|
config = function()
|
|
local cmp = require("cmp")
|
|
cmp.setup({
|
|
snippet = {
|
|
expand = function(args)
|
|
require("luasnip").lsp_expand(args.body)
|
|
end,
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
["<C-n>"] = cmp.mapping.select_next_item(),
|
|
["<C-p>"] = cmp.mapping.select_prev_item(),
|
|
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
|
}),
|
|
sources = cmp.config.sources({
|
|
{ name = "nvim_lsp" },
|
|
{ name = "buffer" },
|
|
}),
|
|
})
|
|
end,
|
|
},
|
|
{
|
|
"hrsh7th/nvim-cmp",
|
|
dependencies = { "hrsh7th/cmp-nvim-lsp", "L3MON4D3/LuaSnip" },
|
|
config = function()
|
|
local cmp = require("cmp")
|
|
cmp.setup({
|
|
snippet = {
|
|
expand = function(args)
|
|
require("luasnip").lsp_expand(args.body)
|
|
end,
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
["<C-n>"] = cmp.mapping.select_next_item(),
|
|
["<C-p>"] = cmp.mapping.select_prev_item(),
|
|
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
|
}),
|
|
sources = cmp.config.sources({
|
|
{ name = "nvim_lsp" },
|
|
{ name = "buffer" },
|
|
}),
|
|
})
|
|
end,
|
|
},
|
|
}
|