.config/nvim/lua/plugins/completion.lua

changeset 1171
12363689e67e
parent 1168
52750027eff6
child 1173
79c1553aa040
equal deleted inserted replaced
1170:915a78d501d5 1171:12363689e67e
11 "hrsh7th/cmp-path", 11 "hrsh7th/cmp-path",
12 "quangnguyen30192/cmp-nvim-tags", 12 "quangnguyen30192/cmp-nvim-tags",
13 }, 13 },
14 config = function() 14 config = function()
15 local cmp = require("cmp") 15 local cmp = require("cmp")
16 local luasnip = require("luasnip")
17 16
18 local has_words_before = function() 17 local has_words_before = function()
19 local line, col = unpack(vim.api.nvim_win_get_cursor(0)) 18 local line, col = unpack(vim.api.nvim_win_get_cursor(0))
20 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil 19 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
21 end 20 end
25 completion = { 24 completion = {
26 keyword_length = 3, 25 keyword_length = 3,
27 }, 26 },
28 snippet = { 27 snippet = {
29 expand = function(args) 28 expand = function(args)
30 luasnip.lsp_expand(args.body) 29 vim.snippet.expand(args.body)
31 end, 30 end,
32 }, 31 },
33 formatting = { 32 formatting = {
34 format = function(entry, vim_item) 33 format = function(entry, vim_item)
35 if vim_item.kind == "Text" then 34 if vim_item.kind == "Text" then
43 ["<C-b>"] = cmp.mapping.scroll_docs(-4), 42 ["<C-b>"] = cmp.mapping.scroll_docs(-4),
44 ["<C-f>"] = cmp.mapping.scroll_docs(4), 43 ["<C-f>"] = cmp.mapping.scroll_docs(4),
45 ["<Tab>"] = cmp.mapping(function(fallback) 44 ["<Tab>"] = cmp.mapping(function(fallback)
46 if cmp.visible() then 45 if cmp.visible() then
47 cmp.select_next_item() 46 cmp.select_next_item()
48 elseif luasnip.expand_or_locally_jumpable() then 47 elseif vim.snippet.active({direction = 1}) then
49 luasnip.expand_or_jump() 48 vim.snippet.jump(1)
50 elseif has_words_before() then 49 elseif has_words_before() then
51 cmp.complete() 50 cmp.complete()
52 else 51 else
53 fallback() 52 fallback()
54 end 53 end
55 end, { "i", "s" }), 54 end, { "i", "s" }),
56 ["<S-Tab>"] = cmp.mapping(function(fallback) 55 ["<S-Tab>"] = cmp.mapping(function(fallback)
57 if cmp.visible() then 56 if cmp.visible() then
58 cmp.select_prev_item() 57 cmp.select_prev_item()
59 elseif luasnip.jumpable(-1) then 58 elseif vim.snippet.active({direction = -1}) then
60 luasnip.jump(-1) 59 vim.snippet.jump(-1)
61 else 60 else
62 fallback() 61 fallback()
63 end 62 end
64 end, { "i", "s" }), 63 end, { "i", "s" }),
65 ["<C-g>"] = cmp.mapping.abort(), 64 ["<C-g>"] = cmp.mapping.abort(),
78 { name = "calc" }, 77 { name = "calc" },
79 }), 78 }),
80 }) 79 })
81 end, 80 end,
82 }, 81 },
83 {
84 "L3MON4D3/LuaSnip",
85 lazy = true,
86 build = (jit.os ~= "Windows") and "make install_jsregexp",
87 opts = {
88 history = true,
89 delete_check_events = "TextChanged",
90 },
91 },
92 } 82 }

mercurial