WIP: Add Tailwind CSS class auto-sort on save via custom LSP method #3
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
4ndr0m3d4/dots!3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "copilot/update-neovim-lsp-tailwind-sort"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements automatic Tailwind CSS class sorting on file save using the
@/tailwindCSS/sortSelectioncustom method from the Tailwind CSS language server.Changes
sort_tailwind_classes()helper - Scans buffer for allclassandclassNameattributes using pattern matching, requests sorting via@/tailwindCSS/sortSelectionfor each class string, applies sorted results respecting client offset encodingLspAttachautocmd - HooksBufWritePrewhentailwindcssclient attaches, using buffer-specific augroups to prevent duplicate registrationsImplementation
Sorting executes before format-on-save, ensuring classes are ordered per Tailwind's recommended conventions. The implementation finds all
classandclassNameattributes (supporting both single and double quotes) and sorts each individually, applying edits in reverse order to maintain position accuracy.Original prompt
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
@copilot Looking at the source code of the TailwindCSS' language server, the "method" to sort a selection is "@/tailwindCSS/sortSelection". Sorting the entire file has not been implemented AFAIK. The implementation needs to be able to find all the instanced of the class strings (I guess everything after HTML's "class" should be enough for now), request the sorting, and update the instance with the result.
Updated the implementation to use
@/tailwindCSS/sortSelectionmethod instead of code actions. The new approach:classandclassNameattributes using pattern matching@/tailwindCSS/sortSelectionFixed in commit
4eba5ef.Pull request closed