Skip to content
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

What plans exist regarding C# source generator support? #1934

Closed
alexrp opened this issue Sep 10, 2020 · 10 comments
Closed

What plans exist regarding C# source generator support? #1934

alexrp opened this issue Sep 10, 2020 · 10 comments
Labels

Comments

@alexrp
Copy link

alexrp commented Sep 10, 2020

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.)

@jasonmalinowski
Copy link
Contributor

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!

@333fred
Copy link
Contributor

333fred commented Oct 3, 2020

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.

@alexrp
Copy link
Author

alexrp commented Oct 7, 2020

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?

@amis92
Copy link

amis92 commented Oct 9, 2020

@alexrp generators need to target netstandard2.0

@alexrp
Copy link
Author

alexrp commented Oct 9, 2020

@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!

@filipw
Copy link
Member

filipw commented Oct 9, 2020

yes it's the same requirement for analyzers

@SeidChr
Copy link

SeidChr commented Nov 27, 2020

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 :)

@Cifram
Copy link

Cifram commented Mar 6, 2021

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.

@jcawe
Copy link

jcawe commented May 10, 2021

Exists some workaround for the "Go To Definition"?

333fred added a commit to 333fred/omnisharp-roslyn that referenced this issue Jun 1, 2021
This adds a new response element to gotodefinition responses: SourceGeneratedFileInfo. This is similar to MetadataSource, except that unlike MetadataSource it's not tracked on a type/project basis, but rather as a document/project basis. Retrieving info about a source generated file can be done through the SourceGeneratedFileService endpoints:

* SourceGeneratedFileInfo - Gets the file content of a source generated file.
* UpdateSourceGeneratedFileInfo - Gets the updated content of a source generated file, if it has changed since the last time information was returned.
* SourceGeneratedFileClosed - Sent to the server to inform it that the editor has closed the generated file and it can stop tracking Document version info for that file.

Currently, the only way to get the info needed to open a source-generated file is via the gotodefinition endpoint. We'll want to add info to find-usages as well, but that's a job for another day. Contributes to OmniSharp#1934.
333fred added a commit to 333fred/omnisharp-roslyn that referenced this issue Jun 1, 2021
This adds a new response element to gotodefinition responses: SourceGeneratedFileInfo. This is similar to MetadataSource, except that unlike MetadataSource it's not tracked on a type/project basis, but rather as a document/project basis. Retrieving info about a source generated file can be done through the SourceGeneratedFileService endpoints:

* SourceGeneratedFileInfo - Gets the file content of a source generated file.
* UpdateSourceGeneratedFileInfo - Gets the updated content of a source generated file, if it has changed since the last time information was returned.
* SourceGeneratedFileClosed - Sent to the server to inform it that the editor has closed the generated file and it can stop tracking Document version info for that file.

Currently, the only way to get the info needed to open a source-generated file is via the gotodefinition endpoint. We'll want to add info to find-usages as well, but that's a job for another day. Contributes to OmniSharp#1934.
333fred added a commit to 333fred/omnisharp-roslyn that referenced this issue Jun 1, 2021
This adds a new response element to gotodefinition responses: SourceGeneratedFileInfo. This is similar to MetadataSource, except that unlike MetadataSource it's not tracked on a type/project basis, but rather as a document/project basis. Retrieving info about a source generated file can be done through the SourceGeneratedFileService endpoints:

* SourceGeneratedFileInfo - Gets the file content of a source generated file.
* UpdateSourceGeneratedFileInfo - Gets the updated content of a source generated file, if it has changed since the last time information was returned.
* SourceGeneratedFileClosed - Sent to the server to inform it that the editor has closed the generated file and it can stop tracking Document version info for that file.

Currently, the only way to get the info needed to open a source-generated file is via the gotodefinition endpoint. We'll want to add info to find-usages as well, but that's a job for another day. Contributes to OmniSharp#1934.
@filipw
Copy link
Member

filipw commented Dec 15, 2021

Go to def support was added in #2170

@filipw filipw closed this as completed Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants