-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
This comes from #3394 (comment)
I could really use this [API to find references to a symbol] for a few analyzers I've written so far.
NonEncapsulatedOrMutableFieldAnalyzer (Vannevelj/VSDiagnostics#292):
I need to find all the references (in this class and outside of it) to a specific field so I can determine if it is ever passed asreforout. If it is, I can't change it to a property (which is what the corresponding code fix does).RedundantPrivateSetter (Vannevelj/VSDiagnostics#58):
I have to find out whether the property is being set somewhere or not. Now I manually look through all the nodes in the inner class but accounting for partial classes and all that jazz becomes cumbersome.
@jmarolf suggested the following API:
public static Task<IEnumerable<ReferencedSymbol>> FindReferencesAsync(
ISymbol symbol,
Compilation compilation,
CancellationToken cancellationToken = default(CancellationToken))Relevant comment by @srivatsn
I don't think you want a SymbolFinder like API in the compiler layer - it's going to go through the entire compilation on demand and kill analyzer perf. I think this issue is about adding a
RegisterSymbolReferenceAction(callback, ISymbol). The callback will get called whenever there's a reference to the passed in symbol. That way the references are computed as the compiler goes through the project and any cumulative actions can be taken atCompilationEnd.