Add reason to complete function (#529)

fix #528
This commit is contained in:
Lukas Reineke
2021-11-17 01:17:58 +09:00
committed by GitHub
parent 4d800fbcab
commit 17d57f96cc
3 changed files with 14 additions and 6 deletions

View File

@@ -151,7 +151,7 @@ Defines the action of each key mapping. The following lists all the built-in act
- `cmp.mapping.select_prev_item({ cmp.SelectBehavior.{Insert,Select} })`
- `cmp.mapping.select_next_item({ cmp.SelectBehavior.{Insert,Select} })`
- `cmp.mapping.scroll_docs(number)`
- `cmp.mapping.complete()`
- `cmp.mapping.complete({ reason = cmp.ContextReason.{Manual,Auto} })`
- `cmp.mapping.close()`
- `cmp.mapping.abort()`
- `cmp.mapping.confirm({ select = bool, behavior = cmp.ConfirmBehavior.{Insert,Replace} })`: If `select` is true and you haven't select any item, automatically selects the first item.
@@ -508,10 +508,13 @@ NOTE: The `preselected` entry does not returned from this method.
Confirms the current selected item, if possible. If `select` is true and no item has been selected, selects the first item.
#### `cmp.complete()`
#### `cmp.complete({ reason = cmp.ContextReason.{Manual,Auto} })`
Invokes manual completion.
NOTE: manual completion overrules some checks autocompletion does like `keyword_length`.
To make it behave like autocompletion instead, you can overwrite the reason in the argument.
#### `cmp.close()`
Closes the current completion menu.

View File

@@ -13,9 +13,10 @@ mapping = setmetatable({}, {
})
---Invoke completion
mapping.complete = function()
---@param option cmp.ContextOption
mapping.complete = function(option)
return function(fallback)
if not require('cmp').complete() then
if not require('cmp').complete(option) then
fallback()
end
end

View File

@@ -52,8 +52,12 @@ cmp.get_config = function()
end
---Invoke completion manually
cmp.complete = function()
cmp.core:complete(cmp.core:get_context({ reason = cmp.ContextReason.Manual }))
---@param option cmp.ContextOption
cmp.complete = function(option)
option = option or {}
option.reason = option.reason or cmp.ContextReason.Manual
cmp.core:complete(cmp.core:get_context(option))
return true
end