dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
499 stars 191 forks source link

Razor IntelliSense: Allow Different File Extensions #5010

Closed warappa closed 3 years ago

warappa commented 3 years ago

Szenario

I want to use razor functionality with MJML templates in VS Code 1.51.1. (MJML is an responsive email framework to create an all-email-client-compliant html)

MJML-tooling switches file extensions while generating output, so I want to use the .mjml extension to describe the structure in MJML markup with Razor code interwoven, and then with MJML-tooling output a transformed regular .razor file consumed later on by a templating service (RazorEngineCore).

The Problem

I thought I just switch the language mode and everything is good. But:

Expectation

A file-extension should not matter if I explicitly force the language mode to aspnetcorerazor.

Reproduce

  1. Create new empty ASP.NET Core project
  2. Create a model class
    public class TestModel
    {
    public string Value { get; set; }
    }
  3. Add SomeMailTemplate.mjml file

    @{
    // only for IntelliSense
    TestModel Model = null;
    }
    <mjml>
    <mj-head>
    <mj-title>Test</mj-title>
    </mj-head>
    
    <mj-body background-color="#004850">
    <mj-section padding="0" background-color="#ffffff">
      <mj-column>
    
        <mj-text color="#009CAD">
          <h1>Hello!</h1>
        </mj-text>
        <mj-text padding-bottom="0" padding-top="0" color="#2b2216">
          <p>Value</p>
          <p>
            @Model.Value
            </p>
        </mj-text>
    
      </mj-column>
    </mj-section>
    
    </mj-body>
    </mjml>
  4. Switch Language Mode for this file to aspnetcorerazor
  5. Remove Value from @Model.Value and trigger IntelliSense
  6. Only generic suggestions are provided, but no C# IntelliSense
  7. Rename extension to .razor
  8. Repeat steps 4-5
  9. Proper IntelliSense is provided

Further technical details

dotnet --info

.NET SDK (gemäß "global.json"):
 Version:   5.0.100
 Commit:    5044b93829

Laufzeitumgebung:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.100\

Host (useful for support):
  Version: 5.0.0
  Commit:  cf258a14b7     

.NET SDKs installed:      
  2.1.807 [C:\Program Files\dotnet\sdk]
  2.2.207 [C:\Program Files\dotnet\sdk]
  5.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
javiercn commented 3 years ago

@warappa thanks for contacting us.

@NTaylorMullen any thoughts?

NTaylorMullen commented 3 years ago

@NTaylorMullen any thoughts?

So it'd be an interesting idea to decouple our language server from the actual file extensions. It'd be a two fold process where we'd need to make the compiler file path independent and then a second to change how our language server "detects" files.

One problem I don't envision being possible to easily overcome is that our language server has to watch the disk for specific file types (defined by file extension) in order to know when they get renamed, deleted, etc. This influences things like _ViewImports, possible Blazor components etc.

NTaylorMullen commented 3 years ago

Thanks for contacting us. While this may be a great idea, it is not aligned with our long-term vision to make it part of the framework. For many other ideas which don't belong to the framework we encourage the community to build and ship on their own, contributing to the expanding .NET Ecosystem.

You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.