Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

c# - Roslyn: Current Workspace in Diagnostic with code fix project

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...