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?

2 Answers 2

2
  var document = context.GetData(DocumentModel.DataConstants.DOCUMENT);
  var solution = context.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);
  var psiModule = document.GetPsiSourceFile(solution).GetPsiModule();
Sign up to request clarification or add additional context in comments.

Comments

1

You can try getting the solution like so:

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

2 Comments

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. Большое спасибо!
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.