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

Mon, 15 Jul 2024 13:22:56 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 15 Jul 2024 13:22:56 -0500
changeset 1176
1cb4636d6d36
parent 1174
753971334371
permissions
-rw-r--r--

Fix for no-nerdfonts experience

1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
1 return {
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
2 {
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
3 "hrsh7th/nvim-cmp",
1131
f3044a1658fc nvim: switch to preferring last symver tag / add exceptions
Meredith Howard <mhoward@roomag.org>
parents: 1123
diff changeset
4 branch = "main",
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
5 event = "InsertEnter",
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
6 dependencies = {
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
7 "hrsh7th/cmp-buffer",
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
8 "hrsh7th/cmp-calc",
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
9 "hrsh7th/cmp-nvim-lsp",
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
10 "hrsh7th/cmp-path",
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11 "quangnguyen30192/cmp-nvim-tags",
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12 },
1070
72b613de1102 disable lsp preselect
Meredith Howard <mhoward@roomag.org>
parents: 1064
diff changeset
13 config = function()
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
14 local cmp = require("cmp")
1097
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
15
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
16 local has_words_before = function()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
17 local line, col = unpack(vim.api.nvim_win_get_cursor(0))
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
18 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
19 end
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
20
1070
72b613de1102 disable lsp preselect
Meredith Howard <mhoward@roomag.org>
parents: 1064
diff changeset
21 cmp.setup({
72b613de1102 disable lsp preselect
Meredith Howard <mhoward@roomag.org>
parents: 1064
diff changeset
22 preselect = cmp.PreselectMode.None,
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
23 completion = {
1054
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
24 keyword_length = 3,
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
25 },
1097
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
26 snippet = {
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
27 expand = function(args)
1171
12363689e67e Drop LuaSnip for vim.snippet
Meredith Howard <mhoward@roomag.org>
parents: 1168
diff changeset
28 vim.snippet.expand(args.body)
1097
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
29 end,
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
30 },
1174
753971334371 Switch neodev -> lazydev
Meredith Howard <mhoward@roomag.org>
parents: 1173
diff changeset
31 ---@diagnostic disable-next-line: missing-fields
1054
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
32 formatting = {
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
33 format = function(entry, vim_item)
1122
8a56361b077f Replace nvim_lsp_signature_help with lsp_signature.nvim
Meredith Howard <mhoward@roomag.org>
parents: 1098
diff changeset
34 if vim_item.kind == "Text" then
1054
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
35 vim_item.kind = entry.source.name
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
36 end
1098
8d479a558198 Remove long signature previews
Meredith Howard <mhoward@roomag.org>
parents: 1097
diff changeset
37 vim_item.menu = nil
1054
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
38 return vim_item
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
39 end,
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
40 },
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
41 mapping = cmp.mapping.preset.insert({
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
42 ["<C-b>"] = cmp.mapping.scroll_docs(-4),
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
43 ["<C-f>"] = cmp.mapping.scroll_docs(4),
1097
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
44 ["<Tab>"] = cmp.mapping(function(fallback)
1173
79c1553aa040 Change tab completion/snippet maps
Meredith Howard <mhoward@roomag.org>
parents: 1171
diff changeset
45 if vim.snippet.active({direction = 1}) then
79c1553aa040 Change tab completion/snippet maps
Meredith Howard <mhoward@roomag.org>
parents: 1171
diff changeset
46 vim.snippet.jump(1)
79c1553aa040 Change tab completion/snippet maps
Meredith Howard <mhoward@roomag.org>
parents: 1171
diff changeset
47 elseif cmp.visible() then
1097
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
48 cmp.select_next_item()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
49 elseif has_words_before() then
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
50 cmp.complete()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
51 else
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
52 fallback()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
53 end
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
54 end, { "i", "s" }),
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
55 ["<S-Tab>"] = cmp.mapping(function(fallback)
1173
79c1553aa040 Change tab completion/snippet maps
Meredith Howard <mhoward@roomag.org>
parents: 1171
diff changeset
56 if vim.snippet.active({direction = -1}) then
79c1553aa040 Change tab completion/snippet maps
Meredith Howard <mhoward@roomag.org>
parents: 1171
diff changeset
57 vim.snippet.jump(-1)
79c1553aa040 Change tab completion/snippet maps
Meredith Howard <mhoward@roomag.org>
parents: 1171
diff changeset
58 elseif cmp.visible() then
1097
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
59 cmp.select_prev_item()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
60 else
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
61 fallback()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
62 end
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
63 end, { "i", "s" }),
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
64 ["<C-g>"] = cmp.mapping.abort(),
1071
e76020af023d add explicit begin-completion bind
Meredith Howard <mhoward@roomag.org>
parents: 1070
diff changeset
65 ["<C-Space>"] = cmp.mapping.complete(),
1168
52750027eff6 simplify nvim-cmp setup
Meredith Howard <mhoward@roomag.org>
parents: 1148
diff changeset
66 ["<Space>"] = cmp.mapping(function(fallback)
52750027eff6 simplify nvim-cmp setup
Meredith Howard <mhoward@roomag.org>
parents: 1148
diff changeset
67 cmp.confirm({ select = false })
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
68 fallback()
1168
52750027eff6 simplify nvim-cmp setup
Meredith Howard <mhoward@roomag.org>
parents: 1148
diff changeset
69 end, { "i", "s" }),
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
70 }),
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
71 sources = cmp.config.sources({
1174
753971334371 Switch neodev -> lazydev
Meredith Howard <mhoward@roomag.org>
parents: 1173
diff changeset
72 { name = "lazydev" },
753971334371 Switch neodev -> lazydev
Meredith Howard <mhoward@roomag.org>
parents: 1173
diff changeset
73 }, {
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
74 { name = "nvim_lsp" },
1174
753971334371 Switch neodev -> lazydev
Meredith Howard <mhoward@roomag.org>
parents: 1173
diff changeset
75 }, {
1054
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
76 { name = "buffer", option = { keyword_pattern = [[\k\+]] } },
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
77 { name = "path" },
1174
753971334371 Switch neodev -> lazydev
Meredith Howard <mhoward@roomag.org>
parents: 1173
diff changeset
78 }, {
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
79 { name = "tags" },
1054
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
80 { name = "calc" },
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
81 }),
1070
72b613de1102 disable lsp preselect
Meredith Howard <mhoward@roomag.org>
parents: 1064
diff changeset
82 })
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
83 end,
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
84 },
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
85 }

mercurial