|
24 | 24 | in { |
25 | 25 | config = mkIf cfg.enable { |
26 | 26 | vim = { |
27 | | - startPlugins = ["rtp-nvim"]; |
28 | | - lazy.plugins = mkMerge [ |
29 | | - (mapListToAttrs (package: { |
30 | | - name = getPluginName package; |
31 | | - value = { |
32 | | - inherit package; |
33 | | - lazy = true; |
34 | | - after = '' |
35 | | - local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/${getPluginName package}') |
36 | | - require("rtp_nvim").source_after_plugin_dir(path) |
37 | | - ''; |
38 | | - }; |
39 | | - }) |
40 | | - cfg.sourcePlugins) |
41 | | - { |
42 | | - nvim-cmp = { |
43 | | - package = "nvim-cmp"; |
44 | | - after = '' |
45 | | - ${optionalString luasnipEnable "local luasnip = require('luasnip')"} |
46 | | - local cmp = require("cmp") |
47 | | -
|
48 | | - local kinds = require("cmp.types").lsp.CompletionItemKind |
49 | | - local deprio = function(kind) |
50 | | - return function(e1, e2) |
51 | | - if e1:get_kind() == kind then |
52 | | - return false |
53 | | - end |
54 | | - if e2:get_kind() == kind then |
55 | | - return true |
56 | | - end |
57 | | - return nil |
| 27 | + lazy.plugins = { |
| 28 | + nvim-cmp = { |
| 29 | + package = "nvim-cmp"; |
| 30 | + after = '' |
| 31 | + ${optionalString luasnipEnable "local luasnip = require('luasnip')"} |
| 32 | + local cmp = require("cmp") |
| 33 | +
|
| 34 | + local kinds = require("cmp.types").lsp.CompletionItemKind |
| 35 | + local deprio = function(kind) |
| 36 | + return function(e1, e2) |
| 37 | + if e1:get_kind() == kind then |
| 38 | + return false |
| 39 | + end |
| 40 | + if e2:get_kind() == kind then |
| 41 | + return true |
58 | 42 | end |
| 43 | + return nil |
59 | 44 | end |
| 45 | + end |
60 | 46 |
|
61 | | - cmp.setup(${toLuaObject cfg.setupOpts}) |
| 47 | + cmp.setup(${toLuaObject cfg.setupOpts}) |
62 | 48 |
|
63 | | - ${optionalString config.vim.lazy.enable |
64 | | - (concatStringsSep "\n" (map |
65 | | - (package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})") |
66 | | - cfg.sourcePlugins))} |
67 | | - ''; |
| 49 | + ${optionalString config.vim.lazy.enable |
| 50 | + (concatStringsSep "\n" (map |
| 51 | + (package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})") |
| 52 | + cfg.sourcePlugins))} |
| 53 | + ''; |
68 | 54 |
|
69 | | - event = ["InsertEnter" "CmdlineEnter"]; |
70 | | - }; |
71 | | - } |
72 | | - ]; |
73 | | - |
74 | | - autocomplete.nvim-cmp = { |
75 | | - sources = { |
76 | | - nvim-cmp = null; |
77 | | - buffer = "[Buffer]"; |
78 | | - path = "[Path]"; |
| 55 | + event = ["InsertEnter" "CmdlineEnter"]; |
79 | 56 | }; |
| 57 | + }; |
80 | 58 |
|
81 | | - sourcePlugins = ["cmp-buffer" "cmp-path"]; |
82 | | - |
83 | | - setupOpts = { |
84 | | - sources = map (s: {name = s;}) (attrNames cfg.sources); |
| 59 | + autocomplete = { |
| 60 | + enableSharedCmpSources = true; |
85 | 61 |
|
86 | | - window = mkIf borders.enable { |
87 | | - completion.border = borders.style; |
88 | | - documentation.border = borders.style; |
| 62 | + nvim-cmp = { |
| 63 | + sources = { |
| 64 | + nvim-cmp = null; |
| 65 | + buffer = "[Buffer]"; |
| 66 | + path = "[Path]"; |
89 | 67 | }; |
90 | 68 |
|
91 | | - formatting.format = cfg.format; |
92 | | - |
93 | | - # `cmp` and `luasnip` are defined above, in the `nvim-cmp` section |
94 | | - mapping = { |
95 | | - ${mappings.complete} = mkLuaInline "cmp.mapping.complete()"; |
96 | | - ${mappings.close} = mkLuaInline "cmp.mapping.abort()"; |
97 | | - ${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)"; |
98 | | - ${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)"; |
99 | | - ${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })"; |
100 | | - |
101 | | - ${mappings.next} = mkLuaInline '' |
102 | | - cmp.mapping(function(fallback) |
103 | | - local has_words_before = function() |
104 | | - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) |
105 | | - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil |
106 | | - end |
| 69 | + sourcePlugins = ["cmp-buffer" "cmp-path"]; |
107 | 70 |
|
108 | | - if cmp.visible() then |
109 | | - cmp.select_next_item() |
110 | | - ${optionalString luasnipEnable '' |
111 | | - elseif luasnip.locally_jumpable(1) then |
112 | | - luasnip.jump(1) |
113 | | - ''} |
114 | | - elseif has_words_before() then |
115 | | - cmp.complete() |
116 | | - else |
117 | | - fallback() |
118 | | - end |
119 | | - end) |
120 | | - ''; |
121 | | - |
122 | | - ${mappings.previous} = mkLuaInline '' |
123 | | - cmp.mapping(function(fallback) |
124 | | - if cmp.visible() then |
125 | | - cmp.select_prev_item() |
126 | | - ${optionalString luasnipEnable '' |
127 | | - elseif luasnip.locally_jumpable(-1) then |
128 | | - luasnip.jump(-1) |
129 | | - ''} |
130 | | - else |
131 | | - fallback() |
132 | | - end |
133 | | - end) |
134 | | - ''; |
| 71 | + setupOpts = { |
| 72 | + sources = map (s: {name = s;}) (attrNames cfg.sources); |
| 73 | + |
| 74 | + window = mkIf borders.enable { |
| 75 | + completion.border = borders.style; |
| 76 | + documentation.border = borders.style; |
| 77 | + }; |
| 78 | + |
| 79 | + formatting.format = cfg.format; |
| 80 | + |
| 81 | + # `cmp` and `luasnip` are defined above, in the `nvim-cmp` section |
| 82 | + mapping = { |
| 83 | + ${mappings.complete} = mkLuaInline "cmp.mapping.complete()"; |
| 84 | + ${mappings.close} = mkLuaInline "cmp.mapping.abort()"; |
| 85 | + ${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)"; |
| 86 | + ${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)"; |
| 87 | + ${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })"; |
| 88 | + |
| 89 | + ${mappings.next} = mkLuaInline '' |
| 90 | + cmp.mapping(function(fallback) |
| 91 | + local has_words_before = function() |
| 92 | + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) |
| 93 | + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil |
| 94 | + end |
| 95 | +
|
| 96 | + if cmp.visible() then |
| 97 | + cmp.select_next_item() |
| 98 | + ${optionalString luasnipEnable '' |
| 99 | + elseif luasnip.locally_jumpable(1) then |
| 100 | + luasnip.jump(1) |
| 101 | + ''} |
| 102 | + elseif has_words_before() then |
| 103 | + cmp.complete() |
| 104 | + else |
| 105 | + fallback() |
| 106 | + end |
| 107 | + end) |
| 108 | + ''; |
| 109 | + |
| 110 | + ${mappings.previous} = mkLuaInline '' |
| 111 | + cmp.mapping(function(fallback) |
| 112 | + if cmp.visible() then |
| 113 | + cmp.select_prev_item() |
| 114 | + ${optionalString luasnipEnable '' |
| 115 | + elseif luasnip.locally_jumpable(-1) then |
| 116 | + luasnip.jump(-1) |
| 117 | + ''} |
| 118 | + else |
| 119 | + fallback() |
| 120 | + end |
| 121 | + end) |
| 122 | + ''; |
| 123 | + }; |
135 | 124 | }; |
136 | 125 | }; |
137 | 126 | }; |
|
0 commit comments