Implement config.confirmation.get_commit_characters

This commit is contained in:
hrsh7th
2021-09-03 21:35:23 +09:00
parent 675a72e2e8
commit b832719c68
4 changed files with 67 additions and 59 deletions

118
README.md
View File

@@ -238,6 +238,17 @@ The source specific keyword_length for override.
The source specific maximum item count.
#### preselect (type: cmp.PreselectMode)
Specify preselect mode. The following modes are available.
- cmp.Preselect.Item
- If the item has `preselect = true`, `nvim-cmp` will preselect it.
- cmp.Preselect.None
- Disable preselect feature.
Default: `cmp.PreselectMode.Item`
#### completion.autocomplete (type: cmp.TriggerEvent[])
Which events should trigger `autocompletion`.
@@ -274,63 +285,15 @@ vim's `completeopt` setting. Warning: Be careful when changing this value.
Default: `menu,menuone,noselect`
#### documentation (type: false | cmp.DocumentationConfig)
A documentation configuration or false to disable feature.
#### documentation.border (type: string[])
Border characters used for documentation window.
#### documentation.winhighlight (type: string)
A neovim's `winhighlight` option for documentation window.
#### documentation.maxwidth (type: number)
The documentation window's max width.
#### documentation.maxheight (type: number)
The documentation window's max height.
#### confirmation.default_behavior (type: cmp.ConfirmBehavior)
A default `cmp.ConfirmBehavior` value when to use confirmed by commitCharacters
Default: `cmp.ConfirmBehavior.Insert`
#### formatting.deprecated (type: boolean)
#### confirmation.get_commit_characters (type: fun(commit_characters: string[]): string[])
Specify deprecated candidate should be marked as deprecated or not.
Default: `true`
#### formatting.format (type: fun(entry: cmp.Entry, vim_item: vim.CompletedItem): vim.CompletedItem)
A function to customize completion menu.
The return value is defined by vim. See `:help complete-items`.
You can display the fancy icons to completion-menu with [lspkind-nvim](https://github.com/onsails/lspkind-nvim).
Please see [FAQ](#how-to-show-name-of-item-kind-and-source-like-compe) if you would like to show symbol-text (e.g. function) and source (e.g. LSP) like compe.
```lua
local lspkind = require('lspkind')
cmp.setup {
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.presets.default[vim_item.kind]
return vim_item
end
}
}
```
#### event.on_confirm_done (type: fun(entry: cmp.Entry))
A callback function called when the item is confirmed.
The function to resolve commit_characters.
#### sorting.priority_weight (type: number)
@@ -363,16 +326,57 @@ Default:
}
```
#### preselect (type: cmp.PreselectMode)
#### documentation (type: false | cmp.DocumentationConfig)
Specify preselect mode. The following modes are available.
A documentation configuration or false to disable feature.
- cmp.Preselect.Item
- If the item has `preselect = true`, `nvim-cmp` will preselect it.
- cmp.Preselect.None
- Disable preselect feature.
#### documentation.border (type: string[])
Default: `cmp.PreselectMode.Item`
Border characters used for documentation window.
#### documentation.winhighlight (type: string)
A neovim's `winhighlight` option for documentation window.
#### documentation.maxwidth (type: number)
The documentation window's max width.
#### documentation.maxheight (type: number)
The documentation window's max height.
#### formatting.deprecated (type: boolean)
Specify deprecated candidate should be marked as deprecated or not.
Default: `true`
#### formatting.format (type: fun(entry: cmp.Entry, vim_item: vim.CompletedItem): vim.CompletedItem)
A function to customize completion menu.
The return value is defined by vim. See `:help complete-items`.
You can display the fancy icons to completion-menu with [lspkind-nvim](https://github.com/onsails/lspkind-nvim).
Please see [FAQ](#how-to-show-name-of-item-kind-and-source-like-compe) if you would like to show symbol-text (e.g. function) and source (e.g. LSP) like compe.
```lua
local lspkind = require('lspkind')
cmp.setup {
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.presets.default[vim_item.kind]
return vim_item
end
}
}
```
#### event.on_confirm_done (type: fun(entry: cmp.Entry))
A callback function called when the item is confirmed.
#### experimental.ghost_text (type: boolean)

View File

@@ -35,6 +35,9 @@ return function()
confirmation = {
default_behavior = types.cmp.ConfirmBehavior.Insert,
get_commit_characters = function(commit_characters)
return commit_characters
end
},
sorting = {

View File

@@ -24,7 +24,7 @@ core.GHOST_TEXT_NS = vim.api.nvim_create_namespace('cmp:GHOST_TEXT')
---@type cmp.Menu
core.menu = menu.new({
on_select = function(e)
for _, c in ipairs(e:get_commit_characters()) do
for _, c in ipairs(config.get().confirmation.get_commit_characters(e:get_commit_characters())) do
keymap.listen('i', c, core.on_keymap)
end
core.ghost_text(e)
@@ -144,7 +144,7 @@ core.on_keymap = function(keys, fallback)
--Commit character. NOTE: This has a lot of cmp specific implementation to make more user-friendly.
local chars = keymap.t(keys)
local e = core.menu:get_selected_entry()
if e and vim.tbl_contains(e:get_commit_characters(), chars) then
if e and vim.tbl_contains(config.get().confirmation.get_commit_characters(e:get_commit_characters()), chars) then
local is_printable = char.is_printable(string.byte(chars, 1))
core.confirm(e, {
behavior = is_printable and 'insert' or 'replace',

View File

@@ -74,6 +74,7 @@ cmp.PreselectMode.None = 'none'
---@class cmp.ConfirmationConfig
---@field public default_behavior cmp.ConfirmBehavior
---@field public get_commit_characters fun(commit_characters: string[]): string[]
---@class cmp.SortingConfig
---@field public priority_weight number