Add preselect configuration option

This commit is contained in:
hrsh7th
2021-08-25 21:23:54 +09:00
parent 5df8233081
commit 6bc0ddb58b
6 changed files with 22 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
.PHONY: fmt .PHONY: fmt
fmt: fmt:
./utils/stylua --config-path stylua.toml --glob lua/**/*.lua -- lua stylua --config-path stylua.toml --glob lua/**/*.lua -- lua
.PHONY: lint .PHONY: lint
lint: lint:

View File

@@ -283,6 +283,17 @@ Default:
} }
``` ```
#### 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`
FAQ FAQ
==================== ====================

View File

@@ -21,6 +21,8 @@ return function()
end, end,
}, },
preselect = types.cmp.PreselectMode.Item,
documentation = { documentation = {
border = { '', '', '', ' ', '', '', '', ' ' }, border = { '', '', '', ' ', '', '', '', ' ' },
winhighlight = 'NormalFloat:CmpDocumentation,FloatBorder:CmpDocumentationBorder', winhighlight = 'NormalFloat:CmpDocumentation,FloatBorder:CmpDocumentationBorder',

View File

@@ -54,7 +54,7 @@ cmp.abort = function()
keymap.feedkeys(keymap.t('<C-e>'), 'n', function() keymap.feedkeys(keymap.t('<C-e>'), 'n', function()
core.reset() core.reset()
end) end)
return true; return true
else else
return false return false
end end

View File

@@ -1,4 +1,5 @@
local debug = require('cmp.utils.debug') local debug = require('cmp.utils.debug')
local types = require('cmp.types')
local async = require('cmp.utils.async') local async = require('cmp.utils.async')
local float = require('cmp.float') local float = require('cmp.float')
local config = require('cmp.config') local config = require('cmp.config')
@@ -116,7 +117,7 @@ menu.update = check.wrap(function(self, ctx, sources)
local abbrs = {} local abbrs = {}
local preselect = 0 local preselect = 0
for i, e in ipairs(entries) do for i, e in ipairs(entries) do
if preselect == 0 and e.completion_item.preselect then if preselect == 0 and e.completion_item.preselect and config.get().preselect ~= types.cmp.PreselectMode.None then
preselect = i preselect = i
end end

View File

@@ -17,10 +17,10 @@ cmp.TriggerEvent = {}
cmp.TriggerEvent.InsertEnter = 'InsertEnter' cmp.TriggerEvent.InsertEnter = 'InsertEnter'
cmp.TriggerEvent.TextChanged = 'TextChanged' cmp.TriggerEvent.TextChanged = 'TextChanged'
---@alias cmp.ScrollDirection "'up'" | "'down'" ---@alias cmp.PreselectMode "'item'" | "'None'"
cmp.ScrollDirection = {} cmp.PreselectMode = {}
cmp.ScrollDirection.Up = 'up' cmp.PreselectMode.Item = 'item'
cmp.ScrollDirection.Down = 'down' cmp.PreselectMode.None = 'none'
---@class cmp.ContextOption ---@class cmp.ContextOption
---@field public reason cmp.ContextReason|nil ---@field public reason cmp.ContextReason|nil
@@ -47,6 +47,7 @@ cmp.ScrollDirection.Down = 'down'
---@class cmp.ConfigSchema ---@class cmp.ConfigSchema
---@field private revision number ---@field private revision number
---@field public preselect cmp.PreselectMode
---@field public completion cmp.CompletionConfig ---@field public completion cmp.CompletionConfig
---@field public documentation cmp.DocumentationConfig ---@field public documentation cmp.DocumentationConfig
---@field public confirmation cmp.ConfirmationConfig ---@field public confirmation cmp.ConfirmationConfig