Skip to content

RubyMine, IntelliJ, PHPStorm, …

Matouš Borák edited this page Oct 17, 2023 · 4 revisions

Using the File Watcher plugin

The File Watcher plugin allows calling the Tailwind sorter automatically upon saving a changed file.

Installation

  1. Install the File Watchers plugin to the IDE. Installing File Watchers plugin

  2. Go to Tools ⟶ File Watchers section of the main Preferences and add a new File Watcher with the following settings: image

  • click the "+" symbol to add a new file watcher
  • name it e.g. "Tailwind Sorter"
  • set the File type according to your needs; by default, Tailwind sorter supports Slim templates
  • set the Scope to Project files so that changes in any relevant file across the whole project triggers the file watcher
  • set the Program to the path to tailwind_sorter binstub, i.e. tailwind_sorter if you have it accessible from $PATH or $ProjectFileDir$/bin/tailwind_sorter otherwise
  • set the Arguments to $FilePath$, i.e. to the name of the edited file
  • we recommend to un-check the checkboxes ”Auto-save the edited files to trigger the watcher“ and ”Trigger the watcher on external changes“ to prevent ”random“ run-loops in certain scenarios
  • set the Show console parameter to ”On Error“; the ”Always“ option is helpful if you want to debug / develop the script itself
  • confirm the dialog and check the ”Enable“ checkbox to actually set this file watcher ready

Working with the file watcher

Now, whenever you make a change to any file conforming to the ”File type“ selection above and save the file, the file watcher triggers the Tailwind sorter ⟶ it reorders classes in the file inplace ⟶ the changes are automatically visible in the IDE GUI.

Troubleshooting

Undo does not work properly

After the script is run on a changed file, sometimes the ctrl+z (Undo) action does not work properly, since when you undo the changes, the script is immediately run again, redoing the changes. To fix this behavior, go to the main Settings ⟶ Appearance & Behavior ⟶ System Settings ⟶ the Autosave section ⟶ and un-check the "Save files when switching to a different application" checkbox.

The downside of this fix is that now the currently edited file is not auto-saved by the IDE whenever you switch to a different application.