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

Thu, 11 Apr 2024 13:19:24 -0400

author
Meredith Howard <mhoward@roomag.org>
date
Thu, 11 Apr 2024 13:19:24 -0400
changeset 1145
beb170aa6789
parent 1144
dc1def95331f
child 1148
bca491e2be91
permissions
-rw-r--r--

add .luarc.jsonc

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-nvim-lua",
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11 "hrsh7th/cmp-path",
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12 "quangnguyen30192/cmp-nvim-tags",
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13 },
1070
72b613de1102 disable lsp preselect
Meredith Howard <mhoward@roomag.org>
parents: 1064
diff changeset
14 config = function()
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
15 local cmp = require("cmp")
1097
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
16 local luasnip = require("luasnip")
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
17
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
18 local has_words_before = function()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
19 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
20 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
21 end
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
22
1070
72b613de1102 disable lsp preselect
Meredith Howard <mhoward@roomag.org>
parents: 1064
diff changeset
23 cmp.setup({
72b613de1102 disable lsp preselect
Meredith Howard <mhoward@roomag.org>
parents: 1064
diff changeset
24 preselect = cmp.PreselectMode.None,
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
25 completion = {
1054
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
26 keyword_length = 3,
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
27 },
1097
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
28 snippet = {
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
29 expand = function(args)
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
30 luasnip.lsp_expand(args.body)
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
31 end,
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
32 },
1054
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
33 formatting = {
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
34 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
35 if vim_item.kind == "Text" then
1054
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
36 vim_item.kind = entry.source.name
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
37 end
1098
8d479a558198 Remove long signature previews
Meredith Howard <mhoward@roomag.org>
parents: 1097
diff changeset
38 vim_item.menu = nil
1054
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
39 return vim_item
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
40 end,
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
41 },
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
42 mapping = cmp.mapping.preset.insert({
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
43 ["<C-b>"] = cmp.mapping.scroll_docs(-4),
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
44 ["<C-f>"] = cmp.mapping.scroll_docs(4),
1097
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
45 ["<Tab>"] = cmp.mapping(function(fallback)
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
46 if cmp.visible() then
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
47 cmp.select_next_item()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
48 elseif luasnip.expand_or_locally_jumpable() then
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
49 luasnip.expand_or_jump()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
50 elseif has_words_before() then
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
51 cmp.complete()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
52 else
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
53 fallback()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
54 end
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
55 end, { "i", "s" }),
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
56 ["<S-Tab>"] = cmp.mapping(function(fallback)
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
57 if cmp.visible() then
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
58 cmp.select_prev_item()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
59 elseif luasnip.jumpable(-1) then
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
60 luasnip.jump(-1)
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
61 else
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
62 fallback()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
63 end
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
64 end, { "i", "s" }),
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
65 ["<C-g>"] = cmp.mapping.abort(),
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1056
diff changeset
66 ["<Right>"] = cmp.mapping.confirm({ select = true }),
1071
e76020af023d add explicit begin-completion bind
Meredith Howard <mhoward@roomag.org>
parents: 1070
diff changeset
67 ["<C-Space>"] = cmp.mapping.complete(),
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
68 ["<Space>"] = function(fallback)
1097
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
69 local e = cmp.get_active_entry()
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
70 if cmp.visible() and e then
1064
fcfa295076a8 Apply stylua
Meredith Howard <mhoward@roomag.org>
parents: 1056
diff changeset
71 cmp.confirm({ select = false }, function()
1097
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
72 if e:get_kind() ~= cmp.lsp.CompletionItemKind.Snippet then
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
73 vim.api.nvim_feedkeys(" ", "n", false)
7df98d33285d actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents: 1071
diff changeset
74 end
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
75 end)
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
76 end
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
77 fallback()
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
78 end,
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
79 }),
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
80 sources = cmp.config.sources({
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
81 { name = "nvim_lsp" },
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
82 { name = "nvim_lua" },
1054
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
83 { name = "buffer", option = { keyword_pattern = [[\k\+]] } },
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
84 { name = "path" },
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
85 { name = "tags" },
1054
3a0ff0563a7b tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents: 1044
diff changeset
86 { name = "calc" },
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
87 }),
1070
72b613de1102 disable lsp preselect
Meredith Howard <mhoward@roomag.org>
parents: 1064
diff changeset
88 })
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
89 end,
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
90 },
1139
1359a563b5ce split out LuaSnip spec
Meredith Howard <mhoward@roomag.org>
parents: 1132
diff changeset
91 {
1359a563b5ce split out LuaSnip spec
Meredith Howard <mhoward@roomag.org>
parents: 1132
diff changeset
92 "L3MON4D3/LuaSnip",
1359a563b5ce split out LuaSnip spec
Meredith Howard <mhoward@roomag.org>
parents: 1132
diff changeset
93 lazy = true,
1144
dc1def95331f skip luasnip/jsregexp build on windows (oops)
Meredith Howard <mhoward@roomag.org>
parents: 1143
diff changeset
94 build = (jit.os ~= "Windows") and "make install_jsregexp",
1139
1359a563b5ce split out LuaSnip spec
Meredith Howard <mhoward@roomag.org>
parents: 1132
diff changeset
95 opts = {
1359a563b5ce split out LuaSnip spec
Meredith Howard <mhoward@roomag.org>
parents: 1132
diff changeset
96 history = true,
1359a563b5ce split out LuaSnip spec
Meredith Howard <mhoward@roomag.org>
parents: 1132
diff changeset
97 delete_check_events = "TextChanged",
1359a563b5ce split out LuaSnip spec
Meredith Howard <mhoward@roomag.org>
parents: 1132
diff changeset
98 },
1359a563b5ce split out LuaSnip spec
Meredith Howard <mhoward@roomag.org>
parents: 1132
diff changeset
99 },
1122
8a56361b077f Replace nvim_lsp_signature_help with lsp_signature.nvim
Meredith Howard <mhoward@roomag.org>
parents: 1098
diff changeset
100 {
8a56361b077f Replace nvim_lsp_signature_help with lsp_signature.nvim
Meredith Howard <mhoward@roomag.org>
parents: 1098
diff changeset
101 "ray-x/lsp_signature.nvim",
1131
f3044a1658fc nvim: switch to preferring last symver tag / add exceptions
Meredith Howard <mhoward@roomag.org>
parents: 1123
diff changeset
102 branch = "master",
1132
532c7964b23f Fix event key typo
Meredith Howard <mhoward@roomag.org>
parents: 1131
diff changeset
103 event = { "LspAttach" },
1122
8a56361b077f Replace nvim_lsp_signature_help with lsp_signature.nvim
Meredith Howard <mhoward@roomag.org>
parents: 1098
diff changeset
104 opts = {
8a56361b077f Replace nvim_lsp_signature_help with lsp_signature.nvim
Meredith Howard <mhoward@roomag.org>
parents: 1098
diff changeset
105 toggle_key = "<F12>",
8a56361b077f Replace nvim_lsp_signature_help with lsp_signature.nvim
Meredith Howard <mhoward@roomag.org>
parents: 1098
diff changeset
106 toggle_key_flip_floatwin_setting = true,
8a56361b077f Replace nvim_lsp_signature_help with lsp_signature.nvim
Meredith Howard <mhoward@roomag.org>
parents: 1098
diff changeset
107 floating_window = false,
8a56361b077f Replace nvim_lsp_signature_help with lsp_signature.nvim
Meredith Howard <mhoward@roomag.org>
parents: 1098
diff changeset
108 fix_pos = true,
8a56361b077f Replace nvim_lsp_signature_help with lsp_signature.nvim
Meredith Howard <mhoward@roomag.org>
parents: 1098
diff changeset
109 hint_enable = false,
8a56361b077f Replace nvim_lsp_signature_help with lsp_signature.nvim
Meredith Howard <mhoward@roomag.org>
parents: 1098
diff changeset
110 handler_opts = { border = "none" },
8a56361b077f Replace nvim_lsp_signature_help with lsp_signature.nvim
Meredith Howard <mhoward@roomag.org>
parents: 1098
diff changeset
111 },
8a56361b077f Replace nvim_lsp_signature_help with lsp_signature.nvim
Meredith Howard <mhoward@roomag.org>
parents: 1098
diff changeset
112 },
1044
8b90bfdedd2b spin out completion.lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
113 }

mercurial