Example #1
0
        public void Test1()
        {
            var pcl  = ResolutionTests.CreateCache(@"module modA;

class A(T = int)
{
	static int prop;
	static A statA; // 6
}

A a = new A(); // 9

void main()
{
	A.prop = 3; // 13
	int b = A.prop + 4; // 14
	A.statA.statA = new A!float(); // 15
}
");
            var ctxt = ResolutionContext.Create(pcl, null, pcl[0]["modA"]);

            var refs = ReferencesFinder.Scan(pcl[0]["modA"]["A"].First(), ctxt) as List <ISyntaxRegion>;

            Assert.IsNotNull(refs);
            Assert.AreEqual(8, refs.Count);
        }
Example #2
0
        private static void GetReferencesInModule(DModule ast, StringBuilder refs, DNode n, ResolutionContext ctxt)
        {
            var res = ReferencesFinder.SearchModuleForASTNodeReferences(ast, n, ctxt);

            int cnt = res.Count();

            foreach (var r in res)
            {
                var rfilename = ast.FileName;
                var rloc      = r.Location;
                var ln        = String.Format("{0},{1},{2},{3}:{4}\n", rloc.Line, rloc.Column - 1, rloc.Line, rloc.Column, rfilename);
                refs.Append(ln);
            }
        }
Example #3
0
        private void DrawFooter()
        {
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Space(5);

                if (SearchResultsStorage.ReferencesFinderLastSearched.Length == 0)
                {
                    GUI.enabled = false;
                }
                if (UIHelpers.ImageButton("Refresh", "Restarts references search for the previous results.", CSIcons.Repeat))
                {
                    if (Event.current.control && Event.current.shift)
                    {
                        ReferencesFinder.debugMode = true;
                        AssetsMap.Delete();
                        Event.current.Use();
                    }
                    else
                    {
                        ReferencesFinder.debugMode = false;
                    }

                    EditorApplication.delayCall += () =>
                    {
                        //ReferencesFinder.FindAssetsReferences(SearchResultsStorage.ReferencesFinderLastSearched, false, true);
                        ReferencesFinder.GetReferences(SearchResultsStorage.ReferencesFinderLastSearched, null);
                    };
                }
                GUI.enabled = true;

                if (UIHelpers.ImageButton("Collapse all", "Collapses all tree items.", CSIcons.Collapse))
                {
                    treePanel.CollapseAll();
                }

                if (UIHelpers.ImageButton("Expand all", "Expands all tree items.", CSIcons.Expand))
                {
                    treePanel.ExpandAll();
                }

                if (UIHelpers.ImageButton("Clear results", "Clears results tree and empties cache.", CSIcons.Clear))
                {
                    SearchResultsStorage.ReferencesSearchResults      = null;
                    SearchResultsStorage.ReferencesFinderLastSearched = null;
                    Refresh(true);
                }
                GUILayout.Space(5);
            }
        }
Example #4
0
        public static void FindGameObjectWithComponentsReferences()
        {
            if (Time.unscaledTime.Equals(lastMenuCallTimestamp))
            {
                return;
            }
            if (Selection.gameObjects.Length == 0)
            {
                return;
            }

            ReferencesFinder.FindObjectsReferencesInHierarchy(Selection.gameObjects, true);

            lastMenuCallTimestamp = Time.unscaledTime;
        }
        public void DrawLeftColumnHeader()
        {
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Space(10);
                using (new GUILayout.VerticalScope())
                {
                    GUILayout.Space(10);
                    GUILayout.Label("<size=16><b>Search references of:</b></size>", UIHelpers.richLabel);
                    UIHelpers.Separator();
                    GUILayout.Space(10);

                    if (UIHelpers.ImageButton("All assets",
                                              "Traverses whole project to find where all assets are referenced.", CSIcons.Find))
                    {
                        if (Event.current.control && Event.current.shift)
                        {
                            ReferencesFinder.debugMode = true;
                            AssetsMap.Delete();
                            Event.current.Use();
                        }
                        else
                        {
                            ReferencesFinder.debugMode = false;
                        }

                        EditorApplication.delayCall += StartProjectReferencesScan;
                    }

                    if (ProjectScopeReferencesFinder.GetSelectedAssets().Length == 0)
                    {
                        GUI.enabled = false;
                    }

                    if (UIHelpers.ImageButton("Selected assets",
                                              "Adds selected Project View assets to the current search results.", CSIcons.Find))
                    {
                        EditorApplication.delayCall += () => ReferencesFinder.FindSelectedAssetsReferences();
                    }
                }
                GUILayout.Space(10);
            }

            GUI.enabled = true;
        }
Example #6
0
        protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args)
        {
            var paths            = DragAndDrop.paths;
            var objectReferences = DragAndDrop.objectReferences;

            if (objectReferences == null || objectReferences.Length == 0)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            for (var i = 0; i < objectReferences.Length; i++)
            {
                var monoBehaviour = objectReferences[i] as MonoBehaviour;
                if (monoBehaviour == null)
                {
                    continue;
                }

                var monoScript = MonoScript.FromMonoBehaviour(monoBehaviour);
                if (monoScript == null)
                {
                    continue;
                }

                objectReferences[i] = monoScript;
            }

            var assetsPaths = ReferencesFinder.GetSelectedAssets(objectReferences);

            if (assetsPaths.Length == 0)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            if (Event.current.type == EventType.DragPerform)
            {
                EditorApplication.delayCall += () => { ReferencesFinder.AddToSelectionAndRun(assetsPaths.ToArray()); };
                DragAndDrop.AcceptDrag();
            }

            return(DragAndDropVisualMode.Generic);
        }
Example #7
0
        protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args)
        {
            var objectReferences = DragAndDrop.objectReferences;

            if (objectReferences == null || objectReferences.Length == 0)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            for (var i = 0; i < objectReferences.Length; i++)
            {
                var monoBehaviour = objectReferences[i] as MonoBehaviour;
                if (monoBehaviour == null)
                {
                    continue;
                }

                var monoScript = MonoScript.FromMonoBehaviour(monoBehaviour);
                if (monoScript == null)
                {
                    continue;
                }

                objectReferences[i] = monoScript;
            }

            var ids         = CSObjectTools.GetObjectsInstanceIDs(objectReferences);
            var assetsPaths = ProjectScopeReferencesFinder.GetAssetsFromInstances(ids);

            if (assetsPaths.Length == 0)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            if (Event.current.type == EventType.DragPerform)
            {
                EditorApplication.delayCall += () => { ReferencesFinder.FindAssetsReferences(assetsPaths.ToArray()); };
                DragAndDrop.AcceptDrag();
            }

            return(DragAndDropVisualMode.Generic);
        }
Example #8
0
 public static void FindReferences()
 {
     ReferencesFinder.FindSelectedAssetsReferences();
 }
 private void StartProjectReferencesScan()
 {
     window.RemoveNotification();
     ReferencesFinder.FindAllAssetsReferences();
     window.Focus();
 }
Example #10
0
        private void DrawHeader()
        {
            using (new GUILayout.HorizontalScope())
            {
                using (new GUILayout.VerticalScope())
                {
                    GUILayout.Label("<size=13>Here you may check any project assets for all project references.</size>", UIHelpers.richWordWrapLabel);

                    if (UIHelpers.ImageButton("Find all assets references",
                                              "Traverses whole project to find where all assets are referenced.", CSIcons.Find))
                    {
                        if (Event.current.control && Event.current.shift)
                        {
                            ReferencesFinder.debugMode = true;
                            AssetsMap.Delete();
                            Event.current.Use();
                        }
                        else
                        {
                            ReferencesFinder.debugMode = false;
                        }
                        EditorApplication.delayCall += StartProjectReferencesScan;
                    }

                    if (ReferencesFinder.GetSelectedAssets().Length == 0)
                    {
                        GUI.enabled = false;
                    }
                    if (UIHelpers.ImageButton("Find selected assets references",
                                              "Adds selected Project View assets to the current search results.", CSIcons.Find))
                    {
                        EditorApplication.delayCall += () => ReferencesFinder.AddSelectedToSelectionAndRun();
                    }
                    GUI.enabled = true;
                }

                GUILayout.Space(30);

                using (new GUILayout.VerticalScope(UIHelpers.panelWithBackground, GUILayout.Width(250)))
                {
                    GUILayout.Space(5);
                    using (new GUILayout.HorizontalScope())
                    {
                        GUILayout.Space(3);
                        if (UIHelpers.ImageButton("Manage Filters... (" + MaintainerSettings.References.pathIgnoresFilters.Length + ")",
                                                  CSIcons.Gear, GUILayout.ExpandWidth(false)))
                        {
                            ReferencesFiltersWindow.Create();
                        }
                        GUILayout.FlexibleSpace();
                        if (UIHelpers.ImageButton(null, "Show some extra info and notes about " + ReferencesFinder.ModuleName + ".", CSIcons.HelpOutline, GUILayout.ExpandWidth(false)))
                        {
                            EditorUtility.DisplayDialog(ReferencesFinder.ModuleName + " Extra Info",
                                                        "Except buttons on this tab, you may use these commands to search for references:\n\n" +
                                                        "Search for asset references from the Project Browser context menu:\n" +
                                                        MaintainerMenu.ProjectBrowserContextReferencesFinderName + "\n\n" +
                                                        "Look for the MonoBehaviour and ScriptableObject references from the Components' or ScriptableObjects' context menus\n" +
                                                        MaintainerMenu.ScriptReferencesContextMenuName + "\n\n" +
                                                        "Or just drag && drop items from Project Browser or Inspector to the list." + "\n\n" +
                                                        "Note #1: you'll see only those references which Maintainer was able to figure out. " +
                                                        "Some kinds of references can't be statically found or not supported yet." + "\n\n" +
                                                        "Note #2: not referenced assets still may be used at runtime or from Editor scripting.", "OK");
                        }

                        GUILayout.Space(3);
                    }

                    MaintainerPersonalSettings.References.showAssetsWithoutReferences = GUILayout.Toggle(
                        MaintainerPersonalSettings.References.showAssetsWithoutReferences,
                        new GUIContent("Add assets without found references", "Check to see all scanned assets in the list even if there was no any references to the asset found in project."), GUILayout.ExpandWidth(false));

                    MaintainerPersonalSettings.References.selectedFindClearsResults = GUILayout.Toggle(
                        MaintainerPersonalSettings.References.selectedFindClearsResults,
                        new GUIContent(@"Clear results on selected assets search", "Check to automatically clear last results on selected assets find both from context menu and main window.\nUncheck to add new results to the last results."), GUILayout.ExpandWidth(false));

                    GUILayout.Space(3);
                }
            }
        }
Example #11
0
        protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args)
        {
            var objectReferences = DragAndDrop.objectReferences;

            if (objectReferences == null || objectReferences.Length == 0)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
            var validItems  = new List <Object>(objectReferences.Length);

            foreach (var reference in objectReferences)
            {
                // reject any objects from assets
                if (AssetDatabase.Contains(reference))
                {
                    continue;
                }

                var validObject = false;
                var component   = reference as Component;
                var gameObject  = reference as GameObject;
                if (component != null)
                {
                    gameObject = component.gameObject;
                }
                else if (gameObject == null)
                {
                    continue;
                }

                if (gameObject != null)
                {
                    if (prefabStage != null && PrefabStageUtility.GetPrefabStage(gameObject) == prefabStage)
                    {
                        validObject = true;
                    }
                    else if (gameObject.scene.IsValid())
                    {
                        validObject = true;
                    }
                }

                if (validObject)
                {
                    validItems.Add(reference);
                }
            }

            if (validItems.Count == 0)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            if (Event.current.type == EventType.DragPerform)
            {
                var alt = Event.current.alt;

                EditorApplication.delayCall += () =>
                {
                    ReferencesFinder.FindObjectsReferencesInHierarchy(validItems.ToArray(), !alt);
                };
                DragAndDrop.AcceptDrag();
            }

            return(DragAndDropVisualMode.Generic);
        }
Example #12
0
        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);
        }
Example #13
0
        public override Task <LocationContainer> Handle(ReferenceParams request, CancellationToken cancellationToken)
        {
            var workDone = ProgressManager.WorkDone(request, new WorkDoneProgressBegin
            {
                Title      = "Begin resolving references",
                Percentage = 0
            });

            var editorData       = DResolverWrapper.CreateEditorData(request, cancellationToken);
            var nodeSymbolToFind = DResolverWrapper
                                   .ResolveHoveredCodeLoosely(editorData, out LooseResolution.NodeResolutionAttempt _, out ISyntaxRegion _)
                                   .Select(ExpressionTypeEvaluation.GetResultMember)
                                   .FirstOrDefault();

            if (nodeSymbolToFind == null)
            {
                workDone.OnNext(new WorkDoneProgressReport()
                {
                    Message    = "No symbol found",
                    Percentage = 100
                });
                workDone.OnCompleted();
                return(Task.FromResult(new LocationContainer()));
            }

            var modules = editorData.ParseCache.EnumRootPackagesSurroundingModule(editorData.SyntaxTree)
                          .SelectMany(package => (IEnumerable <DModule>)package)
                          .Where(module => module != null)
                          .OrderBy(module => module.FileName)
                          .ToList();

            var progress           = ProgressManager.For(request, cancellationToken);
            var allFoundReferences = new List <Location>();
            var ctxt          = ResolutionContext.Create(editorData, true);
            int progressIndex = 0;

            foreach (var module in modules)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                try
                {
                    var references = ReferencesFinder.SearchModuleForASTNodeReferences(module, nodeSymbolToFind, ctxt, request.Context.IncludeDeclaration)
                                     .Where(region => region != null)
                                     .OrderBy(region => region.Location)
                                     .Select(region => ToLocation(region, module))
                                     .Where(location => location != default)
                                     .ToList();
                    progressIndex++;
                    if (references.Count > 0)
                    {
                        workDone.OnNext(new WorkDoneProgressReport
                        {
                            Message    = "Scanned " + module.FileName,
                            Percentage = ((double)progressIndex / modules.Count) * 100.0
                        });
                        allFoundReferences.AddRange(references);
                        progress?.OnNext(new Container <Location>(allFoundReferences));
                    }
                }
                catch (Exception ex)
                {
                    workDone.OnError(ex);
                    if (progress != null)
                    {
                        progress.OnError(ex);
                        return(Task.FromResult(new LocationContainer()));
                    }
                    return(Task.FromException <LocationContainer>(ex));
                }
            }

            workDone.OnCompleted();
            progress?.OnCompleted();

            // if $progress sent, result must be empty
            return(Task.FromResult(progress != null ? new LocationContainer()
                : new LocationContainer(allFoundReferences)));
        }
Example #14
0
        public override Task <DocumentHighlightContainer> Handle(DocumentHighlightParams request,
                                                                 CancellationToken cancellationToken)
        {
            var workDone = ProgressManager.WorkDone(request, new WorkDoneProgressBegin
            {
                Title      = "Begin finding highlights",
                Percentage = 0
            });

            var editorData       = DResolverWrapper.CreateEditorData(request, cancellationToken);
            var nodeSymbolToFind = DResolverWrapper
                                   .ResolveHoveredCodeLoosely(editorData, out LooseResolution.NodeResolutionAttempt _,
                                                              out ISyntaxRegion _)
                                   .Select(GetResultMember)
                                   .FirstOrDefault();

            if (nodeSymbolToFind == null)
            {
                workDone.OnNext(new WorkDoneProgressReport()
                {
                    Message    = "No symbol found",
                    Percentage = 100
                });
                workDone.OnCompleted();
                return(Task.FromResult(new DocumentHighlightContainer()));
            }

            var progress = ProgressManager.For(request, cancellationToken);
            List <DocumentHighlight> allFoundReferences;
            var ctxt = ResolutionContext.Create(editorData, true);

            try
            {
                allFoundReferences = cancellationToken.IsCancellationRequested
                    ? new List <DocumentHighlight>()
                    : ReferencesFinder
                                     .SearchModuleForASTNodeReferences(editorData.SyntaxTree, nodeSymbolToFind, ctxt)
                                     .Where(region => region != null)
                                     .OrderBy(region => region.Location)
                                     .Select(ToDocumentHighlight)
                                     .ToList();
            }
            catch (Exception ex)
            {
                workDone.OnError(ex);
                if (progress != null)
                {
                    progress.OnError(ex);
                    return(Task.FromResult(new DocumentHighlightContainer()));
                }

                return(Task.FromException <DocumentHighlightContainer>(ex));
            }

            if (allFoundReferences.Count > 0)
            {
                progress?.OnNext(new DocumentHighlightContainer(allFoundReferences));
            }

            workDone.OnCompleted();
            progress?.OnCompleted();

            return(Task.FromResult(progress != null
                ? new DocumentHighlightContainer()
                : new DocumentHighlightContainer(allFoundReferences)));
        }
Example #15
0
        public static void FindScriptReferences(MenuCommand command)
        {
            var scriptPath = CSObjectTools.GetScriptPathFromObject(command.context);

            ReferencesFinder.FindAssetReferences(scriptPath);
        }
Example #16
0
        private void CellGUI(Rect cellRect, ReferencesTreeViewItem <T> item, Columns column, ref RowGUIArgs args)
        {
            baseIndent = item.depth * DepthIndentation;

            CenterRectUsingSingleLineHeight(ref cellRect);

            switch (column)
            {
            case Columns.Path:

                var iconPadding = !Provider.isActive ? 0 : IconPadding;
                var entryRect   = cellRect;

                var num = GetContentIndent(item) + extraSpaceBeforeIconAndLabel;
                entryRect.xMin += num;

                if (item.icon != null)
                {
                    var iconRect = entryRect;
                    iconRect.width  = IconWidth;
                    iconRect.x     += iconPadding;
                    iconRect.height = EditorGUIUtility.singleLineHeight;

                    GUI.DrawTexture(iconRect, item.icon, ScaleMode.ScaleToFit);

                    // BASED ON DECOMPILED CODE
                    // AssetsTreeViewGUI:
                    // float num = (!Provider.isActive) ? 0f : 7f;
                    // iconRightPadding = num;
                    // iconLeftPadding = num;

                    // TreeViewGUI:
                    // iconTotalPadding = iconLeftPadding + iconRightPadding

                    entryRect.xMin +=

                        // TreeViewGUI: public float k_IconWidth = 16f;
                        IconWidth +

                        // TreeViewGUI: iconTotalPadding
                        iconPadding * 2 +

                        // TreeViewGUI: public float k_SpaceBetweenIconAndText = 2f;
                        2f;
                }

                Rect lastRect;

                var eyeButtonRect = entryRect;
                eyeButtonRect.width  = UIHelpers.EyeButtonSize;
                eyeButtonRect.height = UIHelpers.EyeButtonSize;
                eyeButtonRect.x     += UIHelpers.EyeButtonPadding;

                lastRect = eyeButtonRect;

                if (UIHelpers.IconButton(eyeButtonRect, CSIcons.Show))
                {
                    ShowItem(item);
                }

                if (item.depth == 1 && item.data.isReferenced)
                {
                    var findButtonRect = entryRect;
                    findButtonRect.width  = UIHelpers.EyeButtonSize;
                    findButtonRect.height = UIHelpers.EyeButtonSize;
                    findButtonRect.x     += UIHelpers.EyeButtonPadding * 2 + UIHelpers.EyeButtonSize;

                    lastRect = findButtonRect;

                    if (UIHelpers.IconButton(findButtonRect, CSIcons.Find, "Search for references"))
                    {
                        EditorApplication.delayCall += () => ReferencesFinder.FindAssetReferencesFromResults(item.data.assetPath);
                    }
                }

                var labelRect = entryRect;
                labelRect.xMin = lastRect.xMax + UIHelpers.EyeButtonPadding;

                if (item.data.depth == 0 && !item.data.HasChildren)
                {
                    GUI.contentColor = CSColors.labelDimmedColor;
                }
                DefaultGUI.Label(labelRect, args.label, args.selected, args.focused);

                GUI.contentColor = Color.white;

                break;

            case Columns.Type:

                DefaultGUI.Label(cellRect, item.data.assetTypeName, args.selected, args.focused);
                break;

            case Columns.Size:

                DefaultGUI.Label(cellRect, item.data.assetSizeFormatted, args.selected, args.focused);
                break;

            case Columns.ReferencesCount:

                if (item.depth == 0)
                {
                    DefaultGUI.Label(cellRect, item.data.ChildrenCount.ToString(), args.selected, args.focused);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException("column", column, null);
            }
        }
Example #17
0
 private static void FindAllReferences()
 {
     ReferencesFinder.FindAllAssetsReferences();
 }
Example #18
0
        public static void FindComponentReferences(MenuCommand command)
        {
            var scriptPath = CSObjectTools.GetScriptPathFromObject(command.context);

            ReferencesFinder.AddToSelectionAndRun(scriptPath);
        }
Example #19
0
 public static void FindReferences()
 {
     ReferencesFinder.AddSelectedToSelectionAndRun();
 }
Example #20
0
 public static bool ValidateFindReferences()
 {
     return(ReferencesFinder.GetSelectedAssets().Length > 0);
 }
Example #21
0
 private static void FindAllReferences()
 {
     ReferencesFinder.GetReferences();
 }
Example #22
0
        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);
        }