|
| 1 | +return { |
| 2 | + { |
| 3 | + 'windwp/nvim-autopairs', |
| 4 | + config = function() |
| 5 | + require('nvim-autopairs').setup {} |
| 6 | + require('nvim-autopairs').remove_rule '`' |
| 7 | + end, |
| 8 | + }, |
| 9 | + |
| 10 | + { -- completion |
| 11 | + 'hrsh7th/nvim-cmp', |
| 12 | + event = 'InsertEnter', |
| 13 | + dependencies = { |
| 14 | + { 'hrsh7th/cmp-nvim-lsp' }, |
| 15 | + { 'hrsh7th/cmp-nvim-lsp-signature-help' }, |
| 16 | + { 'hrsh7th/cmp-buffer' }, |
| 17 | + { 'hrsh7th/cmp-path' }, |
| 18 | + { 'hrsh7th/cmp-calc' }, |
| 19 | + { 'hrsh7th/cmp-emoji' }, |
| 20 | + { 'saadparwaiz1/cmp_luasnip' }, |
| 21 | + { 'f3fora/cmp-spell' }, |
| 22 | + { 'ray-x/cmp-treesitter' }, |
| 23 | + { 'kdheepak/cmp-latex-symbols' }, |
| 24 | + { 'jmbuhr/cmp-pandoc-references' }, |
| 25 | + { 'L3MON4D3/LuaSnip' }, |
| 26 | + { 'rafamadriz/friendly-snippets' }, |
| 27 | + { 'onsails/lspkind-nvim' }, |
| 28 | + }, |
| 29 | + config = function() |
| 30 | + local cmp = require 'cmp' |
| 31 | + local luasnip = require 'luasnip' |
| 32 | + local lspkind = require 'lspkind' |
| 33 | + |
| 34 | + local has_words_before = function() |
| 35 | + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) |
| 36 | + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil |
| 37 | + end |
| 38 | + |
| 39 | + cmp.setup { |
| 40 | + snippet = { |
| 41 | + expand = function(args) |
| 42 | + luasnip.lsp_expand(args.body) |
| 43 | + end, |
| 44 | + }, |
| 45 | + completion = { completeopt = 'menu,menuone,noinsert' }, |
| 46 | + mapping = { |
| 47 | + ['<C-f>'] = cmp.mapping.scroll_docs(-4), |
| 48 | + ['<C-d>'] = cmp.mapping.scroll_docs(4), |
| 49 | + |
| 50 | + ['<C-n>'] = cmp.mapping(function(fallback) |
| 51 | + if luasnip.expand_or_jumpable() then |
| 52 | + luasnip.expand_or_jump() |
| 53 | + fallback() |
| 54 | + end |
| 55 | + end, { 'i', 's' }), |
| 56 | + ['<C-p>'] = cmp.mapping(function(fallback) |
| 57 | + if luasnip.jumpable(-1) then |
| 58 | + luasnip.jump(-1) |
| 59 | + else |
| 60 | + fallback() |
| 61 | + end |
| 62 | + end, { 'i', 's' }), |
| 63 | + ['<C-e>'] = cmp.mapping.abort(), |
| 64 | + ['<c-y>'] = cmp.mapping.confirm { |
| 65 | + select = true, |
| 66 | + }, |
| 67 | + ['<CR>'] = cmp.mapping.confirm { |
| 68 | + select = true, |
| 69 | + }, |
| 70 | + |
| 71 | + ['<Tab>'] = cmp.mapping(function(fallback) |
| 72 | + if cmp.visible() then |
| 73 | + cmp.select_next_item() |
| 74 | + elseif has_words_before() then |
| 75 | + cmp.complete() |
| 76 | + else |
| 77 | + fallback() |
| 78 | + end |
| 79 | + end, { 'i', 's' }), |
| 80 | + ['<S-Tab>'] = cmp.mapping(function(fallback) |
| 81 | + if cmp.visible() then |
| 82 | + cmp.select_prev_item() |
| 83 | + else |
| 84 | + fallback() |
| 85 | + end |
| 86 | + end, { 'i', 's' }), |
| 87 | + |
| 88 | + ['<C-l>'] = cmp.mapping(function() |
| 89 | + if luasnip.expand_or_locally_jumpable() then |
| 90 | + luasnip.expand_or_jump() |
| 91 | + end |
| 92 | + end, { 'i', 's' }), |
| 93 | + ['<C-h>'] = cmp.mapping(function() |
| 94 | + if luasnip.locally_jumpable(-1) then |
| 95 | + luasnip.jump(-1) |
| 96 | + end |
| 97 | + end, { 'i', 's' }), |
| 98 | + }, |
| 99 | + autocomplete = false, |
| 100 | + |
| 101 | + ---@diagnostic disable-next-line: missing-fields |
| 102 | + formatting = { |
| 103 | + format = lspkind.cmp_format { |
| 104 | + mode = 'symbol', |
| 105 | + menu = { |
| 106 | + otter = '[🦦]', |
| 107 | + nvim_lsp = '[LSP]', |
| 108 | + luasnip = '[snip]', |
| 109 | + buffer = '[buf]', |
| 110 | + path = '[path]', |
| 111 | + spell = '[spell]', |
| 112 | + pandoc_references = '[ref]', |
| 113 | + tags = '[tag]', |
| 114 | + treesitter = '[TS]', |
| 115 | + calc = '[calc]', |
| 116 | + latex_symbols = '[tex]', |
| 117 | + emoji = '[emoji]', |
| 118 | + }, |
| 119 | + }, |
| 120 | + }, |
| 121 | + sources = { |
| 122 | + { name = 'otter' }, -- for code chunks in quarto |
| 123 | + { name = 'path' }, |
| 124 | + { name = 'nvim_lsp' }, |
| 125 | + { name = 'nvim_lsp_signature_help' }, |
| 126 | + { name = 'luasnip', keyword_length = 3, max_item_count = 3 }, |
| 127 | + { name = 'pandoc_references' }, |
| 128 | + { name = 'buffer', keyword_length = 5, max_item_count = 3 }, |
| 129 | + { name = 'spell' }, |
| 130 | + { name = 'treesitter', keyword_length = 5, max_item_count = 3 }, |
| 131 | + { name = 'calc' }, |
| 132 | + { name = 'latex_symbols' }, |
| 133 | + { name = 'emoji' }, |
| 134 | + }, |
| 135 | + view = { |
| 136 | + entries = 'native', |
| 137 | + }, |
| 138 | + window = { |
| 139 | + documentation = { |
| 140 | + border = require('misc.style').border, |
| 141 | + }, |
| 142 | + }, |
| 143 | + } |
| 144 | + |
| 145 | + -- for friendly snippets |
| 146 | + require('luasnip.loaders.from_vscode').lazy_load() |
| 147 | + -- for custom snippets |
| 148 | + require('luasnip.loaders.from_vscode').lazy_load { paths = { vim.fn.stdpath 'config' .. '/snips' } } |
| 149 | + -- link quarto and rmarkdown to markdown snippets |
| 150 | + luasnip.filetype_extend('quarto', { 'markdown' }) |
| 151 | + luasnip.filetype_extend('rmarkdown', { 'markdown' }) |
| 152 | + end, |
| 153 | + }, |
| 154 | + |
| 155 | + { -- gh copilot |
| 156 | + 'zbirenbaum/copilot.lua', |
| 157 | + enabled = false, |
| 158 | + config = function() |
| 159 | + require('copilot').setup { |
| 160 | + suggestion = { |
| 161 | + enabled = true, |
| 162 | + auto_trigger = true, |
| 163 | + debounce = 75, |
| 164 | + keymap = { |
| 165 | + accept = '<c-a>', |
| 166 | + accept_word = false, |
| 167 | + accept_line = false, |
| 168 | + next = '<M-]>', |
| 169 | + prev = '<M-[>', |
| 170 | + dismiss = '<C-]>', |
| 171 | + }, |
| 172 | + }, |
| 173 | + panel = { enabled = false }, |
| 174 | + } |
| 175 | + end, |
| 176 | + }, |
| 177 | +} |
0 commit comments