Skip to content

Commit dd643c1

Browse files
authored
Fix/tailwind issues (#128)
* fix: do not add tailwind colors to trie if tailwind == "lsp" * ref: refactors tailwind module * ref: update options parameter to ud_options to indicate it satisfies `user_default_options` * fix: before applying tailwind lsp highlights, clear default namespace for line * ref: removes colorizer.default_namespace. namespaces are available in constants module * ref: refactors tailwind module * feat: creates tailwind_names_parser, which will be used to parse tailwind class names from a data table in it's own namespace * ref: create namespace for tailwind names, which is cleared upon tailwind lsp highlighting when tailwind = "both" * feat: tailwind lsp only highlights visible rows * ref: rename utils.view_range to utils.visible_line_range * ref: use client:supports_method * feat: tailwind lsp results can be configured to be added to tailwind_names color map * ref: validate options during applying aliases * perf: tailwind LSP results are cached to be returned from WinScrolled event * feat: update tailwind named Trie from LSP results * doc: updates readme with tailwind information * fix(sass): pass in correct matcher.make function * fix(sass): use correct field name (COLOR_PARSER -> color_parser) * fix(sass): use updated hl_opts argument for colorizer.highlight * ref(sass): rename options key to ud_opts to remain consistent with plugin parameters * doc: updates readme
1 parent 359d456 commit dd643c1

36 files changed

+1733
-824
lines changed

README.md

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
- [Why another highlighter?](#why-another-highlighter)
1414
- [Customization](#customization)
1515
- [Updating color even when buffer is not focused](#updating-color-even-when-buffer-is-not-focused)
16+
- [Tailwind](#tailwind)
1617
- [Testing](#testing)
1718
- [Extras](#extras)
1819
- [TODO](#todo)
19-
- [Similar projects](#similar-projects)
2020
<!--toc:end-->
2121

2222
[![luadoc](https://img.shields.io/badge/luadoc-0.1-blue)](https://catgoose.github.io/nvim-colorizer.lua/)
@@ -27,15 +27,11 @@ dependencies**! Written in performant Luajit.
2727
As long as you have `malloc()` and `free()` on your system, this will work.
2828
Which includes Linux, OSX, and Windows.
2929

30-
![Demo.gif](https://raw.githubusercontent.com/norcalli/github-assets/master/nvim-colorizer.lua-demo-short.gif)
30+
![Demo.gif](https://github.com/catgoose/screenshots/blob/51466fa599efe6d9821715616106c1712aad00c3/nvim-colorizer.lua/demo-short.gif)
3131

3232
## Installation and Usage
3333

3434
Requires Neovim >= 0.7.0 and `set termguicolors`.
35-
If you don't have true color for your terminal or are
36-
unsure, [read this excellent guide](https://github.com/termstandard/colors).
37-
38-
Use your plugin manager or clone directly into your package.
3935

4036
### Plugin managers
4137

@@ -58,33 +54,33 @@ use("catgoose/nvim-colorizer.lua")
5854

5955
#### Manual
6056

61-
One line setup. This will create an `autocmd` for `FileType *` to highlight
62-
every filetype.
63-
6457
> [!NOTE]
6558
> You should add this line after/below where your plugins are setup.
6659
6760
```lua
6861
require("colorizer").setup()
6962
```
7063

64+
This will create an `autocmd` for `FileType *` to highlight
65+
every filetype.
66+
7167
### User commands
7268

69+
> [!NOTE]
70+
> User commands can be enabled/disabled in setup opts
71+
7372
| Command | Description |
7473
| ----------------------------- | ----------------------------------------------------------- |
7574
| **ColorizerAttachToBuffer** | Attach to the current buffer with given or default settings |
7675
| **ColorizerDetachFromBuffer** | Stop highlighting the current buffer |
7776
| **ColorizerReloadAllBuffers** | Reload all buffers that are being highlighted currently |
7877
| **ColorizerToggle** | Toggle highlighting of the current buffer |
7978

80-
> [!NOTE]
81-
> User commands can be enabled/disabled in setup opts
82-
8379
### Lua API
8480

8581
```lua
8682
-- All options that can be passed to `user_default_options` in setup() can be
87-
-- passed here
83+
-- passed to `attach_to_buffer`
8884
-- Similar for other functions
8985

9086
-- Attach to buffer
@@ -107,10 +103,6 @@ is that _this only works for Neovim_, and that will never change.
107103
Apart from that, it only applies the highlights to the current visible contents,
108104
so even if a big file is opened, the editor won't just choke on a blank screen.
109105

110-
This idea was copied from
111-
[brenoprata10/nvim-highlight-colors](https://github.com/brenoprata10/nvim-highlight-colors)
112-
Credits to [brenoprata10](https://github.com/brenoprata10)
113-
114106
Additionally, having a Lua API that's available means users can use this as a
115107
library to do custom highlighting themselves.
116108

@@ -122,6 +114,10 @@ library to do custom highlighting themselves.
122114
```lua
123115
require("colorizer").setup({
124116
filetypes = { "*" },
117+
-- all the sub-options of filetypes apply to buftypes
118+
buftypes = {},
119+
-- Boolean | List of usercommands to enable. See User commands section.
120+
user_commands = true, -- Enable all or some usercommands
125121
user_default_options = {
126122
names = true, -- "Name" codes like Blue or red. Added from `vim.api.nvim_get_color_map()`
127123
names_opts = { -- options for mutating/filtering names.
@@ -149,6 +145,9 @@ library to do custom highlighting themselves.
149145
mode = "background", -- Set the display mode
150146
-- Tailwind colors. boolean|'normal'|'lsp'|'both'. True is same as normal
151147
tailwind = false, -- Enable tailwind colors
148+
tailwind_opts = { -- Options for highlighting tailwind names
149+
update_names = false, -- When using tailwind = 'both', update tailwind names from LSP results. See tailwind section
150+
},
152151
-- parsers can contain values used in |user_default_options|
153152
sass = { enable = false, parsers = { "css" } }, -- Enable sass colors
154153
-- Virtualtext character to use
@@ -161,20 +160,18 @@ library to do custom highlighting themselves.
161160
-- example use: cmp_menu, cmp_docs
162161
always_update = false,
163162
},
164-
-- all the sub-options of filetypes apply to buftypes
165-
buftypes = {},
166-
-- Boolean | List of usercommands to enable
167-
user_commands = true, -- Enable all or some usercommands
168163
})
169164
```
170165

171-
MODES:
166+
Highlighting modes:
172167

173168
- `background`: sets the background text color.
174169
- `foreground`: sets the foreground text color.
175170
- `virtualtext`: indicate the color behind the virtualtext.
176171

177-
For basic setup, you can use a command like the following.
172+
Virtualtext symbol can be displayed at end of line, or
173+
174+
Setup examples:
178175

179176
```lua
180177
-- Attaches to every FileType with default options
@@ -260,9 +257,9 @@ In `user_default_options`, there are 2 types of options
260257

261258
1. Alias options - `css`, `css_fn`
262259

263-
If `css_fn` is true, then `hsl_fn`, `rgb_fn` becomes `true`
260+
If `css_fn` is true `hsl_fn`, `rgb_fn` becomes `true`
264261

265-
If `css` is true, then `names`, `RGB`, `RGBA`, `RRGGBB`, `RRGGBBAA`, `hsl_fn`, `rgb_fn`
262+
If `css` is true `names`, `RGB`, `RGBA`, `RRGGBB`, `RRGGBBAA`, `hsl_fn`, `rgb_fn`
266263
becomes `true`
267264

268265
These options have a priority, Individual options have the highest priority,
@@ -332,6 +329,38 @@ For lower level interface, see
332329
[LuaDocs for API details](https://catgoose.github.io/nvim-colorizer.lua/modules/colorizer.html)
333330
or use `:h colorizer` once installed.
334331

332+
### Tailwind
333+
334+
Tailwind colors can either be parsed from the Tailwind colors file (found in
335+
`lua/colorizer/data/tailwind_colors.lua`) or by requesting
336+
`textDocument/documentColor` from the LSP.
337+
338+
When using `tailwind="normal"`, only standard color names/values are parsed.
339+
340+
Using the `tailwind_opts.update_names` configuration option, the `tailwind_names`
341+
color mapping will be updated with results from Tailwind LSP, including custom
342+
colors defined in `tailwind.config.{js,ts}`.
343+
344+
This can be useful if you are highlighting `cmp_menu` filetype.
345+
346+
```typescript
347+
// tailwind.config.ts
348+
extend: {
349+
colors: {
350+
gray: {
351+
600: '#2CEF6F',
352+
700: '#AC50EF',
353+
800: '#2ECFF6',
354+
},
355+
},
356+
},
357+
```
358+
359+
![tailwind.update_names](https://github.com/catgoose/screenshots/blob/51466fa599efe6d9821715616106c1712aad00c3/nvim-colorizer.lua/tailwind_update_names.png)
360+
361+
To improve highlighting performance with the slow Tailwind LSP, results from LSP
362+
are cached and returned on `WinScrolled` event.
363+
335364
## Testing
336365

337366
For troubleshooting use `test/minimal.lua`.
@@ -350,7 +379,7 @@ to conveniently reattach Colorizer to `test/expect.lua` on save.
350379

351380
## Extras
352381

353-
Documentaion is generated using ldoc. See
382+
Documentation is generated using ldoc. See
354383
[scripts/gen_docs.sh](https://github.com/colorizer/nvim-colorizer.lua/blob/master/scripts/gen_docs.sh)
355384

356385
## TODO
@@ -359,7 +388,4 @@ Documentaion is generated using ldoc. See
359388
- [ ] Add more display modes. E.g - sign column
360389
- [ ] Use a more space efficient trie implementation.
361390
- [ ] Support custom parsers
362-
363-
## Similar projects
364-
365-
[nvim-highlight-colors](https://github.com/brenoprata10/nvim-highlight-colors)
391+
- [ ] Options support providing function to enable/disable instead of just boolean

0 commit comments

Comments
 (0)