Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions lua/colorizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,30 @@ local matcher_mod = require("colorizer.matcher")
local utils = require("colorizer.utils")

--- State and configuration dynamic holding information table tracking
--- Detect whether vim.lsp.document_color.enable accepts a filter table
--- as its second argument instead of a plain bufnr number.
local dc_uses_filter_api = (function()
if not vim.lsp.document_color then
return false
end
local info = debug.getinfo(vim.lsp.document_color.enable, "u")
if info.nparams == 2 then
-- 2-param version is the new (enable, filter) API
return true
end
return false
end)()

--- Disable vim.lsp.document_color for a buffer.
--- Handles both old (enable, bufnr) and new (enable, filter) Neovim APIs.
--- Handles both old `enable(enable, bufnr)` and new `enable(enable, filter)` Neovim APIs.
local function disable_document_color(bufnr)
if not vim.lsp.document_color then
return
end
-- Neovim nightly changed the signature to enable(enable, filter_table).
-- Detect by trying the new API first; fall back to the old one.
local ok = pcall(vim.lsp.document_color.enable, false, { bufnr = bufnr })
if not ok then
disable_document_color(bufnr)
if dc_uses_filter_api then
vim.lsp.document_color.enable(false, { bufnr = bufnr })
else
vim.lsp.document_color.enable(false, bufnr)
end
end

Expand Down
Loading