Convert from coc to nvim lsp for Rust support

This commit is contained in:
Nicole Tietz-Sokolskaya 2022-10-14 14:54:53 -04:00
parent 97fbe00d9b
commit 3eec62fae2
4 changed files with 71 additions and 7 deletions

View File

@ -0,0 +1,42 @@
local cmp = require 'cmp'
cmp.setup {
completion = {
autocomplete = {
},
},
mapping = {
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-k>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
['<C-n>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
['<C-p>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { "i", "s" }),
},
sources = {
-- { name = 'buffer' },
-- { name = 'spell' },
{ name = 'nvim_lsp' },
-- { name = 'path' },
},
}

View File

@ -4,6 +4,8 @@ source $HOME/.config/nvim/plug/plug.vim
source $HOME/.config/nvim/plugs.vim source $HOME/.config/nvim/plugs.vim
source $HOME/.config/nvim/lean.lua source $HOME/.config/nvim/lean.lua
source $HOME/.config/nvim/rust.lua
source $HOME/.config/nvim/completion.lua
syntax on syntax on
filetype plugin indent on filetype plugin indent on
@ -58,8 +60,5 @@ au BufRead,BufNewFile *.tla setf tla
" I like pretty things " I like pretty things
source $HOME/.config/nvim/colors.vim source $HOME/.config/nvim/colors.vim
" Manually trigger completions
inoremap <silent><expr> <C-k> coc#refresh()
" Conceal markdown syntax " Conceal markdown syntax
set conceallevel=2 set conceallevel=2

View File

@ -30,10 +30,12 @@ Plug 'editorconfig/editorconfig-vim'
" Make things real pretty " Make things real pretty
Plug 'flazz/vim-colorschemes' Plug 'flazz/vim-colorschemes'
" Completion and other inline type hints " Completions <3
Plug 'neoclide/coc.nvim', {'branch': 'release'} Plug 'hrsh7th/nvim-cmp', { 'branch': 'main' }
" After installation, run this to setup with Rust: Plug 'hrsh7th/cmp-nvim-lsp', { 'branch': 'main' }
" :CocInstall coc-rust-analyzer
" Rust support
Plug 'simrat39/rust-tools.nvim'
" Lean theorem prover support " Lean theorem prover support
Plug 'neovim/nvim-lspconfig' Plug 'neovim/nvim-lspconfig'

View File

@ -0,0 +1,21 @@
local rt = require("rust-tools")
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- " Manually trigger completions
-- inoremap <silent><expr> <C-k> coc#refresh()
rt.setup({
server = {
on_attach = function(_, bufnr)
-- Hover actions
vim.keymap.set("n", "<C-k>", 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 })
end,
capabilities = capabilities,
},
})
rt.inlay_hints.set()
rt.inlay_hints.enable()