public static IEnumerable<MemberReference> FindReferences (Solution solution, INode member, ISearchProgressMonitor monitor = null) { var scope = GetScope (member); ReferenceFinder finder; ProjectDom dom = null; ICompilationUnit unit = null; IEnumerable<INode> searchNodes = new INode[] { member }; if (member is LocalVariable) { dom = ((LocalVariable)member).DeclaringMember.DeclaringType.SourceProjectDom; unit = ((LocalVariable)member).CompilationUnit; } else if (member is IParameter) { dom = ((IParameter)member).DeclaringMember.DeclaringType.SourceProjectDom; unit = ((IParameter)member).DeclaringMember.DeclaringType.CompilationUnit; } else if (member is IType) { dom = ((IType)member).SourceProjectDom; unit = ((IType)member).CompilationUnit; } else if (member is IMember) { dom = ((IMember)member).DeclaringType.SourceProjectDom; unit = ((IMember)member).DeclaringType.CompilationUnit; searchNodes = CollectMembers (dom, (IMember)member); } switch (scope) { case RefactoryScope.File: case RefactoryScope.DeclaringType: if (dom == null || unit == null) yield break; finder = GetReferenceFinder (DesktopService.GetMimeTypeForUri (unit.FileName)); if (finder == null) yield break; foreach (var searchNode in searchNodes) { foreach (var foundReference in finder.FindReferences (dom, unit.FileName, searchNode)) { yield return foundReference; } } break; case RefactoryScope.Project: if (dom == null) yield break; if (monitor != null) monitor.BeginTask (GettextCatalog.GetString ("Search reference in project..."), dom.Project.Files.Count); int counter = 0; foreach (var file in dom.Project.Files) { finder = GetReferenceFinder (DesktopService.GetMimeTypeForUri (file.FilePath)); if (finder == null) continue; foreach (var searchNode in searchNodes) { foreach (var foundReference in finder.FindReferences (dom, file.FilePath, searchNode)) { yield return foundReference; } } if (monitor != null) { if (counter % 10 == 0) monitor.Step (10); counter++; } } if (monitor != null) monitor.EndTask (); break; case RefactoryScope.Solution: if (monitor != null) monitor.BeginTask (GettextCatalog.GetString ("Search reference in solution..."), solution.GetAllProjects ().Count); foreach (var project in solution.GetAllProjects ()) { var currentDom = ProjectDomService.GetProjectDom (project); foreach (var file in project.Files) { finder = GetReferenceFinder (DesktopService.GetMimeTypeForUri (file.FilePath)); if (finder == null) continue; foreach (var searchNode in searchNodes) { foreach (var foundReference in finder.FindReferences (currentDom, file.FilePath, searchNode)) { yield return foundReference; } } } if (monitor != null) monitor.Step (1); } if (monitor != null) monitor.EndTask (); break; } }
static IEnumerable <SearchResult> FindReferences( AbstractDProject project, INode member, ISearchProgressMonitor monitor = null) { var searchResults = new List <SearchResult>(); var parseCache = project != null ? project.ParseCache : DCompilerService.Instance.GetDefaultCompiler().GenParseCacheView(); var modules = new List <DModule>(); if (project != null) { foreach (var p in project.GetSourcePaths(IdeApp.Workspace.ActiveConfiguration)) { modules.AddRange(GlobalParseCache.EnumModulesRecursively(p, null)); } } else { modules.Add((IdeApp.Workbench.ActiveDocument.ParsedDocument as MonoDevelop.D.Parser.ParsedDModule).DDom); } if (monitor != null) { monitor.BeginStepTask("Scan for references", modules.Count, 1); } List <ISyntaxRegion> references = null; var ctxt = ResolutionContext.Create(parseCache, null); foreach (var mod in modules) { if (mod == null) { continue; } try { references = ReferencesFinder.Scan(mod, member, ctxt).ToList(); if (references.Count < 1) { if (monitor != null) { monitor.Step(1); } continue; } // Sort the references by code location references.Sort(new IdLocationComparer()); // Get actual document code var targetDoc = TextFileProvider.Instance.GetTextEditorData(new FilePath(mod.FileName)); foreach (var reference in references) { CodeLocation loc; if (reference is AbstractTypeDeclaration) { loc = ((AbstractTypeDeclaration)reference).NonInnerTypeDependendLocation; } else if (reference is IExpression) { loc = reference.Location; } else { continue; } searchResults.Add(new SearchResult(new FileProvider(mod.FileName, project), targetDoc.LocationToOffset(loc.Line, loc.Column), member.Name.Length)); } } catch (Exception ex) { LoggingService.LogWarning("Error during reference search", ex); } if (monitor != null) { monitor.Step(1); } } if (monitor != null) { monitor.EndTask(); } return(searchResults); }
static IEnumerable <SearchResult> FindReferences( DProject project, INode member, ISearchProgressMonitor monitor = null) { var searchResults = new List <SearchResult>(); var parseCache = project != null ? project.ParseCache : ParseCacheList.Create(DCompilerService.Instance.GetDefaultCompiler().ParseCache); var modules = project == null ? project.LocalFileCache as IEnumerable <IAbstractSyntaxTree> : new[] { (Ide.IdeApp.Workbench.ActiveDocument.ParsedDocument as MonoDevelop.D.Parser.ParsedDModule).DDom }; if (monitor != null) { monitor.BeginStepTask("Scan for references", modules.Count(), 1); } List <ISyntaxRegion> references = null; foreach (var mod in modules) { if (mod == null) { continue; } try { references = ReferencesFinder.Scan(mod, member, new ResolverContextStack(parseCache, new ResolverContext())).ToList(); if (member != null && member.NodeRoot != null && (member.NodeRoot as IAbstractSyntaxTree).FileName == mod.FileName) { references.Insert(0, new IdentifierDeclaration(member.Name) { Location = member.NameLocation, EndLocation = new CodeLocation(member.NameLocation.Column + member.Name.Length, member.NameLocation.Line) }); } if (references.Count < 1) { if (monitor != null) { monitor.Step(1); } continue; } // Sort the references by code location references.Sort(new IdLocationComparer()); // Get actual document code var targetDoc = Ide.TextFileProvider.Instance.GetTextEditorData(new FilePath(mod.FileName)); foreach (var reference in references) { CodeLocation loc; if (reference is AbstractTypeDeclaration) { loc = ((AbstractTypeDeclaration)reference).NonInnerTypeDependendLocation; } else if (reference is IExpression) { loc = ((IExpression)reference).Location; } else { continue; } searchResults.Add(new SearchResult(new FileProvider(mod.FileName, project), targetDoc.LocationToOffset(loc.Line, loc.Column), member.Name.Length)); } } catch (Exception ex) { LoggingService.LogWarning("Error during reference search", ex); } if (monitor != null) { monitor.Step(1); } } if (monitor != null) { monitor.EndTask(); } return(searchResults); }