-
Notifications
You must be signed in to change notification settings - Fork 676
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
Support for source generators #4215
Comments
@iSazonov Sorry you are running into issues with Generators. Can you share your full OmniSharp log from the Output pane? |
@JoeRobich I experimented with source generators in last days and they works very strange. I see .Net team intends to improve them in the next .Net 6.0 milestone and actively use them in the .Net Runtime. I guess they will have to make a lot of changes to how it works. I don't think there is anything that can be done in OmniSharp right now due to the limitations in their implementation. PS: after I disabled analyzers in OmniSharp config IntelliSense works in the source generator file. |
@iSazonov shared the implementation in another issue as iSazonov/PowerShell@80e5ba9 I'm not sure if this is because of the System.Reflection.MetadataLoadContext reference there; the that's going to be bringing in other dependencies that aren't being packaged by the generator package. @iSazonov was there a reason you're using MetadataLoadContext to access symbols as opposed to accessing them in via the Roslyn symbol models? That'll be a lot faster (you're not reloading symbols multiple times) and would also avoid your loading issue. |
@jakubfijalkowski I used a code from TypeCatalogGen project from PowerShell repository (the tool is used today in design time.). Thanks for the idea to use Roslyn symbol models! I will try this after source generators become more available in .Net 6.0. |
I got similar error:
I was getting same error in Visual Studio 2022 and Omnisharp, however building and running tests work. FIXED Your Generator project must target This is a CSProj that worked for the generator: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.0.0" PrivateAssets="all" />
</ItemGroup>
</Project> (Note that main project can still target .net6.0) |
Omnisharp and Visual Studio 2022 aren't internally running on net6.0, so we can't run code targeting that. (It's still a mix of Mono and the traditional .NET Framework). That's why we have you target netstandard2.0, so stuff can run everywhere. |
Unclear if this is related to #4550 - the inability to properly navigate generated source files - but that's the challenge I'm running into. More specifically, while you can access generated source, that generated source won't let you navigate back to the main project or to other symbol references/definitions. Let's say you have a source generator project public namespace MyProj;
public class GeneratedClass1
{
public void DoWork()
{
throw new NotSupportedException();
}
} If you hit F12 on a usage of Here's where the problem comes in - because of that weird folder name. If you then click on
I would expect to get the metadata for If you set |
I did just discover that if I'm in the debugger in VS Code I can step into and out of generated code just fine, so it does appear to primarily be an issue with navigating and not with actually locating or stepping into/out of that code at runtime. |
#5339 will add support for find-references when the result exists in a generated file. Features in the generated files themselves (such as find references, outline viewer, etc) need work to be enabled. |
@333fred Are these great additions already in public version we can use? And is there anything else that needs to be done to finally resolve this request? |
They will be in the next release of the vscode extension, I believe. |
Issue Type: Bug
.Net team introduced source generators and OmniSharp doesn't work correctly with them.
I enabled Analyzers in VS Code and this works well. After I added a source generator to a project Intellisense doesn't work in the source generator file and I see errors in log.
It seems OmniSharp run the source generator like an analyzer although it shouldn't have to.
Extension version: 1.23.6
VS Code version: Code 1.51.1 (e5a624b788d92b8d34d1392e4c4d9789406efe8f, 2020-11-10T23:34:32.027Z)
OS version: Windows_NT x64 10.0.18363
System Info
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: unavailable_off
opengl: enabled_on
protected_video_decode: unavailable_off
rasterization: unavailable_off
skia_renderer: disabled_off_ok
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
The text was updated successfully, but these errors were encountered: