razor icon indicating copy to clipboard operation
razor copied to clipboard

C# snippets do not expand in *.razor files Visual Studio 17.2.0

Open Oblomoff opened this issue 3 years ago • 12 comments

C# snippets do not expand in *.razor files Visual Studio 17.2.0

To reproduce: Open *.razor file in Visual Studio, select custom snippet, hit tab twice

Expected behavior: Official blog claims "The new Razor editor now supports snippet functionality in C# code!"

Actual behavior: RazorSnippets

Oblomoff avatar May 14 '22 08:05 Oblomoff

Most built-in snippets work - it appears custom snippets and built-ins with functions do not. Dirty, dirty workaround: edit a built-in snippet you don't use, and restart VS. else and unsafe snippets have never saved me any time, and now serve a higher purpose, along with several of their friends.

blake-fm avatar May 17 '22 10:05 blake-fm

@dibarbet what are your thoughts about enabling the custom snippets and if they fall over they fall over? 😄

NTaylorMullen avatar May 19 '22 21:05 NTaylorMullen

@NTaylorMullen totally open to trying it, simple snippets should work just fine, however I know of a couple scenarios that will for sure not work. There is some cleanup required so we can identify and log when we're in one of those unsupported scenarios.

dibarbet avatar May 19 '22 21:05 dibarbet

Ah one thing we'll also want to do - switch the client side to use the async wait indicator so that we do not need to specify all the custom snippet keywords upfront. Then tab would just trigger the async wait and let the server decide if it has something.

dibarbet avatar May 19 '22 22:05 dibarbet

Thanks for the details, I'll park this for now to gauge interest. For folks seeing this message be sure to upvote the original report.

NTaylorMullen avatar May 19 '22 22:05 NTaylorMullen

@NTaylorMullen It is a big mistake to estimate interest by the number of votes. Because if a young programmer sees that there are no snippets in the editor in 2022 (!) then he will not vote, he will simply switch to another platform, not .NET. Snippets are not a backlog, snippets are a must have. The modern IT industry is not democracy, it is competition.

Oblomoff avatar May 20 '22 13:05 Oblomoff

@NTaylorMullen It is a big mistake to estimate interest by the number of votes. Because if a young programmer sees that there are no snippets in the editor in 2022 (!) then he will not vote, he will simply switch to another platform, not .NET. Snippets are not a backlog, snippets are a must have. The modern IT industry is not democracy, it is competition.

@Oblomoff I hear you and FWIW I'm also a custom snippets user 😁

To be totally transparent let me share some more info. According to our telemetry, custom snippets usage was incredddddddiiiibbblllyy rare and in order to warrant revitalizing the tech I'm trying to capture additional data. Ultimately I'm trying to build a case to bring them back and right now the data we have indicates we shouldn't. Therefore I'm trying to give this every chance it has to make the cut!

Now all that said there has been many conversations about reworking the snippet system to make them a far better experience than they've ever been (to increase usage), which is exciting! However, that's a bit longer out in the VS journey but it's definitely top of mind.

Hope this info helps

NTaylorMullen avatar May 20 '22 16:05 NTaylorMullen

If you want to stay with VS, the workaround solution is to use the legacy editor: stackoverflow

alix-tlse avatar Mar 26 '23 06:03 alix-tlse

Fyi @ryzngard

I wish GitHub had a way to merge issues, because this and https://github.com/dotnet/razor/issues/4331 both have good comments and votes.

davidwengier avatar Mar 26 '23 07:03 davidwengier

@NTaylorMullen I've used VS since the beginning and only recently discovered Snippets. Probably glossed over them 1000 times at least! It's a great feature, definitely worth using, but VS has so many buried capabilities that I just wasn't seeing them. I'm tempted to say they should be promoted more, but, there's like 100 other features also worth promoting. Ugh.

And (eventually) if some sort of AI gets brought in to help code, that could easily take the place of Snippets because now, in a way, you effectively have auto-created custom snippets.

All this said, it's Mar 2023 and my custom snippets still don't work on .cshtml pages. Stinks.

beagley avatar Apr 05 '23 01:04 beagley

The limitations are listed by @ryzngard in #9327:

No Function, Declarations, Id, Import(s), Keyword(s), Literal, Namespace, Object, Reference(s), or Command support.

The listed limitations only apply to custom snippets, correct? Built-in snippets seem to work correctly in the Razor editor, e.g. prop is correctly tabbing through the individual Declarations after inserting.

For custom snippets, if they have a Declaration, they don't insert at all.

@DustinCampbell

Herdo avatar Aug 19 '24 16:08 Herdo

I just thought I'd add a report that custom snippets are still not working in 17.12.0 Preview 2.1; built-in snippets work fine, I've upvoted the report as suggested.

Specifically, in blazor .cshtml files, my custom ones work OK in raw .cs files.

I get the matching list of snippets popping up - all mine are prefixed with my initials - when I enter them, I get a list of all my snippets, but double-tabbing doesn't add the selected or fully-typed one to my code.

I've got into the habit of switching to a .cs file, adding the snippet and cut/pasting back into the cshtml, but it does rather interrupt the flow, especially if I have to dig around in the solution, or even create a .cs file specifically for the purpose.

silentdiverchris avatar Oct 05 '24 14:10 silentdiverchris