Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27348

VS 2013 Need some help making a VS Addin

$
0
0
I have followed the steps here: http://msdn.microsoft.com/en-us/libr...code-snippet-2
to the tee and it works well ...

I want to change its functionality and highlight all of the comments and strings in the VS editor... so I modified it to this:

vb Code:
  1. <Export(GetType(IViewTaggerProvider))>
  2. <ContentType("text")>
  3. <TagType(GetType(TextMarkerTag))>
  4. Friend Class HighlightWordTaggerProvider
  5.     Implements IViewTaggerProvider
  6.  
  7.     <Import> _
  8.     Public Property Classifiers() As IClassifierAggregatorService
  9.  
  10.     Public Function CreateTagger(Of T As ITag)(ByVal textView As ITextView, ByVal buffer As ITextBuffer) As ITagger(Of T) Implements IViewTaggerProvider.CreateTagger
  11.         'provide highlighting only on the top buffer
  12.         If textView.TextBuffer IsNot buffer Then
  13.             Return Nothing
  14.         End If
  15.  
  16.         Return TryCast(New HighlightWordTagger(Classifiers.GetClassifier(buffer)), ITagger(Of T))
  17.     End Function
  18.  
  19. End Class

And...

vb Code:
  1. Friend Class HighlightWordTagger
  2.     Implements ITagger(Of HighlightWordTag)
  3.  
  4.     Public Property Classifier As IClassifier
  5.  
  6.     Public Function GetTags(spans As NormalizedSnapshotSpanCollection) As IEnumerable(Of ITagSpan(Of HighlightWordTag)) Implements ITagger(Of HighlightWordTag).GetTags
  7.         If Classifier Is Nothing OrElse spans Is Nothing OrElse spans.Count = 0 Then
  8.             Return Nothing
  9.         End If
  10.         Dim List = New List(Of TagSpan(Of HighlightWordTag))()
  11.      
  12.         For Each snapshotSpan In spans
  13.             For Each ClassificationSpan As ClassificationSpan In Classifier.GetClassificationSpans(snapshotSpan)
  14.                 Dim name As String = ClassificationSpan.ClassificationType.Classification.ToLowerInvariant()
  15.  
  16.                 If (name.Contains("comment") OrElse name.Contains("string")) AndAlso (name.Contains("xml") = False AndAlso name.Contains("doc") = False AndAlso name.Contains("tag") = False) Then
  17.                     List.Add(New TagSpan(Of HighlightWordTag)(ClassificationSpan.Span, New HighlightWordTag()))
  18.                 End If
  19.             Next
  20.         Next
  21.         Return List
  22.     End Function
  23.  
  24.     Public Sub New(Classifier As IClassifier)
  25.         Me.Classifier = Classifier
  26.     End Sub
  27.  
  28.     Public Event TagsChanged(sender As Object, e As SnapshotSpanEventArgs) Implements ITagger(Of HighlightWordTag).TagsChanged
  29. End Class

And all works fine ... until some text is entered using the keyboard then all of the highlights disappear until the enter key is pressed...

Does anyone know why this may be happening?

Also here is a link to the project so you can easily see what's going on: http://i00Productions.org/TextAdornment1.zip

Thanks in advance,
Kris

Viewing all articles
Browse latest Browse all 27348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>