internal static void Run()
        {
            var doc = IdeApp.Workbench.ActiveDocument;

            if (doc == null)
            {
                return;
            }
            var selectionRange = doc.Editor.SelectionRange;
            var parsedDocument = doc.ParsedDocument;

            if (parsedDocument == null)
            {
                return;
            }
            var model = parsedDocument.GetAst <SemanticModel> ();

            if (model == null)
            {
                return;
            }
            var unit = model.SyntaxTree.GetRoot();
            var node = unit.FindNode(Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(selectionRange.Offset, selectionRange.EndOffset));

            if (node == null)
            {
                return;
            }

            if (doc.Editor.IsSomethingSelected)
            {
                while (node != null && ShrinkSelectionHandler.IsSelected(doc.Editor, node.Span))
                {
                    node = node.Parent;
                }
            }

            if (node != null)
            {
                var selectionAnnotation = GetSelectionAnnotation(doc.Editor);
                selectionAnnotation.Stack.Push(node);
                doc.Editor.SetSelection(node.SpanStart, node.Span.End);
            }
        }
Esempio n. 2
0
        internal static async void Run(Ide.Gui.Document doc)
        {
            var selectionRange   = doc.Editor.SelectionRange;
            var analysisDocument = doc.DocumentContext.AnalysisDocument;

            if (analysisDocument == null)
            {
                return;
            }
            var model = await analysisDocument.GetSemanticModelAsync();

            if (model == null)
            {
                return;
            }
            var unit = model.SyntaxTree.GetRoot();
            var node = unit.FindNode(Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(selectionRange.Offset, selectionRange.EndOffset));

            if (node == null)
            {
                return;
            }

            if (doc.Editor.IsSomethingSelected)
            {
                while (node != null && ShrinkSelectionHandler.IsSelected(doc.Editor, node.Span))
                {
                    node = node.Parent;
                }
            }

            if (node != null)
            {
                var selectionAnnotation = GetSelectionAnnotation(doc.Editor);
                selectionAnnotation.Stack.Push(node);
                doc.Editor.SetSelection(node.SpanStart, node.Span.End);
            }
        }