Browse Source

Totally upgrade the LSP experience

master
Taylor Bockman 10 months ago
parent
commit
38645ad587
  1. 11
      README.md
  2. 54
      lua/conf/langs/completion.lua
  3. 8
      lua/conf/langs/general.lua
  4. 12
      lua/conf/langs/rust.lua
  5. 17
      lua/conf/plugins.lua
  6. 8
      lua/conf/ui.lua

11
README.md

@ -99,11 +99,14 @@ To move seamlessly between splits.
### Autocompletion
Autocompletion is provided by [asyncomplete.vim](https://github.com/prabirshrestha/asyncomplete.vim). Additionally
LSP-based autocompletion is installed.
Autocomplete is provided by [nvim-cmp](https://github.com/hrsh7th/nvim-cmp).
Automatic popups are disabled. In order to see suggestions begin typing and then hit `<C-Space>` in insert mode.
Once in the popup you can use `<Tab>` and `<S-Tab>` to go up and down the suggestions.
Important commands:
* `<TAB>`: Will attempt to autocomplete your current line.
* `<C-Space>`: Will provide documentation and other details.
This is, of course, depending entirely on which LSP you have installed.
### Default Leader

54
lua/conf/langs/completion.lua

@ -0,0 +1,54 @@
-- Credit to https://rsdlt.github.io/ for this code.
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-S-f>'] = 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 = '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
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
formatting = {
fields = {'menu', 'abbr', 'kind'},
format = function(entry, item)
local menu_icon ={
nvim_lsp = 'λ',
vsnip = '',
buffer = 'Ω',
path = '🖫',
}
item.menu = menu_icon[entry.source.name]
return item
end,
},
})

8
lua/conf/langs/general.lua

@ -31,6 +31,7 @@ require'nvim-treesitter.configs'.setup {
"markdown",
"python",
"rust",
"toml",
"query",
"vim",
"vimdoc",
@ -55,4 +56,11 @@ require'nvim-treesitter.configs'.setup {
-- Disable vim regex highlighting. May intefer with some `indent` style stuff.
additional_vim_regex_highlighting = false,
},
ident = {enable = true },
rainbow = {
enable = true,
extended_mode = true,
max_file_lines = nil,
}
}

12
lua/conf/langs/rust.lua

@ -0,0 +1,12 @@
local rt = require("rust-tools")
rt.setup({
server = {
on_attach = function(_, bufnr)
-- 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,
},
})

17
lua/conf/plugins.lua

@ -10,7 +10,7 @@ vim.cmd [[
if !(has('win16') || has('win32') || has('win64'))
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
\ https://raw.githubPlugrcontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall | source %
endif
endif
@ -47,9 +47,15 @@ Plug('williamboman/mason.nvim', {['do'] = vim.fn[':MasonUpdate']})
Plug('williamboman/mason-lspconfig.nvim')
Plug('neovim/nvim-lspconfig')
-- Autocomplete
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
-- Completion framework
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-nvim-lua'
Plug 'hrsh7th/cmp-nvim-lsp-signature-help'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/vim-vsnip'
-- Tmux Helper
Plug 'preservim/vimux'
@ -78,4 +84,7 @@ if vim.fn.executable('pyenv') == 1 then
Plug 'lambdalisue/vim-pyenv'
end
-- Rust
Plug 'simrat39/rust-tools.nvim'
vim.call('plug#end')

8
lua/conf/ui.lua

@ -9,11 +9,6 @@ vim.cmd [[colorscheme nord]]
-- Always show hidden files in nerdtree
vim.g.NERDTreeShowHidden = 1
-- Disable auto-popup for autocomplete
-- This prevents autocomplete spamming when
-- you dont want it.
vim.g.asyncomplete_auto_popup = 0
require('telescope').setup{
defaults = {},
pickers = {
@ -23,6 +18,3 @@ require('telescope').setup{
},
extensions = {}
}

Loading…
Cancel
Save