public IEnumerable <ITagSpan <IClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans) { var context = buffer.TryGetSignatureHelpClassifierContext(); Debug.Assert(context != null); if (context == null || context.Session.IsDismissed) { yield break; } if (context.Type == SignatureHelpClassifierContextTypes.ParameterName) { var paramContext = (ParameterNameSignatureHelpClassifierContext)context; var parameter = paramContext.Parameter as Parameter; if (parameter?.Name != null) { var snapshot = buffer.CurrentSnapshot; var span = new Span(paramContext.NameOffset, parameter.Name.Length); Debug.Assert(span.End <= snapshot.Length); if (span.End > snapshot.Length) { yield break; } var tag = new ClassificationTag(themeClassificationTypeService.GetClassificationType(TextColor.Parameter)); yield return(new TagSpan <IClassificationTag>(new SnapshotSpan(snapshot, span), tag)); } } else if (context.Type == SignatureHelpClassifierContextTypes.ParameterDocumentation) { var paramContext = (ParameterDocumentationSignatureHelpClassifierContext)context; var parameter = paramContext.Parameter as Parameter; if (parameter != null) { var snapshot = buffer.CurrentSnapshot; var snapshotLength = snapshot.Length; int pos = 0; foreach (var taggedText in parameter.DocumentationTaggedText) { var span = new Span(pos, taggedText.Text.Length); Debug.Assert(span.End <= snapshotLength); if (span.End > snapshotLength) { yield break; } var color = TextTagsHelper.ToTextColor(taggedText.Tag); var tag = new ClassificationTag(themeClassificationTypeService.GetClassificationType(color)); yield return(new TagSpan <IClassificationTag>(new SnapshotSpan(snapshot, span), tag)); pos = span.End; } Debug.Assert(pos == parameter.Documentation.Length); } } }
IEnumerable <TextRunPropertiesAndSpan> CreateTextRunPropertiesAndSpans(ImmutableArray <TaggedText> taggedParts, IClassificationFormatMap classificationFormatMap, IThemeClassificationTypeService themeClassificationTypeService) { int pos = 0; foreach (var part in taggedParts) { var color = TextTagsHelper.ToTextColor(part.Tag); var classificationType = themeClassificationTypeService.GetClassificationType(color); yield return(new TextRunPropertiesAndSpan(new Span(pos, part.Text.Length), classificationFormatMap.GetTextProperties(classificationType))); pos += part.Text.Length; } }
public IEnumerable <ITagSpan <IClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans) { var signature = session.SelectedSignature as Signature; if (signature == null) { yield break; } var usePrettyPrintedContent = buffer.GetUsePrettyPrintedContent(); var snapshot = buffer.CurrentSnapshot; var snapshotLength = snapshot.Length; bool lenOk = usePrettyPrintedContent ? snapshotLength == signature.PrettyPrintedContent.Length : snapshotLength == signature.Content.Length; Debug.Assert(lenOk); if (!lenOk) { yield break; } int pos = 0; var taggedTextColl = usePrettyPrintedContent ? signature.PrettyPrintedContentTaggedText : signature.ContentTaggedText; foreach (var taggedText in taggedTextColl) { var span = new Span(pos, taggedText.Text.Length); Debug.Assert(span.End <= snapshotLength); if (span.End > snapshotLength) { yield break; } var color = TextTagsHelper.ToTextColor(taggedText.Tag); var tag = new ClassificationTag(themeClassificationTypeService.GetClassificationType(color)); yield return(new TagSpan <IClassificationTag>(new SnapshotSpan(snapshot, span), tag)); pos = span.End; } Debug.Assert(usePrettyPrintedContent ? pos == signature.PrettyPrintedContent.Length : pos == signature.Content.Length); }
public IEnumerable <TextClassificationTag> GetTags(TextClassifierContext context) { var completionContext = context as CompletionDisplayTextClassifierContext; if (completionContext == null) { yield break; } var completion = completionContext.Completion as RoslynCompletion; if (completion == null) { yield break; } var completionSet = completionContext.CompletionSet as RoslynCompletionSet; if (completionSet == null) { yield break; } // The completion API doesn't create tagged text so try to extract that information // from the string so we get nice colorized text. var color = completion.CompletionItem.Tags.ToCompletionKind().ToTextColor(); var text = context.Text; // Check if the namespace or enclosing class name is part of the text if (text.IndexOf('.') < 0) { // The common case is just an identifier, and in that case, the tag is correct int punctIndex = text.IndexOfAny(punctuationChars, 0); if (punctIndex < 0) { yield return(new TextClassificationTag(new Span(0, text.Length), themeClassificationTypeService.GetClassificationType(color))); yield break; } // Check for CLASS<> or METHOD() if (punctIndex + 2 == text.Length && text.IndexOfAny(punctuationChars, punctIndex + 1) == punctIndex + 1) { yield return(new TextClassificationTag(new Span(0, punctIndex), themeClassificationTypeService.GetClassificationType(color))); yield return(new TextClassificationTag(new Span(punctIndex, 2), punctuationClassificationType)); yield break; } // Check for Visual Basic generics special case const string VBOf = "(Of …)"; if (text.Length - VBOf.Length == punctIndex && text.EndsWith(VBOf)) { yield return(new TextClassificationTag(new Span(0, punctIndex), themeClassificationTypeService.GetClassificationType(color))); yield return(new TextClassificationTag(new Span(punctIndex, 1), punctuationClassificationType)); yield return(new TextClassificationTag(new Span(punctIndex + 1, 2), themeClassificationTypeService.GetClassificationType(TextColor.Keyword))); yield return(new TextClassificationTag(new Span(punctIndex + VBOf.Length - 1, 1), punctuationClassificationType)); yield break; } } // The text is usually identical to the description and it's classified var description = completionSet.GetDescriptionAsync(completion).GetAwaiter().GetResult(); var indexes = GetMatchIndexes(completion, description); if (indexes != null) { int pos = 0; var parts = description.TaggedParts; int endIndex = indexes.Value.Value; for (int i = indexes.Value.Key; i <= endIndex; i++) { var part = parts[i]; if (part.Tag == TextTags.LineBreak) { break; } var color2 = TextTagsHelper.ToTextColor(part.Tag); yield return(new TextClassificationTag(new Span(pos, part.Text.Length), themeClassificationTypeService.GetClassificationType(color2))); pos += part.Text.Length; } if (pos < text.Length) { // The remaining text is unknown, just use the tag color yield return(new TextClassificationTag(Span.FromBounds(pos, text.Length), themeClassificationTypeService.GetClassificationType(color))); } yield break; } // Give up, use the same color for all the text yield return(new TextClassificationTag(new Span(0, text.Length), themeClassificationTypeService.GetClassificationType(color))); }