Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

EDIT: I have code like this:

var syntax = (LocalDeclarationStatementSyntax) node;
var type = syntax.Declaration.Type;
var typeSymbol = semanticModel.GetTypeInfo(type).ConvertedType;

I would like to find out all usages / references of typeSymbol. TypeSymbol represents Class located in source code.

To do so, I wanted to use SymbolFinder, but methods of SymbolFinder require instance of Solution... In older version of Roslyn, Document was given as Method Parameter of diagnostics, you could get to project and solution.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
346 views
Welcome To Ask or Share your Answers For Others

1 Answer

There is no current way to get at workspace or to do multi-project analysis when implementing a diagnostic analyzer, as these need to be able to run against a single compilation using only the command-line compiler. You can, however, do this work in the code fix provider once a diagnostic is determined.

If you just want to find all places where once class implements another, you can make a compilation wide diagnostic analyzer and examine all declarations before deciding on a diagnostic. You can do this by implementing both ICompilationStartedAnalyzer and ICompilationEndedAnalyzer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...