public static ContextRange ToContextRange([NotNull] this ITextControl textControl) { if (textControl == null) { throw new ArgumentNullException("textControl"); } return(ContextRange.Smart(textControl.ToDataContext())); }
protected virtual void DumperShortCutAction(IProjectFile projectFile, TextWriter textwriter) { Lifetimes.Using((lifetime => { using (ITextControl textControl = OpenTextControl(projectFile)) { var jumpToTestFileAction = GetShortcutAction(textwriter); if (jumpToTestFileAction == null) { return; } IDataContext context = DataContextOfTestTextControl.Create(lifetime, textControl, _loadedTestSolution); Func <Lifetime, DataContexts, IDataContext> dataContext = textControl.ToDataContext(); if ((jumpToTestFileAction).Update(context, new ActionPresentation(), null)) { (jumpToTestFileAction).Execute(context, null); } } })); }
void IExecutableAction.Execute(IDataContext context, DelegateExecute nextExecute) { ITextControl textControl = context.GetData(TextControlDataConstants.TEXT_CONTROL); if (textControl == null) { MessageBox.ShowError("Text control unavailable."); return; } ISolution solution = context.GetData(JetBrains.ProjectModel.DataContext.ProjectModelDataConstants.SOLUTION); if (solution == null) { return; } IClrTypeName clrTypeClassName = ResharperHelper.GetClassNameAppropriateToLocation(solution, textControl); if (clrTypeClassName == null) { return; } var typeDeclaration = ResharperHelper.FindFirstCharpTypeDeclarationInDocument(solution, textControl.Document); if (typeDeclaration == null) { return; } var currentProject = context.GetData(JetBrains.ProjectModel.DataContext.ProjectModelDataConstants.Project); if (currentProject == null) { ResharperHelper.AppendLineToOutputWindow("Internal Error: No current project"); return; } var targetProjects = currentProject.GetAssociatedProjects(textControl.ToProjectFile(solution)); if (targetProjects.IsEmpty()) { ResharperHelper.AppendLineToOutputWindow("Unable to locate associated assembly - check project namespaces and testcop Regex"); //ProjectMappingHelper.GetProjectMappingHeper().DumpDebug(solution); return; } var settings = solution.GetPsiServices().SettingsStore .BindToContextTransient(ContextRange.Smart(textControl.ToDataContext())) .GetKey <TestFileAnalysisSettings>(SettingsOptimization.OptimizeDefault); var baseFileName = ResharperHelper.GetBaseFileName(context, solution); bool isTestFile = baseFileName.EndsWith(settings.TestClassSuffixes()); if (isTestFile != currentProject.IsTestProject()) { ResharperHelper.AppendLineToOutputWindow( string.Format("Don't know how to navigate with '{0}' within project '{1}'. It is a {2} file within a {3} project" , baseFileName, currentProject.Name, isTestFile ? "test" : "code", currentProject.IsTestProject() ? "test" : "code")); return; } var elementsFoundInTarget = new List <IClrDeclaredElement>(); var elementsFoundInSolution = new List <IClrDeclaredElement>(); foreach (var singleTargetProject in targetProjects) { foreach (var patternMatcher in singleTargetProject.FilePattern) { //FindByClassName elementsFoundInSolution.AddRangeIfMissing(ResharperHelper.FindClass(solution, patternMatcher.RegEx.ToString()), _declElementMatcher); elementsFoundInTarget.AddRangeIfMissing(ResharperHelper.FindClass(solution, patternMatcher.RegEx.ToString(), new List <IProject>() { singleTargetProject.Project }), _declElementMatcher); if (!isTestFile) { //Find via filename (for when we switch to test files) var otherMatches = ResharperHelper.FindFirstTypeWithinCodeFiles(solution, patternMatcher.RegEx, singleTargetProject.Project); elementsFoundInTarget.AddRangeIfMissing(otherMatches, _declElementMatcher); } } } if (!isTestFile) { var references = FindReferencesWithinAssociatedAssembly(context, solution, textControl, clrTypeClassName, targetProjects); elementsFoundInTarget.AddRangeIfMissing(references, _declElementMatcher); } JumpToTestMenuHelper.PromptToOpenOrCreateClassFiles(_menuDisplayer, textControl.Lifetime, context, solution , currentProject, clrTypeClassName, targetProjects , elementsFoundInTarget, elementsFoundInSolution); }