vscode-styled-components icon indicating copy to clipboard operation
vscode-styled-components copied to clipboard

Backticks are always expanded

Open massimo-cassandro opened this issue 2 years ago • 6 comments

Describe the bug (including copyable syntax) A clear and concise description of what the bug is. If you're planning on posting a screenshot, please paste the accompanying code here.

Backticks are always expanded, even in comments or other situations where it's not needed, this is really annoying

Screenshot Screenshots are alway useful!

Schermata 2022-11-25 alle 12 07 22

To Reproduce Steps to reproduce the issue, or JavaScript code that causes this failure. If you showed a screenshot, it will help a lot to paste accompanying code which matches

insert a backticks ina. comment or elewhere

Expected behavior Explain what you expected to happen, and what is happening instead.

backticks shoiuld be expanded only when necessary

Build environment (please complete the following information):

  • OS: mac os 12.6.1
  • VSCode Version: 1.73.1
  • Extension Version 1.7.5

Additional context Add any other context about the problem here.

massimo-cassandro avatar Nov 25 '22 11:11 massimo-cassandro

Thanks for raising this @massimo-cassandro We currently always show that option whenever backticks are opened inside a "TypeScript React" or "JavaScript React" file. I don't think there's an easy way to know when you want to use it for styled components vs when you want to use it as normal template string.

One option would be to check the TypeScript AST and see if you're within a CSS declaration but this would take some work, it isn't something I have time to look at right now.

Would you be willing to work on this?

jasonwilliams avatar Dec 15 '22 09:12 jasonwilliams

Hi @jasonwilliams, I can have a try, but I'm not very versed in vscode extensions. Let me take a look, and in the next days I'll let you know if I'm able to do it... Thanks

massimo-cassandro avatar Dec 15 '22 10:12 massimo-cassandro

https://github.com/styled-components/vscode-styled-components/blob/main/CONTRIBUTING.md

jasonwilliams avatar Dec 15 '22 15:12 jasonwilliams

One option would be to check the TypeScript AST and see if you're within a CSS declaration but this would take some work, it isn't something I have time to look at right now.

I had experience to do it earlier and I see an easy way to do this, but it involves weird workaround and creating another TS plugin within repo. @jasonwilliams just curios, how do you think it should be done? There is no obvious way to send a command to TS plugin from vscode ext host to ask something and also, please, its important to understand that this is not a native snippet, which means it can't be disabled atm, I might not need this snippet at all (probably because user using some other way to expand it). For example I'm using this to get it even quicker (notice TS completion insert text):

Screenshot 2022-12-17 at 11 19 30

if you're within a CSS declaration

Also just curios what does it mean? Can you throw some examples? The only case I see so far:

const foo = css`|

// | - cursor pos, but why don't we check that last char on previous line is `?

zardoy avatar Dec 17 '22 08:12 zardoy

HI @jasonwilliams, unfortunately I could not deal with this thing and I do not think I will have much time available in the near future...

massimo-cassandro avatar Jan 28 '23 17:01 massimo-cassandro

fyi I added a way to disable this commpletion provider with Extensions Control

zardoy avatar Jul 09 '23 23:07 zardoy