razor: Snippets don't work in Razor Editor

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


[severity:It’s more difficult to complete my work] The purpose of snippets is to speed up coding by using a short code and tab+tab to get a pre-populated section of code, along with completion.

In the Razor Editor VS2022 built-in snippets work but are so slow as to defeat the object of having them. It takes several seconds Also custom user-defined snippets seem to be unsupported?

In the example screen recording I create a new component. In the code section I want to create a property, so type prop then tab+tab … nothing

Remove the tabs, try ctrl-. … wait a bit… we finally get the intellisense up. We can now hit tab-tab

Issues:

  1. this is too slow - it’s several seconds before Intellisense or snippets are available (I realise this is beta and speeds will improve but it’s going to have to improve a LOT!)
  2. I created some C# code snippets, e.g. “param” to create a [Parameter] property. These don’t show up in the Razor Editor at all (but do appear in C# files)
  3. I created some HTML snippets but these don’t appear in the HTML section at all

Snippets used attached… [BlazorEditForm.zip] (https://aka.ms/dc/file?name=Be4bf04031c6a4b5fbce94bfa38fcb290637655751023473639_BlazorEditForm.zip&tid=e4bf04031c6a4b5fbce94bfa38fcb290637655751023473639) [BlazorParameter.zip] (https://aka.ms/dc/file?name=Be84736daeef049388461d67d7e033e85637655751264497080_BlazorParameter.zip&tid=e84736daeef049388461d67d7e033e85637655751264497080)


Original Comments

Feedback Bot on 8/26/2021, 08:27 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Crazy how it’s been 2 years and this issue hasn’t been fixed. I don’t imagine it to be an incredibly difficult addition and yet the benefit of having this is so great.

Conveniently, the Square Root walkthrough snippet from the MS site is one that doesn’t work…

https://learn.microsoft.com/en-us/visualstudio/ide/walkthrough-creating-a-code-snippet?view=vs-2022

<?xml version="1.0" encoding="utf-8"?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>Square Root</Title> <Shortcut>sqrt</Shortcut> </Header> <Snippet> <Code Language="CSharp"> <![CDATA[double root = Math.Sqrt(16);]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>

When you are evaluating the issue please consider the third-party control vendors’ point of view. Currently, if we want to provide our clients with snippets for our controls through a Visual Studio extension we need to workaround the lack of native support. Ideally, there would be a way to register the snippets that we want to be available in an ASP.NET Core/Blazor project. Similar to the current behavior in Visual Studio Code where we ship a json file with the snippets descriptions and they work out of the box.