void RenameReferencesInFile(SymbolRenameArgs args, IFindReferenceSearchScope searchScope, FileName fileName, Action <PatchedFile> callback, Action <Error> errorCallback, bool isNameValid, CancellationToken cancellationToken)
        {
            ITextSource textSource = args.ParseableFileContentFinder.Create(fileName);

            if (textSource == null)
            {
                return;
            }
            if (searchScope.SearchTerm != null)
            {
                if (textSource.IndexOf(searchScope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) < 0)
                {
                    return;
                }
            }

            var parseInfo = SD.ParserService.Parse(fileName, textSource) as CSharpFullParseInformation;

            if (parseInfo == null)
            {
                return;
            }
            ReadOnlyDocument         document    = null;
            IHighlighter             highlighter = null;
            List <RenameResultMatch> results     = new List <RenameResultMatch>();

            // Grab the unresolved file matching the compilation version
            // (this may differ from the version created by re-parsing the project)
            CSharpUnresolvedFile unresolvedFile = null;
            IProjectContent      pc             = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;

            if (pc != null)
            {
                unresolvedFile = pc.GetFile(fileName) as CSharpUnresolvedFile;
            }

            CSharpAstResolver resolver = new CSharpAstResolver(compilation, parseInfo.SyntaxTree, unresolvedFile);

            fr.RenameReferencesInFile(
                new[] { searchScope }, args.NewName, resolver,
                delegate(RenameCallbackArguments callbackArgs) {
                var node       = callbackArgs.NodeToReplace;
                string newCode = callbackArgs.NewNode.ToString();
                if (document == null)
                {
                    document = new ReadOnlyDocument(textSource, fileName);

                    if (args.ProvideHighlightedLine)
                    {
                        highlighter = SD.EditorControlService.CreateHighlighter(document);
                        highlighter.BeginHighlighting();
                    }
                }
                var startLocation = node.StartLocation;
                var endLocation   = node.EndLocation;
                int offset        = document.GetOffset(startLocation);
                int length        = document.GetOffset(endLocation) - offset;
                if (args.ProvideHighlightedLine)
                {
                    var builder          = SearchResultsPad.CreateInlineBuilder(node.StartLocation, node.EndLocation, document, highlighter);
                    var defaultTextColor = highlighter != null ? highlighter.DefaultTextColor : null;
                    results.Add(new RenameResultMatch(fileName, startLocation, endLocation, offset, length, newCode, builder, defaultTextColor));
                }
                else
                {
                    results.Add(new RenameResultMatch(fileName, startLocation, endLocation, offset, length, newCode));
                }
            },
                errorCallback, cancellationToken);
            if (highlighter != null)
            {
                highlighter.Dispose();
            }
            if (results.Count > 0)
            {
                if (!isNameValid)
                {
                    errorCallback(new Error(ErrorType.Error, string.Format("The name '{0}' is not valid in the current context!", args.NewName),
                                            new DomRegion(fileName, results[0].StartLocation)));
                    return;
                }
                IDocument changedDocument = new TextDocument(document);
                var       oldVersion      = changedDocument.Version;
                foreach (var result in results.OrderByDescending(m => m.StartOffset))
                {
                    changedDocument.Replace(result.StartOffset, result.Length, result.NewCode);
                }
                callback(new PatchedFile(fileName, results, oldVersion, changedDocument.Version));
            }
        }