Finding references of a variable in SDK

I am beginning to explore the possibility of using the ReSharper SDK to implement some custom plugins to help out our development.  The first one I started with will need to look at the parameters being passed into a constructor and find all the references to those parameters to determine the appropriate action.  I am struggling to figure out how to do this in my ContextAction.  Could someone point me to some documentation or provide me with some help to programmatically get a list of all the references of a parameter?

Comment actions Permalink

Hi Evan. You should be able to use an instance of the IFinder interface to get what you need. Once you've got the parameter, you can call something like:

var finder = parameter.GetPsiServices().Finder;
var references = finder.FindAllReferences(parameter);

FindAllReferences is an extension method on the IFinder interface, and there are a couple of other useful extension methods that might be worth checking out. For example, if you want to find references for all parameters, you can call finder.Find and pass in an array of the parameter elements.

Hope this helps.

Comment actions Permalink

Thanks Matt!  That does help.  I had stumbled across the finder stuff, but didn't see the extension methods to use it programmatically.


Please sign in to leave a comment.