Thu, 18 May 2023 01:49:15 -0500
add neo-tree
1044 | 1 | return { |
2 | { | |
3 | "hrsh7th/nvim-cmp", | |
4 | event = "InsertEnter", | |
5 | dependencies = { | |
6 | "hrsh7th/cmp-buffer", | |
7 | "hrsh7th/cmp-calc", | |
8 | "hrsh7th/cmp-nvim-lsp", | |
9 | "hrsh7th/cmp-nvim-lsp-signature-help", | |
10 | "hrsh7th/cmp-nvim-lua", | |
11 | "hrsh7th/cmp-omni", | |
12 | "hrsh7th/cmp-path", | |
1097
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
13 | { "L3MON4D3/LuaSnip", opts = { history = true, delete_check_events = "TextChanged" } }, |
1044 | 14 | "quangnguyen30192/cmp-nvim-tags", |
15 | }, | |
1070
72b613de1102
disable lsp preselect
Meredith Howard <mhoward@roomag.org>
parents:
1064
diff
changeset
|
16 | config = function() |
1044 | 17 | local cmp = require("cmp") |
1097
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
18 | local luasnip = require("luasnip") |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
19 | |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
20 | local has_words_before = function() |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
21 | 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
|
22 | 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
|
23 | end |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
24 | |
1070
72b613de1102
disable lsp preselect
Meredith Howard <mhoward@roomag.org>
parents:
1064
diff
changeset
|
25 | cmp.setup({ |
72b613de1102
disable lsp preselect
Meredith Howard <mhoward@roomag.org>
parents:
1064
diff
changeset
|
26 | preselect = cmp.PreselectMode.None, |
1044 | 27 | completion = { |
1054
3a0ff0563a7b
tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents:
1044
diff
changeset
|
28 | keyword_length = 3, |
1044 | 29 | }, |
1097
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
30 | snippet = { |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
31 | expand = function(args) |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
32 | luasnip.lsp_expand(args.body) |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
33 | end, |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
34 | }, |
1054
3a0ff0563a7b
tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents:
1044
diff
changeset
|
35 | formatting = { |
3a0ff0563a7b
tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents:
1044
diff
changeset
|
36 | format = function(entry, vim_item) |
1056 | 37 | if entry.source.name == "nvim_lsp_signature_help" then |
38 | vim_item.kind = "" | |
39 | elseif vim_item.kind == "Text" then | |
1054
3a0ff0563a7b
tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents:
1044
diff
changeset
|
40 | vim_item.kind = entry.source.name |
3a0ff0563a7b
tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents:
1044
diff
changeset
|
41 | end |
1098
8d479a558198
Remove long signature previews
Meredith Howard <mhoward@roomag.org>
parents:
1097
diff
changeset
|
42 | vim_item.menu = nil |
1054
3a0ff0563a7b
tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents:
1044
diff
changeset
|
43 | return vim_item |
3a0ff0563a7b
tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents:
1044
diff
changeset
|
44 | end, |
3a0ff0563a7b
tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents:
1044
diff
changeset
|
45 | }, |
1044 | 46 | mapping = cmp.mapping.preset.insert({ |
47 | ["<C-b>"] = cmp.mapping.scroll_docs(-4), | |
48 | ["<C-f>"] = cmp.mapping.scroll_docs(4), | |
1097
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
49 | ["<Tab>"] = cmp.mapping(function(fallback) |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
50 | if cmp.visible() then |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
51 | cmp.select_next_item() |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
52 | elseif luasnip.expand_or_locally_jumpable() then |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
53 | luasnip.expand_or_jump() |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
54 | elseif has_words_before() then |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
55 | cmp.complete() |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
56 | else |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
57 | fallback() |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
58 | end |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
59 | end, { "i", "s" }), |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
60 | ["<S-Tab>"] = cmp.mapping(function(fallback) |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
61 | if cmp.visible() then |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
62 | cmp.select_prev_item() |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
63 | elseif luasnip.jumpable(-1) then |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
64 | luasnip.jump(-1) |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
65 | else |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
66 | fallback() |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
67 | end |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
68 | end, { "i", "s" }), |
1044 | 69 | ["<C-g>"] = cmp.mapping.abort(), |
1064 | 70 | ["<Right>"] = cmp.mapping.confirm({ select = true }), |
1071
e76020af023d
add explicit begin-completion bind
Meredith Howard <mhoward@roomag.org>
parents:
1070
diff
changeset
|
71 | ["<C-Space>"] = cmp.mapping.complete(), |
1044 | 72 | ["<Space>"] = function(fallback) |
1097
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
73 | local e = cmp.get_active_entry() |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
74 | if cmp.visible() and e then |
1064 | 75 | cmp.confirm({ select = false }, function() |
1097
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
76 | if e:get_kind() ~= cmp.lsp.CompletionItemKind.Snippet then |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
77 | vim.api.nvim_feedkeys(" ", "n", false) |
7df98d33285d
actually set up lsp snippets
Meredith Howard <mhoward@roomag.org>
parents:
1071
diff
changeset
|
78 | end |
1044 | 79 | end) |
80 | end | |
81 | fallback() | |
82 | end, | |
83 | }), | |
84 | sources = cmp.config.sources({ | |
85 | { name = "nvim_lsp" }, | |
86 | { name = "nvim_lsp_signature_help" }, | |
87 | { name = "nvim_lua" }, | |
1054
3a0ff0563a7b
tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents:
1044
diff
changeset
|
88 | { name = "buffer", option = { keyword_pattern = [[\k\+]] } }, |
1044 | 89 | { name = "path" }, |
1055
ba91fd3b81e1
completion fixes, but leave omni off
Meredith Howard <mhoward@roomag.org>
parents:
1054
diff
changeset
|
90 | -- { name = "omni" }, |
1044 | 91 | { name = "tags" }, |
1054
3a0ff0563a7b
tweak completion a little more
Meredith Howard <mhoward@roomag.org>
parents:
1044
diff
changeset
|
92 | { name = "calc" }, |
1044 | 93 | }), |
1070
72b613de1102
disable lsp preselect
Meredith Howard <mhoward@roomag.org>
parents:
1064
diff
changeset
|
94 | }) |
1044 | 95 | end, |
96 | }, | |
97 | } |