| skipped 8 lines |
9 | 9 | | opts = function(_, opts) |
10 | 10 | | local cmp = require "cmp" |
11 | 11 | | local compare = require "cmp.config.compare" |
12 | | - | local luasnip = require "luasnip" |
13 | | - | |
14 | | - | local function has_words_before() |
15 | | - | local line, col = unpack(vim.api.nvim_win_get_cursor(0)) |
16 | | - | return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil |
17 | | - | end |
18 | 12 | | |
19 | 13 | | return require("astrocore").extend_tbl(opts, { |
20 | 14 | | window = { completion = { col_offset = -1, side_padding = 0 } }, |
| skipped 29 lines |
50 | 44 | | compare.length, |
51 | 45 | | compare.order, |
52 | 46 | | }, |
53 | | - | }, |
54 | | - | mapping = { |
55 | | - | -- tab complete |
56 | | - | ["<Tab>"] = cmp.mapping(function(fallback) |
57 | | - | if cmp.visible() and has_words_before() then |
58 | | - | cmp.confirm { select = true } |
59 | | - | else |
60 | | - | fallback() |
61 | | - | end |
62 | | - | end, { "i", "s" }), |
63 | | - | -- <C-n> and <C-p> for navigating snippets |
64 | | - | ["<C-n>"] = cmp.mapping(function() |
65 | | - | if luasnip.jumpable(1) then luasnip.jump(1) end |
66 | | - | end, { "i", "s" }), |
67 | | - | ["<C-p>"] = cmp.mapping(function() |
68 | | - | if luasnip.jumpable(-1) then luasnip.jump(-1) end |
69 | | - | end, { "i", "s" }), |
70 | | - | -- <C-j> for starting completion |
71 | | - | ["<C-j>"] = cmp.mapping(function() |
72 | | - | if cmp.visible() then |
73 | | - | cmp.select_next_item { behavior = cmp.SelectBehavior.Insert } |
74 | | - | else |
75 | | - | cmp.complete() |
76 | | - | end |
77 | | - | end, { "i", "s" }), |
78 | 47 | | }, |
79 | 48 | | }) |
80 | 49 | | end, |
| skipped 2 lines |