merrickluo / lsp-tailwindcss

the lsp-mode client for tailwindcss
GNU General Public License v3.0
180 stars 21 forks source link

[[https://melpa.org/#/lsp-tailwindcss][file:https://melpa.org/packages/lsp-tailwindcss-badge.svg]]

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]]

in ~config.el~

+begin_src emacs-lisp

(use-package! lsp-tailwindcss)

+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

*** Update

*** minor changes

** 0.2 *** breaking changes

*** major changes

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:

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

+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 :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 :init (setq! lsp-tailwindcss-experimental-class-regex ["tw([^])" "tw=\"([^\"])" "tw={\"([^\"}])" "tw\.\w+([^])" "tw\(.?\)([^])"]) (setq! lsp-tailwindcss-add-on-mode t))

+end_src