Skip to content

Commit

Permalink
+ Supported "b", "i", "u" in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Apr 30, 2018
1 parent 238c3ed commit b876045
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 51 deletions.
27 changes: 21 additions & 6 deletions Codist/Helpers/UIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<TPanel>(this TPanel parent, string text)
where TPanel : Panel {
return parent.AddText(text, false, false, null);
Expand Down
35 changes: 25 additions & 10 deletions Codist/Helpers/XmlDocParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ public static XElement GetNamedDocItem(this XElement doc, string element, string
public static IEnumerable<XElement> GetExceptions(this XElement doc) {
return doc?.Elements("exception");
}
public static TextBlock ToUIText(this XElement content, Action<string, TextBlock, SymbolKind> symbolRenderer) {
public static TextBlock ToUIText(this XElement content, Action<string, InlineCollection, SymbolKind> 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<string, TextBlock, SymbolKind> symbolRenderer) {
public static void ToUIText(this XContainer content, InlineCollection text, Action<string, InlineCollection, SymbolKind> symbolRenderer) {
foreach (var item in content.Nodes()) {
switch (item.NodeType) {
case XmlNodeType.Element:
Expand Down Expand Up @@ -104,9 +104,19 @@ public static void ToUIText(this XContainer content, TextBlock text, Action<stri
symbolRenderer(typeParamName.Value, text, SymbolKind.TypeParameter);
}
break;
case "list":
case "description":
case "c":
case "b":
StyleInner(e, text, new Bold(), symbolRenderer);
break;
case "i":
StyleInner(e, text, new Italic(), symbolRenderer);
break;
case "u":
StyleInner(e, text, new Underline(), symbolRenderer);
break;
//case "list":
//case "description":
//case "c":
default:
ToUIText(e, text, symbolRenderer);
break;
}
Expand All @@ -115,25 +125,30 @@ public static void ToUIText(this XContainer content, TextBlock text, Action<stri
string t = (item as XText).Value;
if (item.Parent.Name != "code") {
var previous = (item.PreviousNode as XElement)?.Name;
if (previous == null || previous != "see" && previous != "paramref" && previous != "typeparamref" && previous != "c") {
if (previous == null || previous != "see" && previous != "paramref" && previous != "typeparamref" && previous != "c" && previous != "b" && previous != "i" && previous != "u") {
t = item.NextNode == null ? t.Trim() : t.TrimStart();
}
else if (item.NextNode == null) {
t = t.TrimEnd();
}
t = _FixWhitespaces.Replace(t.Replace('\n', ' '), " ");
}
text.AddText(t);
text.Add(new Run(t));
break;
case XmlNodeType.CDATA:
text.AddText((item as XText).Value);
text.Add(new Run((item as XText).Value));
break;
case XmlNodeType.EntityReference:
case XmlNodeType.Entity:
text.AddText(item.ToString());
text.Add(new Run(item.ToString()));
break;
}
}
}

static void StyleInner(XElement element, InlineCollection text, Span span, Action<string, InlineCollection, SymbolKind> symbolRenderer) {
text.Add(span);
ToUIText(element, span.Inlines, symbolRenderer);
}
}
}
2 changes: 1 addition & 1 deletion Codist/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
22 changes: 11 additions & 11 deletions Codist/QuickInfo/CSharpQuickInfoSourceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -189,32 +189,32 @@ 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);
if (rs == null) {
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;
}
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -910,7 +910,7 @@ void ShowParameterInfo(IList<object> 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);
}
Expand Down
44 changes: 22 additions & 22 deletions Codist/QuickInfo/SymbolFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ITypeParameterSymbol> arguments) {
text.AddText("<");
void AddTypeArguments(System.Windows.Documents.InlineCollection text, System.Collections.Immutable.ImmutableArray<ITypeParameterSymbol> 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(">");
}
}
}
2 changes: 1 addition & 1 deletion Codist/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="Codist.WMJ.c7b93d20-621f-4b21-9d28-d51157ef0b94" Version="2.7.0.975" Language="en-US" Publisher="WMJ" />
<Identity Id="Codist.WMJ.c7b93d20-621f-4b21-9d28-d51157ef0b94" Version="2.7.0.976" Language="en-US" Publisher="WMJ" />
<DisplayName>Codist</DisplayName>
<Description xml:space="preserve">A plugin which enhances coding experience with advanced syntax highlighting, scrollbar marking and Super Quick Info for C# programmers.</Description>
<MoreInfo>https://github.com/wmjordan/Codist</MoreInfo>
Expand Down
1 change: 1 addition & 0 deletions TestProject/Comments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace TestProject
/// is accessible, like <see cref="MyEnum"/>, <see cref="MyStruct._instanceField"/>,
/// <see cref="ConcreteClass.Method"/>, or <see cref="ConcreteClass.Method{TGeneric}"/>.</para>
/// <para>The "para" elements no longer generate empty lines.</para>
/// <para>You can style your comment with <b>bold</b>, <i>italic</i> and <u>underline</u>, or <b><i><u>combinations of them</u></i></b>.</para>
/// </summary>
class Comments
{
Expand Down

0 comments on commit b876045

Please sign in to comment.