Ejemplo n.º 1
0
        public ISelectedRange GetSelectedRange(IPsiSourceFile sourceFile, DocumentRange documentRange)
        {
            (IT4File t4File, IFile codeBehindFile) = GetFiles(sourceFile, documentRange);

            ITreeNode t4Node = t4File?.FindNodeAt(documentRange);

            if (t4Node == null)
            {
                return(null);
            }

            // if the current selection is inside C# code, use the C# extend selection directly
            if (codeBehindFile != null)
            {
                ISelectEmbracingConstructProvider codeBehindProvider = PsiShared.GetComponent <PsiProjectFileTypeCoordinator>()
                                                                       .GetByPrimaryPsiLanguageType(codeBehindFile.Language)
                                                                       .SelectNotNull(fileType => Shell.Instance.GetComponent <IProjectFileTypeServices>().TryGetService <ISelectEmbracingConstructProvider>(fileType))
                                                                       .FirstOrDefault();

                ISelectedRange codeBehindRange = codeBehindProvider?.GetSelectedRange(sourceFile, documentRange);
                if (codeBehindRange != null)
                {
                    return(new T4CodeBehindWrappedSelection(t4File, codeBehindRange));
                }
            }

            return(new T4NodeSelection(t4File, t4Node));
        }
Ejemplo n.º 2
0
        private IEnumerable <IClrDeclaredElement> FindReferencesWithinAssociatedAssembly(IDataContext context,
                                                                                         ISolution solution, ITextControl textControl, IClrTypeName clrTypeClassName,
                                                                                         IEnumerable <TestCopProjectItem> targetProjects)
        {
            if (clrTypeClassName == null)
            {
                ResharperHelper.AppendLineToOutputWindow(solution.Locks,
                                                         "FindReferencesWithinAssociatedAssembly() - clrTypeClassName was null");
                return(new List <IClrDeclaredElement>());
            }

            IPsiServices services = solution.GetPsiServices();

            ISearchDomain searchDomain;

            if (this.Settings.FindAnyUsageInTestAssembly)
            {
                searchDomain = PsiShared.GetComponent <SearchDomainFactory>().CreateSearchDomain(
                    targetProjects.SelectMany(proj => proj.Project.GetAllProjectFiles().Select(p => p.GetPsiModule())));
            }
            else
            {
                // look for similar named files that also have references to this code
                List <ProjectFileFinder.Match> items = new List <ProjectFileFinder.Match>();

                foreach (TestCopProjectItem projectItem in targetProjects)
                {
                    projectItem.Project.Accept(new ProjectFileFinder(items, projectItem.FilePattern));
                }

                searchDomain = PsiShared.GetComponent <SearchDomainFactory>()
                               .CreateSearchDomain(items.Select(p => p.ProjectFile.ToSourceFile()));
            }

            ISymbolScope declarationsCache = solution.GetPsiServices().Symbols
                                             .GetSymbolScope(LibrarySymbolScope.NONE, false); //, currentProject.GetResolveContext());

            ITypeElement declaredElement = declarationsCache.GetTypeElementByCLRName(clrTypeClassName);

            IReference[] findReferences =
                services.Finder.FindReferences(declaredElement, searchDomain, new ProgressIndicator(textControl.Lifetime));

            List <IClassDeclaration> findReferencesWithinAssociatedAssembly =
                findReferences.Select(p => p.GetTreeNode().GetContainingNode <IClassDeclaration>(true)).ToList();

            return(findReferencesWithinAssociatedAssembly
                   .Select(p => p.DeclaredElement).ToList()
                   .Select(p => p as IClrDeclaredElement).ToList());
        }