Repository navigation
Add Razor syntax highlighting for .razor and .cshtml - #113
Open
bancho4560 wants to merge 1 commit into
Open
bancho4560 wants to merge 1 commit into
bancho4560 wants to merge 1 commit into
Conversation
Register the razor grammar and a Razor language, highlight Razor directives and transitions, and port the C# query set for embedded code. Markup is highlighted by injecting Zed's HTML language over top-level elements, which also supplies CSS/JS highlighting inside <style> and <script>. This is syntax highlighting only; no language server is attached to Razor buffers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds syntax highlighting for
.razorand.cshtmlfiles, addressing #41.This is highlighting only: no language server, completion, or diagnostics are attached to Razor buffers. Roslyn/Razor LSP support (as proposed in #110) is intentionally out of scope.
What's included
Razorlanguage withpath_suffixes = ["razor", "cshtml"], Razor block comments (@* ... *@), and@as a word character.@page,@model,@using,@inject,@section, ...), transitions (@if,@foreach,@try,@:,@( ... ),@code, ...), tag helpers (@onclick,@bind-Value, ...), Razor comments, and doctypes.<style>and<script>.Grammar
alfpricot/tree-sitter-razor-modernatfa9264bcc1af01c260a28749f180ac5577a40fea.The grammar parses current Razor/Blazor syntax with zero ERROR nodes in my test corpus, including
@pagewith and without a route,<!DOCTYPE>,@mediainside<style>,${...}inside<script>, tag helpers,@@,@:, and@* ... *@. In the same tests, thetris203/Meeksoftgrammar lineage used in #103/#110 produced ERROR nodes on several of those constructs.Implementation notes
; inherits: c_sharp, so the C# highlight rules are ported intolanguages/razor/highlights.scm. The one deliberate difference is that<,>,=and other comparison/assignment operators are scoped to expression nodes; a bare token list would paint HTML tags and attributes.elementnode, so markup cannot be captured directly.injections.scmreparses top-level elements with Zed's bundled HTML language.injection.combinedis intentionally not used: nested elements would produce overlapping included ranges and the layer would be rejected.<style>/<script>still highlight through the HTML extension's own injections.Verification
=,>,=>captures occur only inside Razor/C# expressions..cshtmland.razor..csfiles, their highlighting, and their language servers are unchanged.Scope / limitations
aspnetcorerazorregistration and should be a separate change.