No description
Find a file
hrsh7th d23d3533cf
dev (#1)
* dev

* Improve sync design

* Support buffer local mapping

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* stylua

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* integration

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* update

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp

* tmp
2021-08-04 01:07:12 +09:00
.githooks dev (#1) 2021-08-04 01:07:12 +09:00
.github dev (#1) 2021-08-04 01:07:12 +09:00
autoload dev (#1) 2021-08-04 01:07:12 +09:00
lua/cmp dev (#1) 2021-08-04 01:07:12 +09:00
plugin dev (#1) 2021-08-04 01:07:12 +09:00
.luacheckrc dev (#1) 2021-08-04 01:07:12 +09:00
init.sh dev (#1) 2021-08-04 01:07:12 +09:00
LICENSE Initial commit 2021-06-30 03:01:05 +09:00
Makefile dev (#1) 2021-08-04 01:07:12 +09:00
README.md dev (#1) 2021-08-04 01:07:12 +09:00
stylua.toml dev (#1) 2021-08-04 01:07:12 +09:00

nvim-cmp

A completion plugin for neovim written in Lua.

Status

design and development

Development

You should read type definitions and LSP spec to develop core or sources.

Overview

nvim-cmp emphasizes compatibility with the VSCode behavior and the LSP specification but there are some little differences.

  1. In nvim-cmp, the CompletionItem can have word and dup property that introduced by vim's completion mechanism.

Create custom source

The example source is here.

  • The complete function is required but others can be omitted.
  • The callback argument must always be called.
local source = {}

---Create source.
source.new = function()
  local self = setmetatable({}, { __index = source })
  self.your_awesome_variable = 1
  return self
end

---Return keyword pattern which will be used by the followings.
---  1. Trigger keyword completion
---  2. Detect menu start offset
---  3. Reset completion state
---@return string
function source:get_keyword_pattern()
  return '???'
end

---Return trigger characters.
---@return string[]
function source:get_trigger_characters()
  return { ??? }
end

---Invoke completion.
---@param request  cmp.CompletionRequest
---@param callback fun(response: lsp.CompletionResponse|nil)
---NOTE: This method is required.
function source:complete(request, callback)
  callback({
    { label = 'January' },
    { label = 'February' },
    { label = 'March' },
    { label = 'April' },
    { label = 'May' },
    { label = 'June' },
    { label = 'July' },
    { label = 'August' },
    { label = 'September' },
    { label = 'October' },
    { label = 'November' },
    { label = 'December' },
  })
end

---Resolve completion item that will be called when the item selected or before the item confirmation.
---@param completion_item lsp.CompletionItem
---@param callback fun(completion_item: lsp.CompletionItem|nil)
function source:resolve(completion_item, callback)
  callback(completion_item)
end

---Execute command that will be called when after the item confirmation.
---@param completion_item lsp.CompletionItem
---@param callback fun(completion_item: lsp.CompletionItem|nil)
function source:execute(completion_item, callback)
  callback(completion_item)
end

return source