예제 #1
0
        public TreeItemViewModel(
            TextSpan textSpan,
            SourceText sourceText,
            DocumentId documentId,
            string fileName,
            Glyph glyph,
            ImmutableArray <ClassifiedSpan> classifiedSpans,
            ValueTrackingTreeViewModel treeViewModel,
            IGlyphService glyphService,
            IThreadingContext threadingContext,
            Workspace workspace,
            ImmutableArray <TreeItemViewModel> children = default)
            : base()
        {
            FileName         = fileName;
            TextSpan         = textSpan;
            _sourceText      = sourceText;
            ClassifiedSpans  = classifiedSpans;
            TreeViewModel    = treeViewModel;
            ThreadingContext = threadingContext;

            _glyph        = glyph;
            _glyphService = glyphService;
            Workspace     = workspace;
            DocumentId    = documentId;

            if (!children.IsDefaultOrEmpty)
            {
                foreach (var child in children)
                {
                    ChildItems.Add(child);
                }
            }

            sourceText.GetLineAndOffset(textSpan.Start, out var lineStart, out var _);
            sourceText.GetLineAndOffset(textSpan.End, out var lineEnd, out var _);
            LineSpan = LineSpan.FromBounds(lineStart, lineEnd);

            PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(IsLoading))
                {
                    NotifyPropertyChanged(nameof(ShowGlyph));
                }
            };

            TreeViewModel.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(TreeViewModel.HighlightBrush))
                {
                    // If the highlight changes we need to recalculate the inlines so the
                    // highlighting is correct
                    NotifyPropertyChanged(nameof(Inlines));
                }
            };
        }
예제 #2
0
 public static void GetLinesAndOffsets(
     this SourceText text,
     TextSpan textSpan,
     out int startLineNumber,
     out int startOffset,
     out int endLineNumber,
     out int endOffset)
 {
     text.GetLineAndOffset(textSpan.Start, out startLineNumber, out startOffset);
     text.GetLineAndOffset(textSpan.End, out endLineNumber, out endOffset);
 }
예제 #3
0
            public override AdjustNewLinesOperation GetAdjustNewLinesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, NextOperation <AdjustNewLinesOperation> nextOperation)
            {
                // Since we know the general shape of these new import statements, we simply look for where
                // tokens are not on the same line and force them to only be separated by a single newline.

                _text.GetLineAndOffset(previousToken.Span.Start, out int previousLine, out _);
                _text.GetLineAndOffset(currentToken.Span.Start, out int currentLine, out _);

                if (previousLine != currentLine)
                {
                    return(FormattingOperations.CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.ForceLines));
                }

                return(null);
            }
예제 #4
0
        public static VsTextSpan GetVsTextSpanForPosition(this SourceText text, int position, int virtualSpace)
        {
            text.GetLineAndOffset(position, out var lineNumber, out var offset);

            offset += virtualSpace;

            return(text.GetVsTextSpanForLineOffset(lineNumber, offset));
        }