自定义 Roslyn 代码分析器在实时分析中运行的具体要求?
我有一个基于 Roslyn 的代码分析器和 Codefix。当直接从 AnalyzerCodeBlock 创建 ReportDiagnostic 时,它们将显示在实时分析中(Jetbrains Rider 中的问题)。
然而,它需要从解决方案中解析额外的数据来构建依赖树来做出决定。所以现在它的工作原理是这样的:
RegisterCompilationStartAction -> then it registers a RegisterCodeBlockStartAction to build a dependency tree
RegisterOperationAction -> Instead of generating the ReportDiagnostic directly, it puts the particular calls into a ConcurrentBag to analyze later.
RegisterCompilationEndAction -> When called, this analyzes the calls from RegisterOperationAction with the dependency tree generated in the RegisterCodeBlockStartAction and generates ReportDiagnostics with the combined information.
现在它只适用于构建,不适用于实时分析。我很想让它在实时分析中恢复工作(我已经启用了解决方案范围的分析),因为允许使用代码修复非常有用。
任何已知原因(例如使用任何 CompilationStart-End)的想法都不会在实时模式下自动工作,或者有没有办法将其重构为与实时分析兼容的不同结构?
I've got a Roslyn based Code Analyzer and Codefix. When directly creating the ReportDiagnostic from an AnalyzerCodeBlock, they would show up in live analysis (Problems in Jetbrains Rider).
However, it needs to parse additional data from the solution to build a dependency tree to make the decision. So now it works like this:
RegisterCompilationStartAction -> then it registers a RegisterCodeBlockStartAction to build a dependency tree
RegisterOperationAction -> Instead of generating the ReportDiagnostic directly, it puts the particular calls into a ConcurrentBag to analyze later.
RegisterCompilationEndAction -> When called, this analyzes the calls from RegisterOperationAction with the dependency tree generated in the RegisterCodeBlockStartAction and generates ReportDiagnostics with the combined information.
Now it only works on build, not in live analysis. I would love to get this back working in live analysis (I have enable solution-wide analysis enabled) since allowing use of the codefixes are incredibly useful.
Any idea of a known reason (like using any CompilationStart-End) this automatically doesn't work in live mode, or is there a way to refactor this into a different structure compatible with live analysis?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CompilationStart 不是问题。它不会导致分析器仅构建。然而,CompilationEnd 是问题所在。它们仅是构建的,并且其相关的代码修复不会显示在 IDE 中。这是出于性能原因。
相关讨论:https://github.com/dotnet/roslyn/issues/51653
CompilationStart isn't a problem. It doesn't cause an analyzer to be build-only. However, CompilationEnd is the problem. They're build only, and also their associated code fixes won't show in the IDE. This is for performance reasons.
Related discussion: https://github.com/dotnet/roslyn/issues/51653