This repository was archived by the owner on May 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathREADME.org
More file actions
131 lines (97 loc) · 5.62 KB
/
Copy pathREADME.org
File metadata and controls
131 lines (97 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
[[https://melpa.org/#/lsp-tailwindcss][file:https://melpa.org/packages/lsp-tailwindcss-badge.svg]]
* lsp-tailwindcss
*This project is deprecated.* It has been integrated into [[https://github.com/emacs-lsp/lsp-mode][lsp-mode]] directly. See [[https://github.com/emacs-lsp/lsp-mode/pull/5061][emacs-lsp/lsp-mode#5061]] for details.
-----
The [[https://github.com/emacs-lsp/lsp-mode][lsp-mode]] client for tailwindcss, using language server from [[https://github.com/tailwindlabs/tailwindcss-intellisense][official vscode plugin]].
[[file:images/autocomplete.png]]
* Installation
** Doom Emacs
in ~packages.el~
#+begin_src emacs-lisp
(package! lsp-tailwindcss :recipe (:host github :repo "merrickluo/lsp-tailwindcss"))
#+end_src
in ~config.el~
#+begin_src emacs-lisp
(use-package! lsp-tailwindcss :after lsp-mode)
#+end_src
** straight.el
#+begin_src emacs-lisp
(straight-use-package
'(lsp-tailwindcss :type git :host github :repo "merrickluo/lsp-tailwindcss"))
#+end_src
** Language Server
*** Installation
+ =M-x lsp-install-server=, then select =tailwindcss=.
*** Update
+ =C-u M-x lsp-install-server=, then select =tailwindcss=.
* Changelog
** 0.3
*** breaking changes
+ back to use the vscode extension asset for language server installation, since the npm package don't get updates.
*** minor changes
+ more language server settings mapped to custom variables.
+ add new configuration =lsp-tailwindcss-skip-config-check= to skip the config file check, since it's hard to keep it the same with the language server.
** 0.2
*** breaking changes
+ now uses [[https://www.npmjs.com/package/@tailwindcss/language-server][tailwindcss language server]] instead of manually download the vscode extension file.
*** major changes
+ added =lsp-tailwindcss-major-modes=, see details in #Customization section.
+ allow global and workspace configuration for tailwindcss-language-server.
+ make variables =lsp-tailwindcss-server-dir=, =lsp-tailwindcss-server-file=, =lsp-tailwindcss-auto-install-server=, =lsp-tailwindcss-server-version= obsolete.
* Customization
** lsp-tailwindcss
*** =lsp-tailwindcss-add-on-mode=
Specify that if lsp-tailwindcss runs in add-on mode, see [[https://emacs-lsp.github.io/lsp-mode/page/faq/][in lsp-mode's documentation.]] This must be set before the package loads (use the init block in use-package instead of config block).
#+begin_src emacs-lisp
(use-package lsp-tailwindcss
:after lsp-mode
:init
(setq lsp-tailwindcss-add-on-mode t))
#+end_src
default: =nil=.
*** =lsp-tailwindcss-major-modes= (since 0.2)
Specify lsp-tailwindcss should only starts when major-mode in the list or derived from them.
default: =rjsx-mode web-mode html-mode css-mode typescript-mode typescript-tsx-mode=.
** tailwindcss-language-server
All settings described in [[https://github.com/tailwindlabs/tailwindcss-intellisense#extension-settings][tailwindcss-intellisense]] except:
+ =tailwindCSS.includeLanguages=
The activation of the language server is controlled by =lsp-tailwindcss--activate-p=, so this is not needed.
+ =tailwindCSS.colorDecorators=
Emacs does not support color decorators.
Default value follows the default value in the documentation.
*** Global Configuration
Custom variable naming convention:
=tailwindCSS.emmetCompletions= => =lsp-tailwindcss-emmet-completions=.
** Rustywind (class sorter)
There are two functions integrate the [[https://github.com/avencera/rustywind][rustywind]] class sorter, =lsp-tailwindcss-rustywind= and =lsp-tailwindcss-rustywind-before-save=.
After install rustywind =npm i -g rustywind=, run =lsp-tailwindcss-rustywind= manually or add it to before-save-hook to use it.
#+begin_src emacs-lisp
(add-hook 'before-save-hook 'lsp-tailwindcss-rustywind-before-save)
#+end_src
* Troubleshooting
1. make sure the language server is installed, see [[#language-server][Install language server]].
2. run =M-x lsp-describe-sessions= to see if the =tailwindcss= language server is running.
3. run =M-x lsp-workspace-show-log= to see if there are any errors reported by language server.
* Q&A
** Unable to calculate the languageId for buffer ...
If you want to use lsp-tailwindcss in some other file types, like =erb=, you might see this error report from =lsp-mode=, the solution is configure the language id for it.
#+begin_src emacs-lisp
(add-to-list 'lsp-language-id-configuration '(".*\\.erb$" . "html"))
#+end_src
This is a requirement for lsp-mode, not just for =lsp-tailwindcss=, see https://github.com/emacs-lsp/lsp-mode/blob/563233fe72de6f32ffc6a1b3db0ec7f49c12cb50/lsp-mode.el#L694 .
** How to set up [[https://github.com/ben-rogerson/twin.macro][twin.macro]]?
twin.macro can be integrated using =lsp-tailwindcss-experimental-class-regex= variable (which is alias to =tailwindCSS.experimental.classRegex= . see the reference to [[https://github.com/ben-rogerson/twin.macro/discussions/227][discussion]])
#+begin_src emacs-lisp
(use-package! lsp-tailwindcss
:after lsp-mode
:init
(setq! lsp-tailwindcss-experimental-class-regex ["tw([^]*)" "tw=\"([^\"]*)" "tw={\"([^\"}]*)" "tw\\.\\w+([^]*)" "tw\\(.*?\\)([^]*)"]))
#+end_src
Take a note that it can lead to [[https://emacs-lsp.github.io/lsp-mode/page/faq/#i-have-multiple-language-servers-registered-for-language-foo-which-one-will-be-used-when-opening-a-project][the conflict of lsp-servers priorities]] (i.e. some of the servers will not start). To fix this you need to use =lsp-tailwindcss-add-on-mode= too.
Set up with add-on mode:
#+begin_src emacs-lisp
(use-package! lsp-tailwindcss
:after lsp-mode
:init
(setq! lsp-tailwindcss-experimental-class-regex ["tw`([^`]*)" "tw=\"([^\"]*)" "tw={\"([^\"}]*)" "tw\\.\\w+`([^`]*)" "tw\\(.*?\\)`([^`]*)"]) (setq! lsp-tailwindcss-add-on-mode t))
#+end_src