Modified neovim for better Rust auto complete

This commit is contained in:
Eduardo Cueto-Mendoza 2024-12-23 17:10:03 +00:00
parent cd9a19d75a
commit 45aeddb69b
Signed by: TastyPancakes
GPG Key ID: 941DF56C7242C3F1
5 changed files with 44 additions and 32 deletions

View File

@ -3,6 +3,7 @@ local lspconfig = require 'lspconfig'
-- local on_attach = function(client) -- local on_attach = function(client)
-- require 'completion'.on_attach(client) -- require 'completion'.on_attach(client)
-- end -- end
vim.lsp.inlay_hint.enable(true)
local capabilities = require('cmp_nvim_lsp').default_capabilities() local capabilities = require('cmp_nvim_lsp').default_capabilities()
@ -64,7 +65,7 @@ lspconfig.lua_ls.setup {
}, },
diagnostics = { diagnostics = {
-- Get the language server to recognize the `vim` global -- Get the language server to recognize the `vim` global
globals = { 'vim', 'require' }, globals = { 'vim', 'require', 'select_opts' },
}, },
format = { format = {
-- Put format options here -- 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
},
}
}
})

View File

@ -22,9 +22,13 @@ cmp.setup({
mapping = cmp.mapping.preset.insert({ mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4), ['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4), ['<C-f>'] = cmp.mapping.scroll_docs(4),
-- Allows selection with tab and shift-tab
['<S-Tab>'] = cmp.mapping.select_prev_item(select_opts),
['<Tab>'] = cmp.mapping.select_next_item(select_opts),
['<C-Space>'] = cmp.mapping.complete(), ['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(), ['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. -- ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}), }),
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
@ -100,7 +104,3 @@ require('lspconfig')['pylsp'].setup {
capabilities = capabilities capabilities = capabilities
} }
-- RUST
require('lspconfig')['rust_analyzer'].setup {
capabilities = capabilities
}

View File

@ -0,0 +1,18 @@
local bufnr = vim.api.nvim_get_current_buf()
vim.keymap.set(
"n",
"<leader>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 }
)

View File

@ -36,6 +36,12 @@ local plugins = {
{ 'hrsh7th/cmp-buffer' }, { 'hrsh7th/cmp-buffer' },
{ 'hrsh7th/cmp-path' }, { 'hrsh7th/cmp-path' },
{ 'hrsh7th/cmp-cmdline' }, { 'hrsh7th/cmp-cmdline' },
-- Rust cmp & lsp
{
'mrcjkb/rustaceanvim',
version = '^5', -- Recommended
lazy = false, -- This plugin is already lazy
},
-- -- For luasnip users -- -- For luasnip users
{ {
@ -49,8 +55,7 @@ local plugins = {
'nvim-lua/plenary.nvim', 'nvim-lua/plenary.nvim',
}, },
{ 'echasnovski/mini.nvim', version = '*' }, { 'echasnovski/mini.nvim', version = '*' },
-- Rust & vim auxiliary packages -- vim auxiliary packages
{ "simrat39/rust-tools.nvim" },
{ {
"lervag/vimtex", "lervag/vimtex",
lazy = false, -- we don't want to lazy load VimTeX lazy = false, -- we don't want to lazy load VimTeX
@ -151,7 +156,7 @@ local plugins = {
{ 'nvim-telescope/telescope.nvim' }, { 'nvim-telescope/telescope.nvim' },
}, },
}, },
'jinh0/eyeliner.nvim', { 'jinh0/eyeliner.nvim' },
{ {
"anuvyklack/windows.nvim", "anuvyklack/windows.nvim",
dependencies = { dependencies = {
@ -193,6 +198,8 @@ local plugins = {
{ {
'sakhnik/nvim-gdb', 'sakhnik/nvim-gdb',
}, },
-- Rust debug
{ 'mfussenegger/nvim-dap' },
-- Compiler -- Compiler
{ -- This plugin { -- This plugin
"Zeioth/compiler.nvim", "Zeioth/compiler.nvim",

View File

@ -206,6 +206,15 @@ then
-- optionally enable 24-bit colour -- optionally enable 24-bit colour
-- vim.opt.termguicolors = true -- 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.scrolloff = 8
vim.opt.signcolumn = "yes" vim.opt.signcolumn = "yes"
vim.opt.isfname:append("@-@") vim.opt.isfname:append("@-@")