vim-files

Форк
0
/
completion.lua 
152 строки · 5.4 Кб
1
require('nvim-config-loader').add_pack {
2
  completion = {
3
    vim_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
    },
16
    setup = function()
17
      -- Set up nvim-cmp.
18
      local cmp = require('cmp')
19
      local cmp_autopairs = require('nvim-autopairs.completion.cmp')
20
      local lspkind = require('lspkind')
21
      local luasnip = require("luasnip")
22

23
      require("luasnip.loaders.from_vscode").lazy_load()
24

25
      -- Add parentheses after selecting function or method item
26
      cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done())
27

28
      -- require("lsp_signature").setup({})
29

30
      local has_words_before = function()
31
        local line, col = unpack(vim.api.nvim_win_get_cursor(0))
32
        return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
33
      end
34

35
      cmp.setup({
36
        formatting = {
37
          format = lspkind.cmp_format({
38
            mode = 'symbol_text', -- show only symbol annotations
39
            maxwidth = 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,
42
            ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
43
            show_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
        },
53
        view = {
54
          entries = { name = 'custom', selection_order = 'near_cursor' }
55
        },
56
        performance = {
57
          trigger_debounce_time = 500,
58
          throttle = 550,
59
          fetching_timeout = 80,
60
        },
61
        sources = cmp.config.sources({
62
          { name = 'luasnip' },
63
          { name = 'nvim_lsp_signature_help' },
64
          { name = 'nvim_lsp' },
65
          {
66
            name = 'buffer',
67
            option = {
68
              get_bufnrs = function()
69
                return vim.api.nvim_list_bufs()
70
              end
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
        }),
81
        snippet = {
82
          -- you must specify a snippet engine
83
          expand = function(args)
84
            require('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.
88
          end,
89
        },
90
        -- window = {
91
        --   completion = cmp.config.window.bordered(),
92
        --   documentation = cmp.config.window.bordered(),
93
        -- },
94
        mapping = 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)
101
            if not cmp.select_next_item() then
102
              if vim.bo.buftype ~= 'prompt' and has_words_before() then
103
                cmp.complete()
104
              else
105
                fallback()
106
              end
107
            end
108
          end,
109
          -- prev completion item with
110
          ['<S-Tab>'] = function(fallback)
111
            if not cmp.select_prev_item() then
112
              if vim.bo.buftype ~= 'prompt' and has_words_before() then
113
                cmp.complete()
114
              else
115
                fallback()
116
              end
117
            end
118
          end,
119
        }),
120
      })
121

122
      -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
123
      cmp.setup.cmdline({ '/', '?' }, {
124
        mapping = cmp.mapping.preset.cmdline(),
125
        sources = {
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).
134
      cmp.setup.cmdline(':', {
135
        mapping = cmp.mapping.preset.cmdline(),
136
        sources = 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
      -- }
150
    end
151
  }
152
}
153

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.