我设法通过一些插件的组合来完成所有工作,以便在 neovim 中完成。他们是:
这与neovim 的 Wikinvim-cmp
推荐的插件列表相同。
我正在使用打包程序来管理插件。我还在配置插件之前安装它们。这是安装线:
use 'neovim/nvim-lspconfig'
use 'nvim-treesitter/completion-treesitter' -- Only if you are using TS
use 'hrsh7th/nvim-cmp' -- Autocompletion plugin
use 'hrsh7th/cmp-nvim-lsp' -- LSP source for nvim-cmp
use 'saadparwaiz1/cmp_luasnip' -- Snippets source for nvim-cmp
use 'L3MON4D3/LuaSnip' -- Snippets plugin
然后是配置部分:
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- Configure ElixirLS as the LSP server for Elixir.
require'lspconfig'.elixirls.setup{
cmd = { "/home/my-user/path-to/elixir-ls/release/language_server.sh" },
-- on_attach = custom_attach, -- this may be required for extended functionalities of the LSP
capabilities = capabilities,
flags = {
debounce_text_changes = 150,
},
elixirLS = {
dialyzerEnabled = false,
fetchDeps = false,
};
}
local luasnip = require 'luasnip'
-- nvim-cmp
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = 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.Replace,
select = true,
},
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
你可以在我的 dotfiles repo 中找到我所有的 neovim 配置:https ://github.com/philss/dotfiles
作为参考,这是我正在使用的 nvim 版本(从源代码安装):
NVIM v0.7.0-dev+864-g2818de8b7
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Features: +acl +iconv +tui