vimrc/lsp.vim

107 lines
2.8 KiB
VimL
Raw Normal View History

2021-09-06 20:57:07 +00:00
" from: https://sharksforarms.dev/posts/neovim-rust/
" Set completeopt to have a better completion experience
" :help completeopt
" menuone: popup even when there's only one match
" noinsert: Do not insert text until a selection is made
" noselect: Do not select, force user to select one from the menu
set completeopt=menuone,noinsert,noselect
" Avoid showing extra messages when using completion
set shortmess+=c
2023-05-07 19:44:11 +00:00
" Recognize slint files
autocmd BufEnter *.slint :setlocal filetype=slint
2021-09-06 20:57:07 +00:00
" Configure LSP through rust-tools.nvim plugin.
" rust-tools will configure and enable certain LSP features for us.
" See https://github.com/simrat39/rust-tools.nvim#configuration
lua <<EOF
2022-08-14 13:46:16 +00:00
local rt = require('rust-tools')
rt.setup({
server = {
server = {
on_attach = function(_, buffnr)
-- Hover actions
vim.keymap.set("n", "<C-space>", 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
2021-09-06 20:57:07 +00:00
},
2022-08-14 13:46:16 +00:00
}, -- rust-analyer options
})
2021-09-06 20:57:07 +00:00
EOF
" Setup Completion
" See https://github.com/hrsh7th/nvim-cmp#basic-configuration
lua <<EOF
local cmp = require'cmp'
cmp.setup({
-- Enable LSP snippets
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
-- Add tab support
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<Tab>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
})
},
-- Installed sources
sources = {
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
{ name = 'path' },
{ name = 'buffer' },
},
})
EOF
" Set updatetime for CursorHold
" 300ms of no cursor movement to trigger CursorHold
2021-09-16 22:15:33 +00:00
set updatetime=750
2021-09-06 20:57:07 +00:00
" Show diagnostic popup on cursor hold
2022-01-04 20:27:36 +00:00
autocmd CursorHold * lua vim.diagnostic.open_float()
2021-09-16 22:15:33 +00:00
" have a fixed column for the diagnostics to appear in
" this removes the jitter when warnings/errors flow in
set signcolumn=yes
2021-12-29 20:52:08 +00:00
let g:LanguageClient_serverCommands = {
\ 'rust': ['rust-analyzer'],
\ }
lua<<EOF
2023-02-16 16:41:01 +00:00
vim.g.markdown_fenced_languages = {
"ts=typescript"
}
2023-05-07 19:44:11 +00:00
require("nvim-lsp-installer").setup {}
2023-02-16 16:41:01 +00:00
local lspconfig = require('lspconfig')
local util = require('lspconfig.util')
lspconfig.denols.setup {
on_attach = on_attach,
root_dir = util.root_pattern("deno.json", "deno.jsonc"),
init_options = {
enabled = true,
unstable = true
}
}
lspconfig.tsserver.setup {
on_attach = on_attach,
root_dir = util.root_pattern("package.json"),
single_file_support = false
}
2021-12-29 20:52:08 +00:00
EOF