summaryrefslogtreecommitdiff
path: root/mut/neovim/pack/plugins/start/blink.cmp/lua/blink/cmp/config/completion/accept.lua
blob: a81aa5588790f4fbb705ca69ac005d85d84db124 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--- @class (exact) blink.cmp.CompletionAcceptConfig
--- @field create_undo_point boolean Create an undo point when accepting a completion item
--- @field auto_brackets blink.cmp.AutoBracketsConfig

--- @class (exact) blink.cmp.AutoBracketsConfig
--- @field enabled boolean Whether to auto-insert brackets for functions
--- @field default_brackets string[] Default brackets to use for unknown languages
--- @field override_brackets_for_filetypes table<string, string[] | fun(item: blink.cmp.CompletionItem): string[]>
--- @field force_allow_filetypes string[] Overrides the default blocked filetypes
--- @field blocked_filetypes string[]
--- @field kind_resolution blink.cmp.AutoBracketResolutionConfig Synchronously use the kind of the item to determine if brackets should be added
--- @field semantic_token_resolution blink.cmp.AutoBracketSemanticTokenResolutionConfig Asynchronously use semantic token to determine if brackets should be added

--- @class (exact) blink.cmp.AutoBracketResolutionConfig
--- @field enabled boolean
--- @field blocked_filetypes string[]

--- @class (exact) blink.cmp.AutoBracketSemanticTokenResolutionConfig
--- @field enabled boolean
--- @field blocked_filetypes string[]
--- @field timeout_ms number How long to wait for semantic tokens to return before assuming no brackets should be added

local validate = require('blink.cmp.config.utils').validate
local accept = {
  --- @type blink.cmp.CompletionAcceptConfig
  default = {
    create_undo_point = true,
    auto_brackets = {
      enabled = true,
      default_brackets = { '(', ')' },
      override_brackets_for_filetypes = {},
      force_allow_filetypes = {},
      blocked_filetypes = {},
      kind_resolution = {
        enabled = true,
        blocked_filetypes = { 'typescriptreact', 'javascriptreact', 'vue', 'rust' },
      },
      semantic_token_resolution = {
        enabled = true,
        blocked_filetypes = { 'java' },
        timeout_ms = 400,
      },
    },
  },
}

function accept.validate(config)
  validate('completion.accept', {
    create_undo_point = { config.create_undo_point, 'boolean' },
    auto_brackets = { config.auto_brackets, 'table' },
  }, config)
  validate('completion.accept.auto_brackets', {
    enabled = { config.auto_brackets.enabled, 'boolean' },
    default_brackets = { config.auto_brackets.default_brackets, 'table' },
    override_brackets_for_filetypes = { config.auto_brackets.override_brackets_for_filetypes, 'table' },
    force_allow_filetypes = { config.auto_brackets.force_allow_filetypes, 'table' },
    blocked_filetypes = { config.auto_brackets.blocked_filetypes, 'table' },
    kind_resolution = { config.auto_brackets.kind_resolution, 'table' },
    semantic_token_resolution = { config.auto_brackets.semantic_token_resolution, 'table' },
  }, config.auto_brackets)
  validate('completion.accept.auto_brackets.kind_resolution', {
    enabled = { config.auto_brackets.kind_resolution.enabled, 'boolean' },
    blocked_filetypes = { config.auto_brackets.kind_resolution.blocked_filetypes, 'table' },
  }, config.auto_brackets.kind_resolution)
  validate('completion.accept.auto_brackets.semantic_token_resolution', {
    enabled = { config.auto_brackets.semantic_token_resolution.enabled, 'boolean' },
    blocked_filetypes = { config.auto_brackets.semantic_token_resolution.blocked_filetypes, 'table' },
    timeout_ms = { config.auto_brackets.semantic_token_resolution.timeout_ms, 'number' },
  }, config.auto_brackets.semantic_token_resolution)
end

return accept