nvim: Remove lsp-zero in favor of built-in lsp support

This commit is contained in:
Oshgnacknak 2025-09-06 22:11:05 +02:00
parent d5f92f0fb9
commit 585f1404b3
Signed by: Oshgnacknak
GPG key ID: 8CB7375654585956
4 changed files with 78 additions and 64 deletions

View file

@ -0,0 +1,19 @@
return {
-- Command and arguments to start the server.
cmd = { 'lua-language-server' },
-- Filetypes to automatically attach to.
filetypes = { 'lua' },
-- Sets the "workspace" to the directory where any of these files is found.
-- Files that share a root directory will reuse the LSP server connection.
-- Nested lists indicate equal priority, see |vim.lsp.Config|.
root_markers = { { '.luarc.json', '.luarc.jsonc' }, '.git' },
-- Specific settings to send to the server. The schema is server-defined.
-- Example: https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json
settings = {
Lua = {
runtime = {
version = 'LuaJIT',
}
}
}
}

View file

@ -1,49 +1,58 @@
vim.diagnostic.config({ virtual_text = true })
vim.lsp.enable('ts_ls')
vim.lsp.enable('luals')
vim.lsp.enable('clangd')
local lsp = require('lsp-zero').preset({})
-- LSP keymaps to mimic lsp-zero's defaults
-- Source for lsp-zero defaults: see note at bottom
lsp.on_attach(function(client, bufnr)
-- see :help lsp-zero-keybindings
-- to learn the available actions
lsp.default_keymaps({buffer = bufnr})
end)
-- Create the autocommand once
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspKeymaps', { clear = true }),
callback = function(ev)
local buf = ev.buf
-- " (Optional) Configure lua language server for neovim
require('lspconfig').lua_ls.setup(lsp.nvim_lua_ls())
local function map(mode, lhs, rhs, desc)
vim.keymap.set(mode, lhs, rhs, { buffer = buf, silent = true, noremap = true, desc = desc })
end
-- You need to setup `cmp` after lsp-zero
local cmp = require('cmp')
local cmp_action = require('lsp-zero').cmp_action()
-- Hover
map('n', 'K', vim.lsp.buf.hover, 'LSP: Hover')
cmp.setup({
mapping = {
-- `Enter` key to confirm completion
['<CR>'] = cmp.mapping.confirm({select = false}),
-- Go to...
map('n', 'gd', vim.lsp.buf.definition, 'LSP: Go to Definition')
map('n', 'gD', vim.lsp.buf.declaration, 'LSP: Go to Declaration')
map('n', 'gi', vim.lsp.buf.implementation, 'LSP: Go to Implementation')
map('n', 'go', vim.lsp.buf.type_definition, 'LSP: Go to Type Definition')
map('n', 'gr', vim.lsp.buf.references, 'LSP: List References')
-- Ctrl+Space to trigger completion menu
['<C-Space>'] = cmp.mapping.complete(),
-- Signatures
map('n', 'gs', vim.lsp.buf.signature_help, 'LSP: Signature Help')
-- Navigate between snippet placeholder
['<C-f>'] = cmp_action.luasnip_jump_forward(),
['<C-b>'] = cmp_action.luasnip_jump_backward(),
}
})
lsp.ensure_installed({
'ts_ls',
})
local null_ls = require('null-ls')
local null_opts = lsp.build_options('null-ls', {})
null_ls.setup({
on_attach = function(client, bufnr)
null_opts.on_attach(client, bufnr)
--- you can add more stuff here if you need it
-- Rename / Actions / Format (normal + visual)
map('n', '<F2>', vim.lsp.buf.rename, 'LSP: Rename')
map({ 'n', 'x' }, '<F3>', function()
vim.lsp.buf.format({ async = false })
end, 'LSP: Format')
map({ 'n', 'x' }, '<F4>', vim.lsp.buf.code_action, 'LSP: Code Action')
end,
sources = {
null_ls.builtins.formatting.black,
}
})
lsp.setup()
require("mason").setup()
require("mason-lspconfig").setup {
ensure_installed = { "rust_analyzer" },
}
local cmp = require('cmp')
local cmp_nvim_lsp = require('cmp_nvim_lsp')
vim.opt.completeopt = { 'menu', 'menuone', 'noselect' }
cmp.setup({
sources = {
{ name = 'nvim_lsp' },
},
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({ select = false }),
}),
})
cmp_nvim_lsp.default_capabilities()

View file

@ -1,13 +1,10 @@
local rt = require("rust-tools")
rt.setup({
require('rust-tools').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 })
-- Example keymaps
vim.keymap.set("n", "<C-space>", require("rust-tools").hover_actions.hover_actions, { buffer = bufnr })
vim.keymap.set("n", "<Leader>a", require("rust-tools").code_action_group.code_action_group,
{ buffer = bufnr })
end,
},
})

View file

@ -4,14 +4,7 @@ Plug 'tpope/vim-fugitive'
Plug 'vim-syntastic/syntastic'
Plug 'junegunn/fzf.vim'
Plug 'tpope/vim-surround'
" Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
" Plug 'deoplete-plugins/deoplete-clang'
" Plug 'deoplete-plugins/deoplete-jedi'
" Plug 'deoplete-plugins/deoplete-go', { 'do': 'make'}
" Plug 'carlitux/deoplete-ternjs', { 'do': 'npm install tern'}
" Plug 'tbodt/deoplete-tabnine', { 'do': './install.sh' }
Plug 'mg979/vim-visual-multi'
" Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
" Plug 'ndmitchell/ghcid', { 'rtp': 'plugins/nvim' }
Plug 'luochen1990/rainbow'
" Plug 'wlangstroth/vim-racket'
@ -24,18 +17,14 @@ Plug 'neovim/nvim-lspconfig'
Plug 'williamboman/mason.nvim'
Plug 'williamboman/mason-lspconfig.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvimtools/none-ls.nvim'
" Autocompletion
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'L3MON4D3/LuaSnip'
Plug 'VonHeikemen/lsp-zero.nvim', {'branch': 'v2.x'}
Plug 'simrat39/rust-tools.nvim'
" Debugging
Plug 'mfussenegger/nvim-dap'
Plug 'rcarriga/nvim-dap-ui'
Plug 'nvim-neotest/nvim-nio'