nvim-cmp icon indicating copy to clipboard operation
nvim-cmp copied to clipboard

PmenuSbar and PmenuThumb highlights are not customisable!

Open HacksPloiter opened this issue 1 year ago • 6 comments

FAQ

  • [X] I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

  135     window = {
  136     completion = {
  137       winhighlight = "Normal:Pmenu,PmenuSbar:expera,PmenuThumb:experb,FloatBorder:Pmenu,Search:None",
  138       col_offset = -3,
  139       side_padding = 0,
  140     },
  141     documentation = {
  142       winhighlight = "Normal:Pmenu,PmenuSbar:experc,PmenuThumb:experd,FloatBorder:Pmenu,Search:None",
  143       col_offset = -3,
  144       side_padding = 0,
  145     },
  146   },

and colours are:

  172 vim.cmd([[
  173   highlight! expera guibg=red guifg=#00ff00"
  174   highlight! experb guibg=red guifg=#00ff00"
  175   highlight! experc guibg=red guifg=#00ff00"
  176   highlight! experd guibg=red guifg=#00ff00"
  177   ]])

Description

The highlights are not taking effect for popup window scroll bar. Did several experiments with configurations and colours but couldn't achieve the same!

Steps to reproduce

Configure the scrollbar highlights as per the snippet shared.

Expected behavior

Colours should change.

Actual behavior

Colours are not changing.

Additional context

No response

HacksPloiter avatar Dec 13 '23 19:12 HacksPloiter

Hm...

The highlight does not support.

https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L381

Shougo avatar Dec 14 '23 01:12 Shougo

I have read the source code.

cmp-config.window.completion.winhighlight only works for main completion window. The scrollbar is another window. So your config does not work.

Please see the code.

local window = {}

window.bordered = function(opts)
  opts = opts or {}
  return {
    border = opts.border or 'rounded',
    winhighlight = opts.winhighlight or 'Normal:Normal,FloatBorder:FloatBorder,CursorLine:Visual,Search:None',
    zindex = opts.zindex or 1001,
    scrolloff = opts.scrolloff or 0,
    col_offset = opts.col_offset or 0,
    side_padding = opts.side_padding or 1,
    scrollbar = opts.scrollbar == nil and true or opts.scrollbar,
  }
end

return window
    -- Draw the scrollbar thumb
    local thumb_height = math.floor(info.inner_height * (info.inner_height / self:get_content_height()) + 0.5)
    local thumb_offset = math.floor(info.inner_height * (vim.fn.getwininfo(self.win)[1].topline / self:get_content_height()))

    local style = {
      relative = 'editor',
      style = 'minimal',
      width = 1,
      height = math.max(1, thumb_height),
      row = info.row + thumb_offset + (info.border_info.visible and info.border_info.top or 0),
      col = info.col + info.width - 1, -- info.col was already added scrollbar offset.
      zindex = (self.style.zindex and (self.style.zindex + 2) or 2),
    }
    if self.thumb_win and vim.api.nvim_win_is_valid(self.thumb_win) then
      vim.api.nvim_win_set_config(self.thumb_win, style)
    else
      style.noautocmd = true
      self.thumb_win = vim.api.nvim_open_win(buffer.ensure(self.name .. 'thumb_buf'), false, style)
      opt.win_set_option(self.thumb_win, 'winhighlight', 'EndOfBuffer:PmenuThumb,NormalFloat:PmenuThumb')
    end

cmp-config.window.scrollbar.winhighlight is needed for the feature.

Shougo avatar Dec 14 '23 01:12 Shougo

I have read the source code.

cmp-config.window.completion.winhighlight only works for main completion window. The scrollbar is another window. So your config does not work.

Please see the code.

local window = {}

window.bordered = function(opts)
  opts = opts or {}
  return {
    border = opts.border or 'rounded',
    winhighlight = opts.winhighlight or 'Normal:Normal,FloatBorder:FloatBorder,CursorLine:Visual,Search:None',
    zindex = opts.zindex or 1001,
    scrolloff = opts.scrolloff or 0,
    col_offset = opts.col_offset or 0,
    side_padding = opts.side_padding or 1,
    scrollbar = opts.scrollbar == nil and true or opts.scrollbar,
  }
end

return window
   -- Draw the scrollbar thumb
   local thumb_height = math.floor(info.inner_height * (info.inner_height / self:get_content_height()) + 0.5)
   local thumb_offset = math.floor(info.inner_height * (vim.fn.getwininfo(self.win)[1].topline / self:get_content_height()))

   local style = {
     relative = 'editor',
     style = 'minimal',
     width = 1,
     height = math.max(1, thumb_height),
     row = info.row + thumb_offset + (info.border_info.visible and info.border_info.top or 0),
     col = info.col + info.width - 1, -- info.col was already added scrollbar offset.
     zindex = (self.style.zindex and (self.style.zindex + 2) or 2),
   }
   if self.thumb_win and vim.api.nvim_win_is_valid(self.thumb_win) then
     vim.api.nvim_win_set_config(self.thumb_win, style)
   else
     style.noautocmd = true
     self.thumb_win = vim.api.nvim_open_win(buffer.ensure(self.name .. 'thumb_buf'), false, style)
     opt.win_set_option(self.thumb_win, 'winhighlight', 'EndOfBuffer:PmenuThumb,NormalFloat:PmenuThumb')
   end

cmp-config.window.scrollbar.winhighlight is needed for the feature.

Thanks for the response. I tried with the scrollbar config you shared cmp-config.window.scrollbar, in below fashion. It still didn't work. Interestingly other components such as border colour are taking effect.

      window = {
        documentation = cmp.config.window.bordered({
          winhighlight = "Normal:None,FloatBorder:CmpDocFloatBorder,Search:None",
        }),
        completion = cmp.config.window.bordered({
          winhighlight = "Normal:None,"..
                         "FloatBorder:CmpComFloatBorder,"..
                         "CursorLine:PmenuSel,"..
                         "Search:None",
        }),
        scrollbar = {
          winhighlight = "PmenuSbar:CmpSbPmenuSbar,"..
                         "Scrollbar:CmpSbScrollbar,"..
                         "PmenuThumb:CmpSbPmenuThumb,",
        },
      },

      -- LSP settings (for overriding per client)
      experimental = {
        ghost_text = false,
        native_menu = false,
      },
    }

    -- Customise pop-up window colours
    vim.cmd([[
    highlight! CmpDocFloatBorder guibg=None guifg=#00ff00"
    highlight! CmpComFloatBorder guibg=None guifg=#00ff00"
    highlight! CmpSbPmenuSbar guibg=blue guifg=red"
    highlight! CmpSbScrollbar guibg=blue guifg=#00ff00"
    highlight! CmpSbPmenuThumb guibg=yellow guifg=#00ff00"]])

also I had this doubt, I found below from the :h cmp-config.window.completion.scrollbar

*cmp-config.window.completion.scrollbar*
  window.completion.scrollbar~
    `boolean`
    Whether the scrollbar should be enabled if there are more items that fit

but didn't find any scrollbar highlight related thing here.

Can you please share the config snippet if you meant something different (or if I didn't get it correctly)? Thanks @Shougo

HacksPloiter avatar Dec 14 '23 14:12 HacksPloiter

Thanks for the response. I tried with the scrollbar config you shared cmp-config.window.scrollbar, in below fashion. It still didn't work. Interestingly other components such as border colour are taking effect.

Sorry. cmp-config.window.scrollbar.winhighlight is not implemented. So it does not work unfortunately. You can implement the feature. Because it is open source.

Shougo avatar Dec 15 '23 00:12 Shougo

Thanks for the response. I tried with the scrollbar config you shared cmp-config.window.scrollbar, in below fashion. It still didn't work. Interestingly other components such as border colour are taking effect.

Sorry. cmp-config.window.scrollbar.winhighlight i is not implemented. So it does not work unfortunately. You can implement the feature. Because it is open source.

Hi @Shougo, Thanks for your response. Sure, I'll find time and raise a pull request adding this feature. Amazing plugin, I must admit, thanks to all the contributors and the author.

HacksPloiter avatar Dec 16 '23 11:12 HacksPloiter

note: related PR #1741 (not exactly the solution that was mentioned though)

bew avatar Feb 26 '24 00:02 bew