atom / language-csharp

C# language support for Atom
Other
62 stars 53 forks source link

WIP: Add Razor Pages grammar #120

Closed worldbeater closed 6 years ago

worldbeater commented 6 years ago

This pull request brings syntax highlighting to C# Razor Pages — a templating engine that powers ASP .NET Core server-side rendering. Razor Pages files have .cshtml extension.

The grammar was taken from demyte/language-cshtml repository that doesn't seem to be actively maintained. The PR is heavily based on @austincummings work (Thank you, Austin!) I've converted the grammar to CSON format to improve readability and maintainability.

Benefits

If we include this grammar into atom/language-csharp repository, there will be no need to install additional Atom plugins — everything that is needed for a C# developer will be included in a single package that is available out-of-box.

Another benefit is, that we will also make GitHub syntax highlighting for .cshtml work as expected. For now, it is completely broken — GitHub uses C# grammar for Razor Pages, so HTML doesn't get highlighted at all.

This may close https://github.com/github/linguist/issues/3760

Lightshow

Atom! One Light color theme.

image

GitHub Lightshow. There is also a playground here.

image

damieng commented 6 years ago

I'm really not sure about this - a lot of stuff that probably shouldn't ship with Atom already does and it can be a bottleneck for getting improvements through given the resource constraints the team operates under and the surface area they are responsible for.

The package ecosystem was very much created to alleviate this problem.

Perhaps the owner of demyte/language-cshtml would be amenable to transferring the repo over to a community member who wants to maintain the Razor syntax.

damieng commented 6 years ago

The other caveat is that this repo right now is just a mirror from the C# language grammar from Microsoft with some tweaks - that I hope to push back upstream or provide an automated script-to- re-apply.

I'd rather not revert this repository to original work. How different is the proposed one from Microsoft's cshtml grammar?

austincummings commented 6 years ago

@worldbeater You may be interested in looking at this repo instead of the PR I made, I believe it's more up to date.

@damieng The proposed grammar is very different. I completely rewrote the one it is based off of from the ground up originally for the VS Code extension I mentioned to @worldbeater.

this repo right now is just a mirror from the C# language grammar from Microsoft

Does this mean that Atom relies on the grammars that VS Code uses? Which in turn relies on demyte/language-cshtml? If so then resolving this issue I opened up on VS Code should cascade down to Atom with the new grammar. (The issue is closed for now, I haven't had the chance lately to take it forward).

damieng commented 6 years ago

@austincummings Atom relies on the same C# grammar as VSCode and gets it from the same upstream location - notably https://github.com/dotnet/csharp-tmLanguage

VSCode may rely on demyte/language-cshtml but that is further downstream in VSCode's own dependencies not where we obtain the grammar from.

worldbeater commented 6 years ago

So what are the preferred options? Should we reference https://github.com/austincummings/razor-plus from Linguist and Atom and continue contributing there? Grammar that VSCode uses doesn't seem to highlight markup and code properly, that's why @austincummings has begun his work. And both Atom and GitHub don't provide .cshtml highlighting out-of-box 😢