From 03324d92c8efbae022ee95b185e68c1d5fa9594e Mon Sep 17 00:00:00 2001 From: _N0x Date: Mon, 28 Oct 2024 11:00:43 +0100 Subject: [PATCH] Added better rust handling to nvim --- nvim/.config/nvim/init.lua | 1 + nvim/.config/nvim/lua/user/cmp.lua | 26 ++++++++++-------- nvim/.config/nvim/lua/user/lsp/init.lua | 36 +++++++++++++++++++++++++ nvim/.config/nvim/lua/user/plugins.lua | 13 +++++++-- 4 files changed, 63 insertions(+), 13 deletions(-) diff --git a/nvim/.config/nvim/init.lua b/nvim/.config/nvim/init.lua index 1eb7147..5a4fad4 100644 --- a/nvim/.config/nvim/init.lua +++ b/nvim/.config/nvim/init.lua @@ -10,3 +10,4 @@ require "user.nvim-tree" require "user.bufferline" require "user.statusline" require "user.gitsigns" +require "user.rust-tools" diff --git a/nvim/.config/nvim/lua/user/cmp.lua b/nvim/.config/nvim/lua/user/cmp.lua index bf78040..5c96856 100644 --- a/nvim/.config/nvim/lua/user/cmp.lua +++ b/nvim/.config/nvim/lua/user/cmp.lua @@ -52,10 +52,10 @@ cmp.setup { end, }, mapping = { - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), - [""] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), [""] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. [""] = cmp.mapping { @@ -102,19 +102,23 @@ cmp.setup { -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind vim_item.menu = ({ nvim_lsp = "[LSP]", - luasnip = "[Snippet]", - buffer = "[Buffer]", + luasnip = "[Snip]", + buffer = "[Buff]", path = "[Path]", + vsnip = "[VSnip]", })[entry.source.name] return vim_item end, }, sources = { - { name = "nvim_lsp" }, - { name = "luasnip" }, - { name = "buffer" }, - { name = "path" }, - }, + { name = 'path' }, -- file paths + { name = 'nvim_lsp', keyword_length = 3 }, -- from language server + { name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized + { name = 'nvim_lua', keyword_length = 2}, -- complete neovim's Lua runtime API such vim.lsp.* + { name = 'buffer', keyword_length = 2 }, -- source current buffer + { name = 'vsnip', keyword_length = 2 }, -- nvim-cmp source for vim-vsnip + { name = 'calc'}, -- source for math calculation + }, confirm_opts = { behavior = cmp.ConfirmBehavior.Replace, select = false, diff --git a/nvim/.config/nvim/lua/user/lsp/init.lua b/nvim/.config/nvim/lua/user/lsp/init.lua index c8eef0f..c493e7d 100644 --- a/nvim/.config/nvim/lua/user/lsp/init.lua +++ b/nvim/.config/nvim/lua/user/lsp/init.lua @@ -6,3 +6,39 @@ end require "user.lsp.mason" require("user.lsp.handlers").setup() require "user.lsp.null-ls" + + + +-- LSP Diagnostics Options Setup +local sign = function(opts) + vim.fn.sign_define(opts.name, { + texthl = opts.name, + text = opts.text, + numhl = '' + }) +end + +sign({name = 'DiagnosticSignError', text = ''}) +sign({name = 'DiagnosticSignWarn', text = ''}) +sign({name = 'DiagnosticSignHint', text = ''}) +sign({name = 'DiagnosticSignInfo', text = ''}) + +vim.diagnostic.config({ + virtual_text = false, + signs = true, + update_in_insert = true, + underline = true, + severity_sort = false, + float = { + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, +}) + +vim.cmd([[ +set signcolumn=yes +autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) +]]) + diff --git a/nvim/.config/nvim/lua/user/plugins.lua b/nvim/.config/nvim/lua/user/plugins.lua index 5993973..f851a22 100644 --- a/nvim/.config/nvim/lua/user/plugins.lua +++ b/nvim/.config/nvim/lua/user/plugins.lua @@ -47,13 +47,20 @@ return packer.startup(function(use) -- Colorschemes use "shaunsingh/nord.nvim" + -- cmp plugins use "hrsh7th/nvim-cmp" -- The completion plugin - use "hrsh7th/cmp-buffer" -- buffer completions + use "hrsh7th/cmp-nvim-lsp" + + use 'hrsh7th/cmp-nvim-lua' + use 'hrsh7th/cmp-nvim-lsp-signature-help' + + use 'hrsh7th/cmp-vsnip' use "hrsh7th/cmp-path" -- path completions + use "hrsh7th/cmp-buffer" -- buffer completions + use "hrsh7th/vim-vsnip" use "hrsh7th/cmp-cmdline" -- cmdline completions use "saadparwaiz1/cmp_luasnip" -- snippet completions - use "hrsh7th/cmp-nvim-lsp" -- snippets use "L3MON4D3/LuaSnip" --snippet engine @@ -65,6 +72,8 @@ return packer.startup(function(use) use "williamboman/mason-lspconfig.nvim" -- simple to use language server installer use 'jose-elias-alvarez/null-ls.nvim' -- LSP diagnostics and code actions + use 'simrat39/rust-tools.nvim' + -- Telescope use "nvim-telescope/telescope.nvim" use 'nvim-telescope/telescope-media-files.nvim'