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

CodeFixProvider for diagnostics reported by IIncrementalGenerator #67354

Closed
GianvitoDifilippo opened this issue Mar 17, 2023 · 2 comments · Fixed by #67953
Closed

CodeFixProvider for diagnostics reported by IIncrementalGenerator #67354

GianvitoDifilippo opened this issue Mar 17, 2023 · 2 comments · Fixed by #67953
Labels
Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@GianvitoDifilippo
Copy link

GianvitoDifilippo commented Mar 17, 2023

I wrote a source generator that implements IIncrementalGenerator and can report diagnostics. Then, I wrote a CodeFixProvider for such diagnostics, but the code actions do not show up.
I think I followed all the steps for implementing the code fix provider because another one I wrote works fine for diagnostics reported by a DiagnosticAnalyzer.
Is this not supported or is there something I missed?
I am using Visual Studio 17.5.1 with Roslyn 4.0.1 - I also tried version 4.5.0 but nothing changed.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 17, 2023
@CyrusNajmabadi
Copy link
Member

I don't see anything that woudl make this work. @mavasani i would only expect that we call into DiagnosticAnalyzers to get the diagnostics that a code fix can fix. Correct?

@GianvitoDifilippo
Copy link
Author

GianvitoDifilippo commented Mar 22, 2023

I'm in a situation where I need to gather contextual information from symbol analysis and then elaborate on these pieces of information both for generating source code and for reporting diagnostics, for which I wrote some code fixes.
I tried moving the analysis to a separate DiagnosticAnalyzer, but the diagnostic pipeline was composed of a Symbol action and a CompilationEnd action, which I have found it cannot run inside the IDE, let alone code fixing.
The workaround I'm using now is serializing the diagnostics produced by the generator to a generated file, which is then analyzed by a DiagnosticAnalyzer, which then reports the actual diagnostics. This works, but I find it a bit cumbersome and not the best for performance; better workarounds would be very welcomed :)

It would be very helpful if code fix providers could also fix generator-reported diagnostics.

@mavasani mavasani changed the title Question: CodeFixProvider for diagnostics reported by IIncrementalGenerator CodeFixProvider for diagnostics reported by IIncrementalGenerator Apr 25, 2023
mavasani added a commit to mavasani/roslyn that referenced this issue Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants