void ShowSymbolToolTip(object sender, ToolTipEventArgs e) { var tooltip = new ThemedToolTip(); tooltip.Title .Append(_Symbol.GetAccessibility() + _Symbol.GetAbstractionModifier() + _Symbol.GetSymbolKindName() + " ") .Append(_Symbol.Name, true) .Append(_Symbol.GetParameterString()); var content = tooltip.Content .Append("namespace: " + _Symbol.ContainingNamespace?.ToString()) .Append("\nassembly: " + _Symbol.GetAssemblyModuleName()); ITypeSymbol t = _Symbol.ContainingType; if (t != null) { content.Append("\n" + t.GetSymbolKindName() + ": ") .Append(t.ToDisplayString(QuickInfoSymbolDisplayFormat)); } ; t = _Symbol.GetReturnType(); if (t != null) { content.Append("\nreturn value: ").Append(t.ToDisplayString(QuickInfoSymbolDisplayFormat), true); } var f = _Symbol as IFieldSymbol; if (f != null && f.IsConst) { content.Append("\nconst: " + f.ConstantValue.ToString()); } ToolTip = tooltip; ToolTipOpening -= ShowSymbolToolTip; }
static void ShowXmlDocSummary(ISymbol symbol, Compilation compilation, ThemedToolTip tip) { var doc = new XmlDoc(symbol, compilation); var summary = doc.Summary ?? (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.DocumentationFromInheritDoc) ? doc.ExplicitInheritDoc?.Summary : null); if (summary != null) { var docContent = tip.AddTextBlock(); new XmlDocRenderer(compilation, SymbolFormatter.Empty, symbol).Render(summary, docContent); tip.MaxWidth = Config.Instance.QuickInfoMaxWidth; } }
public static ThemedToolTip CreateToolTip(ISymbol symbol) { var tooltip = new ThemedToolTip(); tooltip.Title .Append(ThemeHelper.GetImage(symbol.GetImageId()).WrapMargin(WpfHelper.GlyphMargin)) .Append(symbol.GetAccessibility() + symbol.GetAbstractionModifier() + symbol.GetSymbolKindName() + " ") .Append(symbol.Name, true) .Append(symbol.GetParameterString()); var content = tooltip.Content; ITypeSymbol t = symbol.ContainingType; bool c = false; if (t != null) { content.Append(t.GetSymbolKindName() + ": ") .Append(t.ToDisplayString(WpfHelper.QuickInfoSymbolDisplayFormat)); c = true; } ; t = symbol.GetReturnType(); if (t != null) { if (c) { content.AppendLine(); } c = true; content.Append("return type: ").Append(t.ToDisplayString(WpfHelper.QuickInfoSymbolDisplayFormat), true); } var f = symbol as IFieldSymbol; if (f != null && f.IsConst) { if (c) { content.AppendLine(); } c = true; content.Append("const: " + f.ConstantValue.ToString()); } if (c) { content.AppendLine(); } content.Append("namespace: " + symbol.ContainingNamespace?.ToString()) .Append("\nassembly: " + symbol.GetAssemblyModuleName()); return(tooltip); }
static void ShowNumericForms(ISymbol symbol, ThemedToolTip tip) { if (Config.Instance.SymbolToolTipOptions.MatchFlags(SymbolToolTipOptions.NumericValues)) { var f = symbol as IFieldSymbol; if (f != null && f.IsConst) { var p = ShowNumericForms(f); if (p != null) { tip.AddBorder().Child = p; } } } }
static void ShowXmlDocSummary(ISymbol symbol, Compilation compilation, ThemedToolTip tip) { var doc = new XmlDoc(symbol, compilation); var summary = doc.GetDescription(symbol) ?? (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.DocumentationFromInheritDoc) ? doc.GetInheritedDescription(symbol, out doc) : null); if (summary != null) { var docContent = tip.AddTextBlock(); new XmlDocRenderer(compilation, SymbolFormatter.Instance).Render(summary, docContent); if (Config.Instance.QuickInfoMaxWidth >= 100) { tip.MaxWidth = Config.Instance.QuickInfoMaxWidth; } } }
static StackPanel ShowSymbolLocation(ISymbol symbol, string path) { var tooltip = new ThemedToolTip(); tooltip.Title.Append(symbol.Name, true); var t = tooltip.Content .Append("defined in ") .Append(String.IsNullOrEmpty(path) ? "?" : path, true); if (symbol.IsMemberOrType() && symbol.ContainingNamespace != null) { t.Append("\nnamespace: ").Append(symbol.ContainingNamespace.ToDisplayString()); } if (symbol.Kind == SymbolKind.Method) { var m = (symbol as IMethodSymbol).ReducedFrom; if (m != null) { t.Append("\nclass: ").Append(m.ContainingType.Name); } } return(tooltip); }
void OverrideDiagnosticInfo(StackPanel panel) { var infoPanel = panel.Children[1].GetFirstVisualChild <ItemsControl>()?.GetFirstVisualChild <StackPanel>(); if (infoPanel == null) { // try the first item (symbol title may be absent) infoPanel = panel.Children[0].GetFirstVisualChild <ItemsControl>()?.GetFirstVisualChild <StackPanel>(); if (infoPanel?.GetFirstVisualChild <WrapPanel>() != null) { return; } } if (infoPanel == null) { return; } foreach (var item in infoPanel.Children) { var cp = (item as UIElement).GetFirstVisualChild <TextBlock>(); if (cp == null) { continue; } if (Diagnostics != null && Diagnostics.Count > 0) { var t = cp.GetText(); var d = Diagnostics.FirstOrDefault(i => i.GetMessage() == t); if (d != null) { cp.ToolTip = String.Empty; cp.Tag = d; cp.SetGlyph(ThemeHelper.GetImage(GetGlyphForSeverity(d.Severity))); cp.ToolTipOpening += ShowToolTipForDiagnostics; } } else { cp.SetGlyph(ThemeHelper.GetImage(KnownImageIds.StatusInformation)); } } int GetGlyphForSeverity(DiagnosticSeverity severity) { switch (severity) { case DiagnosticSeverity.Warning: return(KnownImageIds.StatusWarning); case DiagnosticSeverity.Error: return(KnownImageIds.StatusError); case DiagnosticSeverity.Hidden: return(KnownImageIds.StatusHidden); default: return(KnownImageIds.StatusInformation); } } void ShowToolTipForDiagnostics(object sender, ToolTipEventArgs e) { var t = sender as TextBlock; var d = t.Tag as Diagnostic; var tip = new ThemedToolTip(); tip.Title.Append(d.Descriptor.Category + " (" + d.Id + ")", true); tip.Content.Append(d.Descriptor.Title.ToString()); if (String.IsNullOrEmpty(d.Descriptor.HelpLinkUri) == false) { tip.Content.AppendLine().Append("Help: " + d.Descriptor.HelpLinkUri); } if (d.IsSuppressed) { tip.Content.AppendLine().Append("Suppressed"); } if (d.IsWarningAsError) { tip.Content.AppendLine().Append("Content as error"); } t.ToolTip = tip; t.ToolTipOpening -= ShowToolTipForDiagnostics; } }
public static ThemedToolTip CreateToolTip(ISymbol symbol, bool forMemberList, Compilation compilation) { var tip = new ThemedToolTip(); if ((Config.Instance.DisplayOptimizations & DisplayOptimizations.CodeWindow) != 0) { WpfHelper.SetUITextRenderOptions(tip, true); } tip.Title .Append(symbol.GetAccessibility() + symbol.GetAbstractionModifier() + symbol.GetSymbolKindName() + " ") .Append(symbol.Name, true) .Append(symbol.GetParameterString()); var content = tip.Content; var t = symbol.GetReturnType(); if (t != null) { content.Append("member type: ") .Append(t.ToDisplayString(WpfHelper.MemberNameFormat), true); } t = symbol.ContainingType; if (t != null) { if (content.Inlines.FirstInline != null) { content.AppendLine(); } content.Append(t.GetSymbolKindName() + ": ") .Append(t.ToDisplayString(WpfHelper.MemberNameFormat), true); } if (content.Inlines.FirstInline != null) { content.AppendLine(); } content.Append("namespace: " + symbol.ContainingNamespace?.ToString()) .Append("\nassembly: " + symbol.GetAssemblyModuleName()); if (forMemberList == false) { var f = symbol as IFieldSymbol; if (f != null && f.IsConst) { content.Append("\nconst: " + f.ConstantValue?.ToString()); // sometimes the const value could be null } } foreach (var attr in symbol.GetAttributes()) { SymbolFormatter.Empty.ToUIText(content.AppendLine().Inlines, attr); } var doc = new XmlDoc(symbol, compilation); var summary = doc.Summary ?? (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.DocumentationFromInheritDoc) ? doc.ExplicitInheritDoc?.Summary : null); if (summary != null) { var docContent = ThemedToolTip.CreateContentBlock(); new XmlDocRenderer(compilation, SymbolFormatter.Empty, symbol).Render(summary, docContent); tip.Children.Add(docContent); tip.MaxWidth = Config.Instance.QuickInfoMaxWidth; } return(tip); }
public static ThemedToolTip CreateToolTip(ISymbol symbol, bool forMemberList, SemanticContext context) { var tip = new ThemedToolTip(); if (Config.Instance.DisplayOptimizations.MatchFlags(DisplayOptimizations.CodeWindow)) { WpfHelper.SetUITextRenderOptions(tip, true); } if (forMemberList == false) { tip.Title.Append(ThemeHelper.GetImage(symbol.GetImageId()).WrapMargin(WpfHelper.GlyphMargin)); } tip.Title .Append(symbol.GetAccessibility() + symbol.GetAbstractionModifier() + (symbol as IMethodSymbol).GetSpecialMethodModifier() + symbol.GetSymbolKindName() + " ") .Append(symbol.Name, true) .Append(symbol.GetParameterString()); var content = tip.Content; var t = symbol.GetReturnType(); if (t != null) { content.Append(R.T_MemberType) .Append(t.ToDisplayString(CodeAnalysisHelper.MemberNameFormat), true); } else if (symbol.Kind == SymbolKind.TypeParameter) { content.Append(R.T_DefinedInType) .Append(symbol.ContainingSymbol?.ToDisplayString(CodeAnalysisHelper.MemberNameFormat) ?? String.Empty, true); var tp = symbol as ITypeParameterSymbol; if (tp.HasConstraint()) { content.AppendLine().Append(R.T_Constraint); SymbolFormatter.Instance.ShowTypeConstaints(tp, content); } } t = symbol.ContainingType; if (t != null && t.TypeKind != TypeKind.Enum) { content.AppendLineBreak() .Append(t.GetSymbolKindName(), SymbolFormatter.Instance.Keyword).Append(": ") .Append(t.ToDisplayString(CodeAnalysisHelper.MemberNameFormat), true); } if (forMemberList == false) { content.AppendLineBreak() .Append(R.T_Namespace + symbol.ContainingNamespace?.ToString()).AppendLine(); if (symbol.Kind == SymbolKind.Namespace) { // hack: workaround to exclude references that returns null from GetDocument content.Append(R.T_Assembly).Append(String.Join(", ", ((INamespaceSymbol)symbol).ConstituentNamespaces.Select(n => n.GetAssemblyModuleName()).Distinct())) .AppendLine().Append(R.T_Project).Append(String.Join(", ", symbol.GetSourceReferences().Select(r => context.GetProject(r.SyntaxTree)).Where(p => p != null).Distinct().Select(p => p.Name))) .AppendLine().Append(R.T_Location).Append(symbol.Locations.Length); } else { if (symbol.HasSource()) { content.Append(R.T_SourceFile).Append(String.Join(", ", symbol.GetSourceReferences().Select(r => System.IO.Path.GetFileName(r.SyntaxTree.FilePath)))) .AppendLine().Append(R.T_Project).Append(String.Join(", ", symbol.GetSourceReferences().Select(r => context.GetProject(r.SyntaxTree)).Where(p => p != null).Distinct().Select(p => p.Name))); } else { content.Append(R.T_Assembly).Append(symbol.GetAssemblyModuleName()); } if (symbol.Kind == SymbolKind.NamedType) { switch (((INamedTypeSymbol)symbol).TypeKind) { case TypeKind.Delegate: ShowDelegateSignature(content, (INamedTypeSymbol)symbol); break; case TypeKind.Enum: ShowEnumType(content, symbol); break; } } } } ShowAttributes(symbol, content); if (context.SemanticModel?.Compilation != null && Config.Instance.SymbolToolTipOptions.MatchFlags(SymbolToolTipOptions.XmlDocSummary)) { ShowXmlDocSummary(symbol, context.SemanticModel.Compilation, tip); } ShowNumericForms(symbol, tip); return(tip); }
static StackPanel ShowSymbolLocation(ISymbol symbol, string path) { var tooltip = new ThemedToolTip(); tooltip.Title.Append(symbol.GetOriginalName(), true); var t = tooltip.Content; if (symbol.Kind != SymbolKind.Namespace) { var sr = symbol.GetSourceReferences(); if (sr.Length > 0) { t.Append(R.T_DefinedIn); var s = false; foreach (var(name, ext) in sr.Select(r => DeconstructFileName(System.IO.Path.GetFileName(r.SyntaxTree.FilePath))).Distinct().OrderBy(i => i.name)) { if (s) { t.AppendLine(); } t.Append(name, true); if (ext.Length > 0) { t.Append(ext); } s = true; } } } t.AppendLineBreak().Append(R.T_Assembly); if (symbol.Kind == SymbolKind.Namespace) { var s = false; foreach (var(name, ext) in ((INamespaceSymbol)symbol).ConstituentNamespaces.Select(n => n.ContainingModule?.Name).Where(m => m != null).Select(DeconstructFileName).Distinct().OrderBy(i => i.name)) { if (s) { t.AppendLine(); } t.Append(name, true); if (ext.Length > 0) { t.Append(ext); } s = true; } } else { t.Append(symbol.ContainingModule?.Name); } if (symbol.IsMemberOrType() && symbol.ContainingNamespace != null) { t.AppendLineBreak().Append(R.T_Namespace).Append(symbol.ContainingNamespace.ToDisplayString()); } if (symbol.Kind == SymbolKind.Method) { var m = ((IMethodSymbol)symbol).ReducedFrom; if (m != null) { t.AppendLineBreak().Append(R.T_Class).Append(m.ContainingType.Name); } } return(tooltip); (string name, string ext) DeconstructFileName(string fileName) { int i = fileName.LastIndexOf('.'); if (i >= 0) { return(fileName.Substring(0, i), fileName.Substring(i)); } return(fileName, String.Empty); } }
public static ThemedToolTip CreateToolTip(ISymbol symbol, bool forMemberList, Compilation compilation) { var tip = new ThemedToolTip(); if ((Config.Instance.DisplayOptimizations & DisplayOptimizations.CodeWindow) != 0) { WpfHelper.SetUITextRenderOptions(tip, true); } if (forMemberList == false) { tip.Title.Append(ThemeHelper.GetImage(symbol.GetImageId()).WrapMargin(WpfHelper.GlyphMargin)); } tip.Title .Append(symbol.GetAccessibility() + symbol.GetAbstractionModifier() + (symbol as IMethodSymbol).GetSpecialMethodModifier() + symbol.GetSymbolKindName() + " ") .Append(symbol.Name, true) .Append(symbol.GetParameterString()); var content = tip.Content; var t = symbol.GetReturnType(); if (t != null) { content.Append("member type: ") .Append(t.ToDisplayString(WpfHelper.MemberNameFormat), true); } else if (symbol.Kind == SymbolKind.TypeParameter) { content.Append("defined in: ") .Append(symbol.ContainingSymbol.ToDisplayString(WpfHelper.MemberNameFormat), true); var tp = symbol as ITypeParameterSymbol; if (tp.HasConstraint()) { content.Append(" ("); SymbolFormatter.Empty.ShowTypeConstaints(tp, content); content.Append(")"); } } t = symbol.ContainingType; if (t != null) { if (content.Inlines.FirstInline != null) { content.AppendLine(); } content.Append(t.GetSymbolKindName() + ": ") .Append(t.ToDisplayString(WpfHelper.MemberNameFormat), true); } if (forMemberList == false) { if (content.Inlines.FirstInline != null) { content.AppendLine(); } content.Append("namespace: " + symbol.ContainingNamespace?.ToString()) .Append("\nassembly: " + symbol.GetAssemblyModuleName()); if (symbol.Kind == SymbolKind.NamedType && ((INamedTypeSymbol)symbol).TypeKind == TypeKind.Delegate) { ShowDelegateSignature(content, (INamedTypeSymbol)symbol); } } ShowAttributes(symbol, content); if (compilation != null && Config.Instance.SymbolToolTipOptions.MatchFlags(SymbolToolTipOptions.XmlDocSummary)) { ShowXmlDocSummary(symbol, compilation, tip); } ShowNumericForms(symbol, tip); return(tip); }