├── lua └── cmp │ └── init.lua ├── readme.md └── stylua.toml /lua/cmp/init.lua: -------------------------------------------------------------------------------- 1 | local care_cmp = {} 2 | 3 | ---@param cmp_source care.source 4 | function care_cmp.register_source(name, cmp_source) 5 | cmp_source.name = "cmp_" .. name 6 | cmp_source.display_name = name .. " (cmp)" 7 | if not cmp_source.is_available then 8 | cmp_source.is_available = function() 9 | return true 10 | end 11 | end 12 | local old_complete = cmp_source.complete 13 | cmp_source.complete = function(completion_context, callback) 14 | local cursor = { completion_context.context.cursor.row, completion_context.context.cursor.col } 15 | local cursor_line = completion_context.context.line 16 | local cmp_context = { 17 | option = { reason = completion_context.completion_context.triggerKind == 1 and "manual" or "auto" }, 18 | filetype = vim.api.nvim_get_option_value("filetype", { 19 | buf = 0, 20 | }), 21 | time = vim.uv.now(), 22 | bufnr = completion_context.context.bufnr, 23 | cursor_line = completion_context.context.line, 24 | cursor = { 25 | row = cursor[1], 26 | col = cursor[2] - 1, 27 | line = cursor[1] - 1, 28 | character = cursor[2] - 1, 29 | }, 30 | get_reason = function(self) 31 | return self.option.reason 32 | end, 33 | cursor_before_line = completion_context.context.line_before_cursor, 34 | cursor_after_line = string.sub(cursor_line, cursor[2] - 1), 35 | } 36 | local TODO = 3 37 | old_complete(cmp_source, { 38 | context = cmp_context, 39 | offset = TODO, 40 | completion_context = completion_context.completion_context, 41 | option = {}, 42 | ---@diagnostic disable-next-line: redundant-parameter 43 | }, function(response) 44 | if not response then 45 | callback({}) 46 | return 47 | end 48 | if response.isIncomplete ~= nil then 49 | callback(response.items or {}, response.isIncomplete == true) 50 | return 51 | end 52 | callback(response.items or response) 53 | end) 54 | end 55 | local old_get_keyword_pattern = cmp_source.get_keyword_pattern 56 | if old_get_keyword_pattern then 57 | cmp_source.get_keyword_pattern = function(self) 58 | return old_get_keyword_pattern(self, { option = {} }) 59 | end 60 | end 61 | local old_execute = cmp_source.execute 62 | if old_execute then 63 | cmp_source.execute = function(self, entry) 64 | old_execute(self, entry.completion_item, function() end) 65 | end 66 | end 67 | local old_resolve = cmp_source.resolve 68 | if old_resolve then 69 | cmp_source.resolve_item = function(self, completion_item, callback) 70 | old_resolve(self, completion_item, callback) 71 | end 72 | end 73 | require("care.sources").register_source(vim.deepcopy(cmp_source)) 74 | end 75 | 76 | care_cmp.lsp = {} 77 | care_cmp.lsp.CompletionItemKind = { 78 | Text = 1, 79 | Method = 2, 80 | Function = 3, 81 | Constructor = 4, 82 | Field = 5, 83 | Variable = 6, 84 | Class = 7, 85 | Interface = 8, 86 | Module = 9, 87 | Property = 10, 88 | Unit = 11, 89 | Value = 12, 90 | Enum = 13, 91 | Keyword = 14, 92 | Snippet = 15, 93 | Color = 16, 94 | File = 17, 95 | Reference = 18, 96 | Folder = 19, 97 | EnumMember = 20, 98 | Constant = 21, 99 | Struct = 22, 100 | Event = 23, 101 | Operator = 24, 102 | TypeParameter = 25, 103 | } 104 | 105 | care_cmp.lsp.MarkupKind = { PlainText = "plaintext", Markdown = "markdown" } 106 | 107 | care_cmp.ContextReason = { 108 | Auto = "auto", 109 | Manual = "manual", 110 | TriggerOnly = "triggerOnly", 111 | None = "none", 112 | } 113 | 114 | return care_cmp 115 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Care-cmp 2 | 3 | Bridge module between care and cmp sources. 4 | Just install this plugin. Cmp sources should register themselves. 5 | 6 | To configure notice that all sources names are prefixed with `cmp_` (e.g. 7 | `cmp_luasnip` instead of just `luasnip`) 8 | -------------------------------------------------------------------------------- /stylua.toml: -------------------------------------------------------------------------------- 1 | column_width = 120 2 | line_endings = "Unix" 3 | indent_type = "Spaces" 4 | indent_width = 4 5 | quote_style = "AutoPreferDouble" 6 | call_parentheses = "Always" 7 | --------------------------------------------------------------------------------