public static Span GetSpan(this IMappingSpan mappingTagSpan) { var buffer = mappingTagSpan.AnchorBuffer; var startSnapshotPoint = mappingTagSpan.Start.GetPoint(buffer, positionAffinity).Value; var endSnapshotPoint = mappingTagSpan.End.GetPoint(buffer, positionAffinity).Value; var length = endSnapshotPoint.Position - startSnapshotPoint.Position; return(new Span(startSnapshotPoint.Position, length)); }
/// <summary> /// Initializes a new instance of <see cref="TagsChangedEventArgs"/> with the specified <see cref="IMappingSpan" />. /// </summary> /// <param name="span">The <see cref="IMappingSpan" />.</param> /// <exception cref="ArgumentNullException"><paramref name="span"/> is null.</exception> public TagsChangedEventArgs(IMappingSpan span) { if (span == null) { throw new ArgumentNullException("span"); } Span = span; }
/// <summary> /// Initializes a new instance of <see cref="TextAndAdornmentSequenceChangedEventArgs"/> with the specified <see cref="IMappingSpan" />. /// </summary> /// <param name="span">The span that changed.</param> /// <exception cref="ArgumentNullException"><paramref name="span"/> is null.</exception> public TextAndAdornmentSequenceChangedEventArgs(IMappingSpan span) { if (span == null) { throw new ArgumentNullException("span"); } this.Span = span; }
private void NotifyTagChanged(ITextSnapshot snapshot) { IMappingSpan t = tagsChanged.Dequeue(); NormalizedSnapshotSpanCollection sp = t.GetSpans(snapshot); if (TagsChanged != null) { TagsChanged.Invoke(this, new SnapshotSpanEventArgs(sp.First())); } }
public IEnumerable <IOverviewMark> GetOverviewMarks(IMappingSpan span) { foreach (var tag in _markerAggregator.GetTags(span)) { Mark mark = Mark.Create(tag); if (mark != null) { yield return(mark); } } }
/// <summary> /// When a source tagger sends out a change event, we translate the SnapshotSpan /// that was changed into a mapping span for our consumers. /// </summary> void SourceTaggerTagsChanged(object sender, SnapshotSpanEventArgs e) { if (this.disposed) { return; } // Create a mapping span for the region and return that in our own event IMappingSpan span = this.BufferGraph.CreateMappingSpan(e.Span, SpanTrackingMode.EdgeExclusive); RaiseEvents(sender, span); }
/// <summary> /// Creates a mapping tag span. /// </summary> /// <param name="span">The mapping span with which to associate the tag.</param> /// <param name="tag">The tag associated with the span.</param> /// <exception cref="ArgumentNullException"><paramref name="span"/> or <paramref name="tag"/> is null.</exception> public MappingTagSpan(IMappingSpan span, T tag) { if (span == null) { throw new ArgumentNullException("span"); } if (tag == null) { throw new ArgumentNullException("tag"); } Span = span; Tag = tag; }
/// <summary> /// Creates a <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> for the provided configuration. /// </summary> /// <param name = "formattedLineSource">The <see cref = "T:Microsoft.VisualStudio.Text.Formatting.IFormattedLineSource" /> that's performing the formatting of the line. You can access useful properties about the ongoing formatting operation from this object.</param> /// <param name = "textProperties">The <see cref = "T:Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties" /> of the line for which <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> are to be provided. This paramter can be used to obtain formatting information about the textual contents of the line.</param> /// <param name = "line">The <see cref = "T:Microsoft.VisualStudio.Text.IMappingSpan" /> corresponding to the line that's being formatted/rendered.</param> /// <param name = "lineStart">The <see cref = "T:Microsoft.VisualStudio.Text.IMappingPoint" /> corresponding to the beginning of the line segment that's being formatted. This paramter is relevant for word-wrap scenarios where a single <see cref = "T:Microsoft.VisualStudio.Text.ITextSnapshotLine" /> results in multiple formatted/rendered lines on the view.</param> /// <param name = "lineSegment">The segment number of the line segment that's been currently formatted. This is a zero-based index and is applicable to word-wrapped lines. If a line is word-wrapped into 4 segments, you will receive 4 calls for the line with lineSegments of 0, 1, 2, and 3.</param> /// <returns> /// A <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> to be used when the line is being formatted. /// </returns> /// <remarks> /// Please note that you can return a <see cref = "T:Microsoft.VisualStudio.Text.Formatting.TextFormattingParagraphProperties" /> which has a convenient set of basic properties defined. /// </remarks> public TextParagraphProperties Create( IFormattedLineSource formattedLineSource, TextFormattingRunProperties textProperties, IMappingSpan line, IMappingPoint lineStart, int lineSegment) { if (_TextParagraphProperties == null) { _TextParagraphProperties = new PowerShellTextFormattingParagraphProperties( textProperties, formattedLineSource, ServiceProvider ); } return TextParagraphProperties; }
public string WriteErrorTags(IList <IMappingTagSpan <IErrorTag> > tags) { var sb = new StringBuilder(); foreach (var c in tags) { IMappingSpan span = c.Span; SnapshotPoint?ptStart = span.Start.GetPoint(span.AnchorBuffer, PositionAffinity.Successor); SnapshotPoint?ptEnd = span.End.GetPoint(span.AnchorBuffer, PositionAffinity.Successor); sb.AppendLine($"[{ptStart.Value.Position} - {ptEnd.Value.Position}] {c.Tag.ToolTipContent}"); } return(sb.ToString()); }
private void EnsureInitialized() { if (!(this.disposed || this.initialized)) { this.Initialize(); //Raise the tags changed event over the entire buffer since we didn't give the correct results //to anyone who might have called GetTags() before. ITextSnapshot snapshot = this.BufferGraph.TopBuffer.CurrentSnapshot; IMappingSpan span = this.BufferGraph.CreateMappingSpan(new SnapshotSpan(snapshot, 0, snapshot.Length), SpanTrackingMode.EdgeInclusive); this.RaiseEvents(this, span); } }
/// <summary> /// Creates a <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> for the provided configuration. /// </summary> /// <param name = "formattedLineSource">The <see cref = "T:Microsoft.VisualStudio.Text.Formatting.IFormattedLineSource" /> that's performing the formatting of the line. You can access useful properties about the ongoing formatting operation from this object.</param> /// <param name = "textProperties">The <see cref = "T:Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties" /> of the line for which <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> are to be provided. This paramter can be used to obtain formatting information about the textual contents of the line.</param> /// <param name = "line">The <see cref = "T:Microsoft.VisualStudio.Text.IMappingSpan" /> corresponding to the line that's being formatted/rendered.</param> /// <param name = "lineStart">The <see cref = "T:Microsoft.VisualStudio.Text.IMappingPoint" /> corresponding to the beginning of the line segment that's being formatted. This paramter is relevant for word-wrap scenarios where a single <see cref = "T:Microsoft.VisualStudio.Text.ITextSnapshotLine" /> results in multiple formatted/rendered lines on the view.</param> /// <param name = "lineSegment">The segment number of the line segment that's been currently formatted. This is a zero-based index and is applicable to word-wrapped lines. If a line is word-wrapped into 4 segments, you will receive 4 calls for the line with lineSegments of 0, 1, 2, and 3.</param> /// <returns> /// A <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> to be used when the line is being formatted. /// </returns> /// <remarks> /// Please note that you can return a <see cref = "T:Microsoft.VisualStudio.Text.Formatting.TextFormattingParagraphProperties" /> which has a convenient set of basic properties defined. /// </remarks> public TextParagraphProperties Create(IFormattedLineSource formattedLineSource, TextFormattingRunProperties textProperties, IMappingSpan line, IMappingPoint lineStart, int lineSegment) { if (_TextParagraphProperties == null) { _TextParagraphProperties = new PowerShellTextFormattingParagraphProperties(textProperties, formattedLineSource, ServiceProvider); } return(TextParagraphProperties); }
public static Mock <IMappingTagSpan <ITag> > CreateMappingTagSpan( IMappingSpan span, ITag tag = null, MockRepository factory = null) { factory = factory ?? new MockRepository(MockBehavior.Strict); var mock = factory.Create <IMappingTagSpan <ITag> >(); mock.SetupGet(x => x.Span).Returns(span); if (tag != null) { mock.SetupGet(x => x.Tag).Returns(tag); } return(mock); }
private void UpdateSelection(ITextSelection sel) { List <Span> spanList = new List <Span>(); for (int s = 0; s < sel.SelectedSpans.Count; ++s) { SnapshotSpan selectedSpan = sel.SelectedSpans[s]; IMappingSpan m = this.textView.BufferGraph.CreateMappingSpan(selectedSpan, SpanTrackingMode.EdgeExclusive); // todo: this should be on ITextSelection! NormalizedSnapshotSpanCollection spans = m.GetSpans(this.textBuffer); // TODO: add NormalizedSpanCollection property to NormalizedSnapshotSpanCollection foreach (var sp in spans) { spanList.Add(sp.Span); } } this.SelectionCombo.ItemsSource = spanList; if (spanList.Count < 2) { if (!this.selectionLabelInstalled) { this.SelectionPanel.Children.Clear(); this.SelectionPanel.Children.Add(this.SelectionLabel); this.selectionLabelInstalled = true; } if (spanList.Count == 0) { this.SelectionLabel.Content = "-"; } else { this.SelectionLabel.Content = spanList[0]; } } else { if (this.selectionLabelInstalled) { this.SelectionPanel.Children.Clear(); this.SelectionPanel.Children.Add(this.SelectionCombo); this.selectionLabelInstalled = false; } this.SelectionCombo.Text = spanList[0].ToString(); } }
private SnapshotSpan MapTo(SnapshotSpan span, ITextSnapshot snapshot, SpanTrackingMode spanTrackingMode) { if (span.Snapshot.TextBuffer == snapshot.TextBuffer) { return(span.TranslateTo(snapshot, spanTrackingMode)); } IBufferGraph graph = _bufferGraphFactoryService.CreateBufferGraph(snapshot.TextBuffer); IMappingSpan mappingSpan = graph.CreateMappingSpan(span, spanTrackingMode); NormalizedSnapshotSpanCollection mapped = mappingSpan.GetSpans(snapshot); if (mapped.Count == 1) { return(mapped[0]); } return(new SnapshotSpan(mapped[0].Start, mapped[mapped.Count - 1].End)); }
/// <summary> /// If the content type of any of the source buffers changes, we need to dispose /// all the taggers on the buffer that we have cached (if they are disposable) and get /// new ones. /// </summary> void BufferGraph_GraphBufferContentTypeChanged(object sender, GraphBufferContentTypeChangedEventArgs e) { if (this.disposed || !this.initialized || (((TagAggregatorOptions2)this.options).HasFlag(TagAggregatorOptions2.NoProjection) && (e.TextBuffer != this.BufferGraph.TopBuffer))) { return; } DisposeAllTaggersOverBuffer(e.TextBuffer); taggers[e.TextBuffer] = GatherTaggers(e.TextBuffer); // Send out an event to say that tags have changed over the entire text buffer, to // be safe. ITextSnapshot snapshot = e.TextBuffer.CurrentSnapshot; SnapshotSpan entireSnapshot = new SnapshotSpan(snapshot, 0, snapshot.Length); IMappingSpan span = this.BufferGraph.CreateMappingSpan(entireSnapshot, SpanTrackingMode.EdgeInclusive); this.RaiseEvents(this, span); }
private IEnumerable <IMappingTagSpan <T> > InternalGetTags(IMappingSpan mappingSpan, CancellationToken?cancel) { foreach (var bufferAndTaggers in taggers) { if (bufferAndTaggers.Value.Count > 0) { NormalizedSnapshotSpanCollection spans = mappingSpan.GetSpans(bufferAndTaggers.Key); if (spans.Count > 0) { foreach (var tagSpan in this.GetTagsForBuffer(bufferAndTaggers, spans, null, cancel)) { yield return(tagSpan); } } } } }
public IEnumerable <IMappingTagSpan <T> > GetTags(IMappingSpan span) { if (span == null) { throw new ArgumentNullException(nameof(span)); } if (this.disposed) { throw new ObjectDisposedException("TagAggregator"); } if (initialized && (uniqueTaggers.Count > 0)) { return(InternalGetTags(span, cancel: null)); } return(Enumerable.Empty <IMappingTagSpan <T> >()); }
void RaiseTagsChanged(SnapshotSpan span, object sender = null) { if (IsDisposed) { return; } IMappingSpan mappingSpan = null; TagsChanged?.Invoke(sender ?? this, new TagsChangedEventArgs(mappingSpan = BufferGraph.CreateMappingSpan(span, SpanTrackingMode.EdgeExclusive))); if (BatchedTagsChanged != null) { lock (lockObj) { batchedTagsChangedList.Add(mappingSpan ?? BufferGraph.CreateMappingSpan(span, SpanTrackingMode.EdgeExclusive)); if (batchedTagsChangedList.Count == 1) { dispatcher.BeginInvoke(new Action(RaiseOnUIThread), DispatcherPriority.Normal); } } } }
public IEnumerable <IMappingTagSpan <T> > GetTags(IMappingSpan span) { if (span == null) { throw new ArgumentNullException("span"); } if (this.disposed) { throw new ObjectDisposedException("TagAggregator"); } if (this.uniqueTaggers.Count == 0) { return(Enumerable.Empty <IMappingTagSpan <T> >()); } else { return(InternalGetTags(span, cancel: null)); } }
private IEnumerable <IMappingTagSpan <T> > InternalGetTags(IMappingSpan mappingSpan, CancellationToken?cancel) { foreach (var bufferAndState in bufferStates) { if (bufferAndState.Value.Taggers.Count > 0) { var spans = mappingSpan.GetSpans(bufferAndState.Key); if (spans.Count > 0) { foreach (var tag in this.GetTagsForBuffer(spans, bufferAndState.Value, null, cancel)) { yield return(tag); } if (cancel.HasValue && cancel.Value.IsCancellationRequested) { yield break; } } } } }
private String getKeywordAt(List <IMappingTagSpan <IClassificationTag> > tagList, int tagIndex) { string keyword = null; if (tagIndex < tagList.Count) { var buffer = _textView.TextBuffer; IClassificationTag currentTag = tagList[tagIndex].Tag; IMappingSpan currentSpan = tagList[tagIndex].Span; // if (currentTag.ClassificationType.IsOfType("keyword")) { var spans = currentSpan.GetSpans(buffer); if (spans.Count > 0) { SnapshotSpan kwSpan = spans[0]; keyword = kwSpan.GetText(); keyword = keyword.ToUpper(); } } } return(keyword); }
public static Mock<IMappingTagSpan<ITag>> CreateMappingTagSpan( IMappingSpan span, ITag tag = null, MockRepository factory = null) { factory = factory ?? new MockRepository(MockBehavior.Strict); var mock = factory.Create<IMappingTagSpan<ITag>>(); mock.SetupGet(x => x.Span).Returns(span); if (tag != null) { mock.SetupGet(x => x.Tag).Returns(tag); } return mock; }
public TextSequenceElement(IMappingSpan span) => Span = span ?? throw new ArgumentNullException(nameof(span));
public MappingSpanLink(MappingSpanLink next, IMappingSpan span) { this.Next = next; this.Span = span; }
/// <summary> /// Get the first keyword in Line. The modifiers (Private, Protected, ... ) are ignored /// If the first Keyword is a Comment, "//" is returned /// </summary> /// <param name="line">The line to analyze</param> /// <param name="doSkipped">Bool value indicating if a "DO" keyword has been skipped</param> /// <param name="minIndent"></param> /// <returns></returns> private String getFirstKeywordInLine(ITextSnapshotLine line, out bool doSkipped, out int minIndent) { minIndent = -1; doSkipped = false; List <IMappingTagSpan <IClassificationTag> > tagList = GetTagsInLine(line); String keyword = ""; // if (tagList.Count > 0) { var buffer = this._textView.TextBuffer; IMappingSpan currentSpan = tagList[0].Span; /////////////////////////////////////////// //SnapshotPoint? snapPointFirst = currentSpan.Start.GetPoint(buffer, PositionAffinity.Predecessor); //// Extract the start of line //SnapshotSpan toIndent = new SnapshotSpan(line.Start, snapPointFirst.Value.Position - line.Start.Position); //String startOfLine = toIndent.GetText(); //// Convert Tabs to Spaces //startOfLine = startOfLine.Replace("\t", new String(' ', _tabSize)); //// So, at least, to align to previous line, we will need... //minIndent = startOfLine.Length; //////////////////////////////////////////// String startOfLine = line.GetText(); startOfLine = startOfLine.Replace("\t", new String(' ', _tabSize)); // So, at least, to align to previous line, we will need... minIndent = (startOfLine.Length - startOfLine.TrimStart(' ').Length); // int tagIndex = 0; while (tagIndex < tagList.Count) { IClassificationTag currentTag = tagList[tagIndex].Tag; currentSpan = tagList[tagIndex].Span; // if (currentTag.ClassificationType.IsOfType("keyword")) { var spans = currentSpan.GetSpans(buffer); if (spans.Count > 0) { SnapshotSpan kwSpan = spans[0]; keyword = kwSpan.GetText(); keyword = keyword.ToUpper(); // it could be modifier... switch (keyword) { case "PROTECTED": case "INTERNAL": case "HIDDEN": case "PRIVATE": case "EXPORT": case "PUBLIC": case "STATIC": case "SEALED": case "ABSTRACT": case "VIRTUAL": case "PARTIAL": tagIndex++; keyword = ""; continue; case "DO": tagIndex++; keyword = ""; doSkipped = true; continue; default: break; } } } else if (currentTag.ClassificationType.IsOfType("comment")) { // keyword = "//"; } // out please break; } ; } return(keyword); }
private int?alignToSpecificTokens(ITextSnapshotLine currentLine, String tokenList) { int indentValue = 0; bool found = false; Stack <String> context = new Stack <String>(); // try { String[] possibleTokens = tokenList.Split(','); // On what line are we ? int lineNumber = currentLine.LineNumber; // We need to analyze the Previous line lineNumber = lineNumber - 1; while (lineNumber > 0) { // We need to analyze the Previous line lineNumber = lineNumber - 1; ITextSnapshotLine line = currentLine.Snapshot.GetLineFromLineNumber(lineNumber); List <IMappingTagSpan <IClassificationTag> > tagList = GetTagsInLine(line); String currentKeyword = ""; // if (tagList.Count > 0) { var buffer = this._textView.TextBuffer; IMappingSpan currentSpan = tagList[0].Span; /* * SnapshotPoint? snapPointFirst = currentSpan.Start.GetPoint(buffer, PositionAffinity.Predecessor); * // Extract the start of line * SnapshotSpan toIndent = new SnapshotSpan(line.Start, snapPointFirst.Value.Position - line.Start.Position); * String startOfLine = toIndent.GetText(); * // Convert Tabs to Spaces * startOfLine = startOfLine.Replace("\t", new String(' ', _tabSize)); * // So, at least, to align to previous line, we will need... * indentValue = startOfLine.Length; */ String startOfLine = line.GetText(); startOfLine = startOfLine.Replace("\t", new String(' ', _tabSize)); // So, at least, to align to previous line, we will need... indentValue = (startOfLine.Length - startOfLine.TrimStart(' ').Length); // IClassificationTag currentTag = tagList[0].Tag; currentSpan = tagList[0].Span; // if (currentTag.ClassificationType.IsOfType("keyword")) { var spans = currentSpan.GetSpans(buffer); if (spans.Count > 0) { SnapshotSpan kwSpan = spans[0]; currentKeyword = kwSpan.GetText(); currentKeyword = currentKeyword.ToUpper(); if (possibleTokens.Contains <String>(currentKeyword)) { if (context.Count == 0) { found = true; break; } else { tokenList = context.Pop(); possibleTokens = tokenList.Split(','); } } // Here we should also check for nested construct or we might get false positive... string outdentToken; if ((outdentToken = this.searchSpecialOutdentKeyword(currentKeyword)) != null) { context.Push(tokenList); tokenList = outdentToken; possibleTokens = tokenList.Split(','); } } } // indentValue = 0; } } } finally { // } // if (found) { return(indentValue); } else { return(null); } }
private int?alignToSpecificToken_(ITextSnapshotLine currentLine, String token) { int indentValue = 0; bool found = false; try { // On what line are we ? int lineNumber = currentLine.LineNumber; // We need to analyze the Previous line lineNumber = lineNumber - 1; while (lineNumber > 0) { // We need to analyze the Previous line lineNumber = lineNumber - 1; ITextSnapshotLine line = currentLine.Snapshot.GetLineFromLineNumber(lineNumber); List <IMappingTagSpan <IClassificationTag> > tagList = GetTagsInLine(line); String keyword = ""; // if (tagList.Count > 0) { var buffer = this._textView.TextBuffer; IMappingSpan currentSpan = tagList[0].Span; /* * SnapshotPoint? snapPointFirst = currentSpan.Start.GetPoint(buffer, PositionAffinity.Predecessor); * // Extract the start of line * SnapshotSpan toIndent = new SnapshotSpan(line.Start, snapPointFirst.Value.Position - line.Start.Position); * String startOfLine = toIndent.GetText(); * // Convert Tabs to Spaces * startOfLine = startOfLine.Replace("\t", new String(' ', _tabSize)); * // So, at least, to align to previous line, we will need... * indentValue = startOfLine.Length; */ String startOfLine = line.GetText(); startOfLine = startOfLine.Replace("\t", new String(' ', _tabSize)); // So, at least, to align to previous line, we will need... indentValue = (startOfLine.Length - startOfLine.TrimStart(' ').Length); // IClassificationTag currentTag = tagList[0].Tag; currentSpan = tagList[0].Span; // if (currentTag.ClassificationType.IsOfType("keyword")) { var spans = currentSpan.GetSpans(buffer); if (spans.Count > 0) { SnapshotSpan kwSpan = spans[0]; keyword = kwSpan.GetText(); keyword = keyword.ToUpper(); if (keyword == token) { found = true; break; } } } // indentValue = 0; } } } finally { // } // if (found) { return(indentValue); } else { return(null); } }
public IEnumerable <IMappingTagSpan <T> > GetTags(IMappingSpan span) { throw new NotImplementedException(); }