vim-files
/
completion.lua
152 строки · 5.4 Кб
1require('nvim-config-loader').add_pack {
2completion = {
3vim_plug_bundle = {
4'hrsh7th/cmp-nvim-lsp',
5'hrsh7th/cmp-buffer',
6'hrsh7th/cmp-path',
7'hrsh7th/cmp-cmdline',
8'hrsh7th/cmp-nvim-lsp-signature-help',
9'hrsh7th/cmp-nvim-lsp-document-symbol',
10'quangnguyen30192/cmp-nvim-tags',
11'hrsh7th/nvim-cmp',
12'ray-x/cmp-treesitter',
13'hrsh7th/cmp-omni',
14'saadparwaiz1/cmp_luasnip',
15},
16setup = function()
17-- Set up nvim-cmp.
18local cmp = require('cmp')
19local cmp_autopairs = require('nvim-autopairs.completion.cmp')
20local lspkind = require('lspkind')
21local luasnip = require("luasnip")
22
23require("luasnip.loaders.from_vscode").lazy_load()
24
25-- Add parentheses after selecting function or method item
26cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done())
27
28-- require("lsp_signature").setup({})
29
30local has_words_before = function()
31local line, col = unpack(vim.api.nvim_win_get_cursor(0))
32return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
33end
34
35cmp.setup({
36formatting = {
37format = lspkind.cmp_format({
38mode = 'symbol_text', -- show only symbol annotations
39maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
40-- can also be a function to dynamically calculate max width such as
41-- maxwidth = function() return math.floor(0.45 * vim.o.columns) end,
42ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
43show_labelDetails = true, -- show labelDetails in menu. Disabled by default
44
45-- The function below will be called before any actual modifications from lspkind
46-- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
47-- before = function (entry, vim_item)
48-- -- ...
49-- return vim_item
50-- end
51})
52},
53view = {
54entries = { name = 'custom', selection_order = 'near_cursor' }
55},
56performance = {
57trigger_debounce_time = 500,
58throttle = 550,
59fetching_timeout = 80,
60},
61sources = cmp.config.sources({
62{ name = 'luasnip' },
63{ name = 'nvim_lsp_signature_help' },
64{ name = 'nvim_lsp' },
65{
66name = 'buffer',
67option = {
68get_bufnrs = function()
69return vim.api.nvim_list_bufs()
70end
71}
72},
73{ name = 'tags' },
74-- { name = "rg" },
75-- { name = 'vsnip' }, -- For vsnip users.
76-- { name = 'ultisnips' }, -- For ultisnips users.
77-- { name = 'snippy' }, -- For snippy users.
78}, {
79{ name = 'path' },
80}),
81snippet = {
82-- you must specify a snippet engine
83expand = function(args)
84require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
85-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
86-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
87-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
88end,
89},
90-- window = {
91-- completion = cmp.config.window.bordered(),
92-- documentation = cmp.config.window.bordered(),
93-- },
94mapping = cmp.mapping.preset.insert({
95['<C-b>'] = cmp.mapping.scroll_docs(-4),
96['<C-f>'] = cmp.mapping.scroll_docs(4),
97-- select completion item
98['<CR>'] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Insert, select = true },
99-- next completion item with
100['<Tab>'] = function(fallback)
101if not cmp.select_next_item() then
102if vim.bo.buftype ~= 'prompt' and has_words_before() then
103cmp.complete()
104else
105fallback()
106end
107end
108end,
109-- prev completion item with
110['<S-Tab>'] = function(fallback)
111if not cmp.select_prev_item() then
112if vim.bo.buftype ~= 'prompt' and has_words_before() then
113cmp.complete()
114else
115fallback()
116end
117end
118end,
119}),
120})
121
122-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
123cmp.setup.cmdline({ '/', '?' }, {
124mapping = cmp.mapping.preset.cmdline(),
125sources = {
126{ name = 'buffer' },
127-- { name = 'nvim_lsp_document_symbol' },
128}
129})
130
131-- NOTE: disabled, causes duplicates entries after plug update
132
133-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
134cmp.setup.cmdline(':', {
135mapping = cmp.mapping.preset.cmdline(),
136sources = cmp.config.sources({
137{ name = 'cmdline' },
138{ name = 'path' },
139})
140})
141
142-- TODO:
143
144-- Set up lspconfig.
145-- local capabilities = require('cmp_nvim_lsp').default_capabilities()
146
147-- require('lspconfig').solargraph.setup {
148-- capabilities = capabilities
149-- }
150end
151}
152}
153