Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Syntax highlighting breaks if there is a linebreak between "styled" and opening backtick ` #174

Closed
Livven opened this issue May 29, 2019 · 7 comments · Fixed by #287
Closed

Comments

@Livven
Copy link

Livven commented May 29, 2019

See the screenshot, once there is a linebreak between styled and the opening backtick ` CSS syntax highlighting stops working. A normal use case for this would be e.g. declaring an anonymous interface for props in Typescript that spans multiple lines.

Screenshot

@TyMick
Copy link
Contributor

TyMick commented Feb 18, 2021

I tried replacing every <.+> in the regex with <.*?(?:\\n.*?)*?> and later with <[^>]*?> to try to allow new line characters, but neither of those fixed the issue for me, either. 😔

@rkingon
Copy link

rkingon commented Apr 21, 2021

i'm trying to convert to styled components and this is killlllllling me =x

@jasonwilliams
Copy link
Collaborator

The issue is this https://github.com/styled-components/vscode-styled-components/blob/master/CONTRIBUTING.md#a-line-break-seems-to-break-the-syntax-highlighting so we know what is causing it now it’s just a case of fixing it.

jasonwilliams added a commit to jasonwilliams/vscode-styled-components that referenced this issue Apr 23, 2021
* create a multiline fixture from issue styled-components#174
* Fixed by creating two groups, one which was the same as before, and one which adds support for }>` syntax as the beginning. Tests have passed
jasonwilliams added a commit that referenced this issue Apr 23, 2021
)

The issue with #174 was the main regex, specially the beginning match, which only matches an expression which ends with a back tick. When you use multiline properties your top line no longer ends the same way (`styled.div<{`). This means we need to set a new beginning match. I tried doing this as a new rule but it just didn't work, instead I split the regex into 2 (non-captured) groups and the second group matches:
```
}>`
```

and sets that as the beginning match, so anything after the above will be treated as SCSS, up until the next backtick

* [before](https://regex101.com/r/yi6jOv/1/)
* [after](https://regex101.com/r/mNfB4E/1/)
* Set colorize-fixtures as the folder for extensionHost (debugging)
* create a multiline fixture from issue #174
* Fixed by creating two groups, one which was the same as before, and one which adds support for }>` syntax as the beginning. Tests have passed
@jasonwilliams
Copy link
Collaborator

This has been fixed in v1.5.1 please let us know or raise an issue if this is still happening

@rkingon
Copy link

rkingon commented May 7, 2021

It looks like there is still a scenario in which the syntax stops working (though I have found it to be greatly improved from other areas (like defining types or attributes).

Screen Shot 2021-05-07 at 11 35 11 AM

@rkingon
Copy link

rkingon commented May 7, 2021

Just for fun, here are two other screenshots, where if I pull the FC out into a variable and keep the styled call on a single line, it works -- but if I make it multi line, it stops.

Screen Shot 2021-05-07 at 11 39 13 AM

Screen Shot 2021-05-07 at 11 39 25 AM

@jasonwilliams
Copy link
Collaborator

jasonwilliams commented May 7, 2021

Hey @rkingon, thanks for finding this.
I think #169 is the same issue which should address that

jasonwilliams added a commit to jasonwilliams/vscode-styled-components that referenced this issue May 10, 2021
jasonwilliams added a commit that referenced this issue May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants