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); }
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); }
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); }