diff options
Diffstat (limited to '.config/nvim/lua/plugins/cmp.lua')
| -rw-r--r-- | .config/nvim/lua/plugins/cmp.lua | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua index 78ff9a9..828d7c2 100644 --- a/.config/nvim/lua/plugins/cmp.lua +++ b/.config/nvim/lua/plugins/cmp.lua | |||
| @@ -1,4 +1,3 @@ | |||
| 1 | -- autocompletion | ||
| 2 | return { | 1 | return { |
| 3 | { | 2 | { |
| 4 | "hrsh7th/nvim-cmp", | 3 | "hrsh7th/nvim-cmp", |
| @@ -46,18 +45,35 @@ return { | |||
| 46 | TypeParameter = "", | 45 | TypeParameter = "", |
| 47 | } | 46 | } |
| 48 | 47 | ||
| 48 | ---@diagnostic disable-next-line: missing-fields | ||
| 49 | cmp.setup({ | 49 | cmp.setup({ |
| 50 | enabled = true, | 50 | enabled = function() |
| 51 | -- disable autocompletion in prompt | ||
| 52 | local buftype = vim.api.nvim_buf_get_option(0, "buftype") | ||
| 53 | if buftype == "prompt" then return false end | ||
| 54 | |||
| 55 | local context = require 'cmp.config.context' | ||
| 56 | -- disable autocompletion in comments | ||
| 57 | return not context.in_treesitter_capture("comment") and not context.in_syntax_group("Comment") | ||
| 58 | end, | ||
| 59 | ---@diagnostic disable-next-line: missing-fields | ||
| 60 | completion = { | ||
| 61 | completeopt = "menu,menuone,noselect", | ||
| 62 | }, | ||
| 63 | window = { | ||
| 64 | documentation = cmp.config.window.bordered(), | ||
| 65 | completion = cmp.config.window.bordered(), | ||
| 66 | }, | ||
| 51 | snippet = { | 67 | snippet = { |
| 52 | expand = function(args) | 68 | expand = function(args) |
| 53 | luasnip.lsp_expand(args.body) | 69 | luasnip.lsp_expand(args.body) |
| 54 | end, | 70 | end, |
| 55 | }, | 71 | }, |
| 56 | mapping = cmp.mapping.preset.insert({ | 72 | mapping = cmp.mapping.preset.insert({ |
| 73 | ["<C-f>"] = cmp.mapping.scroll_docs(-4), | ||
| 74 | ["<C-d>"] = cmp.mapping.scroll_docs(4), | ||
| 57 | ["<C-k>"] = cmp.mapping.select_prev_item(), | 75 | ["<C-k>"] = cmp.mapping.select_prev_item(), |
| 58 | ["<C-j>"] = cmp.mapping.select_next_item(), | 76 | ["<C-j>"] = cmp.mapping.select_next_item(), |
| 59 | ["<C-d>"] = cmp.mapping.scroll_docs(-4), | ||
| 60 | ["<C-f>"] = cmp.mapping.scroll_docs(4), | ||
| 61 | ["<CR>"] = cmp.mapping.confirm({ | 77 | ["<CR>"] = cmp.mapping.confirm({ |
| 62 | behavior = cmp.ConfirmBehavior.Replace, | 78 | behavior = cmp.ConfirmBehavior.Replace, |
| 63 | select = false, | 79 | select = false, |
| @@ -81,6 +97,7 @@ return { | |||
| 81 | end | 97 | end |
| 82 | end, { "i", "s" }), | 98 | end, { "i", "s" }), |
| 83 | }), | 99 | }), |
| 100 | ---@diagnostic disable-next-line: missing-fields | ||
| 84 | formatting = { | 101 | formatting = { |
| 85 | fields = { "kind", "abbr", "menu" }, | 102 | fields = { "kind", "abbr", "menu" }, |
| 86 | format = function(entry, vim_item) | 103 | format = function(entry, vim_item) |
| @@ -103,12 +120,41 @@ return { | |||
| 103 | }, | 120 | }, |
| 104 | }) | 121 | }) |
| 105 | 122 | ||
| 106 | -- If you want insert `(` after select function or method item | 123 | -- insert `(` after select function or method item |
| 107 | local cmp_autopairs = require('nvim-autopairs.completion.cmp') | 124 | local cmp_autopairs = require('nvim-autopairs.completion.cmp') |
| 108 | cmp.event:on( | 125 | cmp.event:on( |
| 109 | 'confirm_done', | 126 | 'confirm_done', |
| 110 | cmp_autopairs.on_confirm_done() | 127 | cmp_autopairs.on_confirm_done() |
| 111 | ) | 128 | ) |
| 129 | |||
| 130 | ---@diagnostic disable-next-line: missing-fields | ||
| 131 | cmp.setup.filetype('gitcommit', { | ||
| 132 | sources = cmp.config.sources({ | ||
| 133 | { name = 'git' }, | ||
| 134 | }, { | ||
| 135 | { name = 'buffer' }, | ||
| 136 | }) | ||
| 137 | }) | ||
| 138 | |||
| 139 | -- use buffer source for `/` . | ||
| 140 | ---@diagnostic disable-next-line: missing-fields | ||
| 141 | cmp.setup.cmdline('/', { | ||
| 142 | mapping = cmp.mapping.preset.cmdline(), | ||
| 143 | sources = { | ||
| 144 | { name = 'buffer' } | ||
| 145 | } | ||
| 146 | }) | ||
| 147 | |||
| 148 | -- use cmdline & path source for ':' . | ||
| 149 | ---@diagnostic disable-next-line: missing-fields | ||
| 150 | cmp.setup.cmdline(':', { | ||
| 151 | mapping = cmp.mapping.preset.cmdline(), | ||
| 152 | sources = cmp.config.sources({ | ||
| 153 | { name = 'path' } | ||
| 154 | }, { | ||
| 155 | { name = 'cmdline' } | ||
| 156 | }) | ||
| 157 | }) | ||
| 112 | end, | 158 | end, |
| 113 | }, | 159 | }, |
| 114 | } | 160 | } |
