Skip to content

Commit

Permalink
feat: improve performance of highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
uga-rosa committed Oct 2, 2022
1 parent 19483e6 commit 5a9e394
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 92 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

## Colorizer

- supported colors are `hex`, `rgb()`, `hsl()`, 147 color names, and `textDocument/documentColor` of LSP.
- Color names and LSP are disabled by default.
- LSP `textDocument/documentColor` is supported.
- Highlighting is possible without LSP and supports `hex`, `rgb()`, `hsl()`, 147 color names.
- Color names are disabled by default.

![image](https://user-images.githubusercontent.com/430272/192379267-7b069281-021a-4ee5-bc65-58def20f9c0d.png)

Expand All @@ -27,15 +28,14 @@
Super powerful color picker plugin.

- Features
- RGB, HSL, CMYK, and other color space sliders for color adjustment.
- No dependency.
- RGB, HSL, CMYK, and other color space sliders for color creation.
- Dynamic highlighting of sliders.
- Restore previously used colors.
- Selectable output formats.
- Transparent slider (for css `rgb()`/`hsl()`).
- Transparent slider for `rgb()` and `hsl()`.
- Fast colorizer.

**If you use release version (0.7.2), use branch** `0.7.2`

# Setup

If you do not want to change the default setting, there is no need to call `setup` (Empty `setup` is called automatically by plugin/ccc.lua).
Expand Down Expand Up @@ -71,13 +71,16 @@ This plugin provides five commands and one mapping.
- `:CccHighlighterEnable`
- `:CccHighlighterDisable`
- Highlight colors in the buffer.
- The colors to be highlighted are those registered in `ccc-option-pickers` and those returned by `textDocument/documentColor` request.
- The colors to be highlighted are those returned by textDocument/documentColor request or those registered in `ccc-option-pickers`.
- Highlight is managed on a buffer-by-buffer basis, so you must use this command each time to enable highlight on a new buffer.
- You can use `ccc-option-highlighter-auto-enable` to enable automatically on `BufEnter`.
- The following options are available.
- `ccc-option-highlighter-auto-enable`
- `ccc-option-highlighter-filetypes`
- `ccc-option-highlighter-events`
- `ccc-option-highlighter-excludes`
- `ccc-option-highlighter-lsp`


# Action

All actions have been implemented as lua functions.
Expand Down
26 changes: 12 additions & 14 deletions doc/ccc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ table
highlighter.auto_enable ~
boolean
Default: false
Whether to enable at startup.
Whether to enable automatically on BufEnter.


*ccc-option-highlighter-filetypes*
Expand All @@ -246,19 +246,13 @@ Default: {}
can specify file types to be excludes.


*ccc-option-highlighter-events*
highlighter.events ~
string[]
Default: { "WinScrolled", "TextChanged", "TextChangedI", "BufEnter" }
Events to update highlighting.


*ccc-option-highlighter-lsp*
highlighter.lsp ~
boolean
Default: false
If true, highlight using textDocument/documentColor.
Note: even if highlighted by this option, it cannot be picked up
Default: true
If true, highlight using textDocument/documentColor. If LS with the
color provider is not attached to a buffer, it falls back to highlight
with pickers. The color informations returned by LS are saved and used
by |:CccPick|.


Expand Down Expand Up @@ -329,12 +323,16 @@ Command *ccc-command*
*:CccHighlighterEnable*
:CccHighlighterEnable ~
Highlight colors in the buffer. The colors to be highlighted are those
registered in |ccc-option-pickers| and those returned by
textDocument/documentColor request.
returned by textDocument/documentColor request or those registered in
|ccc-option-pickers|.
Highlight is managed on a buffer-by-buffer basis, so you must use this
command each time to enable highlight on a new buffer. You can use
|ccc-option-highlighter-auto-enable| to enable automatically on
|BufEnter|.
The following options are available.
|ccc-option-highlighter-auto-enable|
|ccc-option-highlighter-filetypes|
|ccc-option-highlighter-events|
|ccc-option-highlighter-excludes|
|ccc-option-highlighter-lsp|


Expand Down
5 changes: 2 additions & 3 deletions lua/ccc/config/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ return {
highlight_mode = "bg",
---@type function
output_line = ccc.output_line,
---@type { auto_enable: boolean, filetypes: string[], excludes: string[], events: string[], lsp: boolean }
---@type { auto_enable: boolean, filetypes: string[], excludes: string[], lsp: boolean }
highlighter = {
auto_enable = false,
filetypes = {},
excludes = {},
events = { "WinScrolled", "TextChanged", "TextChangedI", "BufEnter" },
lsp = false,
lsp = true,
},
---@type {[1]: ColorPicker, [2]: ColorOutput}[]
convert = {
Expand Down
14 changes: 12 additions & 2 deletions lua/ccc/config/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local api = vim.api

local M = {
config = {},
}
Expand Down Expand Up @@ -35,13 +37,21 @@ function M.setup(opt)
["config.highlighter.auto_enable"] = { M.config.highlighter.auto_enable, "b" },
["config.highlighter.filetypes"] = { M.config.highlighter.filetypes, "t" },
["config.highlighter.excludes"] = { M.config.highlighter.excludes, "t" },
["config.highlighter.events"] = { M.config.highlighter.events, "t" },
["config.highlighter.lsp"] = { M.config.highlighter.lsp, "b" },
["config.convert"] = { M.config.convert, "t" },
["config.mappings"] = { M.config.mappings, "t" },
})

if M.config.highlighter.auto_enable then
require("ccc.highlighter"):enable()
local aug_name = "ccc-highlighter-auto-enable"
api.nvim_create_augroup(aug_name, {})
api.nvim_create_autocmd("BufEnter", {
pattern = "*",
group = aug_name,
callback = function()
require("ccc.highlighter"):enable()
end,
})
end
end

Expand Down
Loading

0 comments on commit 5a9e394

Please sign in to comment.