/// <summary>
        /// Finds all references to resources (except the definition) using the specified
        /// <see cref="IResourceReferenceFinder"/> object.
        /// </summary>
        /// <param name="finder">The <see cref="IResourceReferenceFinder"/> to use to find resource references.</param>
        /// <param name="monitor">An object implementing <see cref="IProgressMonitor"/> to report the progress of the operation. Can be <c>null</c>.</param>
        /// <param name="scope">The scope which should be searched.</param>
        /// <returns>A list of references to resources.</returns>
        public static List <Reference> FindReferences(IResourceReferenceFinder finder, IProgressMonitor monitor, SearchScope scope)
        {
            if (finder == null)
            {
                throw new ArgumentNullException("finder");
            }

            if (ParserService.LoadSolutionProjectsThreadRunning)
            {
                if (monitor != null)
                {
                    monitor.ShowingDialog = true;
                }
                MessageService.ShowMessage("${res:SharpDevelop.Refactoring.LoadSolutionProjectsThreadRunning}");
                if (monitor != null)
                {
                    monitor.ShowingDialog = false;
                }
                return(null);
            }

            DateTime startTime = DateTime.UtcNow;

            List <Reference> references = new List <Reference>();

            try {
                NRefactoryAstCacheService.EnableCache();

                ICollection <string> files = GetPossibleFiles(scope);

                if (monitor != null)
                {
                    monitor.BeginTask("${res:SharpDevelop.Refactoring.FindingReferences}", files.Count, true);
                }

                foreach (string fileName in files)
                {
                    if (monitor != null && monitor.IsCancelled)
                    {
                        return(null);
                    }

                    IDocument doc = null;
                    try {
                        // The following line throws an exception if the file does not exist.
                        // But the file may be in an unsaved view content (which would be found by GetDocumentInformation),
                        // so we cannot simply loop on !File.Exists(...).
                        doc = FindReferencesAndRenameHelper.GetDocumentInformation(fileName).CreateDocument();
                    } catch (FileNotFoundException) {
                    }
                    if (doc == null)
                    {
                        if (monitor != null)
                        {
                            ++monitor.WorkDone;
                        }
                        continue;
                    }

                    string fileContent = doc.TextContent;
                    if (String.IsNullOrEmpty(fileContent))
                    {
                        if (monitor != null)
                        {
                            ++monitor.WorkDone;
                        }
                        continue;
                    }

                    int pos = -1;
                    while ((pos = finder.GetNextPossibleOffset(fileName, fileContent, pos)) >= 0)
                    {
                        TextLocation          docPos = doc.OffsetToPosition(pos);
                        ResourceResolveResult rrr    = ResourceResolverService.Resolve(fileName, doc, docPos.Y, docPos.X, null);

                        if (rrr != null && rrr.ResourceFileContent != null)
                        {
                            if (finder.IsReferenceToResource(rrr))
                            {
                                if (rrr.Key != null)
                                {
                                    // The actual location of the key string may be after 'pos' because
                                    // the resolvers may find an expression just before it.
                                    string keyString = rrr.Key;
                                    int    keyPos    = fileContent.IndexOf(keyString, pos, StringComparison.OrdinalIgnoreCase);

                                    if (keyPos < pos)
                                    {
                                        // The key may be escaped in some way in the document.
                                        // Try using the code generator to find this out.
                                        keyPos = FindStringLiteral(fileName, fileContent, rrr.Key, pos, out keyString);
                                    }

                                    if (keyPos < pos)
                                    {
                                        if (monitor != null)
                                        {
                                            monitor.ShowingDialog = true;
                                        }
                                        MessageService.ShowWarning("ResourceToolkit: The key '" + rrr.Key + "' could not be located at the resolved position in the file '" + fileName + "'.");
                                        if (monitor != null)
                                        {
                                            monitor.ShowingDialog = false;
                                        }
                                    }
                                    else
                                    {
                                        references.Add(new Reference(fileName, keyPos, keyString.Length, keyString, rrr));
                                    }
                                }
                                else
                                {
                                    references.Add(new Reference(fileName, pos, 0, null, rrr));
                                }
                            }
                        }
                    }

                    if (monitor != null)
                    {
                        ++monitor.WorkDone;
                    }
                }

                LoggingService.Info("ResourceToolkit: FindReferences finished in " + (DateTime.UtcNow - startTime).TotalSeconds.ToString(System.Globalization.CultureInfo.CurrentCulture) + "s");
            } finally {
                NRefactoryAstCacheService.DisableCache();
                if (monitor != null)
                {
                    monitor.Done();
                }
            }

            return(references);
        }
 public void AstCacheEnableTwice()
 {
     NRefactoryAstCacheService.EnableCache();
     NRefactoryAstCacheService.EnableCache();
 }