This project is read-only.

Current Workspace in Diagnostic with code fix project

Topics: APIs
Apr 21, 2014 at 7:42 PM
How can I get information about current Workspace (e.g project path, solution path) in Diagnostic with code fix project?

I am implementing Diagnostic of type ISyntaxNodeAnalyzer

I need to access SymbolFinder.FindImplementationsAsync, but to do so, I need Solution instance
Apr 22, 2014 at 9:34 PM
There is no way to get to a workspace (at least currently) from a diagnostic analyzer. The analyzers need to be able to run from the command-line compiler so can only be concerned with at most a single compilation. The SymbolFinder works across entire solutions with multiple projects/compilations. You can, however, implement an analyzer that is used across an entire compilation by implementing ICompilationStartedAnalyzer. ICompilationStartedAnalyzer is basically a factory for another analyzer that is constructed once per compilation analysis. This analyzer must implement ICompilationEndedAnalyzer but it can also implement other interfaces such as ISyntaxNodeAnalyzer. So you could make a single analyzer that observes all type declarations in a compilation and identifies those that implement a specific interface, and then at the end of all analysis, when ICompilationEndedAnalzyer.OnCompilationEnded is invoked, you can produce a diagnostic if you choose.
Marked as answer by mattwar on 4/22/2014 at 1:35 PM
Apr 22, 2014 at 10:35 PM
Edited Apr 22, 2014 at 10:35 PM
Thx for answer, but even if I implement ICompilationStartedAnalyzer and ICompilationEndedAnalyzer I still need to have instance of Solution to run SymbolFinder methods.
How can I use SymbolFinder in Diagnostic? Can you post me simple example?
Apr 23, 2014 at 12:21 AM
You won't be able to use SymbolFinder. I was trying to point out an alternative (albeit a lot more difficult to implement).