Esempio n. 1
0
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			var vm = value as ValueVM;
			var tag = parameter as string;
			if (vm == null || tag == null)
				return null;

			var writer = Cache.GetWriter();
			try {
				var printer = new ValuePrinter(writer, vm.PrinterContext.UseHexadecimal);
				if (tag == PredefinedTextClassifierTags.LocalsWindowName)
					printer.WriteName(vm);
				else if (tag == PredefinedTextClassifierTags.LocalsWindowValue)
					printer.WriteValue(vm);
				else if (tag == PredefinedTextClassifierTags.LocalsWindowType)
					printer.WriteType(vm);
				else
					return null;

				var context = new TextClassifierContext(writer.Text, tag, vm.PrinterContext.SyntaxHighlight, writer.Colors);
				return vm.PrinterContext.TextElementProvider.CreateTextElement(vm.PrinterContext.ClassificationFormatMap, context, ContentTypes.LocalsWindow, TextElementFlags.FilterOutNewLines | TextElementFlags.CharacterEllipsis);
			}
			finally {
				Cache.FreeWriter(writer);
			}
		}
Esempio n. 2
0
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			var vm = value as TabVM;
			var tag = parameter as string;
			if (vm == null || tag == null)
				return null;

			var writer = Cache.GetWriter();
			try {
				var printer = new TabPrinter(writer);
				if (tag == PredefinedTextClassifierTags.TabsDialogName)
					printer.WriteName(vm);
				else if (tag == PredefinedTextClassifierTags.TabsDialogModule)
					printer.WriteModule(vm);
				else if (tag == PredefinedTextClassifierTags.TabsDialogPath)
					printer.WritePath(vm);
				else
					return null;

				var context = new TextClassifierContext(writer.Text, tag, vm.Owner.Settings.SyntaxHighlight, writer.Colors);
				return vm.Owner.TextElementProvider.CreateTextElement(vm.Owner.ClassificationFormatMap, context, ContentTypes.TabsDialog, TextElementFlags.FilterOutNewLines | TextElementFlags.CharacterEllipsis);
			}
			finally {
				Cache.FreeWriter(writer);
			}
		}
		public IEnumerable<TextClassificationTag> GetTags(TextClassifierContext context) {
			if (!context.Colorize)
				yield break;
			if (!(context is CompletionSuffixClassifierContext))
				yield break;
			yield return new TextClassificationTag(new Span(0, context.Text.Length), completionSuffixClassificationType);
		}
		public IEnumerable<TextClassificationTag> GetTags(TextClassifierContext context) {
			var optionsContext = context as AppSettingsTextClassifierContext;
			if (optionsContext == null)
				yield break;
			foreach (var span in optionsContext.SearchMatcher.GetMatchSpans(optionsContext.Text))
				yield return new TextClassificationTag(span, appSettingsTextMatchHighlightClassificationType);
		}
Esempio n. 5
0
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			try {
				var flags = WriteObjectFlags.None;
				if (parameter != null) {
					foreach (var c in (string)parameter) {
						if (c == 's')
							flags |= WriteObjectFlags.ShortInstruction;
					}
				}

				var writer = Cache.GetWriter();
				try {
					BodyUtils.WriteObject(writer, value, flags);
					const bool colorize = true;
					var context = new TextClassifierContext(writer.Text, PredefinedTextClassifierTags.MethodBodyEditor, colorize, writer.Colors);
					var elem = textElementProvider.CreateTextElement(classificationFormatMap, context, ContentTypes.MethodBodyEditor, TextElementFlags.CharacterEllipsis | TextElementFlags.FilterOutNewLines);
					Cache.FreeWriter(writer);
					return elem;
				}
				finally {
					Cache.FreeWriter(writer);
				}
			}
			catch (Exception ex) {
				Debug.Fail(ex.ToString());
			}

			if (value == null)
				return string.Empty;
			return value.ToString();
		}
		public IEnumerable<TextClassificationTag> GetTags(TextClassifierContext context) {
			if (!context.Colorize)
				yield break;
			foreach (var spanData in context.Colors) {
				var ct = spanData.Data as IClassificationType ?? themeClassificationTypeService.GetClassificationType(spanData.Data as TextColor? ?? TextColor.Text);
				yield return new TextClassificationTag(spanData.Span, ct);
			}
		}
		public IEnumerable<TextClassificationTag> GetTags(TextClassifierContext context) {
			var completionContext = context as CompletionDisplayTextClassifierContext;
			if (completionContext == null)
				yield break;
			var spans = completionContext.CompletionSet.GetHighlightedSpansInDisplayText(context.Text);
			if (spans == null)
				yield break;
			foreach (var span in spans)
				yield return new TextClassificationTag(span, completionMatchHighlightClassificationType);
		}
		public IEnumerable<TextClassificationTag> GetTags(TextClassifierContext context) {
			var listContext = context as OpenDocumentListTextClassifierContext;
			if (listContext == null)
				yield break;
			if (listContext.Tag != PredefinedTextClassifierTags.DocListDialogName)
				yield break;
			foreach (var part in listContext.SearchText.Split(seps, StringSplitOptions.RemoveEmptyEntries)) {
				int index = listContext.Text.IndexOf(part, StringComparison.CurrentCultureIgnoreCase);
				if (index >= 0)
					yield return new TextClassificationTag(new Span(index, part.Length), documentListMatchHighlightClassificationType);
			}
		}
		public IEnumerable<TextClassificationTag> GetTags(TextClassifierContext context) {
			var gacContext = context as OpenFromGACTextClassifierContext;
			if (gacContext == null)
				yield break;
			if (gacContext.Tag != PredefinedTextClassifierTags.GacDialogName && gacContext.Tag != PredefinedTextClassifierTags.GacDialogVersion)
				yield break;
			foreach (var part in gacContext.SearchText.Split(seps, StringSplitOptions.RemoveEmptyEntries)) {
				int index = gacContext.Text.IndexOf(part, StringComparison.CurrentCultureIgnoreCase);
				if (index >= 0)
					yield return new TextClassificationTag(new Span(index, part.Length), gacMatchHighlightClassificationType);
			}
		}
Esempio n. 10
0
		public IEnumerable<TextClassificationTag> GetTags(TextClassifierContext context) {
			if (!context.Colorize)
				yield break;
			var tagContext = context as TaggedTextClassifierContext;
			if (tagContext == null)
				yield break;
			int pos = 0;
			foreach (var part in tagContext.TaggedParts) {
				var color = TextTagsHelper.ToTextColor(part.Tag);
				int len = part.Text.Length;
				yield return new TextClassificationTag(new Span(pos, len), themeClassificationTypeService.GetClassificationType(color));
				pos += len;
			}
			Debug.Assert(pos == context.Text.Length);
		}
Esempio n. 11
0
		public IEnumerable<TextClassificationTag> GetTags(TextClassifierContext context) {
			var tvContext = context as TreeViewNodeClassifierContext;
			if (tvContext == null)
				yield break;

			// Don't do a thing if it's a tooltip
			if (tvContext.IsToolTip)
				yield break;

			// Add the underline
			if (tvContext.Node is AssemblyDocumentNode || tvContext.Node is MethodNode) {
				yield return new TextClassificationTag(new Span(0, context.Text.Length),
					classificationTypeRegistryService.GetClassificationType(TreeViewNodeColorizerClassifications.UnderlineClassificationType));
			}

			// Add light green background in the middle of the text
			yield return new TextClassificationTag(new Span(context.Text.Length / 4, context.Text.Length / 2),
				classificationTypeRegistryService.GetClassificationType(TreeViewNodeColorizerClassifications.LightgreenBackgroundClassificationType));
		}
Esempio n. 12
0
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			var vm = value as ThreadVM;
			var tag = parameter as string;
			if (vm == null || tag == null)
				return null;

			var writer = Cache.GetWriter();
			try {
				var printer = new ThreadPrinter(writer, vm.Context.UseHexadecimal, vm.Context.TheDebugger.Debugger);
				if (tag == PredefinedTextClassifierTags.ThreadsWindowId)
					printer.WriteId(vm);
				else if (tag == PredefinedTextClassifierTags.ThreadsWindowManagedId)
					printer.WriteManagedId(vm);
				else if (tag == PredefinedTextClassifierTags.ThreadsWindowCategoryText)
					printer.WriteCategory(vm);
				else if (tag == PredefinedTextClassifierTags.ThreadsWindowName)
					printer.WriteName(vm);
				else if (tag == PredefinedTextClassifierTags.ThreadsWindowLocation)
					printer.WriteLocation(vm);
				else if (tag == PredefinedTextClassifierTags.ThreadsWindowPriority)
					printer.WritePriority(vm);
				else if (tag == PredefinedTextClassifierTags.ThreadsWindowAffinityMask)
					printer.WriteAffinityMask(vm);
				else if (tag == PredefinedTextClassifierTags.ThreadsWindowSuspended)
					printer.WriteSuspended(vm);
				else if (tag == PredefinedTextClassifierTags.ThreadsWindowProcess)
					printer.WriteProcess(vm);
				else if (tag == PredefinedTextClassifierTags.ThreadsWindowAppDomain)
					printer.WriteAppDomain(vm);
				else if (tag == PredefinedTextClassifierTags.ThreadsWindowUserState)
					printer.WriteUserState(vm);
				else
					return null;

				var context = new TextClassifierContext(writer.Text, tag, vm.Context.SyntaxHighlight, writer.Colors);
				return vm.Context.TextElementProvider.CreateTextElement(vm.Context.ClassificationFormatMap, context, ContentTypes.ThreadsWindow, TextElementFlags.FilterOutNewLines | TextElementFlags.CharacterEllipsis);
			}
			finally {
				Cache.FreeWriter(writer);
			}
		}
Esempio n. 13
0
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			var vm = value as ModuleVM;
			var tag = parameter as string;
			if (vm == null || tag == null)
				return null;

			var writer = Cache.GetWriter();
			try {
				var printer = new ModulePrinter(writer, vm.Context.UseHexadecimal, vm.Context.TheDebugger.Debugger);
				if (tag == PredefinedTextClassifierTags.ModulesWindowName)
					printer.WriteName(vm);
				else if (tag == PredefinedTextClassifierTags.ModulesWindowPath)
					printer.WritePath(vm);
				else if (tag == PredefinedTextClassifierTags.ModulesWindowOptimized)
					printer.WriteOptimized(vm);
				else if (tag == PredefinedTextClassifierTags.ModulesWindowDynamic)
					printer.WriteDynamic(vm);
				else if (tag == PredefinedTextClassifierTags.ModulesWindowInMemory)
					printer.WriteInMemory(vm);
				else if (tag == PredefinedTextClassifierTags.ModulesWindowOrder)
					printer.WriteOrder(vm);
				else if (tag == PredefinedTextClassifierTags.ModulesWindowVersion)
					printer.WriteVersion(vm);
				else if (tag == PredefinedTextClassifierTags.ModulesWindowTimestamp)
					printer.WriteTimestamp(vm);
				else if (tag == PredefinedTextClassifierTags.ModulesWindowAddress)
					printer.WriteAddress(vm);
				else if (tag == PredefinedTextClassifierTags.ModulesWindowProcess)
					printer.WriteProcess(vm);
				else if (tag == PredefinedTextClassifierTags.ModulesWindowAppDomain)
					printer.WriteAppDomain(vm);
				else
					return null;

				var context = new TextClassifierContext(writer.Text, tag, vm.Context.SyntaxHighlight, writer.Colors);
				return vm.Context.TextElementProvider.CreateTextElement(vm.Context.ClassificationFormatMap, context, ContentTypes.ModulesWindow, TextElementFlags.FilterOutNewLines | TextElementFlags.CharacterEllipsis);
			}
			finally {
				Cache.FreeWriter(writer);
			}
		}
Esempio n. 14
0
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			var vm = value as ProcessVM;
			var tag = parameter as string;
			if (vm == null || tag == null)
				return null;

			var writer = Cache.GetWriter();
			try {
				var printer = new ProcessPrinter(writer, false);
				HorizontalAlignment? horizAlign = null;
				if (tag == PredefinedTextClassifierTags.AttachToProcessWindowFullPath)
					printer.WriteFullPath(vm);
				else if (tag == PredefinedTextClassifierTags.AttachToProcessWindowFilename)
					printer.WriteFilename(vm);
				else if (tag == PredefinedTextClassifierTags.AttachToProcessWindowPid) {
					printer.WritePID(vm);
					horizAlign = HorizontalAlignment.Right;
				}
				else if (tag == PredefinedTextClassifierTags.AttachToProcessWindowClrVersion)
					printer.WriteCLRVersion(vm);
				else if (tag == PredefinedTextClassifierTags.AttachToProcessWindowType)
					printer.WriteType(vm);
				else if (tag == PredefinedTextClassifierTags.AttachToProcessWindowMachine)
					printer.WriteMachine(vm);
				else if (tag == PredefinedTextClassifierTags.AttachToProcessWindowTitle)
					printer.WriteTitle(vm);
				else
					return null;

				var context = new TextClassifierContext(writer.Text, tag, vm.Context.SyntaxHighlight, writer.Colors);
				var elem = vm.Context.TextElementProvider.CreateTextElement(vm.Context.ClassificationFormatMap, context, ContentTypes.AttachToProcessWindow, TextElementFlags.FilterOutNewLines | TextElementFlags.CharacterEllipsis);
				if (horizAlign != null)
					elem.HorizontalAlignment = horizAlign.Value;
				return elem;
			}
			finally {
				Cache.FreeWriter(writer);
			}
		}
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			var vm = value as ICallStackFrameVM;
			if (vm == null)
				return null;
			var tag = parameter as string;
			if (tag == null)
				return null;

			var writer = Cache.GetWriter();
			try {
				if (tag == PredefinedTextClassifierTags.CallStackWindowName)
					CreateContent(writer, vm.CachedOutput, vm.Context.SyntaxHighlight);
				else
					return null;

				var context = new TextClassifierContext(writer.Text, tag, vm.Context.SyntaxHighlight, writer.Colors);
				return vm.Context.TextElementProvider.CreateTextElement(vm.Context.ClassificationFormatMap, context, ContentTypes.CallStackWindow, TextElementFlags.FilterOutNewLines | TextElementFlags.CharacterEllipsis);
			}
			finally {
				Cache.FreeWriter(writer);
			}
		}
Esempio n. 16
0
		public FrameworkElement CreateTextElement(IClassificationFormatMap classificationFormatMap, TextClassifierContext context, string contentType, TextElementFlags flags) {
			if (classificationFormatMap == null)
				throw new ArgumentNullException(nameof(classificationFormatMap));
			if (context == null)
				throw new ArgumentNullException(nameof(context));
			if (contentType == null)
				throw new ArgumentNullException(nameof(contentType));
			var ct = contentTypeRegistryService.GetContentType(contentType);
			if (ct == null)
				throw new ArgumentException($"Invalid content type: {contentType}");

			ITextClassifierAggregator aggregator;
			if (!toAggregator.TryGetValue(ct, out aggregator))
				toAggregator.Add(ct, aggregator = textClassifierAggregatorService.Create(ct));
			try {
				tagsList.AddRange(aggregator.GetTags(context));
				return TextElementFactory.Create(classificationFormatMap, context.Text, tagsList, flags);
			}
			finally {
				tagsList.Clear();
			}
		}
		public IEnumerable<TextClassificationTag> GetTags(TextClassifierContext context) {
			if (!context.Colorize)
				yield break;
			var tagContext = context as TaggedTextClassifierContext;
			if (tagContext == null)
				yield break;
			if (tagContext.TaggedParts.Length == 0)
				yield break;
			var part = tagContext.TaggedParts[0];
			if (part.Tag == TextTags.Text) {
				var partText = part.Text;
				// Eg. "AddHandler statement\r\n[...]" contains CRLF
				int endOfLineIndex = partText.IndexOf("\r\n");
				if (endOfLineIndex < 0)
					endOfLineIndex = partText.Length;
				foreach (var s in keywordSuffixes) {
					int endOfKeywordPart = endOfLineIndex - s.Length;
					if (partText.IndexOf(s, 0, endOfLineIndex, StringComparison.Ordinal) == endOfKeywordPart) {
						var keywords = part.Text.Substring(0, endOfKeywordPart);
						int keywordOffset = 0;
						while (keywordOffset < keywords.Length) {
							if (keywords[keywordOffset] == ' ') {
								keywordOffset++;
								continue;
							}
							int end = keywords.IndexOf(' ', keywordOffset);
							if (end < 0)
								end = keywords.Length;
							int keywordLen = end - keywordOffset;
							if (keywordLen > 0)
								yield return new TextClassificationTag(new Span(keywordOffset, keywordLen), themeClassificationTypeService.GetClassificationType(TextColor.Keyword));
							keywordOffset += keywordLen;
						}
						break;
					}
				}
			}
		}
Esempio n. 18
0
		public IEnumerable<TextClassificationTag> GetTags(TextClassifierContext context) {
			if (!context.Colorize)
				yield break;
			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));
		}
Esempio n. 19
0
        public override FrameworkElement CreateTextElement(bool colorize, string tag)
        {
            var context = new CTC.TextClassifierContext(writer.Text, tag, colorize, writer.Colors);

            return(textElementProvider.CreateTextElement(classificationFormatMap, context, contentType, CTC.TextElementFlags.Wrap));
        }