-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linter for cshtml (Razor) files #546
Comments
Unfortunately, OmniSharp doesn't support razor files by itself. VSCode has support using an extra plugin, but it is not simple getting them to work together - if you try in VSCode and check the OmniSharp logs, you can see that there are temp files being generated and sent to OmniSharp-roslyn. For example, an I have no idea how or if we can do something similar here, if someone wants to try then a PR would be great. But just telling OmniSharp-vim to lint |
This capability would be amazing. |
I've had a slightly more detailed look into this, and my conclusion is still that this is not something that this repo can support. Here's what VSCode does with razor files as far as I can tell:
I'm not 100% about this flow but those elements are all involved. We could handle some of this but I don't think we should start secondary language servers in this plugin. If someone wants to work on razor support, my suggestion is to create a new plugin which relies on OmniSharp-vim for the OmniSharp-roslyn part. However it is possible that there are licensing issues preventing rzls from being used outside VSCode (I have no idea if this is the case, I just know that the VSCode debugger is licensed that way). If anyone is interested, this is what the translated .cshtml file looks like:
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
// <auto-generated/>
#pragma warning disable 1591
namespace razor.Pages
{
#line hidden
using TModel = global::System.Object;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
#nullable restore
#line 1 "c:/code/test/razor/Pages/_ViewImports.cshtml"
using razor;
#line default
#line hidden
#nullable disable
public class Pages_Index : global::Microsoft.AspNetCore.Mvc.RazorPages.Page
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
#nullable restore
#line 2 "c:/code/test/razor/Pages/Index.cshtml"
IndexModel __typeHelper = default!;
#line default
#line hidden
#nullable disable
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static System.Object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
#nullable restore
#line 3 "c:/code/test/razor/Pages/Index.cshtml"
ViewData["Title"] = "Home page";
#line default
#line hidden
#nullable disable
}
#pragma warning restore 1998
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; }
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<IndexModel> Html { get; private set; }
public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<IndexModel> ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<IndexModel>)PageContext?.ViewData;
public IndexModel Model => ViewData.Model;
}
}
#pragma warning restore 1591
// 1 |
@nickspoons Thank you for looking into that. In the meantime, I am just creating a vim plugin that will automate the creation of .razor files with code behind files from vim. omnisharp-vim is an amazing plugin with coc and ale. It is unfortunate that coc recommends coc-omnisharp instead. I was sticking with vscode until I discovered that using omnisharp-vim instead of coc-omnisharp was the way to go. As I am just starting to get the skills necessary to know how to do most things in vim, I have just written my first vim scripts for the ftplugins and compiler directories to automate csharp workflow. i.e. (:help 41.12, :help 41.13). Off the top of your head, do you know if I am just rewriting what already exists? |
Hi @dball-adashi, Working out scripts like that is a very good way to get into vimscript. If you want some inspiration, have a look here |
Any news on this? Or steps on how I can implement this? |
Will blazor be supported in any future? |
The same answers as previously, but in short:
|
+1 on this. I don't want to go back to vscode or visual studio, just got addicted to neovim recently. This capability of supporting .razor files would be extremely appreciated given that I work with dotnet and C# daily for my work. @nickspoons, any possible hints here in that issue? sublimelsp/LSP-OmniSharp#3
|
Another +1! |
Would be awesome. A lack of |
+1 here |
Can people stop adding comments saying "+1" please? I've explained why this is not trivial, and that I'm not going to do it. If anyone wants to do the work I'm more than happy to help and provide advice, testing and debug support, whatever you need. Until then "+1" isn't getting us anywhere. |
I will try to make a blazor plugin, but I require more information regarding how the LSP error alert system works. If you could provide me with a guide about it it would be great. |
if ur able to make something for vim this would be a huge win for all non vscode editors |
ok so getting rzls to build and work wasnt so hard (i just cloned razor and |
I am working on a plugin to hopefully work towards support for this is anyone is looking to collaborate |
@tris203, With a recent Neovim version for your plugin, how do we configure it with With the "LspAttach" event. Not sure what to pass to |
Create an issue in the repo if you need more but at the moment it's done through a setup function which creates the autocmds and starts the server etc. The details are in the README It is by no means production ready yet though |
@tris203, thanks. I couldn't get your plugin to work :( I created an issue on your repository. Help is appreciated. Looking forward to get this plugin working and enhance the dev exprience for C# community. |
.cs
files are setup with an Ale linter that works great, but.cshtml
files are not. The Omnisharp linter should work just fine if configured for.cshtml
files as well.The text was updated successfully, but these errors were encountered: