norcalli / nvim-colorizer.lua

The fastest Neovim colorizer.
Other
2.23k stars 117 forks source link

Proposal Wiki (Tips): Colorizer LSP Hover #70

Closed aspeddro closed 6 months ago

aspeddro commented 2 years ago

Great plugin @norcalli

Using vim.lsp.buf.hover() to colorizer menu.

image

Tested in Neovim 0.5.1

vim.lsp.handlers['textDocument/hover'] = (function(_, result)
  local handler = function(_, result)
    if result then
      local lines = vim.split(result.contents.value, '\n')
      local bufnr = vim.lsp.util.open_floating_preview(lines, 'markdown', { border = 'rounded' })
      require('colorizer').highlight_buffer(bufnr, nil, vim.list_slice(lines, 2, #lines), 0, require('colorizer').get_buffer_options(0))
    end
  end
  return handler
end)()

Note: Passing a table with all the rows, colorizer doesn't work

-- lines = {'```lua', 'field c.green: string = "#C3E88D"', '```' }
require('colorizer').highlight_buffer(bufnr, nil, lines, 0, require('colorizer').get_buffer_options(0))