Example #1
0
            public Task OnReferenceFoundAsync(SymbolAndProjectId symbolAndProjectId, ReferenceLocation loc)
            {
                var    fileName = loc.Document.FilePath;
                var    offset   = loc.Location.SourceSpan.Start;
                string projectedName;
                int    projectedOffset;

                if (workspace.TryGetOriginalFileFromProjection(fileName, offset, out projectedName, out projectedOffset))
                {
                    fileName = projectedName;
                    offset   = projectedOffset;
                }
                var sr = new MemberReference(symbolAndProjectId.Symbol, fileName, offset, loc.Location.SourceSpan.Length);

                if (antiDuplicatesSet.Add(sr))
                {
                    var root   = loc.Location.SourceTree.GetRoot();
                    var node   = root.FindNode(loc.Location.SourceSpan);
                    var trivia = root.FindTrivia(loc.Location.SourceSpan.Start);
                    sr.ReferenceUsageType = HighlightUsagesExtension.GetUsage(node);
                }
                return(Task.CompletedTask);
            }
        internal static void FindRefs(ISymbol symbol)
        {
            var monitor   = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true, true);
            var workspace = TypeSystemService.Workspace as MonoDevelopWorkspace;

            if (workspace == null)
            {
                return;
            }
            var solution = workspace.CurrentSolution;

            Task.Run(async delegate {
                try {
                    var antiDuplicatesSet = new HashSet <SearchResult> (new SearchResultComparer());
                    foreach (var loc in symbol.Locations)
                    {
                        if (monitor.CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }

                        if (!loc.IsInSource)
                        {
                            continue;
                        }
                        var fileName = loc.SourceTree.FilePath;
                        var offset   = loc.SourceSpan.Start;
                        string projectedName;
                        int projectedOffset;
                        if (workspace.TryGetOriginalFileFromProjection(fileName, offset, out projectedName, out projectedOffset))
                        {
                            fileName = projectedName;
                            offset   = projectedOffset;
                        }
                        var sr = new MemberReference(symbol, fileName, offset, loc.SourceSpan.Length);
                        sr.ReferenceUsageType = ReferenceUsageType.Declariton;
                        antiDuplicatesSet.Add(sr);
                        monitor.ReportResult(sr);
                    }

                    foreach (var mref in await SymbolFinder.FindReferencesAsync(symbol, solution, monitor.CancellationToken).ConfigureAwait(false))
                    {
                        foreach (var loc in mref.Locations)
                        {
                            if (monitor.CancellationToken.IsCancellationRequested)
                            {
                                return;
                            }
                            var fileName = loc.Document.FilePath;
                            var offset   = loc.Location.SourceSpan.Start;
                            string projectedName;
                            int projectedOffset;
                            if (workspace.TryGetOriginalFileFromProjection(fileName, offset, out projectedName, out projectedOffset))
                            {
                                fileName = projectedName;
                                offset   = projectedOffset;
                            }
                            var sr = new MemberReference(symbol, fileName, offset, loc.Location.SourceSpan.Length);
                            if (antiDuplicatesSet.Add(sr))
                            {
                                var root              = loc.Location.SourceTree.GetRoot();
                                var node              = root.FindNode(loc.Location.SourceSpan);
                                var trivia            = root.FindTrivia(loc.Location.SourceSpan.Start);
                                sr.ReferenceUsageType = HighlightUsagesExtension.GetUsage(node);

                                monitor.ReportResult(sr);
                            }
                        }
                    }
                } catch (OperationCanceledException) {
                } catch (Exception ex) {
                    if (monitor != null)
                    {
                        monitor.ReportError("Error finding references", ex);
                    }
                    else
                    {
                        LoggingService.LogError("Error finding references", ex);
                    }
                } finally {
                    if (monitor != null)
                    {
                        monitor.Dispose();
                    }
                }
            });
        }
Example #3
0
        public override Task <IEnumerable <SearchResult> > FindReferences(string documentationCommentId, MonoDevelop.Projects.Project hintProject, CancellationToken token)
        {
            return(Task.Run(async delegate {
                var result = new List <SearchResult> ();
                var antiDuplicatesSet = new HashSet <SearchResult> (new SearchResultComparer());
                var lookup = await TryLookupSymbol(documentationCommentId, hintProject, token);
                if (lookup == null || !lookup.Success)
                {
                    return Enumerable.Empty <SearchResult> ();
                }

                var workspace = TypeSystemService.AllWorkspaces.FirstOrDefault(w => w.CurrentSolution == lookup.Solution) as MonoDevelopWorkspace;
                if (workspace == null)
                {
                    return Enumerable.Empty <SearchResult> ();
                }
                foreach (var sym in await GatherSymbols(lookup.Symbol, lookup.Solution, token))
                {
                    foreach (var loc in sym.Locations)
                    {
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }

                        if (!loc.IsInSource)
                        {
                            continue;
                        }
                        var fileName = loc.SourceTree.FilePath;
                        var offset = loc.SourceSpan.Start;
                        string projectedName;
                        int projectedOffset;
                        if (workspace.TryGetOriginalFileFromProjection(fileName, offset, out projectedName, out projectedOffset))
                        {
                            fileName = projectedName;
                            offset = projectedOffset;
                        }
                        var sr = new MemberReference(sym, fileName, offset, loc.SourceSpan.Length);
                        sr.ReferenceUsageType = ReferenceUsageType.Declaration;
                        antiDuplicatesSet.Add(sr);
                        result.Add(sr);
                    }

                    foreach (var mref in await SymbolFinder.FindReferencesAsync(sym, lookup.Solution, token).ConfigureAwait(false))
                    {
                        foreach (var loc in mref.Locations)
                        {
                            if (token.IsCancellationRequested)
                            {
                                break;
                            }
                            var fileName = loc.Document.FilePath;
                            var offset = loc.Location.SourceSpan.Start;
                            string projectedName;
                            int projectedOffset;
                            if (workspace.TryGetOriginalFileFromProjection(fileName, offset, out projectedName, out projectedOffset))
                            {
                                fileName = projectedName;
                                offset = projectedOffset;
                            }
                            var sr = new MemberReference(sym, fileName, offset, loc.Location.SourceSpan.Length);


                            if (antiDuplicatesSet.Add(sr))
                            {
                                var root = loc.Location.SourceTree.GetRoot();
                                var node = root.FindNode(loc.Location.SourceSpan);
                                var trivia = root.FindTrivia(loc.Location.SourceSpan.Start);
                                sr.ReferenceUsageType = HighlightUsagesExtension.GetUsage(node);
                                result.Add(sr);
                            }
                        }
                    }
                }
                return (IEnumerable <SearchResult>)result;
            }));
        }