From b8760451803864e88e80f2b80bdb3deb6e173c4d Mon Sep 17 00:00:00 2001 From: WMJ Date: Mon, 30 Apr 2018 08:14:50 +0800 Subject: [PATCH] + Supported "b", "i", "u" in comments --- Codist/Helpers/UIHelper.cs | 27 +++++++++--- Codist/Helpers/XmlDocParser.cs | 35 ++++++++++----- Codist/Properties/AssemblyInfo.cs | 2 +- .../CSharpQuickInfoSourceProvider.cs | 22 +++++----- Codist/QuickInfo/SymbolFormatter.cs | 44 +++++++++---------- Codist/source.extension.vsixmanifest | 2 +- TestProject/Comments.cs | 1 + 7 files changed, 82 insertions(+), 51 deletions(-) diff --git a/Codist/Helpers/UIHelper.cs b/Codist/Helpers/UIHelper.cs index 547058e8..3b414aeb 100644 --- a/Codist/Helpers/UIHelper.cs +++ b/Codist/Helpers/UIHelper.cs @@ -163,18 +163,33 @@ public static TextBlock AddText(this TextBlock block, string text, WpfBrush brus return block.AddText(text, false, false, brush); } public static TextBlock AddSymbol(this TextBlock block, ISymbol symbol, bool bold, WpfBrush brush) { + block.Inlines.Add(Render(symbol, bold, brush)); + return block; + } + + public static Run Render(this ISymbol symbol, WpfBrush brush) { + return symbol.Render(false, brush); + } + public static Run Render(this ISymbol symbol, bool bold, WpfBrush brush) { var run = Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.ClickAndGo) - ? new SymbolLink(symbol) - : new Run(block.Name); + ? new SymbolLink(symbol) + : new Run(symbol.Name); if (bold) { run.FontWeight = FontWeights.Bold; } run.Foreground = brush; run.ToolTip = symbol.ToString(); - block.Inlines.Add(run); - return block; + return run; } + public static TextBlock AddText(this TextBlock block, string text, bool bold, bool italic, WpfBrush brush) { + block.Inlines.Add(Render(text, bold, italic, brush)); + return block; + } + public static Run Render(this string text, WpfBrush brush) { + return text.Render(false, false, brush); + } + public static Run Render(this string text, bool bold, bool italic, WpfBrush brush) { var run = new Run(text); if (bold) { run.FontWeight = FontWeights.Bold; @@ -185,9 +200,9 @@ public static TextBlock AddText(this TextBlock block, string text, bool bold, bo if (brush != null) { run.Foreground = brush; } - block.Inlines.Add(run); - return block; + return run; } + public static TPanel AddText(this TPanel parent, string text) where TPanel : Panel { return parent.AddText(text, false, false, null); diff --git a/Codist/Helpers/XmlDocParser.cs b/Codist/Helpers/XmlDocParser.cs index b657b32f..c8a83a79 100644 --- a/Codist/Helpers/XmlDocParser.cs +++ b/Codist/Helpers/XmlDocParser.cs @@ -57,16 +57,16 @@ public static XElement GetNamedDocItem(this XElement doc, string element, string public static IEnumerable GetExceptions(this XElement doc) { return doc?.Elements("exception"); } - public static TextBlock ToUIText(this XElement content, Action symbolRenderer) { + public static TextBlock ToUIText(this XElement content, Action symbolRenderer) { if (content == null || content.HasElements == false && content.IsEmpty) { return null; } var text = new TextBlock { TextWrapping = TextWrapping.Wrap }; - ToUIText(content, text, symbolRenderer); + ToUIText(content, text.Inlines, symbolRenderer); return text.Inlines.FirstInline != null ? text : null; } - public static void ToUIText(this XContainer content, TextBlock text, Action symbolRenderer) { + public static void ToUIText(this XContainer content, InlineCollection text, Action symbolRenderer) { foreach (var item in content.Nodes()) { switch (item.NodeType) { case XmlNodeType.Element: @@ -104,9 +104,19 @@ public static void ToUIText(this XContainer content, TextBlock text, Action symbolRenderer) { + text.Add(span); + ToUIText(element, span.Inlines, symbolRenderer); + } } } diff --git a/Codist/Properties/AssemblyInfo.cs b/Codist/Properties/AssemblyInfo.cs index ddd74bad..43864b3e 100644 --- a/Codist/Properties/AssemblyInfo.cs +++ b/Codist/Properties/AssemblyInfo.cs @@ -30,4 +30,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("2.7.0.0")] -[assembly: AssemblyFileVersion("2.7.0.978")] +[assembly: AssemblyFileVersion("2.7.0.980")] diff --git a/Codist/QuickInfo/CSharpQuickInfoSourceProvider.cs b/Codist/QuickInfo/CSharpQuickInfoSourceProvider.cs index 4ea54ff3..14e0310b 100644 --- a/Codist/QuickInfo/CSharpQuickInfoSourceProvider.cs +++ b/Codist/QuickInfo/CSharpQuickInfoSourceProvider.cs @@ -167,7 +167,7 @@ void OverrideDocumentation(SyntaxNode node, DefaultQuickInfoPanelWrapper qiWrapp if (baseDocs != null) { var info = new TextBlock { TextWrapping = TextWrapping.Wrap }.AddText("Documentation from "); ToUIText(info, baseMember.ContainingType.ToMinimalDisplayParts(_SemanticModel, node.SpanStart)).AddText(":"); - baseDocs.ToUIText(info, RenderXmlDocSymbol); + baseDocs.ToUIText(info.Inlines, RenderXmlDocSymbol); RenderXmlReturnsDoc(baseMember, baseDocs.Parent, info); qiWrapper.OverrideDocumentation(info); } @@ -189,13 +189,13 @@ void _ConfigUpdated(object sender, EventArgs e) { } } - void RenderXmlDocSymbol(string symbol, TextBlock tb, SymbolKind symbolKind) { + void RenderXmlDocSymbol(string symbol, System.Windows.Documents.InlineCollection tb, SymbolKind symbolKind) { switch (symbolKind) { - case SymbolKind.Parameter: tb.AddText(symbol, _SymbolFormatter.Parameter); return; - case SymbolKind.TypeParameter: tb.AddText(symbol, _SymbolFormatter.TypeParameter); return; + case SymbolKind.Parameter: tb.Add(symbol.Render(_SymbolFormatter.Parameter)); return; + case SymbolKind.TypeParameter: tb.Add(symbol.Render(_SymbolFormatter.TypeParameter)); return; case SymbolKind.DynamicType: // highlight keywords - tb.AddText(symbol, _SymbolFormatter.Keyword); + tb.Add(symbol.Render(_SymbolFormatter.Keyword)); return; } var rs = DocumentationCommentId.GetFirstSymbolForDeclarationId(symbol, _SemanticModel.Compilation); @@ -203,18 +203,18 @@ void RenderXmlDocSymbol(string symbol, TextBlock tb, SymbolKind symbolKind) { if (symbol.Length > 2 && symbol[1] == ':') { switch (symbol[0]) { case 'T': - tb.AddText(symbol.Substring(2), false, true, _SymbolFormatter.Class); + tb.Add(symbol.Substring(2).Render(false, true, _SymbolFormatter.Class)); break; case 'M': - tb.AddText(symbol.Substring(2), false, true, _SymbolFormatter.Method); + tb.Add(symbol.Substring(2).Render(false, true, _SymbolFormatter.Method)); break; case '!': - tb.AddText(symbol.Substring(2), true, true, null); + tb.Add(symbol.Substring(2).Render(true, true, null)); break; } } else { - tb.AddText(symbol); + tb.Add(symbol); } return; } @@ -226,7 +226,7 @@ void RenderXmlReturnsDoc(ISymbol symbol, XElement doc, TextBlock desc) { var returns = doc.GetReturns(); if (returns != null) { desc.AddText("\nReturns", true).AddText(": "); - returns.ToUIText(desc, RenderXmlDocSymbol); + returns.ToUIText(desc.Inlines, RenderXmlDocSymbol); } } } @@ -910,7 +910,7 @@ void ShowParameterInfo(IList qiContent, SyntaxNode node, ArgumentSyntax var info = ToUIText(new TextBlock().AddText("Argument of "), symbol.Symbol.ToMinimalDisplayParts(_SemanticModel, node.SpanStart), ap); if (doc != null) { info.AddText("\n" + argName, true).AddText(": "); - doc.ToUIText(info, RenderXmlDocSymbol); + doc.ToUIText(info.Inlines, RenderXmlDocSymbol); } qiContent.Add(info); } diff --git a/Codist/QuickInfo/SymbolFormatter.cs b/Codist/QuickInfo/SymbolFormatter.cs index 4e6af88a..7e9edfa4 100644 --- a/Codist/QuickInfo/SymbolFormatter.cs +++ b/Codist/QuickInfo/SymbolFormatter.cs @@ -47,12 +47,12 @@ internal void UpdateSyntaxHighlights(IEditorFormatMap formatMap) { _FieldBrush = formatMap.GetBrush(Constants.CSharpFieldName); } - internal void ToUIText(TextBlock text, ISymbol symbol) { + internal void ToUIText(System.Windows.Documents.InlineCollection text, ISymbol symbol) { switch (symbol.Kind) { - case SymbolKind.Event: text.AddSymbol(symbol, false, _DelegateBrush); return; - case SymbolKind.Field: text.AddSymbol(symbol, false, _FieldBrush); return; + case SymbolKind.Event: text.Add(symbol.Render(_DelegateBrush)); return; + case SymbolKind.Field: text.Add(symbol.Render(_FieldBrush)); return; case SymbolKind.Method: - text.AddSymbol(symbol, false, _MethodBrush); + text.Add(symbol.Render(_MethodBrush)); var method = symbol as IMethodSymbol; if (method.IsGenericMethod) { var arguments = method.TypeParameters; @@ -63,44 +63,44 @@ internal void ToUIText(TextBlock text, ISymbol symbol) { var type = symbol as INamedTypeSymbol; switch (type.TypeKind) { case TypeKind.Class: - text.AddSymbol(symbol, false, _ClassBrush); break; + text.Add(symbol.Render(_ClassBrush)); break; case TypeKind.Delegate: - text.AddSymbol(symbol, false, _DelegateBrush); return; + text.Add(symbol.Render(_DelegateBrush)); return; case TypeKind.Dynamic: - text.AddText(symbol.Name, _KeywordBrush); return; + text.Add(symbol.Name.Render(_KeywordBrush)); return; case TypeKind.Enum: - text.AddSymbol(symbol, false, _EnumBrush); return; + text.Add(symbol.Render(_EnumBrush)); return; case TypeKind.Interface: - text.AddSymbol(symbol, false, _InterfaceBrush); break; + text.Add(symbol.Render(_InterfaceBrush)); break; case TypeKind.Struct: - text.AddSymbol(symbol, false, _StructBrush); break; + text.Add(symbol.Render(_StructBrush)); break; case TypeKind.TypeParameter: - text.AddText(symbol.Name, _TypeParameterBrush); return; + text.Add(symbol.Name.Render(_TypeParameterBrush)); return; default: - text.AddText(symbol.MetadataName, _ClassBrush); return; + text.Add(symbol.MetadataName.Render(_ClassBrush)); return; } if (type.IsGenericType) { var arguments = type.TypeParameters; AddTypeArguments(text, arguments); } return; - case SymbolKind.Namespace: text.AddText(symbol.Name, _NamespaceBrush); return; - case SymbolKind.Parameter: text.AddText(symbol.Name, _ParameterBrush); return; - case SymbolKind.Property: text.AddSymbol(symbol, false, _PropertyBrush); return; - case SymbolKind.TypeParameter: text.AddText(symbol.Name, _TypeParameterBrush); return; - default: text.AddText(symbol.Name); return; + case SymbolKind.Namespace: text.Add(symbol.Name.Render(_NamespaceBrush)); return; + case SymbolKind.Parameter: text.Add(symbol.Name.Render(_ParameterBrush)); return; + case SymbolKind.Property: text.Add(symbol.Render(_PropertyBrush)); return; + case SymbolKind.TypeParameter: text.Add(symbol.Name.Render(_TypeParameterBrush)); return; + default: text.Add(symbol.Name); return; } } - void AddTypeArguments(TextBlock text, System.Collections.Immutable.ImmutableArray arguments) { - text.AddText("<"); + void AddTypeArguments(System.Windows.Documents.InlineCollection text, System.Collections.Immutable.ImmutableArray arguments) { + text.Add("<"); for (int i = 0; i < arguments.Length; i++) { if (i > 0) { - text.AddText(", "); + text.Add(", "); } - text.AddText(arguments[i].Name, _TypeParameterBrush); + text.Add(arguments[i].Name.Render(_TypeParameterBrush)); } - text.AddText(">"); + text.Add(">"); } } } diff --git a/Codist/source.extension.vsixmanifest b/Codist/source.extension.vsixmanifest index a155fe47..1df54643 100644 --- a/Codist/source.extension.vsixmanifest +++ b/Codist/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + Codist A plugin which enhances coding experience with advanced syntax highlighting, scrollbar marking and Super Quick Info for C# programmers. https://github.com/wmjordan/Codist diff --git a/TestProject/Comments.cs b/TestProject/Comments.cs index 223af8e9..efed3545 100644 --- a/TestProject/Comments.cs +++ b/TestProject/Comments.cs @@ -19,6 +19,7 @@ namespace TestProject /// is accessible, like , , /// , or . /// The "para" elements no longer generate empty lines. + /// You can style your comment with bold, italic and underline, or combinations of them. /// class Comments {