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?

有帮助吗?

解决方案

  var document = context.GetData(DocumentModel.DataConstants.DOCUMENT);
  var solution = context.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);
  var psiModule = document.GetPsiSourceFile(solution).GetPsiModule();

其他提示

You can try getting the solution like so:

var solution =
  dataContext.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top