Clean up and extend LSP
Move nvim-cmp set up to own file, LSP file was getting unmanageable Add more cmp/lsp plugins to improve capabilities Switch python LSP back to using pyright Remove legacy neovide stuff
This commit is contained in:
parent
8b2f535a2e
commit
8df1e359a5
|
@ -9,8 +9,3 @@ require 'keymaps'
|
|||
|
||||
-- Remaining vim commands to be converted to lua
|
||||
require 'vimcommands'
|
||||
|
||||
-- Neovide specific config, only used if Neovide is runnning
|
||||
if vim.g.neovide then
|
||||
require 'neovide'
|
||||
end
|
||||
|
|
75
config/nvim/lua/config_plugins/config_cmp.lua
Normal file
75
config/nvim/lua/config_plugins/config_cmp.lua
Normal file
|
@ -0,0 +1,75 @@
|
|||
local cmp = require 'cmp'
|
||||
local luasnip = require 'luasnip'
|
||||
|
||||
require('luasnip.loaders.from_vscode').lazy_load()
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body) -- For `luasnip` users.
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<C-u>'] = cmp.mapping.scroll_docs(-4), -- Up
|
||||
['<C-d>'] = cmp.mapping.scroll_docs(4), -- Down
|
||||
['<C-Space>'] = cmp.mapping.complete(),
|
||||
['<CR>'] = cmp.mapping.confirm {
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = true,
|
||||
},
|
||||
['<Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif luasnip.expand_or_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
}),
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' },
|
||||
{ name = 'latex_symbols' },
|
||||
}
|
||||
})
|
||||
|
||||
-- Set configuration for specific filetype.
|
||||
cmp.setup.filetype('gitcommit', {
|
||||
sources = {
|
||||
{ name = 'git' },
|
||||
{ name = 'commit' },
|
||||
{ name = 'buffer' },
|
||||
}
|
||||
})
|
||||
|
||||
cmp.setup.filetype('markdown', {
|
||||
sources = {
|
||||
{ name = 'spell' },
|
||||
{ name = 'buffer' },
|
||||
},
|
||||
})
|
||||
|
||||
cmp.setup.cmdline('/', {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = {
|
||||
{ name = 'buffer' }
|
||||
}
|
||||
})
|
||||
|
||||
cmp.setup.cmdline(':', {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = {
|
||||
{ name = 'path' },
|
||||
{ name = 'cmdline' }
|
||||
}
|
||||
})
|
|
@ -15,9 +15,6 @@ end
|
|||
-- Use an on_attach function to only map the following keys
|
||||
-- after the language server attaches to the current buffer
|
||||
local on_attach = function(client, bufnr)
|
||||
-- Enable completion triggered by <c-x><c-o>
|
||||
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||
|
||||
-- Mappings.
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
local bufopts = { noremap = true, silent = true, buffer = bufnr }
|
||||
|
@ -37,18 +34,9 @@ local on_attach = function(client, bufnr)
|
|||
vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, bufopts)
|
||||
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, bufopts)
|
||||
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, bufopts)
|
||||
-- Keep support for deprecated syntax in vim <= 7
|
||||
if vim.version().minor <= 7 then
|
||||
vim.keymap.set('n', '<leader>i', function()
|
||||
vim.lsp.buf.formatting()
|
||||
end, bufopts)
|
||||
else
|
||||
vim.keymap.set('n', '<leader>i', function()
|
||||
vim.lsp.buf.format({ timeout_ms = 10000, async = false })
|
||||
end, bufopts)
|
||||
end
|
||||
-- Enable aerial support
|
||||
require("aerial").on_attach(client, bufnr)
|
||||
vim.keymap.set('n', '<leader>i', function()
|
||||
vim.lsp.buf.format({ timeout_ms = 10000, async = false })
|
||||
end, bufopts)
|
||||
end
|
||||
|
||||
local lsp_flags = {
|
||||
|
@ -56,87 +44,12 @@ local lsp_flags = {
|
|||
debounce_text_changes = 150,
|
||||
}
|
||||
|
||||
-- Setup nvim-cmp.
|
||||
local cmp = require 'cmp'
|
||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
-- REQUIRED - you must specify a snippet engine
|
||||
expand = function(args)
|
||||
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
|
||||
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
||||
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
|
||||
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
|
||||
end,
|
||||
},
|
||||
window = {
|
||||
completion = cmp.config.window.bordered(),
|
||||
documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
['<C-Space>'] = cmp.mapping.complete(),
|
||||
['<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.
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'vsnip' }, -- For vsnip users.
|
||||
-- { name = 'luasnip' }, -- For luasnip users.
|
||||
-- { name = 'ultisnips' }, -- For ultisnips users.
|
||||
-- { name = 'snippy' }, -- For snippy users.
|
||||
}, {
|
||||
{ name = 'buffer' },
|
||||
})
|
||||
})
|
||||
|
||||
-- Set configuration for specific filetype.
|
||||
cmp.setup.filetype('gitcommit', {
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
|
||||
}, {
|
||||
{ name = 'buffer' },
|
||||
})
|
||||
})
|
||||
|
||||
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
|
||||
cmp.setup.cmdline('/', {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = {
|
||||
{ name = 'buffer' }
|
||||
}
|
||||
})
|
||||
|
||||
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
|
||||
cmp.setup.cmdline(':', {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'path' }
|
||||
}, {
|
||||
{ name = 'cmdline' }
|
||||
})
|
||||
})
|
||||
|
||||
-- Setup lspconfig.
|
||||
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||
|
||||
require('lspconfig')['pylsp'].setup {
|
||||
require('lspconfig')['pyright'].setup{
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags,
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
pylsp = {
|
||||
plugins = {
|
||||
pycodestyle = {
|
||||
maxLineLength = 88
|
||||
},
|
||||
mypy = {
|
||||
report_progress = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
require('lspconfig')['fortls'].setup {
|
||||
|
|
|
@ -25,22 +25,22 @@ require('packer').startup {
|
|||
}
|
||||
use 'kyazdani42/nvim-web-devicons'
|
||||
use 'nvim-lua/plenary.nvim'
|
||||
use {
|
||||
'neovim/nvim-lspconfig',
|
||||
config = function()
|
||||
require 'config_plugins.config_lsp'
|
||||
end,
|
||||
}
|
||||
use 'christoomey/vim-tmux-navigator'
|
||||
use {
|
||||
'neovim/nvim-lspconfig',
|
||||
'hrsh7th/nvim-cmp',
|
||||
'hrsh7th/cmp-nvim-lsp',
|
||||
'hrsh7th/cmp-buffer',
|
||||
'hrsh7th/cmp-path',
|
||||
'hrsh7th/cmp-cmdline',
|
||||
'hrsh7th/cmp-nvim-lua',
|
||||
'hrsh7th/nvim-cmp',
|
||||
'hrsh7th/cmp-vsnip',
|
||||
'hrsh7th/vim-vsnip',
|
||||
'f3fora/cmp-spell',
|
||||
'petertriho/cmp-git',
|
||||
'Dosx001/cmp-commit',
|
||||
'kdheepak/cmp-latex-symbols',
|
||||
'L3MON4D3/LuaSnip',
|
||||
'saadparwaiz1/cmp_luasnip',
|
||||
'rafamadriz/friendly-snippets',
|
||||
'windwp/nvim-autopairs',
|
||||
}
|
||||
use {
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
|
@ -56,7 +56,6 @@ require('packer').startup {
|
|||
}
|
||||
use {
|
||||
'stevearc/aerial.nvim',
|
||||
branch = 'nvim-0.5',
|
||||
config = function()
|
||||
require 'config_plugins.config_aerial'
|
||||
end
|
||||
|
@ -147,3 +146,5 @@ require('packer').startup {
|
|||
},
|
||||
}
|
||||
}
|
||||
require 'config_plugins.config_lsp'
|
||||
require 'config_plugins.config_cmp'
|
||||
|
|
Loading…
Reference in a new issue