Omnisharp-roslyn: What plans exist regarding C# source generator support?

Created on 10 Sep 2020  路  8Comments  路  Source: OmniSharp/omnisharp-roslyn

Hello,

I saw this blog post on the .NET blog recently, which indicates that source generators are far enough along that they're actually usable in practice. So, in one of my projects, I ported a T4 template to a C# source generator to try it out. While this worked fine during build, it turns out that OmniSharp doesn't currently support them well: The generated types do not show up in IntelliSense, so lots of errors appear throughout the solution.

In an earlier post, it says:

Note: you will currently need to restart Visual Studio to see IntelliSense and get rid of errors with the early tooling experience

Restarting OmniSharp, or even VS Code as a whole, does not appear to help.

So, I just wanted to check if there are any plans regarding support for C# source generators in OmniSharp? (Assuming that this is a lack of support, and not just a bug.)

question

Most helpful comment

So from the Roslyn perspective, we expected that the core support added to the Roslyn Workspace APIs was going to mean support in Omnisharp lit up automatically, but it seems it's not always working reliably. There's a couple of bugs we're currently investigating and working on fixing. We are trying to use source generators in the Roslyn project itself, and since we have some developers using VS Code we are working to make sure we don't break ourselves!

All 8 comments

So from the Roslyn perspective, we expected that the core support added to the Roslyn Workspace APIs was going to mean support in Omnisharp lit up automatically, but it seems it's not always working reliably. There's a couple of bugs we're currently investigating and working on fixing. We are trying to use source generators in the Roslyn project itself, and since we have some developers using VS Code we are working to make sure we don't break ourselves!

To update this, basic scenarios (completion, hover, semantic colorization) seem to work. However, things like go-to-def create ugly errors that need to be resolved somehow.

With omnisharp.path set to latest, I get this in the OmniSharp Log window:

        Failure while loading the analyzer reference 'libflare-gen': Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

dotnet build on the command line works fine.

The generator project looks like this:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <AssemblyName>libflare-gen</AssemblyName>
        <RootNamespace>Flare.Generator</RootNamespace>
        <TargetFramework>net5.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.CodeAnalysis" Version="3.8.0-3.final" />
        <!-- TODO: Remove these in the final .NET 5.0 release. -->
        <PackageReference Include="System.Collections.Immutable" Version="5.0.0-rc.1.20451.14" />
        <PackageReference Include="System.Reflection.Metadata" Version="5.0.0-rc.1.20451.14" />
    </ItemGroup>
</Project>

I'm guessing there's probably some sort of version mismatch between the generator project and the Roslyn version used by OmniSharp?

@alexrp generators need to target netstandard2.0

@amis92 I recall I switched from netstandard2.0 to net5.0 for the generator project due to some type load issues at dotnet build time. But I think that was with version 3.7.0 of Roslyn. It seems that switching to netstandard2.0 with Roslyn at 3.8.0-3.final indeed works both for dotnet build and OmniSharp!

yes it's the same requirement for analyzers

Am i correct, that completion end basic things should work in the "latest" omnisharp path?
Is there still a need to restart omnisharp after updating the sourcegenerator?
And if so, is there a button to do so? :)

Edit: i managed to make it work, but its a bit of a hassle:
Runnin on the "latest" path of omnisharp, one has to actually make a build (with dotnet build) and only then a restart of omnisharp with ctrl+p->omnisharp:restart will show the latest highliting for the generated classes.

I hope this can be improved a bit in the near future :)

So, I've been experimenting with source generators recently. My experience is better than what @SeidChr reported back in November, in that I don't need to be on a preview branch (I'm using OmniSharp 1.37.6), and I don't seem to need to restart OmniSharp each time I rebuild the generator DLL.

That said, what doesn't work at all is any diagnostics reported by the generator via GeneratorExecutionContext.ReportDiagnostic(). My generator spits out numerous helpful errors, and they show up as expected when building directly with msbuild. Just not in the error pane in VSCode, or the helpful squiggly underlines in the file pane. It would be extremely helpful if VS Code could show those errors.

Edit: Also, "Go To Definition" is still broken.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RononDex picture RononDex  路  4Comments

nickspoons picture nickspoons  路  4Comments

Nazeehe picture Nazeehe  路  3Comments

david-driscoll picture david-driscoll  路  6Comments

natemcmaster picture natemcmaster  路  5Comments