Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic enabled_providers not longer valid #394

Closed
2 tasks done
OmegaLambda1998 opened this issue Nov 28, 2024 · 4 comments
Closed
2 tasks done

Dynamic enabled_providers not longer valid #394

OmegaLambda1998 opened this issue Nov 28, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@OmegaLambda1998
Copy link

Make sure you have done the following

  • I have updated to the latest version of blink.cmp
  • I have read the README

Bug Description

                         Failed to run `config` for blink.cmp

...share/nvim/lazy/blink.cmp/lua/blink/cmp/config/utils.lua:10: sources.completion.enabled_providers: expected table, got function

# stacktrace:
  - /blink.cmp/lua/blink/cmp/config/utils.lua:10 _in_ **validate**
  - /blink.cmp/lua/blink/cmp/config/sources.lua:73 _in_ **validate**
  - /blink.cmp/lua/blink/cmp/config/init.lua:43 _in_ **validate**
  - /blink.cmp/lua/blink/cmp/config/init.lua:52 _in_ **merge_with**
  - /blink.cmp/lua/blink/cmp/init.lua:6 _in_ **setup**
  - lua/OmegaLambda/setup/debugging.lua:170 _in_ **try**
  - lua/OmegaLambda/setup/modules.lua:24 _in_ **load**
  - lua/OmegaLambda/coding/lsp.lua:207 _in_ **setup_capabilities**
  - lua/OmegaLambda/coding/lsp.lua:303 _in_ **config**

Relevant configuration

sources = {
    completion = {
        enabled_providers = function(ctx)
            local providers = {}
            --- OL.callbacks.cmp.prociders is just a global table I build up which uses the same syntax as sources.completion.providers
            for provider, provider_opts in pairs(OL.callbacks.cmp.providers) do
                if provider_opts.enabled(ctx) then
                    table.insert(providers, provider)
                end
            end
            return providers
        end,
    },
    providers = OL.callbacks.cmp.providers,
}

neovim version

NVIM v0.11.0-dev-1246+g76dcc7029b Build type: Release LuaJIT 2.1.1731601260

blink.cmp version: branch, tag, or commit

git @1b3cd31e

@OmegaLambda1998 OmegaLambda1998 added the bug Something isn't working label Nov 28, 2024
@OmegaLambda1998
Copy link
Author

Similarly, provider.enabled cannot be a function either:

                         Failed to run `config` for blink.cmp

...share/nvim/lazy/blink.cmp/lua/blink/cmp/config/utils.lua:10: sources.providers.buffer.enabled: expected boolean, got function

# stacktrace:
  - /blink.cmp/lua/blink/cmp/config/utils.lua:10 _in_ **validate**
  - /blink.cmp/lua/blink/cmp/config/sources.lua:77 _in_ **validate**
  - /blink.cmp/lua/blink/cmp/config/init.lua:43 _in_ **validate**
  - /blink.cmp/lua/blink/cmp/config/init.lua:52 _in_ **merge_with**
  - /blink.cmp/lua/blink/cmp/init.lua:6 _in_ **setup**
  - lua/OmegaLambda/setup/debugging.lua:170 _in_ **try**
  - lua/OmegaLambda/setup/modules.lua:24 _in_ **load**
  - lua/OmegaLambda/coding/lsp.lua:207 _in_ **setup_capabilities**
  - lua/OmegaLambda/coding/lsp.lua:303 _in_ **config**
{
    name = "Buffer",
    module = "blink.cmp.sources.buffer",
    enabled = function(_)
        return true
    end
}

@OmegaLambda1998
Copy link
Author

Likely just requires updating cmp.config.sources.validate to allow both table and function inputs.

Alternatively you could change cmp.config.utils.validate to:

local utils = {}

---@param path string The path to the field being validated
---@param tbl table The table to validate
---@param dynamic booleon Whether the parameters can accept a function for dynamic behaviour
---@see vim.validate
---@return boolean is_valid
---@return string|nil error_message
function utils.validate(path, tbl, dynamic)
  if dynamic then
    dynamic_tbl = {}
    for param, valid in pairs(tbl)
        local types = valid[2] --- Get the valid types for param
        if type(types) ~= table then
            types = {types}
        end
        if not vim.tbl_contains(types, "function") then
            table.insert(types, "function")
        end
        dynamic_tbl[param] = types
    end
    tbl = dynamic_tbl
  end

  local _, err = pcall(vim.validate, tbl)
  if err then error(path .. '.' .. err) end
end

return utils

Or something less sloppy and more robust :p

@OmegaLambda1998
Copy link
Author

Some other minor points of contention:

  1. cmp.is_in_snippet -> cmp.snippet_active is not propagated to the README
  2. require("blink.cmp.lib.utils").get_tailwind_hl(ctx) -> require('blink.cmp.completion.windows.render.tailwind').get_hl(ctx) is not propagated to the README config

@Saghen Saghen closed this as completed in 56f7cb6 Nov 28, 2024
@Saghen
Copy link
Owner

Saghen commented Nov 28, 2024

Super helpful, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants