-
-
Notifications
You must be signed in to change notification settings - Fork 232
Add command to apply all canonical class suggestions at once (#2) #1508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
* Initial plan * Add applyAllCanonicalClasses command implementation Co-authored-by: damien-schneider <74979845+damien-schneider@users.noreply.github.com> * Format code with prettier Co-authored-by: damien-schneider <74979845+damien-schneider@users.noreply.github.com> * Address code review feedback: use edits.length and improve error handling Co-authored-by: damien-schneider <74979845+damien-schneider@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: damien-schneider <74979845+damien-schneider@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a new VS Code command tailwindCSS.applyAllCanonicalClasses that allows users to batch apply all canonical class suggestions in the current document at once, streamlining the process of converting non-canonical Tailwind classes to their canonical forms.
- Implements a new command that filters diagnostics with code
'suggestCanonicalClasses'and applies all suggested replacements - Includes proper error handling and user feedback via information/warning messages
- Registers the command with appropriate enablement conditions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/vscode-tailwindcss/src/extension.ts | Adds the applyAllCanonicalClasses function that retrieves canonical class diagnostics, creates text edits from their suggestions, and applies them via WorkspaceEdit; registers the command with try-catch error handling |
| packages/vscode-tailwindcss/package.json | Registers the new tailwindCSS.applyAllCanonicalClasses command with title and enablement condition for when editor has focus and document is in file or remote scheme |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Sort diagnostics by position (from end to start) to avoid range invalidation | ||
| canonicalDiagnostics.sort((a, b) => { | ||
| if (a.range.start.line !== b.range.start.line) { | ||
| return b.range.start.line - a.range.start.line | ||
| } | ||
| return b.range.start.character - a.range.start.character | ||
| }) | ||
|
|
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sorting logic here is redundant when using WorkspaceEdit.set(). VS Code automatically handles the application order of multiple text edits to prevent range invalidation, so sorting from end to start is unnecessary. Consider removing this sorting or adding a comment explaining why it's needed if there's a specific reason.
| // Sort diagnostics by position (from end to start) to avoid range invalidation | |
| canonicalDiagnostics.sort((a, b) => { | |
| if (a.range.start.line !== b.range.start.line) { | |
| return b.range.start.line - a.range.start.line | |
| } | |
| return b.range.start.character - a.range.start.character | |
| }) |
| for (let diagnostic of canonicalDiagnostics) { | ||
| // Access the canonical class suggestion directly from the suggestions property | ||
| // Type assertion needed since languages.getDiagnostics returns vscode.Diagnostic | ||
| let canonicalClass = (diagnostic as any).suggestions?.[0] | ||
| if (canonicalClass) { | ||
| edits.push(TextEdit.replace(diagnostic.range, canonicalClass)) | ||
| } | ||
| } |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When diagnostics don't have a suggestions property (or it's empty), those diagnostics will be silently skipped, potentially causing a mismatch between the number of diagnostics found and the number of suggestions applied. Consider tracking skipped diagnostics and warning the user if some suggestions couldn't be applied:
let skipped = 0
for (let diagnostic of canonicalDiagnostics) {
let canonicalClass = (diagnostic as any).suggestions?.[0]
if (canonicalClass) {
edits.push(TextEdit.replace(diagnostic.range, canonicalClass))
} else {
skipped++
}
}
if (skipped > 0) {
Window.showWarningMessage(
`Applied ${edits.length} suggestion${edits.length === 1 ? '' : 's'}, but ${skipped} could not be processed.`
)
}|
This should probably be implemented as a "fix all" code action and not a custom command. Look for |
Added a command to batch apply all the suggested class changes.