private void FindTextual(
            [NotNull] string searchText, [NotNull] ISolution solution,
            [NotNull] List <IOccurence> consumer, [NotNull] CheckForInterrupt checkCanceled)
        {
#if RESHARPER8
            using (var pool = new MultiCoreFibersPool(GoToWordPoolName, myShellLocks, myConfigurations))
                using (var fibers = pool.Create("Files scan for textual occurances"))
#elif RESHARPER81 || RESHARPER9
            using (var fibers = myTaskHost.CreateBarrier(
                       myLifetime, checkCanceled, sync: false, takeReadLock: false))
#endif
                {
                    foreach (var psiSourceFile in GetAllSolutionFiles(solution))
                    {
                        if (IsFilteredFile(psiSourceFile))
                        {
                            continue;
                        }

                        var sourceFile = psiSourceFile;
                        fibers.EnqueueJob(() =>
                        {
                            using (ReadLockCookie.Create())
                            {
                                SearchInFile(searchText, sourceFile, consumer, checkCanceled);
                            }
                        });

                        if (checkCanceled())
                        {
                            return;
                        }
                    }
                }
        }
        public override ICollection<IOccurence> Search(IProgressIndicator progressIndicator)
        {
            var typeElements = new List<ITypeDeclaration>();

            var multiCoreFibersPool = new MultiCoreFibersPool("Search type declarations", locks);
            using (IMultiCoreFibers multiCoreFibers = multiCoreFibersPool.Create())
            {
                foreach (var project in solution.GetAllProjects())
                {
                    var sourceFiles = project.GetAllProjectFiles().SelectMany(projectFile => projectFile.ToSourceFiles());
                    foreach (var psiSourceFile in sourceFiles)
                    {
                        IFile file = psiSourceFile.GetPsiFile(CSharpLanguage.Instance);
                        if (file == null)
                        {
                            continue;
                        }

                        multiCoreFibers.EnqueueJob(() => file.ProcessChildren<ITypeDeclaration>(typeElements.Add));
                    }
                }
            }

            return (from typeDeclaration in typeElements
                    let element = typeDeclaration.DeclaredElement
                    where element != null
                    where componentRegistration.IsSatisfiedBy(element)
                    select new DeclaredElementOccurence(element)).Cast<IOccurence>().ToList();
        }
Ejemplo n.º 3
0
        public override ICollection <IOccurence> Search(IProgressIndicator progressIndicator)
        {
            var typeElements = new List <ITypeDeclaration>();

            var multiCoreFibersPool = new MultiCoreFibersPool("Search type declarations", locks);

            using (IMultiCoreFibers multiCoreFibers = multiCoreFibersPool.Create())
            {
                foreach (var project in solution.GetAllProjects())
                {
                    var sourceFiles = project.GetAllProjectFiles().SelectMany(projectFile => projectFile.ToSourceFiles());
                    foreach (var psiSourceFile in sourceFiles)
                    {
                        IFile file = psiSourceFile.GetCSharpFile();
                        if (file == null)
                        {
                            continue;
                        }

                        multiCoreFibers.EnqueueJob(() => file.ProcessChildren <ITypeDeclaration>(typeElements.Add));
                    }
                }
            }

            return((from typeDeclaration in typeElements
                    let element = typeDeclaration.DeclaredElement
                                  where element != null
                                  where componentRegistration.IsSatisfiedBy(element)
                                  select new DeclaredElementOccurence(element)).Cast <IOccurence>().ToList());
        }
        private bool PrepareWordIndex(
            [NotNull] ISolution solution, [NotNull] IWordIndex wordIndex, [NotNull] CheckForInterrupt checkCanceled)
        {
            var persistentIndexManager = solution.GetComponent <IPersistentIndexManager>();

#if RESHARPER8
            using (var pool = new MultiCoreFibersPool(GoToWordPoolName, myShellLocks, myConfigurations))
                using (var fibers = pool.Create("Updating word index cache"))
#elif RESHARPER81 || RESHARPER9
            using (var fibers = myTaskHost.CreateBarrier(
                       myLifetime, checkCanceled, sync: false, takeReadLock: false))
#endif
                {
                    var wordCache = (ICache)wordIndex;
                    foreach (var psiSourceFile in GetAllSolutionFiles(solution))
                    {
                        // workaround WordIndex2 implementation, to force indexing
                        // unknown project file types like *.txt files and other
                        var fileToCheck = psiSourceFile.Properties.ShouldBuildPsi
            ? psiSourceFile : new SourceFileToBuildCache(psiSourceFile);

                        if (!wordCache.UpToDate(fileToCheck))
                        {
                            var sourceFile = psiSourceFile;
                            fibers.EnqueueJob(() =>
                            {
                                using (ReadLockCookie.Create())
                                {
                                    var data = wordCache.Build(sourceFile, false);
                                    wordCache.Merge(sourceFile, data);

                                    persistentIndexManager.OnPersistentCachesUpdated(sourceFile);
                                }
                            });
                        }

                        if (checkCanceled())
                        {
                            return(false);
                        }
                    }
                }

            return(true);
        }
        private bool PrepareWordIndex(
            [NotNull] ISolution solution, [NotNull] IWordIndex wordIndex, [NotNull] CheckForInterrupt checkCancelled)
        {
            var persistentIndexManager = solution.GetComponent<IPersistentIndexManager>();

            #if RESHARPER8
              using (var pool = new MultiCoreFibersPool(GoToWordPoolName, myShellLocks, myConfigurations))
              using (var fibers = pool.Create("Updating word index cache"))
            #elif RESHARPER81
              using (var fibers = myTaskHost.CreateBarrier(
            myLifetime, checkCancelled, sync: false, takeReadLock: false))
            #endif
              {
            var wordCache = (ICache) wordIndex;
            foreach (var psiSourceFile in GetAllSolutionFiles(solution))
            {
              // workaround WordIndex2 implementation, to force indexing
              // unknown project file types like *.txt files and other
              var fileToCheck = psiSourceFile.Properties.ShouldBuildPsi
            ? psiSourceFile : new SourceFileToBuildCache(psiSourceFile);

              if (!wordCache.UpToDate(fileToCheck))
              {
            var sourceFile = psiSourceFile;
            fibers.EnqueueJob(() => {
              var data = wordCache.Build(sourceFile, false);
              wordCache.Merge(sourceFile, data);

              persistentIndexManager.OnPersistentCachesUpdated(sourceFile);
            });
              }

              if (checkCancelled()) return false;
            }
              }

              return true;
        }
        private void FindTextual(
            [NotNull] string searchText, [NotNull] ISolution solution,
            [NotNull] List<IOccurence> consumer, [NotNull] CheckForInterrupt checkCancelled)
        {
            #if RESHARPER8
              using (var pool = new MultiCoreFibersPool(GoToWordPoolName, myShellLocks, myConfigurations))
              using (var fibers = pool.Create("Files scan for textual occurances"))
            #elif RESHARPER81
              using (var fibers = myTaskHost.CreateBarrier(
            myLifetime, checkCancelled, sync: false, takeReadLock: false))
            #endif
              {
            foreach (var psiSourceFile in GetAllSolutionFiles(solution))
            {
              if (IsFilteredFile(psiSourceFile)) continue;

              var sourceFile = psiSourceFile;
              fibers.EnqueueJob(() =>
              {
            SearchInFile(searchText, sourceFile, consumer, checkCancelled);
              });

              if (checkCancelled()) return;
            }
              }
        }