diff options
| author | bh <qn+git@excalibur.computer> | 2025-11-19 14:50:22 +0800 |
|---|---|---|
| committer | bh <qn+git@excalibur.computer> | 2025-11-19 14:50:22 +0800 |
| commit | 5e80cc2081ec616c828a0abe82d246c4dc0a4334 (patch) | |
| tree | 3805b57cdf59e0fa4dafb4c998f82644da19fb38 /lua/config/completion.lua | |
| parent | f3d3e0d5dc32bb5c00a6106aee9027decd345e63 (diff) | |
Fixed snippets and also a little refactoring on the theme
Diffstat (limited to 'lua/config/completion.lua')
| -rw-r--r-- | lua/config/completion.lua | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lua/config/completion.lua b/lua/config/completion.lua new file mode 100644 index 0000000..09a934e --- /dev/null +++ b/lua/config/completion.lua @@ -0,0 +1,59 @@ +-- return a function for lazy.nvim +return function() + local cmp = require("cmp") + local luasnip = require("luasnip") + local lspkind = require("lspkind") + + -- load friendly-snippets + require("luasnip.loaders.from_vscode").lazy_load() + + cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + ["<C-b>"] = cmp.mapping.scroll_docs(-4), + ["<C-f>"] = cmp.mapping.scroll_docs(4), + ["<C-Space>"] = cmp.mapping.complete(), -- manual trigger + ["<CR>"] = cmp.mapping.confirm({ select = true }), + ["<Tab>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + ["<S-Tab>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "path" }, + { name = "luasnip" }, + }, { + { name = "buffer" }, + }), + formatting = { + format = lspkind.cmp_format({ with_text = true, maxwidth = 50 }), + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + completion = { + autocomplete = false, -- only trigger with <C-Space> + }, + }) +end + |
