コード例 #1
0
            public async Task Run()
            {
                var token = default(CancellationToken);

                var oldSolution     = documentContext.AnalysisDocument.Project.Solution;
                var updatedSolution = oldSolution;

                using (var undo = editor.OpenUndoGroup()) {
                    foreach (var operation in await act.GetOperationsAsync(token))
                    {
                        var applyChanges = operation as ApplyChangesOperation;
                        if (applyChanges == null)
                        {
                            operation.TryApply(documentContext.RoslynWorkspace, new RoslynProgressTracker(), token);
                            continue;
                        }
                        if (updatedSolution == oldSolution)
                        {
                            updatedSolution = applyChanges.ChangedSolution;
                        }
                        operation.TryApply(documentContext.RoslynWorkspace, new RoslynProgressTracker(), token);
                    }
                }
                await TryStartRenameSession(documentContext.RoslynWorkspace, oldSolution, updatedSolution, token);
            }
コード例 #2
0
            public async Task Run()
            {
                var token = default(CancellationToken);

                if (act is InsertionAction insertionAction)
                {
                    var insertion = await insertionAction.CreateInsertion(token).ConfigureAwait(false);

                    var document = await IdeApp.Workbench.OpenDocument(insertion.Location.SourceTree.FilePath, documentContext.Project);

                    var parsedDocument = await document.DocumentContext.UpdateParseDocument();

                    var model = await document.DocumentContext.AnalysisDocument.GetSemanticModelAsync(token);

                    if (parsedDocument != null)
                    {
                        var insertionPoints = InsertionPointService.GetInsertionPoints(
                            document.Editor,
                            model,
                            insertion.Type,
                            insertion.Location.SourceSpan.Start
                            );

                        var options = new InsertionModeOptions(
                            insertionAction.Title,
                            insertionPoints,
                            point => {
                            if (!point.Success)
                            {
                                return;
                            }
                            var node = Formatter.Format(insertion.Node, document.DocumentContext.RoslynWorkspace, document.DocumentContext.GetOptionSet(), token);
                            point.InsertionPoint.Insert(document.Editor, document.DocumentContext, node.ToString());
                            // document = await Simplifier.ReduceAsync(document.AnalysisDocument, Simplifier.Annotation, cancellationToken: token).ConfigureAwait(false);
                        }
                            );

                        document.Editor.StartInsertionMode(options);
                        return;
                    }
                }

                var oldSolution     = documentContext.AnalysisDocument.Project.Solution;
                var updatedSolution = oldSolution;

                using (var undo = editor.OpenUndoGroup()) {
                    foreach (var operation in await act.GetOperationsAsync(token))
                    {
                        var applyChanges = operation as ApplyChangesOperation;
                        if (applyChanges == null)
                        {
                            operation.TryApply(documentContext.RoslynWorkspace, new RoslynProgressTracker(), token);
                            continue;
                        }
                        if (updatedSolution == oldSolution)
                        {
                            updatedSolution = applyChanges.ChangedSolution;
                        }
                        operation.TryApply(documentContext.RoslynWorkspace, new RoslynProgressTracker(), token);
                    }
                }
                await TryStartRenameSession(documentContext.RoslynWorkspace, oldSolution, updatedSolution, token);
            }
コード例 #3
0
        public override void HandleSpecialSelectionKey(uint unicodeKey)
        {
            string start, end;

            ((SelectionSurroundingProvider)this).GetSelectionSurroundings(unicodeKey, out start, out end);

            if (editor.SelectionMode == SelectionMode.Block)
            {
                var selection = editor.SelectionRegion;
                int startCol  = System.Math.Min(selection.Begin.Column, selection.End.Column) - 1;
                int endCol    = System.Math.Max(selection.Begin.Column, selection.End.Column);

                int minLine = System.Math.Min(selection.Begin.Line, selection.End.Line);
                int maxLine = System.Math.Max(selection.BeginLine, selection.End.Line);

                var changes = new List <TextChange> ();
                for (int lineNumber = minLine; lineNumber <= maxLine; lineNumber++)
                {
                    var lineSegment = editor.GetLine(lineNumber);

                    if (lineSegment.Offset + startCol < lineSegment.EndOffset)
                    {
                        changes.Add(new TextChange(new TextSpan(lineSegment.Offset + startCol, 0), start));
                    }
                    if (lineSegment.Offset + endCol < lineSegment.EndOffset)
                    {
                        changes.Add(new TextChange(new TextSpan(lineSegment.Offset + endCol, 0), end));
                    }
                }

                editor.ApplyTextChanges(changes);

//				textEditorData.MainSelection = new Selection (
//					new DocumentLocation (selection.Anchor.Line, endCol == selection.Anchor.Column ? endCol + start.Length : startCol + 1 + start.Length),
//					new DocumentLocation (selection.Lead.Line, endCol == selection.Anchor.Column ? startCol + 1 + start.Length : endCol + start.Length),
//					MonoDevelop.Ide.Editor.SelectionMode.Block);
            }
            else
            {
                var selectionRange = editor.SelectionRange;
                int anchorOffset   = selectionRange.Offset;
                int leadOffset     = selectionRange.EndOffset;
                var text           = editor.GetTextAt(selectionRange);

                var formattingService = context.AnalysisDocument.GetLanguageService <IEditorFormattingService> ();


                if (editor.Options.GenerateFormattingUndoStep)
                {
                    using (var undo = editor.OpenUndoGroup()) {
                        editor.ReplaceText(selectionRange, start);
                    }
                    using (var undo = editor.OpenUndoGroup()) {
                        editor.ReplaceText(anchorOffset, 1, start + text + end);
                        editor.SetSelection(anchorOffset + start.Length, leadOffset + start.Length + end.Length);
                    }
                    if (unicodeKey == '{')
                    {
                        if (formattingService != null)
                        {
                            var changes = formattingService.GetFormattingChangesAsync(context.AnalysisDocument, TextSpan.FromBounds(anchorOffset + start.Length - 1, leadOffset + start.Length + end.Length), CancellationToken.None).WaitAndGetResult(CancellationToken.None);
                            editor.ApplyTextChanges(changes);
                        }
                    }
                }
                else
                {
                    using (var undo = editor.OpenUndoGroup()) {
                        editor.InsertText(anchorOffset, start);
                        editor.InsertText(leadOffset >= anchorOffset ? leadOffset + start.Length : leadOffset, end);
                        if (unicodeKey == '{')
                        {
                            if (formattingService != null)
                            {
                                var changes = formattingService.GetFormattingChangesAsync(context.AnalysisDocument, TextSpan.FromBounds(anchorOffset + start.Length, leadOffset + start.Length), CancellationToken.None).WaitAndGetResult(CancellationToken.None);
                                editor.ApplyTextChanges(changes);
                            }
                        }
                        else
                        {
                            editor.SetSelection(anchorOffset + start.Length, leadOffset + start.Length + end.Length);
                        }
                    }
                }
            }
        }