-- blink.lua: Temporarily highlights cursor position after movement to improve visibility.

return {
  "saghen/blink.cmp",
  version = "v1.*", -- stay on stable branch
  build = "cargo build --release", -- compile matcher locally
  lazy = false, -- must load before first lsp attach
  dependencies = {
    "L3MON4D3/LuaSnip",
    "rafamadriz/friendly-snippets",
  },
  opts = {
    -- completion sources ----------------------------------------------------
    sources = {
      min_keyword_length = 2, -- <-- Move it here from trigger section
      default = { "nvim_lsp", "luasnip", "buffer", "path", "cmp_tabnine" },
      providers = {
        nvim_lsp = { name = "LSP", module = "blink.cmp.sources.lsp" },
        luasnip = { name = "Snippets", module = "blink.cmp.sources.luasnip" },
        buffer = { name = "Buffer", module = "blink.cmp.sources.buffer" },
        path = { name = "Path", module = "blink.cmp.sources.path" },
        cmp_tabnine = {
          name = "TabNine",
          module = "blink.compat.source",
          score_offset = 3,
        },
      },
      per_filetype = {
        lua = { default = { "lazydev", "nvim_lsp", "luasnip", "buffer", "path" } },
      },
    },

    -- completion behaviour --------------------------------------------------
    completion = {
      accept = { auto_brackets = { enabled = true } },
      trigger = {
        show_on_trigger_character = true, -- <-- Remove min_keyword_length from here
      },
      list = {
        selection = {
          preselect = function(ctx)
            return ctx.mode ~= "cmdline"
          end,
        },
      },
      documentation = {
        auto_show = true,
        auto_show_delay_ms = 100,
      },
    },

    signature = {
      enabled = true,
      window = { border = "rounded" },
    },

    cmdline = { enabled = true },
  },

  config = function(_, opts)
    require("blink.cmp").setup(opts)
  end,
}
