fix: enhance handling of MPX directive comments in Stylus formatting#105
Conversation
📝 WalkthroughWalkthroughAdds pre-processing and post-processing steps to Stylus formatting to preserve MPX directive comments. Introduces regex pattern to identify comments like Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/language-service/src/plugins/mpx-sfc-style-stylus.ts`:
- Around line 95-97: The placeholder "// __MPX_DIRECTIVE_${index}__" can collide
with user comments; modify the placeholder generation in this module (the code
that creates the placeholder variable and calls directiveComments.set) to use a
collision-proof token—e.g. append a random/unique suffix (crypto.randomUUID() or
a monotonic unique id combined with a hidden sentinel/unicode private-use
sequence) or otherwise encode metadata (index + uuid) so placeholders are
globally unique and unguessable; update all places that create or restore
placeholders (the placeholder variable, directiveComments.set(...) and the
corresponding restoration logic around lines referencing the same placeholder)
to use the new unique token format so restoration matches only generated
placeholders.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 25da8fed-d092-433c-b216-f836d01e79d5
📒 Files selected for processing (1)
packages/language-service/src/plugins/mpx-sfc-style-stylus.ts
fix #99
This pull request enhances the handling of MPX directive comments within Stylus files by ensuring that these comments are preserved in their original positions during formatting. The main improvement is the introduction of logic to temporarily replace MPX directive comments with placeholders before formatting, and then restore them afterward, preventing the formatter from relocating these comments.
Preservation of MPX directive comments during formatting:
mpxDirectiveCommentRegexto accurately match MPX directive comments such as/* @mpx-if (...) */and similar variants.Summary by CodeRabbit