Ejemplo n.º 1
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();
                }
            }
Ejemplo n.º 2
0
            private void ReportMatchResult(Project project, INavigateToSearchResult result)
            {
                var navigateToItem = new NavigateToItem(
                    result.Name,
                    result.Kind,
                    GetNavigateToLanguage(project.Language),
                    result.SecondarySort,
                    result,
                    GetMatchKind(result.MatchKind),
                    result.IsCaseSensitive,
                    _displayFactory);

                _callback.AddItem(navigateToItem);
            }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 4
0
            private void ReportMatchResult(Project project, INavigateToSearchResult result)
            {
                var matchedSpans = result.NameMatchSpans.SelectAsArray(t => t.ToSpan());

                var patternMatch = new PatternMatch(GetPatternMatchKind(result.MatchKind),
                                                    punctuationStripped: true, result.IsCaseSensitive, matchedSpans);

                var navigateToItem = new NavigateToItem(
                    result.Name,
                    result.Kind,
                    GetNavigateToLanguage(project.Language),
                    result.SecondarySort,
                    result,
                    patternMatch,
                    _displayFactory);

                _callback.AddItem(navigateToItem);
            }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
        private void ProcessItem(SyntaxToken name, string nameText, TextSpan nodeSpan, string kind, SyntaxNode parent, Glyph icon)
        {
            if (!nodeSpan.IsInRootFile)
            {
                return;
            }

            if (name == null)
            {
                return;
            }

            if (!Contains(name.Text, _searchValue, StringComparison.CurrentCultureIgnoreCase))
            {
                return;
            }

            var description = GetDescription(parent);

            Action navigateCallback = () => _textView.NavigateTo(
                _bufferGraphFactoryService,
                new SnapshotSpan(_snapshot, nodeSpan.Start, nodeSpan.Length),
                new SnapshotSpan(_snapshot, name.Span.Start, name.Span.Length));

            var itemDisplay = new NavigateToItemDisplay(icon.GetIcon(_glyphService),
                                                        nameText, description, null, navigateCallback);

            _callback.AddItem(new NavigateToItem(
                                  name.Text,
                                  kind,
                                  HlslConstants.LanguageName,
                                  name.Text,
                                  itemDisplay,
                                  (name.Text == _searchValue) ? MatchKind.Exact : MatchKind.Substring,
                                  _displayFactory));
        }
            public bool EnterNode(LibraryNode node, CancellationToken ct)
            {
                if (ct.IsCancellationRequested)
                {
                    _navCallback.Invalidate();
                    return(false);
                }

                var parentNode = _path.Peek();

                _path.Push(node);

                // We don't want to report modules, since they map 1-to-1 to files, and those are already reported by the standard item provider
                if (node.NodeType.HasFlag(LibraryNodeType.Package))
                {
                    return(true);
                }

                // Match name against search string.
                string    name = node.Name ?? "";
                MatchKind matchKind;

                if (_searchValue.Length > 2 && _searchValue.StartsWith("/") && _searchValue.EndsWith("/"))
                {
                    if (!_regexComparer.IsCandidateMatch(name, _searchValue.Substring(1, _searchValue.Length - 2)))
                    {
                        return(true);
                    }
                    matchKind = MatchKind.Regular;
                }
                else if (name.Equals(_searchValue, StringComparison.Ordinal))
                {
                    matchKind = MatchKind.Exact;
                }
                else if (_comparer.IsCandidateMatch(name, _searchValue))
                {
                    matchKind = MatchKind.Regular;
                }
                else
                {
                    return(true);
                }

                string kind;

                if (!_sggToNavItemKind.TryGetValue(node.GlyphType, out kind))
                {
                    kind = "";
                }

                var text = node.GetTextRepresentation(VSTREETEXTOPTIONS.TTO_DISPLAYTEXT);

                if (parentNode != null)
                {
                    switch (parentNode.GlyphType)
                    {
                    case StandardGlyphGroup.GlyphGroupModule:
                        text += string.Format(" [of module {0}]", parentNode.Name);
                        break;

                    case StandardGlyphGroup.GlyphGroupClass:
                        text += string.Format(" [of class {0}]", parentNode.Name);
                        break;

                    case StandardGlyphGroup.GlyphGroupMethod:
                        text += string.Format(" [nested in function {0}]", parentNode.Name);
                        break;
                    }
                }

                var tag = new ItemTag {
                    Node = node, GlyphService = _itemProvider._glyphService
                };

                _navCallback.AddItem(new NavigateToItem(text, kind, "Python", "", tag, matchKind, PythonNavigateToItemDisplayFactory.Instance));
                return(true);
            }
Ejemplo n.º 9
0
        void Response(AsyncServerMessage msg)
        {
            switch (msg)
            {
            case AsyncServerMessage.LanguageLoaded languageInfo:
                var spanClassInfos = languageInfo.spanClassInfos;
                if (_spanClassInfos.IsDefaultOrEmpty)
                {
                    _spanClassInfos = spanClassInfos;
                }
                else if (!spanClassInfos.IsDefaultOrEmpty)
                {
                    var bilder = ImmutableArray.CreateBuilder <SpanClassInfo>(_spanClassInfos.Length + spanClassInfos.Length);
                    bilder.AddRange(_spanClassInfos);
                    bilder.AddRange(spanClassInfos);
                    _spanClassInfos = bilder.MoveToImmutable();
                }
                break;

            case AsyncServerMessage.FindSymbolReferences findSymbolReferences:
                // передать всем вьюхам отображаемым на экране

                foreach (var fileModel in _fileModels)
                {
                    foreach (var textViewModel in fileModel.TextViewModels)
                    {
                        textViewModel.Update(findSymbolReferences);
                    }
                }
                break;

            case AsyncServerMessage.FoundDeclarations found:
                if (_callback == null)
                {
                    break;
                }

                MatchKind calcKibd(DeclarationInfo decl)
                {
                    var spans = decl.NameMatchRuns;

                    switch (spans.Length)
                    {
                    case 0: return(MatchKind.None);

                    case 1:
                        var name = decl.Name;
                        var span = decl.NameMatchRuns[0];
                        if (span.StartPos == 0)
                        {
                            return(span.Length == name.Length ? MatchKind.Exact : MatchKind.Prefix);
                        }
                        return(MatchKind.Substring);

                    default:
                        return(MatchKind.Regular);
                    }
                }

                foreach (var decl in found.declarations)
                {
                    // So far we can use the following kinds "OtherSymbol", "NitraSymbol"
                    // TODO: Allows add user spetified kinds
                    var loc    = decl.Location;
                    var fileId = loc.File.FileId;
                    var path   = fileId == FileId.Invalid ? "<no file>" : Client.StringManager.GetPath(fileId);
                    var ext    = fileId == FileId.Invalid ? "" : Path.GetExtension(path);
                    var lang   = _config.Languages.Where(x => x.Extensions.Contains(ext)).Select(x => x.Name).SingleOrDefault() ?? "<Unknown Nitra language>";
                    _callback.AddItem(new NavigateToItem(decl.Name, "NitraSymbol", lang, decl.FullName, decl, calcKibd(decl), false, _nitraNavigateToItemProvider.GetFactory(this)));
                }

                break;
            }
        }