From 45aeddb69b8d7b2fdf35c8b2903e757ee94f9865 Mon Sep 17 00:00:00 2001 From: Eduardo Cueto-Mendoza Date: Mon, 23 Dec 2024 17:10:03 +0000 Subject: [PATCH] Modified neovim for better Rust auto complete --- .config/nvim/after/plugin/04_lspconfig.lua | 26 ++------------------- .config/nvim/after/plugin/05_completion.lua | 10 ++++---- .config/nvim/after/plugin/07_rust.lua | 18 ++++++++++++++ .config/nvim/lua/eddie/lazy.lua | 13 ++++++++--- .config/nvim/lua/eddie/options.lua | 9 +++++++ 5 files changed, 44 insertions(+), 32 deletions(-) create mode 100644 .config/nvim/after/plugin/07_rust.lua diff --git a/.config/nvim/after/plugin/04_lspconfig.lua b/.config/nvim/after/plugin/04_lspconfig.lua index e45d587..31ba2eb 100644 --- a/.config/nvim/after/plugin/04_lspconfig.lua +++ b/.config/nvim/after/plugin/04_lspconfig.lua @@ -3,6 +3,7 @@ local lspconfig = require 'lspconfig' -- local on_attach = function(client) -- require 'completion'.on_attach(client) -- end +vim.lsp.inlay_hint.enable(true) local capabilities = require('cmp_nvim_lsp').default_capabilities() @@ -64,7 +65,7 @@ lspconfig.lua_ls.setup { }, diagnostics = { -- Get the language server to recognize the `vim` global - globals = { 'vim', 'require' }, + globals = { 'vim', 'require', 'select_opts' }, }, format = { -- Put format options here @@ -109,26 +110,3 @@ lspconfig.pylsp.setup { }, } --- RUST -lspconfig.rust_analyzer.setup({ - -- on_attach = on_attach, - capabilities = capabilities, - settings = { - ["rust-analyzer"] = { - imports = { - granularity = { - group = "module", - }, - prefix = "self", - }, - cargo = { - buildScripts = { - enable = true, - }, - }, - procMacro = { - enable = true - }, - } - } -}) diff --git a/.config/nvim/after/plugin/05_completion.lua b/.config/nvim/after/plugin/05_completion.lua index fb254af..f27c85d 100644 --- a/.config/nvim/after/plugin/05_completion.lua +++ b/.config/nvim/after/plugin/05_completion.lua @@ -22,9 +22,13 @@ cmp.setup({ mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), + -- Allows selection with tab and shift-tab + [''] = cmp.mapping.select_prev_item(select_opts), + [''] = cmp.mapping.select_next_item(select_opts), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + -- [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [''] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, @@ -100,7 +104,3 @@ require('lspconfig')['pylsp'].setup { capabilities = capabilities } --- RUST -require('lspconfig')['rust_analyzer'].setup { - capabilities = capabilities -} diff --git a/.config/nvim/after/plugin/07_rust.lua b/.config/nvim/after/plugin/07_rust.lua new file mode 100644 index 0000000..85fbc7d --- /dev/null +++ b/.config/nvim/after/plugin/07_rust.lua @@ -0,0 +1,18 @@ +local bufnr = vim.api.nvim_get_current_buf() +vim.keymap.set( + "n", + "a", + function() + vim.cmd.RustLsp('codeAction') -- supports rust-analyzer's grouping + -- or vim.lsp.buf.codeAction() if you don't want grouping. + end, + { silent = true, buffer = bufnr } +) +vim.keymap.set( + "n", + "K", -- Override Neovim's built-in hover keymap with rustaceanvim's hover actions + function() + vim.cmd.RustLsp({'hover', 'actions'}) + end, + { silent = true, buffer = bufnr } +) diff --git a/.config/nvim/lua/eddie/lazy.lua b/.config/nvim/lua/eddie/lazy.lua index 2677154..7497c8a 100755 --- a/.config/nvim/lua/eddie/lazy.lua +++ b/.config/nvim/lua/eddie/lazy.lua @@ -36,6 +36,12 @@ local plugins = { { 'hrsh7th/cmp-buffer' }, { 'hrsh7th/cmp-path' }, { 'hrsh7th/cmp-cmdline' }, + -- Rust cmp & lsp + { + 'mrcjkb/rustaceanvim', + version = '^5', -- Recommended + lazy = false, -- This plugin is already lazy + }, -- -- For luasnip users { @@ -49,8 +55,7 @@ local plugins = { 'nvim-lua/plenary.nvim', }, { 'echasnovski/mini.nvim', version = '*' }, - -- Rust & vim auxiliary packages - { "simrat39/rust-tools.nvim" }, + -- vim auxiliary packages { "lervag/vimtex", lazy = false, -- we don't want to lazy load VimTeX @@ -151,7 +156,7 @@ local plugins = { { 'nvim-telescope/telescope.nvim' }, }, }, - 'jinh0/eyeliner.nvim', + { 'jinh0/eyeliner.nvim' }, { "anuvyklack/windows.nvim", dependencies = { @@ -193,6 +198,8 @@ local plugins = { { 'sakhnik/nvim-gdb', }, + -- Rust debug + { 'mfussenegger/nvim-dap' }, -- Compiler { -- This plugin "Zeioth/compiler.nvim", diff --git a/.config/nvim/lua/eddie/options.lua b/.config/nvim/lua/eddie/options.lua index f4b3350..6512e4e 100755 --- a/.config/nvim/lua/eddie/options.lua +++ b/.config/nvim/lua/eddie/options.lua @@ -206,6 +206,15 @@ then -- optionally enable 24-bit colour -- vim.opt.termguicolors = true + -- Folds + vim.opt.foldmethod = "expr" + vim.opt.foldexpr = "v:lua.vim.treesitter.foldexpr()" + vim.opt.foldcolumn = "0" + vim.opt.foldtext = "" + vim.opt.foldlevel = 99 + vim.opt.foldlevelstart = 1 + vim.opt.foldnestmax = 4 + vim.opt.scrolloff = 8 vim.opt.signcolumn = "yes" vim.opt.isfname:append("@-@")