-
Notifications
You must be signed in to change notification settings - Fork 118
Syntax highlighting broken with typescript type literals and with simple elements like styled.div #159
Comments
I'm seeing the same. To clarify this happens when using the generic version of the an element function. Ie. |
I'm experiencing the same issue as stated above - syntax highlighting and css code completion is gone when using types. Also as mentioned above, assigning a type directly to any of the props objects used within the styled component will fix type errors and keep syntax highlighting. However in this example, only |
to all: its finally fixed with 0.0.26 released today 🎉 |
I still have a problem with this when using the styled function even after 0.0.26 because 102f0d8 doesnt take spaces into account VSCode formatter automatically puts a space after the function, this breaks the highlight |
@GU5TAF It doesn't work with inline types like that, so create a type alias: // Doesn't work
const MyComponent = styled.div<{ color: string }>``
// Works
type Props = { color: string };
const MyComponent = styled.div<Props>``; It's just using a regex to detect things, so it can't really detect everything properly. |
Okay, thanks for the reply! 🙏 |
It seems this does work with styled, but not with createGlobalStyle<>. |
Same for |
When the generic type is added also to the And if you declare the type directly in the styled.div.attrs(({ size }: ContainerProps) => ({
size: `${size}px`,
style: { // <-- 'style' does not exist in type 'ContainerProps'
height: `${size}px`,
},
... |
I guess this one should be re-opened. Still issues with css<> and createGlobalStyle<> |
Please reopen the issue. I have the same problem with |
We are looking for contributors, please see #275 |
@jasonwilliams I tried it but I didn't make it. The RegEx was stronger than me. But my issues seems to be connected to a line break. If there isn't any line break it works as shown in the attached screenshots. Maybe this will help somebody else. |
Thanks @pixelkritzel that was useful |
Hey everyone, |
@jasonwilliams, @finnp, do you know how to proceed? 🙂 |
Hmm how are you testing it? It should work. If you have this project checked out locally you should be able to hit “launch extension” in debug view on VSCode and test it on a file. Better yet you can create a test like the others and use that as a test. Run yarn watch then load the extension, the debug launch option should call “watch” automatically |
This has been fixed in v1.5.1 please let me know if it isn't |
@Justkant any help on that one would be appreciated |
@jasonwilliams sure, how can I help ? I'm using emotion and I just saw that I also had a look at the multiline fix (#281) and I haven't had the time to test some changes to the regex In the meantime, here is a fixture for my issue: interface StyledBrokenProps {
multipleLines: boolean;
}
const StyledBroken = styled('h1', {
shouldForwardProp: prop => prop !== 'multipleLines'
})<StyledBrokenProps>`
background: red;
`; |
@Justkant you should be able to clone this repo, hit “lunch extension” in the debug tab. That will load a second VSCode instance with the fixtures folder loaded. Go into a typescript fixture (doesn’t matter which one) and replace it with your fixture. now take one of the regexes (it’s this one https://github.com/styled-components/vscode-styled-components/blob/master/syntaxes/styled-components.json#L159) and tweak it. You can do that by throwing it into regex101 (Unescape it first) and put your fixture in Regex 101 aswell. Then you can tweak there. once you’re happy load it back into the json file (escaped) and hit refresh on the debug bar. https://github.com/styled-components/vscode-styled-components/blob/master/CONTRIBUTING.md Goes into more detail |
@Justkant if you're stuck at any point, let me know. |
Hi, sorry I hadn't much time to try and fix this issue lately. I did try today and found a tweak on Regex 101 that helped but couldn't make it work when debugging the extension in vscode. I'll add more infos later when I have some time |
Feel free to share the tweak you did on Regex 101 I can probably take a look |
Just saw your comment. Yes, it works for this usecase with styled-components. Thank you! |
@jasonwilliams |
Nevermind I found a more specific issue for this: #358 |
#26 only added partial typescript support:
The text was updated successfully, but these errors were encountered: