microsoft / monaco-editor

A browser based code editor
https://microsoft.github.io/monaco-editor/
MIT License
40.43k stars 3.6k forks source link

Razor syntax highlighting does not recognize @code or @functions #1997

Open Merlin04 opened 4 years ago

Merlin04 commented 4 years ago

monaco-editor version: 0.2.0 Browser: Tested on Chromium and Firefox OS: Ubuntu 19.10

When the language is set to razor, @code or @functions is not recognized and shows up (along with all the C# code inside of it) in the default text color. This can be reproduced by going to the Monaco Editor homepage, setting the language to razor, and entering this code:

@{
    @* This C# code will have syntax highlighting *@
    var test = "testing";
    if (true)
    {
        Console.WriteLine("testing");
    }
}
@code {
    @* This C# code will not have syntax highlighting *@
    var test = "testing";
    if (true)
    {
        Console.WriteLine("testing");
    }
}
@functions {
    @* This C# code will also not have syntax highlighting *@
    var test = "testing";
    if (true)
    {
        Console.WriteLine("testing");
    }
}
akorchev commented 3 years ago

I too am interested in making this work. The built-in VS Code razor syntax seems to be here: https://github.com/OmniSharp/omnisharp-vscode/blob/master/src/razor/syntaxes/aspnetcorerazor.tmLanguage.json

How can one translate this to the Monarch syntax?

jokonokon commented 1 year ago

plz

simon-biber commented 1 year ago

Could we at least update razor.contribution.ts to declare the '.razor' extension in addition to '.cshtml'?

This could help to enable syntax highlighting on Azure DevOps Repos for Blazor's .razor files. This doesn't fix the issue about the @code and @function syntax but it should at least make the majority of the file display with highlighting instead of plain text.