Skip to content
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

Custom Labels (customLabels) Not Escaping Properly - Backslash Doesn't Work #223107

Closed
babakfp opened this issue Jul 22, 2024 · 6 comments
Closed
Assignees
Labels
info-needed Issue requires more information from poster workbench-custom-labels Issues related to Workbench Editor Custom Labels

Comments

@babakfp
Copy link

babakfp commented Jul 22, 2024

Hi 👋

#213117

The goal is to match a string that contains [] with whatever inside it. But because of the backslash (\) limitation, this is not possible.

Using something like **/?...slug?.astro is not a good solution because [] may contain any words (with or without ...).

This regex escape limitation is present in other places in vsCode too.

If this issue gets fixed, I can do something like this in my vsCode config:

{
    "workbench.editor.customLabels.enabled": true,
    "workbench.editor.customLabels.patterns": {
        "**/+*.*": "${dirname}/${filename}.${extname}",
        "**/\\[*]\\/+*.*": "${dirname(1)}/${dirname(0)}/${filename}.${extname}",
        "**/routes/+*.*": "${filename}.${extname}"
    },
}

@benibenj

@benibenj
Copy link
Contributor

benibenj commented Aug 15, 2024

I believe this is a limitation we are not able to fix easily, @bpasero do you know if we have a way to escape []? I'm parsing the glob pattern which turns \ into \\.

@bpasero
Copy link
Member

bpasero commented Aug 15, 2024

I think not.

function parseRegExp(pattern: string): string {

@benibenj benibenj added the workbench-custom-labels Issues related to Workbench Editor Custom Labels label Aug 15, 2024
@benibenj
Copy link
Contributor

benibenj commented Aug 15, 2024

@babakfp there might be another way to match the [], but it is a bit hacky. I was able to match the file folder/[hello].py with **/[[]*[]].py. Let me know if this works for your case.

You would probably use "**/[[]*[]]/+*.*"

@benibenj benibenj added the info-needed Issue requires more information from poster label Aug 15, 2024
@babakfp
Copy link
Author

babakfp commented Aug 16, 2024

Thank you, @benibenj. Your solution worked perfectly!

This solves the issue for this specific use case, so if needed, feel free to close the issue.


This is my config for SvelteKit + files:

{
    "workbench.editor.customLabels.patterns": {
        "**/+*.*": "${dirname}/${filename}.${extname}",
        "**/[[]*[]]/+*.*": "${dirname(1)}/${dirname(0)}/${filename}.${extname}",
        "**/routes/+*.*": "${filename}.${extname}"
    },
}

Result:

  • src/routes/+page.svelte will be +page.svelte.
  • src/routes/about/+page.svelte will be about/+page.svelte.
  • src/routes/posts/[id]/+page.svelte will be posts/[id]/+page.svelte.
    Can be turned into posts/[]/+page.svelte by using "${dirname(1)}/[]/${filename}.${extname}" instead.

SEO: Svelte, SvelteKit, Astro, customLabels, Bracket, Brackets, [*], [id], [slug], [...slug], React, Next, NextJS, Next.js

@4lch4

Copy link

Hey @benibenj, this issue might need further attention.

@babakfp, you can help us out by closing this issue if the problem no longer exists, or adding more information.

@benibenj
Copy link
Contributor

benibenj commented Nov 4, 2024

related #213117

@benibenj benibenj closed this as completed Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster workbench-custom-labels Issues related to Workbench Editor Custom Labels
Projects
None yet
Development

No branches or pull requests

5 participants