private async Task FormatAsync(
            Workspace workspace,
            IReadOnlyList<DocumentId> documentIds,
            IReadOnlyList<DocumentId> additionalDocumentIds,
            CancellationToken cancellationToken)
        {
            FormatLogger.WriteLine($"Found {documentIds.Count} documents to be formatted...");
            FormatLogger.WriteLine($"Found {additionalDocumentIds.Count} additional documents to be formatted...");

            var watch = new Stopwatch();
            watch.Start();

            var originalSolution = workspace.CurrentSolution;
            var solution = await FormatCoreAsync(originalSolution, documentIds, cancellationToken);
            solution = await FormatAdditionalDocumentsAsync(solution, additionalDocumentIds, cancellationToken);

            watch.Stop();

            if (!workspace.TryApplyChanges(solution))
            {
                FormatLogger.WriteErrorLine("Unable to save changes to disk");
            }

            FormatLogger.WriteLine("Total time {0}", watch.Elapsed);
        }
Example #2
0
        public async Task FormatAsync(Workspace workspace, IReadOnlyList <DocumentId> documentIds, CancellationToken cancellationToken)
        {
            var watch = new Stopwatch();

            watch.Start();

            var originalSolution = workspace.CurrentSolution;
            var solution         = await FormatCoreAsync(originalSolution, documentIds, cancellationToken);

            var p = solution.Projects.First();

            foreach (Document d in p.Documents)
            {
                if (d.Name == "ExplorerForms.cs")
                {
                    SyntaxTree s;
                    d.TryGetSyntaxTree(out s);

                    string text = s.ToString();
                }
            }

            watch.Stop();

            if (!workspace.TryApplyChanges(solution))
            {
                FormatLogger.WriteErrorLine("Unable to save changes to disk");
            }

            FormatLogger.WriteLine("Total time {0}", watch.Elapsed);
        }
        private async Task FormatAsync(Workspace workspace, IReadOnlyList <DocumentId> documentIds, CancellationToken cancellationToken)
        {
            var watch = new Stopwatch();

            watch.Start();

            var originalSolution = workspace.CurrentSolution;
            var solution         = await FormatCoreAsync(originalSolution, documentIds, cancellationToken).ConfigureAwait(false);

            watch.Stop();

            if (!workspace.TryApplyChanges(solution))
            {
                FormatLogger.WriteErrorLine("Unable to save changes to disk");
            }

            FormatLogger.WriteLine("Total time {0}", watch.Elapsed);
        }
        private async Task FormatAsync(Workspace workspace, IReadOnlyList <DocumentId> documentIds, CancellationToken cancellationToken)
        {
            try
            {
                var watch = new Stopwatch();
                watch.Start();
                var originalSolution = workspace.CurrentSolution;
                var newSolution      = await FormatCoreAsync(originalSolution, documentIds, cancellationToken);

                newSolution.GetChanges(originalSolution).GetProjectChanges().ToList().ForEach(projectChanges =>
                {
                    SaveUpdatedDocumentsToDisk(projectChanges, newSolution);
                });
                watch.Stop();
                FormatLogger.WriteLine("Total time {0}", watch.Elapsed);
            }
            catch (Exception)
            {
                FormatLogger.WriteErrorLine("Unable to save changes to disk");
            }
        }