public IEnumerable <CompletionClassificationTag> GetTags(CompletionClassifierContext context) { var filter = completionCollection.CreateCompletionFilter(context.InputText); foreach (var span in filter.GetMatchSpans(context.Completion, context.DisplayText)) { yield return(new CompletionClassificationTag(span, completionMatchHighlightClassificationType)); } }
public IEnumerable <CompletionClassificationTag> GetTags(CompletionClassifierContext context) { var textClassifierContext = new MyTextClassifierContext(context.Completion.DisplayText ?? string.Empty, context); foreach (var tag in textClassifierAggregator.GetTags(textClassifierContext)) { yield return(new CompletionClassificationTag(tag.Span, tag.ClassificationType)); } }
public IEnumerable <CompletionClassificationTag> GetTags(CompletionClassifierContext context) { var spans = completionSet.GetHighlightedSpansInDisplayText(context.DisplayText); if (spans == null) { yield break; } foreach (var span in spans) { yield return(new CompletionClassificationTag(span, completionMatchHighlightClassificationType)); } }
public IEnumerable <CompletionClassificationTag> GetTags(CompletionClassifierContext context) { var completion = context.Completion as RoslynCompletion; if (completion == null) { yield break; } var color = completion.CompletionItem.Tags.ToCompletionKind().ToTextColor(); if (color != TextColor.Text) { var text = completion.DisplayText; bool seenSpecial = false; for (int textOffset = 0; textOffset < text.Length;) { int specialIndex = text.IndexOfAny(punctuationChars, textOffset); int len = specialIndex < 0 ? text.Length - textOffset : specialIndex - textOffset; if (len > 0) { bool wasSpecialCaseString = false; if (seenSpecial) { var s = text.Substring(textOffset, len); if (s == VBOf) { yield return(new CompletionClassificationTag(new Span(textOffset, 2), themeClassificationTypes.GetClassificationType(TextColor.Keyword))); wasSpecialCaseString = true; } } if (!wasSpecialCaseString) { yield return(new CompletionClassificationTag(new Span(textOffset, len), themeClassificationTypes.GetClassificationType(color))); } textOffset += len; } if (specialIndex >= 0) { seenSpecial = true; yield return(new CompletionClassificationTag(new Span(textOffset, 1), punctuationClassificationType)); textOffset++; } } } }
public FrameworkElement Create(CompletionCollection collection, Completion completion) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (completion == null) { throw new ArgumentNullException(nameof(completion)); } Debug.Assert(collection.FilteredCollection.Contains(completion)); var classifier = GetCompletionClassifier(collection); var inputText = collection.ApplicableTo.GetText(collection.ApplicableTo.TextBuffer.CurrentSnapshot); var context = new CompletionClassifierContext(collection, completion, completion.DisplayText, inputText); return(TextBlockFactory.Create(context.DisplayText, classificationFormatMap.DefaultTextProperties, classifier.GetTags(context).Select(a => new TextRunPropertiesAndSpan(a.Span, classificationFormatMap.GetTextProperties(a.ClassificationType))), TextBlockFactory.Flags.DisableSetTextBlockFontFamily | TextBlockFactory.Flags.DisableFontSize)); }
public FrameworkElement Create(CompletionCollection collection, Completion completion) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (completion == null) { throw new ArgumentNullException(nameof(completion)); } Debug.Assert(collection.FilteredCollection.Contains(completion)); var classifier = GetCompletionClassifier(collection); var inputText = collection.ApplicableTo.GetText(collection.ApplicableTo.TextBuffer.CurrentSnapshot); var context = new CompletionClassifierContext(completion, inputText); var text = completion.DisplayText; var textBlock = new TextBlock(); int textOffset = 0; foreach (var tag in classifier.GetTags(context)) { if (textOffset < tag.Span.Start) { textBlock.Inlines.Add(CreateRun(text.Substring(textOffset, tag.Span.Start - textOffset), null)); } textBlock.Inlines.Add(CreateRun(text.Substring(tag.Span.Start, tag.Span.Length), tag.ClassificationType)); textOffset = tag.Span.End; } if (textOffset < text.Length) { textBlock.Inlines.Add(CreateRun(text.Substring(textOffset), null)); } var defProps = classificationFormatMap.DefaultTextProperties; if (!defProps.ForegroundBrushEmpty) { textBlock.Foreground = classificationFormatMap.DefaultTextProperties.ForegroundBrush; } return(textBlock); }
public IEnumerable <CompletionClassificationTag> GetTags(CompletionClassifierContext context) { var completion = context.Completion as RoslynCompletion; if (completion == null) { yield break; } var collection = context.Collection as RoslynCompletionCollection; if (collection == 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.DisplayText; // 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 CompletionClassificationTag(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 CompletionClassificationTag(new Span(0, punctIndex), themeClassificationTypeService.GetClassificationType(color))); yield return(new CompletionClassificationTag(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 CompletionClassificationTag(new Span(0, punctIndex), themeClassificationTypeService.GetClassificationType(color))); yield return(new CompletionClassificationTag(new Span(punctIndex, 1), punctuationClassificationType)); yield return(new CompletionClassificationTag(new Span(punctIndex + 1, 2), themeClassificationTypeService.GetClassificationType(TextColor.Keyword))); yield return(new CompletionClassificationTag(new Span(punctIndex + VBOf.Length - 1, 1), punctuationClassificationType)); yield break; } // The text is usually identical to the description and it's classified var description = collection.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; } color = TextTagsHelper.ToTextColor(part.Tag); yield return(new CompletionClassificationTag(new Span(pos, part.Text.Length), themeClassificationTypeService.GetClassificationType(color))); pos += part.Text.Length; } yield break; } // Give up, use the same color for all the text yield return(new CompletionClassificationTag(new Span(0, text.Length), themeClassificationTypeService.GetClassificationType(color))); }
public MyTextClassifierContext(string text, CompletionClassifierContext completionClassifierContext) : base(text) { CompletionClassifierContext = completionClassifierContext; }