]> src.twobees.de Git - dotfiles.git/blob - stow/nvim/.config/nvim/lua/cmp-settings.lua
urxvt
[dotfiles.git] / stow / nvim / .config / nvim / lua / cmp-settings.lua
1
2 -- mostly got this stuff from here: https://raw.githubusercontent.com/tjdevries/config_manager/master/xdg_config/nvim/after/plugin/completion.lua
3 vim.opt.completeopt = { "menu", "menuone", "noselect" }
4
5 -- Don't show the dumb matching stuff.
6 vim.opt.shortmess:append "c"
7
8
9 local ok, lspkind = pcall(require, "lspkind")
10 if not ok then
11   return
12 end
13
14 lspkind.init()
15
16 local cmp = require "cmp"
17
18 cmp.setup {
19   mapping = {
20     ["<C-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
21     ["<C-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
22     ["<C-d>"] = cmp.mapping.scroll_docs(-4),
23     ["<C-f>"] = cmp.mapping.scroll_docs(4),
24     ["<C-e>"] = cmp.mapping.abort(),
25     ["<c-y>"] = cmp.mapping(
26       cmp.mapping.confirm {
27         behavior = cmp.ConfirmBehavior.Insert,
28         select = true,
29       },
30       { "i", "c" }
31     ),
32
33     ["<c-space>"] = cmp.mapping {
34       i = cmp.mapping.complete(),
35       c = function(
36         _ --[[fallback]]
37       )
38         if cmp.visible() then
39           if not cmp.confirm { select = true } then
40             return
41           end
42         else
43           cmp.complete()
44         end
45       end,
46     },
47
48     -- ["<tab>"] = false,
49     ["<tab>"] = cmp.config.disable,
50
51     -- Testing
52     ["<c-q>"] = cmp.mapping.confirm {
53       behavior = cmp.ConfirmBehavior.Replace,
54       select = true,
55     },
56
57   },
58
59   sources = {
60
61     -- Youtube: Could enable this only for lua, but nvim_lua handles that already.
62     { name = "nvim_lua" },
63     { name = "nvim_lsp" },
64     { name = "path" },
65     { name = "buffer", keyword_length = 3 },
66   },
67
68   sorting = {
69     -- TODO: Would be cool to add stuff like "See variable names before method names" in rust, or something like that.
70     comparators = {
71       cmp.config.compare.offset,
72       cmp.config.compare.exact,
73       cmp.config.compare.score,
74
75       -- copied from cmp-under, but I don't think I need the plugin for this.
76       -- I might add some more of my own.
77       function(entry1, entry2)
78         local _, entry1_under = entry1.completion_item.label:find "^_+"
79         local _, entry2_under = entry2.completion_item.label:find "^_+"
80         entry1_under = entry1_under or 0
81         entry2_under = entry2_under or 0
82         if entry1_under > entry2_under then
83           return false
84         elseif entry1_under < entry2_under then
85           return true
86         end
87       end,
88
89       cmp.config.compare.kind,
90       cmp.config.compare.sort_text,
91       cmp.config.compare.length,
92       cmp.config.compare.order,
93     },
94   },
95
96   -- do i want luasnip?
97   -- snippet = {
98   --   expand = function(args)
99   --     require("luasnip").lsp_expand(args.body)
100   --   end,
101   -- },
102
103   formatting = {
104     -- Youtube: How to set up nice formatting for your sources.
105     format = lspkind.cmp_format {
106       with_text = true,
107       menu = {
108         buffer = "[buf]",
109         nvim_lsp = "[LSP]",
110         nvim_lua = "[api]",
111         path = "[path]",
112         luasnip = "[snip]",
113         gh_issues = "[issues]",
114         tn = "[TabNine]",
115       },
116     },
117   },
118
119   experimental = {
120     native_menu = false,
121   },
122 }