0

I want to write a ReSharper Action that just calls a ContextAction. Is this possible? A ContextAction takes a Solution as a parameter, and an Action gets a DataContext on construction. So the question really becomes:

Can you get the current Solution from an instance of DataContext?

EDIT: Oops! I asked the wrong thing. The above is true, but not the real problem. Like Dmitri below says, you can get indeed the solution like so:

var solution = 
  dataContext.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);

The tricky bit is getting the _psiModule, which can be gotten from the ICSharpContextDataProvider which is passed in when the ContextAction is constructed, via provider.PsiModule. Can you get an ICSharpContextDataProvider or the correct PsiModule from the DataContext?

Matthew Piziak
  • 3,430
  • 4
  • 35
  • 49

2 Answers2

2
  var document = context.GetData(DocumentModel.DataConstants.DOCUMENT);
  var solution = context.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);
  var psiModule = document.GetPsiSourceFile(solution).GetPsiModule();
Dmitry Osinovskiy
  • 9,999
  • 1
  • 47
  • 38
1

You can try getting the solution like so:

var solution =
  dataContext.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION)
Dmitri Nesteruk
  • 23,067
  • 22
  • 97
  • 166
  • Hi, sorry, I made a mistake. The really difficult part is getting the `PsiModule`. I don't even know if it's possible, but I hope so. Thanks for all your help with the ReSharper questions I've been asking, by the way. Большое спасибо! – Matthew Piziak Jul 13 '12 at 20:54
  • Take a look at what `dataContext` has in it - just set a breakpoint and peek at what it contains. The contents are largely dependant on where you are when this is called. You might have, say, a type declaration, and you can take the PSI Module from that. – Dmitri Nesteruk Jul 13 '12 at 21:12