Example #1
0
        /// <summary>
        /// Is the current selection that of the C# event add pattern?
        /// </summary>
        internal bool IsEventAddSelection(ITextView textView)
        {
            var textSelection = textView.Selection;

            if (textSelection.IsEmpty || textSelection.Mode != TextSelectionMode.Stream)
            {
                return(false);
            }

            var span = textView.Selection.StreamSelectionSpan.SnapshotSpan;

            var lineRange = SnapshotLineRangeUtil.CreateForSpan(span);

            if (lineRange.Count != 1)
            {
                return(false);
            }

            // Include the character after the selection.  Needed to disambiguate a couple
            // of cases
            var endPoint = span.End;

            if (endPoint.Position < lineRange.End.Position)
            {
                endPoint = endPoint.Add(1);
            }

            var beforeSpan = new SnapshotSpan(lineRange.Start, endPoint);

            return(IsPreceededByEventAddSyntax(beforeSpan));
        }
Example #2
0
 private AsyncBackgroundRequest CreateAsyncBackgroundRequest(
     SnapshotSpan span,
     CancellationTokenSource cancellationTokenSource,
     Task task = null)
 {
     task = task ?? new Task(() => { });
     return(new AsyncBackgroundRequest(
                SnapshotLineRangeUtil.CreateForSpan(span),
                cancellationTokenSource,
                new SingleItemQueue <SnapshotLineRange>(),
                task));
 }
Example #3
0
        private ReadOnlyCollection <ITagSpan <IClassificationTag> > GetTags(SnapshotSpan span)
        {
            var lineSpan = SnapshotLineRangeUtil.CreateForSpan(span);
            var snapshot = span.Snapshot;
            var list     = new List <ITagSpan <IClassificationTag> >();

            foreach (var line in lineSpan.Lines)
            {
                if (DirectoryUtil.TryGetDirectorySpan(line, out SnapshotSpan directorySpan))
                {
                    list.Add(new TagSpan <IClassificationTag>(directorySpan, _classificationTag));
                }
            }

            return(list.ToReadOnlyCollectionShallow());
        }
Example #4
0
        /// <summary>
        /// Is the current selection that of the C# event add pattern?
        /// </summary>
        internal bool IsEventAddSelection(ITextView textView)
        {
            var textSelection = textView.Selection;

            if (textSelection.IsEmpty || textSelection.Mode != TextSelectionMode.Stream)
            {
                return(false);
            }

            var span      = textView.Selection.StreamSelectionSpan.SnapshotSpan;
            var lineRange = SnapshotLineRangeUtil.CreateForSpan(span);

            if (lineRange.Count != 1)
            {
                return(false);
            }

            var beforeSpan = new SnapshotSpan(lineRange.Start, span.End);

            return(IsPreceededByEventAddSyntax(beforeSpan));
        }
Example #5
0
        public static Result <SnapshotLineRange> GetVisibleLineRange(this ITextView textView)
        {
            try
            {
                var lines = textView.TextViewLines;
                if (lines.Count == 0)
                {
                    return(Result.Error);
                }

                var start = lines[0].Start;
                var end   = lines[lines.Count - 1].EndIncludingLineBreak;
                var span  = new SnapshotSpan(start, end);
                return(SnapshotLineRangeUtil.CreateForSpan(span));
            }
            catch (Exception ex)
            {
                // TextViewLines can throw when the view is being laid out
                return(Result.CreateError(ex));
            }
        }