0

I'd like to create a new extension that allows some kind of text templating similar to Microsoft's T4 runtime text templating engine.

Those templates can contain C# code and I'd like to have LSP functionality for these snippets within the Visual Studio text editor, i.e. renaming, go to definition, hover tips etc.

Is there a way to use/connect to the existing C# language server in such a way that I can send the C# code snippets to it for processing?

How does the Razor engine in ASP.net do it?

sonntam
  • 358
  • 1
  • 2
  • 14
  • The Razor support code base is at GitHub, https://github.com/dotnet/razor-tooling so if you have time you can dig all goodies out. – Lex Li Feb 19 '22 at 19:33
  • Thanks, I know about the repository already. Without any leads on where to start looking in the code-base I think it is unfathomable for me due to inexperience on my side. I‘m hoping someone with experience can help me get started. – sonntam Feb 19 '22 at 20:46
  • 1
    Sadly Microsoft didn't have complete documentation around that repo, but the top project is `Microsoft.VisualStudio.LanguageServerClient.Razor.csproj` and the things handling Razor/HTML/C# is in `Microsoft.VisualStudio.LanguageServer.ContainedLanguage.csproj`. The project descriptions give you minimal hints on what they are and whether you should look deeper. – Lex Li Feb 19 '22 at 22:35
  • Digging for a while revealed to me, that the Razor project uses the OmiSharp C# language server internally (see [here](https://github.com/dotnet/razor-tooling/blob/main/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs#L79)). As it seems for the C# LSP to be working within Razor documents all of the source files/packages/projects referenced in the opened project need to be parsed by OmniSharp. That means that there are two separate C# LSPs running with the same data. The one VS comes with and OmniSharp. Shame... – sonntam Feb 20 '22 at 18:09

0 Answers0