コード例 #1
0
            public Searcher(
                Solution solution,
                IAsynchronousOperationListener asyncListener,
                INavigateToItemDisplayFactory displayFactory,
                INavigateToCallback callback,
                string searchPattern,
                bool searchCurrentDocument,
                IImmutableSet <string> kinds,
                CancellationToken cancellationToken)
            {
                _solution              = solution;
                _asyncListener         = asyncListener;
                _displayFactory        = displayFactory;
                _callback              = callback;
                _searchPattern         = searchPattern;
                _searchCurrentDocument = searchCurrentDocument;
                _kinds             = kinds;
                _cancellationToken = cancellationToken;
                _progress          = new ProgressTracker((_, current, maximum) => callback.ReportProgress(current, maximum));

                if (_searchCurrentDocument)
                {
                    var documentService = _solution.Workspace.Services.GetService <IDocumentTrackingService>();
                    var activeId        = documentService.TryGetActiveDocument();
                    _currentDocument = activeId != null?_solution.GetDocument(activeId) : null;
                }
            }
コード例 #2
0
            private void DoWork(object unused)
            {
                try
                {
                    var fileList        = GetFiles();
                    var parallelOptions = new ParallelOptions();
                    parallelOptions.CancellationToken      = _cancellationToken;
                    parallelOptions.MaxDegreeOfParallelism = Environment.ProcessorCount;

                    Parallel.For(0, fileList.Count, parallelOptions, i =>
                    {
                        string file = fileList[i];
                        IEnumerable <ParseItem> items = GetItems(file, _searchValue);
                        foreach (ParseItem sel in items)
                        {
                            _cancellationToken.ThrowIfCancellationRequested();
                            _navigateToCallback.AddItem(new NavigateToItem(_searchValue, NavigateToItemKind.Field, "CSS", _searchValue, new CssGoToLineTag(sel, file), MatchKind.Exact, _providerFactory));
                        }

                        var backgroundProgress = Interlocked.Increment(ref _backgroundProgress);
                        _navigateToCallback.ReportProgress(backgroundProgress, fileList.Count);
                    });
                }
                catch
                {
                    // Don't let exceptions from the background thread reach the ThreadPool.  Swallow them
                    // here and complete the navigate operation
                }
                finally
                {
                    _navigateToCallback.Done();
                }
            }
コード例 #3
0
        private async Task FindMatchesAsync(INavigateToCallback callback, string searchValue, CancellationToken token)
        {
            var matchers = new List <Tuple <FuzzyStringMatcher, string, MatchKind> > {
                Tuple.Create(new FuzzyStringMatcher(FuzzyMatchMode.Prefix), searchValue, MatchKind.Prefix),
                Tuple.Create(new FuzzyStringMatcher(_matchMode), searchValue, MatchKind.Regular)
            };

            if (searchValue.Length > 2 && searchValue.StartsWith("/") && searchValue.EndsWith("/"))
            {
                matchers.Insert(0, Tuple.Create(
                                    new FuzzyStringMatcher(FuzzyMatchMode.RegexIgnoreCase),
                                    searchValue.Substring(1, searchValue.Length - 2),
                                    MatchKind.Regular
                                    ));
            }

            var opts = GetMemberOptions.NoMemberRecursion | GetMemberOptions.IntersectMultipleResults | GetMemberOptions.DetailedInformation;

            foreach (var a in _analyzers)
            {
                a.Task = a.Analyzer.SendRequestAsync(new AP.GetAllMembersRequest {
                    options = opts
                });
            }
            foreach (var a in _analyzers)
            {
                a.Result = await a.Task;
            }
            token.ThrowIfCancellationRequested();

            int progress = 0;
            int total    = _analyzers.Sum(r => r.Result?.completions?.Length ?? 0);

            foreach (var a in _analyzers)
            {
                token.ThrowIfCancellationRequested();
                if ((a.Result?.completions?.Length ?? 0) == 0)
                {
                    continue;
                }

                foreach (var res in FilterResults(a.ProjectName, a.Result.completions, matchers))
                {
                    callback.AddItem(res);
                }

                progress += a.Result.completions.Length;
                callback.ReportProgress(progress, total);
            }
        }
コード例 #4
0
        private async Task FindMatchesAsync(INavigateToCallback callback, string searchValue, CancellationToken token)
        {
            var matcher = _services.PatternMatcherFactory.CreatePatternMatcher(
                searchValue,
                new PatternMatcherCreationOptions(CultureInfo.CurrentUICulture, PatternMatcherCreationFlags.AllowFuzzyMatching | PatternMatcherCreationFlags.AllowSimpleSubstringMatching)
                );

            var opts = GetMemberOptions.NoMemberRecursion | GetMemberOptions.IntersectMultipleResults | GetMemberOptions.DetailedInformation;

            foreach (var a in _analyzers)
            {
                a.Task = a.Analyzer.SendRequestAsync(new AP.GetAllMembersRequest {
                    options = opts
                });
            }
            foreach (var a in _analyzers)
            {
                a.Result = await a.Task;
            }
            token.ThrowIfCancellationRequested();

            int progress = 0;
            int total    = _analyzers.Sum(r => r.Result?.completions?.Length ?? 0);

            foreach (var a in _analyzers)
            {
                token.ThrowIfCancellationRequested();
                if ((a.Result?.completions?.Length ?? 0) == 0)
                {
                    continue;
                }

                foreach (var res in FilterResults(a.ProjectName, a.Result.completions, matcher))
                {
                    callback.AddItem(res);
                }

                progress += a.Result.completions.Length;
                callback.ReportProgress(progress, total);
            }
        }
コード例 #5
0
        private void Search(INavigateToCallback callback, string searchValue)
        {
            var i = 0;

            foreach (var file in Util.GetSolutionAllSdmapFiles(_serviceProvider))
            {
                if (_cancellationTokenSource.IsCancellationRequested)
                {
                    break;
                }

                i += 1;

                foreach (var match in SdmapIdListener.FindMatches(file, searchValue))
                {
                    callback.AddItem(match.ToNavigateToItem(_navigateToItemDisplayFactory));
                }

                callback.ReportProgress(i, Math.Max(100, i + 1));
            }

            callback.Done();
        }
コード例 #6
0
 public void ReportProgress(int current, int maximum)
 {
     _callback.ReportProgress(current, maximum);
 }