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

Implement 'Synced Regions' for Svelte #726

Open
milkbump opened this issue Dec 25, 2020 · 5 comments
Open

Implement 'Synced Regions' for Svelte #726

milkbump opened this issue Dec 25, 2020 · 5 comments
Labels
feature request New feature or request limitation Constraints of the existing architecture make this hard to fix

Comments

@milkbump
Copy link

HTML for VS Code recently introduced Synced Regions for HTML tags. In summary, if you edit an opening tag, the same edits appear in the closing tag and vice versa.

This API is available for other extensions as of two weeks ago.

This is an issue to track the implementation of Synced Regions for: (Tip: | is the cursor)

  • Svelte markup (e.g <div|></div|>)
  • Svelte control flow (e.g {#each| n}{/each|}).
  • ** Svelte classes & ids (e.g <div class="apple|"></div> <style> .apple| {color: red}</style> )
  • ** JavaScript
    • <script> let world| = "" </script><div>Hello {world|}</div>.
    • <script> import Component| from "./component"</script><Component|></Component|>

** Syncing JavaScript and CSS classes and ids is iffy since I can imagine wanting to edit a variable/class without changing others in many situations. I haven't experimented with how flexible the LinkedEditingRangeProvider API is, but if possible, we could require a key-binding to get into synced mode for these contentious regions. Requiring a key-binding will likely hurt feature discovery + usage of syncing for these regions, so discussion of other possible implementations is very welcome.

I'd suggest four separate settings options for HTML, flow control, CSS and JS. Where HTML & flow control are on by default, but CSS & JS are off by default.

@jasonlyu123 jasonlyu123 added the feature request New feature or request label Dec 26, 2020
@jasonlyu123
Copy link
Member

The markup part would be easy to implement and it probably is what it's designed for. The svelte control flow is viable but probably only possible when there's no syntax error in the file.
The proposal of CSS class name, id, and javascript identifier feel more like a rename symbol to me. We already have it for javascript but not CSS. And about the partly rename you can always use multiple cursors to achieve it.

@jasonlyu123
Copy link
Member

jasonlyu123 commented Feb 4, 2021

I tried to implement the svelte control flow but the result using svelte AST is not very useful. It's too brittle. During linked editing, the code is very likely to be invalid. So the svelte compiler keeps complaining. We might need to implement a dedicated parser for it to be useful. So this probably won't happen soon.

To be clear, it does work. But once you exit for the linked editing mode, you can't go back because the code is invalid. So you will have to type quickly and correctly before vscode exit the linked editing mode.

@dummdidumm
Copy link
Member

I also think that using the Svelte AST will be too brittle. Writing a custom parser sound like too much work for such a feature. Maybe the html parser we use in other places could be used for that.

@jasonlyu123
Copy link
Member

Element and component tag can be done by the html-language-service. Not much code needed but there is a weird problem I just can't find out why.

@dummdidumm
Copy link
Member

This feature is now live for html tags. Still not sure if other areas are valid use cases.

@jasonlyu123 jasonlyu123 added the limitation Constraints of the existing architecture make this hard to fix label Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request limitation Constraints of the existing architecture make this hard to fix
Projects
None yet
Development

No branches or pull requests

3 participants