razor icon indicating copy to clipboard operation
razor copied to clipboard

cannot format javascript when razor in script tag

Open vsfeedback opened this issue 1 year ago • 3 comments

This issue has been moved from a ticket on Developer Community.


for example:


Original Comments

Armando Aguirre Sepulveda [MSFT] on 29/09/2017, 04:32 AM:

(private comment, text removed)

Mohamad Yahia on 26/09/2019, 03:22 PM:

(private comment, text removed)

ahdung-ai on 26/09/2019, 04:43 PM:

(private comment, text removed)

pauldbentley on 13/08/2022, 01:49 AM:

(private comment, text removed)


Original Solutions

Mohamad Yahia solved on 26/09/2019, 04:55 PM, 1 votes:

I found a simple work around for when I first open a file and it’s not formatted

  • Replace all @ with @@

  • Format Document

  • Replace all @@ with @

That works but it’s a pain and normal formatting should just work.

ahdung-ai on 26/09/2019, 05:01 PM:

(private comment, text removed)

Mohamad Yahia solved on 26/09/2019, 03:23 PM, 0 votes:

*DELETED COMMENT*

vsfeedback avatar May 17 '24 06:05 vsfeedback

Couldn't find an issue for this, and when I tried to repro, I couldn't get JavaScript formatting to work at all, whether there was an @if in there or not.

davidwengier avatar May 17 '24 06:05 davidwengier

I have this issue too. I post it on VS Feedback, and they send me here. I comment here for them to know that others have problem too.

https://developercommunity.visualstudio.com/t/code-formatter-for-javascript-insode-cs/10748043

aliajboy avatar Sep 25 '24 13:09 aliajboy

Thanks @aliajboy , generally we move things to GitHub if we have enough information from the user to verify the bug and no longer directly need more information. As an open source project this works best for us. In general if you find that you have feedback moved and want to make sure to help prioritize, a 👍 on the top of the issue is helpful :) We also monitor activity for comments and other things. Appreciate you following up!

ryzngard avatar Sep 25 '24 22:09 ryzngard

For me, regardless of using razor inside script or not, typing JavaScript is slower than in .js files and intellisense works after a delay. I mostly put script in .js files, but there's definitely times where I have a small amount in .cshtml, inside a <script> inside @section Scripts. Colorization is OK when inside @section Scripts, but if I have a <script> not in @section then I get no syntax coloring...it's all black.

The above is when opening a .cshtml and going straight to the script code to work with it. But if I make changes in HTML, a style block or add/change a razor block in a .cshtml, then working with script in that same file is worse...many times intellisense doesn't work at all and typing is even slower.

Dean-NC avatar Feb 04 '25 14:02 Dean-NC