09-10-2020, 05:51 AM
New experimental Razor editor for Visual Studio
<div style="margin: 5px 5% 10px 5%;"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio.jpg" width="150" height="150" title="" alt="" /></div><div><div class="row justify-content-center">
<div class="col-md-4">
<div><img loading="lazy" src="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio.jpg" width="58" height="58" alt="Daniel Roth" class="avatar avatar-58 wp-user-avatar wp-user-avatar-58 alignnone photo"></p>
<p>Daniel</p>
</div>
</div>
</div>
<div class="entry-meta">
<p>July 15th, 2020</p>
</p></div>
<p><!-- .entry-meta --> </p>
<p>With the release of Visual Studio 2019 16.7 Preview 4, you can now try out our new experimental Razor editor for local development with MVC, Razor Pages, and Blazor. We’re excited for you to give it a try!</p>
<h2>Enabling the new Razor editor</h2>
<p>To enable the new experimental Razor editor in Visual Studio 2019 16.7 Preview 4 or later:</p>
<ol>
<li><a href="https://visualstudio.com/preview">Install the latest Visual Studio preview</a></li>
<li>
<p>Go to <strong>Tools</strong> > <strong>Options</strong> > <strong>Environment</strong> > <strong>Preview Features</strong> and select the <strong>Enable experimental Razor editor</strong> option:</p>
<p><a href="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio.png"> <img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio.png" alt="Enable new experimental Razor editor"></a></p>
</li>
<li>
<p>Select <strong>OK</strong> and restart Visual Studio</p>
</li>
</ol>
<p>That’s it! You’re now setup to use the new Razor editor when working with Razor files locally (.cshtml and .razor).</p>
<h2>What is Razor?</h2>
<p>Razor is a templating language based on HTML and C# used to define dynamic rendering logic for .NET web apps based on MVC, Razor Pages, and Blazor. In MVC and Razor Pages apps you use Razor to define the rendering logic for your views and pages using .cshtml files. In Blazor, you use Razor to author reusable UI components in .razor files. Razor is a critical part of the experience for building web apps with .NET.</p>
<p>You can give Razor a try today by building your first web app with <a href="https://dotnet.microsoft.com/learn/aspnet/hello-world-tutorial/intro">ASP.NET Core</a> or <a href="https://dotnet.microsoft.com/learn/aspnet/blazor-tutorial/intro">Blazor</a>.</p>
<h2>Why a new Razor editor?</h2>
<p>Part of the value of Razor is the rich tooling experience Visual Studio provides for editing Razor files. Visual Studio today provides IntelliSense, completions, and diagnostics for HTML, CSS, JavaScript, C#, and Razor specific syntax all within the same Razor file.</p>
<p>Visual Studio does some tricky gymnastics to enable editor support for all of these languages at the same time in Razor files. The Razor document is parsed to determine its constituent parts, and then each part is projected into a language specific buffer called a projection buffer. What you see in Visual Studio when editing a Razor document are a collection of little windows into each of these projection buffers to make up one whole document. Each language service then independently handles the editing experiences for each of these separate projection buffers.</p>
<p>For example, consider the following Razor code:</p>
<pre><code class="cshtml">@{ ViewData["Title"] = "About";
}
<script type="text/javascript"> alert("Hello, World!");
</script>
</code></pre>
<p>The way Visual Studio handles this Razor code looks something like this:</p>
<p><a href="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio-1.png"> <img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio-1.png" alt="Razor editor architecture"></a></p>
<p>This project buffer setup works well for Visual Studio and Visual Studio for Mac, but it’s problematic for remote editing scenarios, like Visual Studio LiveShare or Visual Studio Codespaces. It also can’t be used for editors that don’t have projection buffer support, like Visual Studio Code. The lack of a central orchestrator for the Razor editor also makes it difficult to enable new features without careful coordination between the various language service implementations (since they each control their own experience in projected scenarios).</p>
<h2>A Razor Language Server</h2>
<p>To enable broader support for Razor editing, we have been working for some time on a new Razor editor for ASP.NET Core projects based on a Razor Language Server. This new Razor Language Server implements editor features like auto completion, go to definition, etc. through the <a href="https://microsoft.github.io/language-server-protocol/">Language Server Protocol</a> (LSP), which defines a standard way for an editor or IDE to enable these features. An IDE specific Razor extension then handles coordinating with the Razor Language Server and the other language servers for HTML & C#.</p>
<p><a href="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio-2.png"> <img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio-2.png" alt="LSP Razor editor architecture"></a></p>
<p>This new Razor Language Server is already being used to enable Razor support in Visual Studio Code as part of the C# extension. It will be the basis for the Razor editing support in Visual Studio Codespaces and Visual Studio LiveShare. And now it is available for local development in Visual Studio as a preview feature.</p>
<p>Currently our focus has been on making the new LSP based Razor editor have functional parity with the existing Visual Studio Razor editing experience (as noted below, there are still a few functional gaps to address). In future releases we expect to fill these functional gaps add significant new functionality, like bringing many more of the C# editing features to Razor, and enabling other new Razor specific productivity improvements.</p>
<h2>Known issues</h2>
<p>The new Razor editor is currently experimental and has some known limitations. The following Razor editor features have not yet been fully implemented and will be added in a future release:</p>
<ul>
<li>JavaScript and CSS IntelliSense support</li>
<li>Colorization for C#, JavaScript, CSS, Blazor components, Tag Helpers, and tooltips</li>
<li>Formatting is limited to only C# code in <code>@code</code> and <code>@functions</code> blocks with no embedded HTML markup or Razor syntax</li>
<li>URL picker support in HTML</li>
<li>C# snippets (‘prop’, ‘ctor’, etc.)</li>
<li>Complex C# completions (for example, generating overrides)</li>
<li>Go-to-definition/implementation from C# to Razor</li>
<li>Renames in C# files do not propagate to Razor files</li>
<li>Matching identifier highlight support for HTML and curly braces</li>
</ul>
<p>There are also some functional issues with the new Razor editor in 16.7 Preview 4 that will be addressed in a future release:</p>
<ul>
<li>C# error squiggles may be misaligned</li>
<li>Unnecessary informational errors reported for unnecessary using directives in Razor files</li>
<li>Blazor components & Tag Helpers are currently colored like C# classes and don’t respect the Tag Helper colorization option</li>
</ul>
<h2>Give feedback</h2>
<p>These are still the early days for the new LSP-based Razor editing experience in Visual Studio. We know that there’s still a lot of work to do before it can replace the existing Razor editing experience in Visual Studio. The new Razor tooling will remain optional and experimental in 16.7 and we don’t expect to make it the default Razor editor until it surpasses the functionality of the existing editor. But, we wanted to share our progress as early as possible to start getting your feedback on how well the new Razor editor works for you. To ensure we ship the best Razor editing experience possible, please give the new Razor tooling a try and let us know what you think. You can share your feedback with us by creating <a href="https://github.com/dotnet/aspnetcore/issues/new?template=razor_tooling.md">Razor Tooling issues on Github</a> in the ASP.NET Core repo. We appreciate your feedback!</p>
</div>
https://www.sickgaming.net/blog/2020/07/...al-studio/
<div style="margin: 5px 5% 10px 5%;"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio.jpg" width="150" height="150" title="" alt="" /></div><div><div class="row justify-content-center">
<div class="col-md-4">
<div><img loading="lazy" src="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio.jpg" width="58" height="58" alt="Daniel Roth" class="avatar avatar-58 wp-user-avatar wp-user-avatar-58 alignnone photo"></p>
<p>Daniel</p>
</div>
</div>
</div>
<div class="entry-meta">
<p>July 15th, 2020</p>
</p></div>
<p><!-- .entry-meta --> </p>
<p>With the release of Visual Studio 2019 16.7 Preview 4, you can now try out our new experimental Razor editor for local development with MVC, Razor Pages, and Blazor. We’re excited for you to give it a try!</p>
<h2>Enabling the new Razor editor</h2>
<p>To enable the new experimental Razor editor in Visual Studio 2019 16.7 Preview 4 or later:</p>
<ol>
<li><a href="https://visualstudio.com/preview">Install the latest Visual Studio preview</a></li>
<li>
<p>Go to <strong>Tools</strong> > <strong>Options</strong> > <strong>Environment</strong> > <strong>Preview Features</strong> and select the <strong>Enable experimental Razor editor</strong> option:</p>
<p><a href="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio.png"> <img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio.png" alt="Enable new experimental Razor editor"></a></p>
</li>
<li>
<p>Select <strong>OK</strong> and restart Visual Studio</p>
</li>
</ol>
<p>That’s it! You’re now setup to use the new Razor editor when working with Razor files locally (.cshtml and .razor).</p>
<h2>What is Razor?</h2>
<p>Razor is a templating language based on HTML and C# used to define dynamic rendering logic for .NET web apps based on MVC, Razor Pages, and Blazor. In MVC and Razor Pages apps you use Razor to define the rendering logic for your views and pages using .cshtml files. In Blazor, you use Razor to author reusable UI components in .razor files. Razor is a critical part of the experience for building web apps with .NET.</p>
<p>You can give Razor a try today by building your first web app with <a href="https://dotnet.microsoft.com/learn/aspnet/hello-world-tutorial/intro">ASP.NET Core</a> or <a href="https://dotnet.microsoft.com/learn/aspnet/blazor-tutorial/intro">Blazor</a>.</p>
<h2>Why a new Razor editor?</h2>
<p>Part of the value of Razor is the rich tooling experience Visual Studio provides for editing Razor files. Visual Studio today provides IntelliSense, completions, and diagnostics for HTML, CSS, JavaScript, C#, and Razor specific syntax all within the same Razor file.</p>
<p>Visual Studio does some tricky gymnastics to enable editor support for all of these languages at the same time in Razor files. The Razor document is parsed to determine its constituent parts, and then each part is projected into a language specific buffer called a projection buffer. What you see in Visual Studio when editing a Razor document are a collection of little windows into each of these projection buffers to make up one whole document. Each language service then independently handles the editing experiences for each of these separate projection buffers.</p>
<p>For example, consider the following Razor code:</p>
<pre><code class="cshtml">@{ ViewData["Title"] = "About";
}
<script type="text/javascript"> alert("Hello, World!");
</script>
</code></pre>
<p>The way Visual Studio handles this Razor code looks something like this:</p>
<p><a href="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio-1.png"> <img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio-1.png" alt="Razor editor architecture"></a></p>
<p>This project buffer setup works well for Visual Studio and Visual Studio for Mac, but it’s problematic for remote editing scenarios, like Visual Studio LiveShare or Visual Studio Codespaces. It also can’t be used for editors that don’t have projection buffer support, like Visual Studio Code. The lack of a central orchestrator for the Razor editor also makes it difficult to enable new features without careful coordination between the various language service implementations (since they each control their own experience in projected scenarios).</p>
<h2>A Razor Language Server</h2>
<p>To enable broader support for Razor editing, we have been working for some time on a new Razor editor for ASP.NET Core projects based on a Razor Language Server. This new Razor Language Server implements editor features like auto completion, go to definition, etc. through the <a href="https://microsoft.github.io/language-server-protocol/">Language Server Protocol</a> (LSP), which defines a standard way for an editor or IDE to enable these features. An IDE specific Razor extension then handles coordinating with the Razor Language Server and the other language servers for HTML & C#.</p>
<p><a href="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio-2.png"> <img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/07/new-experimental-razor-editor-for-visual-studio-2.png" alt="LSP Razor editor architecture"></a></p>
<p>This new Razor Language Server is already being used to enable Razor support in Visual Studio Code as part of the C# extension. It will be the basis for the Razor editing support in Visual Studio Codespaces and Visual Studio LiveShare. And now it is available for local development in Visual Studio as a preview feature.</p>
<p>Currently our focus has been on making the new LSP based Razor editor have functional parity with the existing Visual Studio Razor editing experience (as noted below, there are still a few functional gaps to address). In future releases we expect to fill these functional gaps add significant new functionality, like bringing many more of the C# editing features to Razor, and enabling other new Razor specific productivity improvements.</p>
<h2>Known issues</h2>
<p>The new Razor editor is currently experimental and has some known limitations. The following Razor editor features have not yet been fully implemented and will be added in a future release:</p>
<ul>
<li>JavaScript and CSS IntelliSense support</li>
<li>Colorization for C#, JavaScript, CSS, Blazor components, Tag Helpers, and tooltips</li>
<li>Formatting is limited to only C# code in <code>@code</code> and <code>@functions</code> blocks with no embedded HTML markup or Razor syntax</li>
<li>URL picker support in HTML</li>
<li>C# snippets (‘prop’, ‘ctor’, etc.)</li>
<li>Complex C# completions (for example, generating overrides)</li>
<li>Go-to-definition/implementation from C# to Razor</li>
<li>Renames in C# files do not propagate to Razor files</li>
<li>Matching identifier highlight support for HTML and curly braces</li>
</ul>
<p>There are also some functional issues with the new Razor editor in 16.7 Preview 4 that will be addressed in a future release:</p>
<ul>
<li>C# error squiggles may be misaligned</li>
<li>Unnecessary informational errors reported for unnecessary using directives in Razor files</li>
<li>Blazor components & Tag Helpers are currently colored like C# classes and don’t respect the Tag Helper colorization option</li>
</ul>
<h2>Give feedback</h2>
<p>These are still the early days for the new LSP-based Razor editing experience in Visual Studio. We know that there’s still a lot of work to do before it can replace the existing Razor editing experience in Visual Studio. The new Razor tooling will remain optional and experimental in 16.7 and we don’t expect to make it the default Razor editor until it surpasses the functionality of the existing editor. But, we wanted to share our progress as early as possible to start getting your feedback on how well the new Razor editor works for you. To ensure we ship the best Razor editing experience possible, please give the new Razor tooling a try and let us know what you think. You can share your feedback with us by creating <a href="https://github.com/dotnet/aspnetcore/issues/new?template=razor_tooling.md">Razor Tooling issues on Github</a> in the ASP.NET Core repo. We appreciate your feedback!</p>
</div>
https://www.sickgaming.net/blog/2020/07/...al-studio/