From 585f1404b38bbe26fd6a1b363d71fceb71c5c124 Mon Sep 17 00:00:00 2001 From: Oshgnacknak Date: Sat, 6 Sep 2025 22:11:05 +0200 Subject: [PATCH] nvim: Remove lsp-zero in favor of built-in lsp support --- _config/nvim/lsp/luals.lua | 19 ++++++++ _config/nvim/plugin/lsp.lua | 89 ++++++++++++++++++++---------------- _config/nvim/plugin/rust.lua | 21 ++++----- _config/nvim/plugins.vim | 13 +----- 4 files changed, 78 insertions(+), 64 deletions(-) create mode 100644 _config/nvim/lsp/luals.lua diff --git a/_config/nvim/lsp/luals.lua b/_config/nvim/lsp/luals.lua new file mode 100644 index 0000000..fa01006 --- /dev/null +++ b/_config/nvim/lsp/luals.lua @@ -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', + } + } + } +} diff --git a/_config/nvim/plugin/lsp.lua b/_config/nvim/plugin/lsp.lua index 810e407..31d9862 100644 --- a/_config/nvim/plugin/lsp.lua +++ b/_config/nvim/plugin/lsp.lua @@ -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 + + -- Hover + map('n', 'K', vim.lsp.buf.hover, 'LSP: Hover') + + -- 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') + + -- Signatures + map('n', 'gs', vim.lsp.buf.signature_help, 'LSP: Signature Help') + + -- Rename / Actions / Format (normal + visual) + map('n', '', vim.lsp.buf.rename, 'LSP: Rename') + map({ 'n', 'x' }, '', function() + vim.lsp.buf.format({ async = false }) + end, 'LSP: Format') + map({ 'n', 'x' }, '', vim.lsp.buf.code_action, 'LSP: Code Action') + end, +}) + +require("mason").setup() +require("mason-lspconfig").setup { + ensure_installed = { "rust_analyzer" }, +} --- You need to setup `cmp` after lsp-zero local cmp = require('cmp') -local cmp_action = require('lsp-zero').cmp_action() +local cmp_nvim_lsp = require('cmp_nvim_lsp') +vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } cmp.setup({ - mapping = { - -- `Enter` key to confirm completion - [''] = cmp.mapping.confirm({select = false}), - - -- Ctrl+Space to trigger completion menu - [''] = cmp.mapping.complete(), - - -- Navigate between snippet placeholder - [''] = cmp_action.luasnip_jump_forward(), - [''] = cmp_action.luasnip_jump_backward(), - } + sources = { + { name = 'nvim_lsp' }, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.confirm({ select = false }), + }), }) -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 - end, - sources = { - null_ls.builtins.formatting.black, - } -}) - -lsp.setup() +cmp_nvim_lsp.default_capabilities() diff --git a/_config/nvim/plugin/rust.lua b/_config/nvim/plugin/rust.lua index 24c043d..ce44aba 100644 --- a/_config/nvim/plugin/rust.lua +++ b/_config/nvim/plugin/rust.lua @@ -1,13 +1,10 @@ -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, - }, +require('rust-tools').setup({ + server = { + on_attach = function(_, bufnr) + -- Example keymaps + vim.keymap.set("n", "", require("rust-tools").hover_actions.hover_actions, { buffer = bufnr }) + vim.keymap.set("n", "a", require("rust-tools").code_action_group.code_action_group, + { buffer = bufnr }) + end, + }, }) diff --git a/_config/nvim/plugins.vim b/_config/nvim/plugins.vim index 6420866..5be30f5 100644 --- a/_config/nvim/plugins.vim +++ b/_config/nvim/plugins.vim @@ -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'