Exemplo n.º 1
0
        void RequestPopup(Xwt.Rectangle rect)
        {
            var token = popupSrc.Token;

            Task.Run(async delegate {
                try {
                    foreach (var op in await codeAction.GetPreviewOperationsAsync(token))
                    {
                        if (!(op is ApplyChangesOperation ac))
                        {
                            continue;
                        }
                        var changedDocument = ac.ChangedSolution.GetDocument(documentContext.AnalysisDocument.Id);

                        var changedText       = await changedDocument.GetTextAsync(token);
                        var changedTextSource = new StringTextSource(changedText.ToString());
                        changedTextDocument   = TextEditorFactory.CreateNewDocument(changedTextSource, editor.FileName);

                        try {
                            var processor = new DiffProcessor(editor, changedTextDocument);
                            return(processor.Process());
                        } catch (Exception e) {
                            LoggingService.LogError("Error while getting preview list diff.", e);
                        }
                    }
                } catch (OperationCanceledException) { }

                return(new ProcessResult());
            }).ContinueWith(t => {
Exemplo n.º 2
0
        internal async void RequestPopup(Xwt.Rectangle rect)
        {
            var token = popupSrc.Token;

            diff = await Task.Run(async delegate {
                try {
                    foreach (var op in await codeAction.GetPreviewOperationsAsync(token))
                    {
                        var ac = op as ApplyChangesOperation;
                        if (ac == null)
                        {
                            continue;
                        }
                        var changedDocument = ac.ChangedSolution.GetDocument(documentContext.AnalysisDocument.Id);

                        changedTextDocument = TextEditorFactory.CreateNewDocument(new StringTextSource((await changedDocument.GetTextAsync(token)).ToString()), editor.FileName);
                        try {
                            var list = new List <DiffHunk> (editor.GetDiff(changedTextDocument, new DiffOptions(false, true)));
                            if (list.Count > 0)
                            {
                                return(list);
                            }
                        } catch (Exception e) {
                            LoggingService.LogError("Error while getting preview list diff.", e);
                        }
                    }
                } catch (OperationCanceledException) {}
                return(new List <DiffHunk> ());
            });

            if (diff.Count > 0 && !token.IsCancellationRequested)
            {
                ShowPopup(rect, PopupPosition.Left);
            }
        }
Exemplo n.º 3
0
 protected Task <ImmutableArray <CodeActionOperation> > GetPreviewOperationsAsync(
     CancellationToken cancellationToken
     )
 {
     return(Task.Run(
                () => CodeAction.GetPreviewOperationsAsync(cancellationToken),
                cancellationToken
                ));
 }
        async void RequestPopup(Xwt.Rectangle rect)
        {
            var token = popupSrc.Token;

            diff = await Task.Run(async delegate {
                try {
                    foreach (var op in await codeAction.GetPreviewOperationsAsync(token))
                    {
                        var ac = op as ApplyChangesOperation;
                        if (ac == null)
                        {
                            continue;
                        }
                        var changedDocument = ac.ChangedSolution.GetDocument(documentContext.AnalysisDocument.Id);

                        changedTextDocument = TextEditorFactory.CreateNewDocument(new StringTextSource((await changedDocument.GetTextAsync(token)).ToString()), editor.FileName);
                        try {
                            var list = new List <DiffHunk> (editor.GetDiff(changedTextDocument, new DiffOptions(false, true)));
                            if (list.Count > 0)
                            {
                                return(list);
                            }
                        } catch (Exception e) {
                            LoggingService.LogError("Error while getting preview list diff.", e);
                        }
                    }
                } catch (OperationCanceledException) {}
                return(new List <DiffHunk> ());
            });

            if (diff.Count > 0 && !token.IsCancellationRequested)
            {
                var pos = PopupPosition.Left;
                if (Platform.IsMac)
                {
                    var screenRect = GtkUtil.ToScreenCoordinates(IdeApp.Workbench.RootWindow, IdeApp.Workbench.RootWindow.GdkWindow, rect.ToGdkRectangle());
                    var geometry   = Screen.GetUsableMonitorGeometry(Screen.GetMonitorAtPoint(screenRect.X, screenRect.Y));
                    var request    = SizeRequest();
                    if (screenRect.X - geometry.X < request.Width)
                    {
                        pos = PopupPosition.Top;
                        if (geometry.Bottom - screenRect.Bottom < request.Height)
                        {
                            pos = PopupPosition.Bottom;
                        }
                    }
                    else
                    {
                        pos = PopupPosition.Right;
                    }
                }
                ShowPopup(rect, pos);
            }
        }
Exemplo n.º 5
0
 protected Task <ImmutableArray <CodeActionOperation> > GetPreviewOperationsAsync(CancellationToken cancellationToken)
 {
     return(Task.Run(
                async() => await CodeAction.GetPreviewOperationsAsync(cancellationToken).ConfigureAwait(false), cancellationToken));
 }
Exemplo n.º 6
0
        public async Task <bool> IncludeCodeActionInRevisionsAsync(Solution oldSolution, CodeAction codeAction, RevisionsTracker revisionsTracker, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            ImmutableArray <CodeActionOperation> operations = await codeAction.GetPreviewOperationsAsync(cancellationToken).ConfigureAwait(false);

            ApplyChangesOperation singleApplyChangesOperation = null;

            foreach (var operation in operations)
            {
                if (!(operation is ApplyChangesOperation applyChangesOperation))
                {
                    continue;
                }

                if (singleApplyChangesOperation != null)
                {
                    // Already had an ApplyChangesOperation; only one is supported.
                    singleApplyChangesOperation = null;
                    break;
                }

                singleApplyChangesOperation = applyChangesOperation;
            }

            if (singleApplyChangesOperation == null)
            {
                return(false);
            }

            var changedSolution = singleApplyChangesOperation.ChangedSolution;

            if (await LazinatorCodeFixProvider.WhetherCodeFixFailed(changedSolution))
            {
                return(false);
            }

            var solutionChanges = changedSolution.GetChanges(oldSolution);

            foreach (var projectChange in solutionChanges.GetProjectChanges())
            {
                foreach (var removed in projectChange.GetRemovedDocuments())
                {
                    revisionsTracker.removedDocuments.Add(removed);
                }
            }

            var documentIdsForNew = solutionChanges
                                    .GetProjectChanges()
                                    .SelectMany(p => p.GetAddedDocuments());

            foreach (var documentId in documentIdsForNew)
            {
                if (revisionsTracker.newDocumentsMap.ContainsKey(documentId))
                {
                    throw new LazinatorCodeGenException("Internal exception. Did not expect multiple code fixes to produce same new document.");
                }
                revisionsTracker.newDocumentsMap[documentId] = changedSolution.GetDocument(documentId);
            }

            var documentIdsWithChanges = solutionChanges
                                         .GetProjectChanges()
                                         .SelectMany(p => p.GetChangedDocuments());

            foreach (var documentId in documentIdsWithChanges)
            {
                cancellationToken.ThrowIfCancellationRequested();
                var document = changedSolution.GetDocument(documentId);

                Document existingDocument;
                if (revisionsTracker.changedDocumentsMap.TryGetValue(documentId, out existingDocument))
                {
                    if (existingDocument != null)
                    {
                        revisionsTracker.changedDocumentsMap[documentId] = null;
                        var documentsToMerge = new List <Document>();
                        documentsToMerge.Add(existingDocument);
                        documentsToMerge.Add(document);
                        revisionsTracker.documentsToMergeMap             = revisionsTracker.documentsToMergeMap ?? new Dictionary <DocumentId, List <Document> >();
                        revisionsTracker.documentsToMergeMap[documentId] = documentsToMerge;
                    }
                    else
                    {
                        revisionsTracker.documentsToMergeMap[documentId].Add(document);
                    }
                }
                else
                {
                    revisionsTracker.changedDocumentsMap[documentId] = document;
                }
            }

            return(true);
        }