簡體   English   中英

自定義 Roslyn 代碼分析器在實時分析中運行的具體要求?

[英]Specific Requirements for custom Roslyn Code Analyzer to run in live analysis?

我有一個基於 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)這在實時模式下自動不起作用,或者有沒有辦法將其重構為與實時分析兼容的不同結構?

CompilationStart 不是問題。 它不會導致分析器只能構建。 但是,CompilationEnd 是問題所在。 它們只是構建,並且它們的相關代碼修復不會顯示在 IDE 中。這是出於性能原因。

相關討論: https://github.com/do.net/roslyn/issues/51653

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM