Browse Source

Add Language.GetRichTextTooltip

pull/1654/head
Siegfried Pammer 7 years ago
parent
commit
6baecf85aa
  1. 3
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpAmbience.cs
  2. 1
      ICSharpCode.Decompiler/CSharp/OutputVisitor/ITokenWriter.cs
  3. 122
      ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterTokenWriter.cs
  4. 1
      ILSpy/ILSpy.csproj
  5. 2
      ILSpy/ISmartTextOutput.cs
  6. 5
      ILSpy/Languages/CSharpHighlightingTokenWriter.cs
  7. 13
      ILSpy/Languages/CSharpLanguage.cs
  8. 7
      ILSpy/Languages/Language.cs
  9. 119
      ILSpy/RichTextModelOutput.cs
  10. 12
      ILSpy/TextView/DecompilerTextView.cs
  11. 5
      ILSpy/TextView/XmlDocRenderer.cs

3
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpAmbience.cs

@ -56,6 +56,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
TypeSystemAstBuilder astBuilder = CreateAstBuilder(); TypeSystemAstBuilder astBuilder = CreateAstBuilder();
AstNode node = astBuilder.ConvertSymbol(symbol); AstNode node = astBuilder.ConvertSymbol(symbol);
writer.StartNode(node);
EntityDeclaration entityDecl = node as EntityDeclaration; EntityDeclaration entityDecl = node as EntityDeclaration;
if (entityDecl != null) if (entityDecl != null)
PrintModifiers(entityDecl.Modifiers, writer); PrintModifiers(entityDecl.Modifiers, writer);
@ -167,6 +168,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
} else { } else {
writer.WriteToken(Roles.Semicolon, ";"); writer.WriteToken(Roles.Semicolon, ";");
} }
writer.EndNode(node);
} }
} }
@ -190,6 +192,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
{ {
TypeSystemAstBuilder astBuilder = new TypeSystemAstBuilder(); TypeSystemAstBuilder astBuilder = new TypeSystemAstBuilder();
astBuilder.AddTypeReferenceAnnotations = true; astBuilder.AddTypeReferenceAnnotations = true;
astBuilder.AddResolveResultAnnotations = true;
astBuilder.ShowTypeParametersForUnboundTypes = true; astBuilder.ShowTypeParametersForUnboundTypes = true;
astBuilder.ShowModifiers = (ConversionFlags & ConversionFlags.ShowModifiers) == ConversionFlags.ShowModifiers; astBuilder.ShowModifiers = (ConversionFlags & ConversionFlags.ShowModifiers) == ConversionFlags.ShowModifiers;
astBuilder.ShowAccessibility = (ConversionFlags & ConversionFlags.ShowAccessibility) == ConversionFlags.ShowAccessibility; astBuilder.ShowAccessibility = (ConversionFlags & ConversionFlags.ShowAccessibility) == ConversionFlags.ShowAccessibility;

1
ICSharpCode.Decompiler/CSharp/OutputVisitor/ITokenWriter.cs

@ -79,6 +79,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public interface ILocatable public interface ILocatable
{ {
TextLocation Location { get; } TextLocation Location { get; }
int Length { get; }
} }
public abstract class DecoratingTokenWriter : TokenWriter public abstract class DecoratingTokenWriter : TokenWriter

122
ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterTokenWriter.cs

@ -30,22 +30,20 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public class TextWriterTokenWriter : TokenWriter, ILocatable public class TextWriterTokenWriter : TokenWriter, ILocatable
{ {
readonly TextWriter textWriter; readonly TextWriter textWriter;
int indentation;
bool needsIndent = true; bool needsIndent = true;
bool isAtStartOfLine = true; bool isAtStartOfLine = true;
int line, column; int line, column;
public int Indentation { public int Indentation { get; set; }
get { return this.indentation; }
set { this.indentation = value; }
}
public TextLocation Location { public TextLocation Location {
get { return new TextLocation(line, column + (needsIndent ? indentation * IndentationString.Length : 0)); } get { return new TextLocation(line, column + (needsIndent ? Indentation * IndentationString.Length : 0)); }
} }
public string IndentationString { get; set; } public string IndentationString { get; set; }
public int Length { get; private set; }
public TextWriterTokenWriter(TextWriter textWriter) public TextWriterTokenWriter(TextWriter textWriter)
{ {
if (textWriter == null) if (textWriter == null)
@ -55,73 +53,80 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
this.line = 1; this.line = 1;
this.column = 1; this.column = 1;
} }
public override void WriteIdentifier(Identifier identifier) public override void WriteIdentifier(Identifier identifier)
{ {
WriteIndentation(); WriteIndentation();
if (identifier.IsVerbatim || CSharpOutputVisitor.IsKeyword(identifier.Name, identifier)) { if (identifier.IsVerbatim || CSharpOutputVisitor.IsKeyword(identifier.Name, identifier)) {
textWriter.Write('@'); textWriter.Write('@');
column++; column++;
Length++;
} }
string name = EscapeIdentifier(identifier.Name); string name = EscapeIdentifier(identifier.Name);
textWriter.Write(name); textWriter.Write(name);
column += name.Length; column += name.Length;
Length += name.Length;
isAtStartOfLine = false; isAtStartOfLine = false;
} }
public override void WriteKeyword(Role role, string keyword) public override void WriteKeyword(Role role, string keyword)
{ {
WriteIndentation(); WriteIndentation();
column += keyword.Length; column += keyword.Length;
Length += keyword.Length;
textWriter.Write(keyword); textWriter.Write(keyword);
isAtStartOfLine = false; isAtStartOfLine = false;
} }
public override void WriteToken(Role role, string token) public override void WriteToken(Role role, string token)
{ {
WriteIndentation(); WriteIndentation();
column += token.Length; column += token.Length;
Length += token.Length;
textWriter.Write(token); textWriter.Write(token);
isAtStartOfLine = false; isAtStartOfLine = false;
} }
public override void Space() public override void Space()
{ {
WriteIndentation(); WriteIndentation();
column++; column++;
Length++;
textWriter.Write(' '); textWriter.Write(' ');
} }
protected void WriteIndentation() protected void WriteIndentation()
{ {
if (needsIndent) { if (needsIndent) {
needsIndent = false; needsIndent = false;
for (int i = 0; i < indentation; i++) { for (int i = 0; i < Indentation; i++) {
textWriter.Write(this.IndentationString); textWriter.Write(this.IndentationString);
} }
column += indentation * IndentationString.Length; column += Indentation * IndentationString.Length;
Length += Indentation * IndentationString.Length;
} }
} }
public override void NewLine() public override void NewLine()
{ {
textWriter.WriteLine(); textWriter.WriteLine();
column = 1; column = 1;
line++; line++;
Length += textWriter.NewLine.Length;
needsIndent = true; needsIndent = true;
isAtStartOfLine = true; isAtStartOfLine = true;
} }
public override void Indent() public override void Indent()
{ {
indentation++; Indentation++;
} }
public override void Unindent() public override void Unindent()
{ {
indentation--; Indentation--;
} }
public override void WriteComment(CommentType commentType, string content) public override void WriteComment(CommentType commentType, string content)
{ {
WriteIndentation(); WriteIndentation();
@ -129,6 +134,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
case CommentType.SingleLine: case CommentType.SingleLine:
textWriter.Write("//"); textWriter.Write("//");
textWriter.WriteLine(content); textWriter.WriteLine(content);
Length += 2 + content.Length + textWriter.NewLine.Length;
column = 1; column = 1;
line++; line++;
needsIndent = true; needsIndent = true;
@ -138,6 +144,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
textWriter.Write("/*"); textWriter.Write("/*");
textWriter.Write(content); textWriter.Write(content);
textWriter.Write("*/"); textWriter.Write("*/");
Length += 4 + content.Length;
column += 2; column += 2;
UpdateEndLocation(content, ref line, ref column); UpdateEndLocation(content, ref line, ref column);
column += 2; column += 2;
@ -146,6 +153,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
case CommentType.Documentation: case CommentType.Documentation:
textWriter.Write("///"); textWriter.Write("///");
textWriter.WriteLine(content); textWriter.WriteLine(content);
Length += 3 + content.Length + textWriter.NewLine.Length;
column = 1; column = 1;
line++; line++;
needsIndent = true; needsIndent = true;
@ -155,6 +163,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
textWriter.Write("/**"); textWriter.Write("/**");
textWriter.Write(content); textWriter.Write(content);
textWriter.Write("*/"); textWriter.Write("*/");
Length += 5 + content.Length;
column += 3; column += 3;
UpdateEndLocation(content, ref line, ref column); UpdateEndLocation(content, ref line, ref column);
column += 2; column += 2;
@ -163,10 +172,11 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
default: default:
textWriter.Write(content); textWriter.Write(content);
column += content.Length; column += content.Length;
Length += content.Length;
break; break;
} }
} }
static void UpdateEndLocation(string content, ref int line, ref int column) static void UpdateEndLocation(string content, ref int line, ref int column)
{ {
if (string.IsNullOrEmpty(content)) if (string.IsNullOrEmpty(content))
@ -186,7 +196,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
column++; column++;
} }
} }
public override void WritePreProcessorDirective(PreProcessorDirectiveType type, string argument) public override void WritePreProcessorDirective(PreProcessorDirectiveType type, string argument)
{ {
// pre-processor directive must start on its own line // pre-processor directive must start on its own line
@ -197,14 +207,16 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
string directive = type.ToString().ToLowerInvariant(); string directive = type.ToString().ToLowerInvariant();
textWriter.Write(directive); textWriter.Write(directive);
column += 1 + directive.Length; column += 1 + directive.Length;
Length += 1 + directive.Length;
if (!string.IsNullOrEmpty(argument)) { if (!string.IsNullOrEmpty(argument)) {
textWriter.Write(' '); textWriter.Write(' ');
textWriter.Write(argument); textWriter.Write(argument);
column += 1 + argument.Length; column += 1 + argument.Length;
Length += 1 + argument.Length;
} }
NewLine(); NewLine();
} }
public static string PrintPrimitiveValue(object value) public static string PrintPrimitiveValue(object value)
{ {
TextWriter writer = new StringWriter(); TextWriter writer = new StringWriter();
@ -212,48 +224,55 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
tokenWriter.WritePrimitiveValue(value); tokenWriter.WritePrimitiveValue(value);
return writer.ToString(); return writer.ToString();
} }
public override void WritePrimitiveValue(object value, string literalValue = null) public override void WritePrimitiveValue(object value, string literalValue = null)
{ {
if (literalValue != null) { if (literalValue != null) {
textWriter.Write(literalValue); textWriter.Write(literalValue);
column += literalValue.Length; column += literalValue.Length;
Length += literalValue.Length;
return; return;
} }
if (value == null) { if (value == null) {
// usually NullReferenceExpression should be used for this, but we'll handle it anyways // usually NullReferenceExpression should be used for this, but we'll handle it anyways
textWriter.Write("null"); textWriter.Write("null");
column += 4; column += 4;
Length += 4;
return; return;
} }
if (value is bool) { if (value is bool) {
if ((bool)value) { if ((bool)value) {
textWriter.Write("true"); textWriter.Write("true");
column += 4; column += 4;
Length += 4;
} else { } else {
textWriter.Write("false"); textWriter.Write("false");
column += 5; column += 5;
Length += 5;
} }
return; return;
} }
if (value is string) { if (value is string) {
string tmp = ConvertString(value.ToString()); string tmp = ConvertString(value.ToString());
column += tmp.Length + 2; column += tmp.Length + 2;
Length += tmp.Length + 2;
textWriter.Write('"'); textWriter.Write('"');
textWriter.Write(tmp); textWriter.Write(tmp);
textWriter.Write('"'); textWriter.Write('"');
} else if (value is char) { } else if (value is char) {
string tmp = ConvertCharLiteral((char)value); string tmp = ConvertCharLiteral((char)value);
column += tmp.Length + 2; column += tmp.Length + 2;
Length += tmp.Length + 2;
textWriter.Write('\''); textWriter.Write('\'');
textWriter.Write(tmp); textWriter.Write(tmp);
textWriter.Write('\''); textWriter.Write('\'');
} else if (value is decimal) { } else if (value is decimal) {
string str = ((decimal)value).ToString(NumberFormatInfo.InvariantInfo) + "m"; string str = ((decimal)value).ToString(NumberFormatInfo.InvariantInfo) + "m";
column += str.Length; column += str.Length;
Length += str.Length;
textWriter.Write(str); textWriter.Write(str);
} else if (value is float) { } else if (value is float) {
float f = (float)value; float f = (float)value;
@ -262,16 +281,20 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
// but we still support writing these to make life easier for code generators. // but we still support writing these to make life easier for code generators.
textWriter.Write("float"); textWriter.Write("float");
column += 5; column += 5;
Length += 5;
WriteToken(Roles.Dot, "."); WriteToken(Roles.Dot, ".");
if (float.IsPositiveInfinity(f)) { if (float.IsPositiveInfinity(f)) {
textWriter.Write("PositiveInfinity"); textWriter.Write("PositiveInfinity");
column += "PositiveInfinity".Length; column += "PositiveInfinity".Length;
Length += "PositiveInfinity".Length;
} else if (float.IsNegativeInfinity(f)) { } else if (float.IsNegativeInfinity(f)) {
textWriter.Write("NegativeInfinity"); textWriter.Write("NegativeInfinity");
column += "NegativeInfinity".Length; column += "NegativeInfinity".Length;
Length += "NegativeInfinity".Length;
} else { } else {
textWriter.Write("NaN"); textWriter.Write("NaN");
column += 3; column += 3;
Length += 3;
} }
return; return;
} }
@ -281,9 +304,11 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
// the special case here than to do it in all code generators) // the special case here than to do it in all code generators)
textWriter.Write("-"); textWriter.Write("-");
column++; column++;
Length++;
} }
var str = f.ToString("R", NumberFormatInfo.InvariantInfo) + "f"; var str = f.ToString("R", NumberFormatInfo.InvariantInfo) + "f";
column += str.Length; column += str.Length;
Length += str.Length;
textWriter.Write(str); textWriter.Write(str);
} else if (value is double) { } else if (value is double) {
double f = (double)value; double f = (double)value;
@ -292,16 +317,20 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
// but we still support writing these to make life easier for code generators. // but we still support writing these to make life easier for code generators.
textWriter.Write("double"); textWriter.Write("double");
column += 6; column += 6;
Length += 6;
WriteToken(Roles.Dot, "."); WriteToken(Roles.Dot, ".");
if (double.IsPositiveInfinity(f)) { if (double.IsPositiveInfinity(f)) {
textWriter.Write("PositiveInfinity"); textWriter.Write("PositiveInfinity");
column += "PositiveInfinity".Length; column += "PositiveInfinity".Length;
Length += "PositiveInfinity".Length;
} else if (double.IsNegativeInfinity(f)) { } else if (double.IsNegativeInfinity(f)) {
textWriter.Write("NegativeInfinity"); textWriter.Write("NegativeInfinity");
column += "NegativeInfinity".Length; column += "NegativeInfinity".Length;
Length += "NegativeInfinity".Length;
} else { } else {
textWriter.Write("NaN"); textWriter.Write("NaN");
column += 3; column += 3;
Length += 3;
} }
return; return;
} }
@ -310,20 +339,22 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
// (again, not a primitive expression, but it's better to handle // (again, not a primitive expression, but it's better to handle
// the special case here than to do it in all code generators) // the special case here than to do it in all code generators)
textWriter.Write("-"); textWriter.Write("-");
Length++;
} }
string number = f.ToString("R", NumberFormatInfo.InvariantInfo); string number = f.ToString("R", NumberFormatInfo.InvariantInfo);
if (number.IndexOf('.') < 0 && number.IndexOf('E') < 0) { if (number.IndexOf('.') < 0 && number.IndexOf('E') < 0) {
number += ".0"; number += ".0";
} }
textWriter.Write(number); textWriter.Write(number);
Length += number.Length;
} else if (value is IFormattable) { } else if (value is IFormattable) {
StringBuilder b = new StringBuilder (); StringBuilder b = new StringBuilder();
// if (primitiveExpression.LiteralFormat == LiteralFormat.HexadecimalNumber) { // if (primitiveExpression.LiteralFormat == LiteralFormat.HexadecimalNumber) {
// b.Append("0x"); // b.Append("0x");
// b.Append(((IFormattable)val).ToString("x", NumberFormatInfo.InvariantInfo)); // b.Append(((IFormattable)val).ToString("x", NumberFormatInfo.InvariantInfo));
// } else { // } else {
b.Append(((IFormattable)value).ToString(null, NumberFormatInfo.InvariantInfo)); b.Append(((IFormattable)value).ToString(null, NumberFormatInfo.InvariantInfo));
// } // }
if (value is uint || value is ulong) { if (value is uint || value is ulong) {
b.Append("u"); b.Append("u");
} }
@ -332,12 +363,15 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
} }
textWriter.Write(b.ToString()); textWriter.Write(b.ToString());
column += b.Length; column += b.Length;
Length += b.Length;
} else { } else {
textWriter.Write(value.ToString()); textWriter.Write(value.ToString());
column += value.ToString().Length; int length = value.ToString().Length;
column += length;
Length += length;
} }
} }
/// <summary> /// <summary>
/// Gets the escape sequence for the specified character within a char literal. /// Gets the escape sequence for the specified character within a char literal.
/// Does not include the single quotes surrounding the char literal. /// Does not include the single quotes surrounding the char literal.
@ -349,7 +383,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
} }
return ConvertChar(ch) ?? ch.ToString(); return ConvertChar(ch) ?? ch.ToString();
} }
/// <summary> /// <summary>
/// Gets the escape sequence for the specified character. /// Gets the escape sequence for the specified character.
/// </summary> /// </summary>
@ -412,7 +446,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
/// </summary> /// </summary>
public static string ConvertString(string str) public static string ConvertString(string str)
{ {
StringBuilder sb = new StringBuilder (); StringBuilder sb = new StringBuilder();
foreach (char ch in str) { foreach (char ch in str) {
string s = ch == '"' ? "\\\"" : ConvertChar(ch); string s = ch == '"' ? "\\\"" : ConvertChar(ch);
if (s != null) sb.Append(s); if (s != null) sb.Append(s);
@ -477,17 +511,19 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
return true; return true;
} }
} }
public override void WritePrimitiveType(string type) public override void WritePrimitiveType(string type)
{ {
textWriter.Write(type); textWriter.Write(type);
column += type.Length; column += type.Length;
Length += type.Length;
if (type == "new") { if (type == "new") {
textWriter.Write("()"); textWriter.Write("()");
column += 2; column += 2;
Length += 2;
} }
} }
public override void StartNode(AstNode node) public override void StartNode(AstNode node)
{ {
// Write out the indentation, so that overrides of this method // Write out the indentation, so that overrides of this method
@ -495,7 +531,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
// in the output. // in the output.
WriteIndentation(); WriteIndentation();
} }
public override void EndNode(AstNode node) public override void EndNode(AstNode node)
{ {
} }

1
ILSpy/ILSpy.csproj

@ -173,6 +173,7 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="RichTextModelOutput.cs" />
<Compile Include="Search\AbstractEntitySearchStrategy.cs" /> <Compile Include="Search\AbstractEntitySearchStrategy.cs" />
<Compile Include="Search\AssemblySearchStrategy.cs" /> <Compile Include="Search\AssemblySearchStrategy.cs" />
<Compile Include="Search\LiteralSearchStrategy.cs" /> <Compile Include="Search\LiteralSearchStrategy.cs" />

2
ILSpy/ISmartTextOutput.cs

@ -39,7 +39,7 @@ namespace ICSharpCode.ILSpy
void BeginSpan(HighlightingColor highlightingColor); void BeginSpan(HighlightingColor highlightingColor);
void EndSpan(); void EndSpan();
} }
public static class SmartTextOutputExtensions public static class SmartTextOutputExtensions
{ {
/// <summary> /// <summary>

5
ILSpy/Languages/CSharpHighlightingTokenWriter.cs

@ -419,6 +419,9 @@ namespace ICSharpCode.ILSpy
ISymbol GetCurrentMemberReference() ISymbol GetCurrentMemberReference()
{ {
if (nodeStack == null || nodeStack.Count == 0)
return null;
AstNode node = nodeStack.Peek(); AstNode node = nodeStack.Peek();
var symbol = node.GetSymbol(); var symbol = node.GetSymbol();
if (symbol == null && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression) { if (symbol == null && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression) {
@ -435,7 +438,7 @@ namespace ICSharpCode.ILSpy
return symbol; return symbol;
} }
Stack<AstNode> nodeStack = new Stack<AstNode>(); readonly Stack<AstNode> nodeStack = new Stack<AstNode>();
public override void StartNode(AstNode node) public override void StartNode(AstNode node)
{ {

13
ILSpy/Languages/CSharpLanguage.cs

@ -26,7 +26,9 @@ using System.Reflection.Metadata;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Utils;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.OutputVisitor; using ICSharpCode.Decompiler.CSharp.OutputVisitor;
@ -625,10 +627,15 @@ namespace ICSharpCode.ILSpy
return showAllMembers || !CSharpDecompiler.MemberIsHidden(assembly, member.MetadataToken, new DecompilationOptions().DecompilerSettings); return showAllMembers || !CSharpDecompiler.MemberIsHidden(assembly, member.MetadataToken, new DecompilationOptions().DecompilerSettings);
} }
public override string GetTooltip(IEntity entity) public override RichText GetRichTextTooltip(IEntity entity)
{ {
var flags = ConversionFlags.All & ~(ConversionFlags.ShowBody | ConversionFlags.PlaceReturnTypeAfterParameterList); var flags = ConversionFlags.All & ~(ConversionFlags.ShowBody | ConversionFlags.PlaceReturnTypeAfterParameterList);
return new CSharpAmbience() { ConversionFlags = flags }.ConvertSymbol(entity); var output = new StringWriter();
var decoratedWriter = new TextWriterTokenWriter(output);
var richTextOutput = new RichTextModelOutput(decoratedWriter);
var writer = new CSharpHighlightingTokenWriter(decoratedWriter, richTextOutput);
new CSharpAmbience() { ConversionFlags = flags }.ConvertSymbol(entity, writer, FormattingOptionsFactory.CreateEmpty());
return new RichText(output.ToString(), richTextOutput.Model);
} }
public override CodeMappingInfo GetCodeMappingInfo(PEFile module, EntityHandle member) public override CodeMappingInfo GetCodeMappingInfo(PEFile module, EntityHandle member)

7
ILSpy/Languages/Language.cs

@ -21,6 +21,7 @@ using System.Collections.Generic;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Reflection.PortableExecutable; using System.Reflection.PortableExecutable;
using System.Text; using System.Text;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Solution; using ICSharpCode.Decompiler.Solution;
@ -349,7 +350,11 @@ namespace ICSharpCode.ILSpy
return GetDisplayName(entity, true, true, true); return GetDisplayName(entity, true, true, true);
} }
public virtual object GetFancyTooltip(IEntity entity) /// <summary>
/// Converts a member signature to a string.
/// This is used for displaying the tooltip on a member reference.
/// </summary>
public virtual RichText GetRichTextTooltip(IEntity entity)
{ {
return GetTooltip(entity); return GetTooltip(entity);
} }

119
ILSpy/RichTextModelOutput.cs

@ -0,0 +1,119 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Reflection.Metadata;
using System.Text;
using System.Windows;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp.OutputVisitor;
using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy
{
public class RichTextModelOutput : ISmartTextOutput
{
readonly Stack<HighlightingColor> colorStack = new Stack<HighlightingColor>();
HighlightingColor currentColor = new HighlightingColor();
int currentColorBegin = -1;
ILocatable textOutput;
public string IndentationString { get; set; } = "\t";
public RichTextModel Model { get; set; } = new RichTextModel();
public RichTextModelOutput(ILocatable textOutput)
{
this.textOutput = textOutput;
}
public void AddUIElement(Func<UIElement> element)
{
throw new NotSupportedException();
}
public void BeginSpan(HighlightingColor highlightingColor)
{
if (currentColorBegin > -1)
Model.SetHighlighting(currentColorBegin, textOutput.Length - currentColorBegin, currentColor);
colorStack.Push(currentColor);
currentColor = currentColor.Clone();
currentColorBegin = textOutput.Length;
currentColor.MergeWith(highlightingColor);
currentColor.Freeze();
}
public void EndSpan()
{
Model.SetHighlighting(currentColorBegin, textOutput.Length - currentColorBegin, currentColor);
currentColor = colorStack.Pop();
currentColorBegin = textOutput.Length;
}
public void Indent()
{
}
public void Unindent()
{
}
public void Write(char ch)
{
}
public void Write(string text)
{
}
public void WriteLine()
{
}
public void WriteReference(Decompiler.Disassembler.OpCodeInfo opCode, bool omitSuffix = false)
{
}
public void WriteReference(PEFile module, EntityHandle handle, string text, bool isDefinition = false)
{
}
public void WriteReference(IType type, string text, bool isDefinition = false)
{
}
public void WriteReference(IMember member, string text, bool isDefinition = false)
{
}
public void WriteLocalReference(string text, object reference, bool isDefinition = false)
{
}
public void MarkFoldStart(string collapsedText = "...", bool defaultCollapsed = false)
{
}
public void MarkFoldEnd()
{
}
}
}

12
ILSpy/TextView/DecompilerTextView.cs

@ -92,7 +92,7 @@ namespace ICSharpCode.ILSpy.TextView
} }
}); });
/*HighlightingManager.Instance.RegisterHighlighting( HighlightingManager.Instance.RegisterHighlighting(
"C#", new string[] { ".cs" }, "C#", new string[] { ".cs" },
delegate { delegate {
using (Stream s = typeof(DecompilerTextView).Assembly.GetManifestResourceStream(typeof(DecompilerTextView), "CSharp-Mode.xshd")) { using (Stream s = typeof(DecompilerTextView).Assembly.GetManifestResourceStream(typeof(DecompilerTextView), "CSharp-Mode.xshd")) {
@ -100,7 +100,7 @@ namespace ICSharpCode.ILSpy.TextView
return HighlightingLoader.Load(reader, HighlightingManager.Instance); return HighlightingLoader.Load(reader, HighlightingManager.Instance);
} }
} }
});*/ });
InitializeComponent(); InitializeComponent();
@ -364,7 +364,8 @@ namespace ICSharpCode.ILSpy.TextView
{ {
Language currentLanguage = MainWindow.Instance.CurrentLanguage; Language currentLanguage = MainWindow.Instance.CurrentLanguage;
DocumentationUIBuilder renderer = new DocumentationUIBuilder(new CSharpAmbience(), currentLanguage.SyntaxHighlighting); DocumentationUIBuilder renderer = new DocumentationUIBuilder(new CSharpAmbience(), currentLanguage.SyntaxHighlighting);
renderer.AddSignatureBlock(currentLanguage.GetTooltip(resolved)); RichText richText = currentLanguage.GetRichTextTooltip(resolved);
renderer.AddSignatureBlock(richText.Text, richText.ToRichTextModel());
try { try {
if (resolved.ParentModule == null || resolved.ParentModule.PEFile == null) if (resolved.ParentModule == null || resolved.ParentModule.PEFile == null)
return null; return null;
@ -372,7 +373,6 @@ namespace ICSharpCode.ILSpy.TextView
if (docProvider != null) { if (docProvider != null) {
string documentation = docProvider.GetDocumentation(resolved.GetIdString()); string documentation = docProvider.GetDocumentation(resolved.GetIdString());
if (documentation != null) { if (documentation != null) {
//renderer.AppendText(Environment.NewLine);
renderer.AddXmlDocumentation(documentation); renderer.AddXmlDocumentation(documentation);
} }
} }
@ -392,8 +392,8 @@ namespace ICSharpCode.ILSpy.TextView
viewer = new FlowDocumentScrollViewer(); viewer = new FlowDocumentScrollViewer();
viewer.Document = document; viewer.Document = document;
Border border = new Border { Border border = new Border {
Background = SystemColors.InfoBrush, Background = SystemColors.ControlBrush,
BorderBrush = SystemColors.InfoTextBrush, BorderBrush = SystemColors.ControlDarkBrush,
BorderThickness = new Thickness(1), BorderThickness = new Thickness(1),
MaxHeight = 400, MaxHeight = 400,
Child = viewer Child = viewer

5
ILSpy/TextView/XmlDocRenderer.cs

@ -104,11 +104,10 @@ namespace ICSharpCode.ILSpy.TextView
AddBlock(block); AddBlock(block);
} }
public void AddSignatureBlock(string signature) public void AddSignatureBlock(string signature, RichTextModel highlighting = null)
{ {
var document = new TextDocument(signature); var document = new TextDocument(signature);
var highlighter = new DocumentHighlighter(document, highlightingDefinition); var richText = highlighting ?? DocumentPrinter.ConvertTextDocumentToRichText(document, new DocumentHighlighter(document, highlightingDefinition)).ToRichTextModel();
var richText = DocumentPrinter.ConvertTextDocumentToRichText(document, highlighter).ToRichTextModel();
var block = new Paragraph(); var block = new Paragraph();
block.Inlines.AddRange(richText.CreateRuns(document)); block.Inlines.AddRange(richText.CreateRuns(document));
block.FontFamily = GetCodeFont(); block.FontFamily = GetCodeFont();

Loading…
Cancel
Save