Browse Source

Implement semantic highlighting and links in rich text tooltips.

pull/1654/head
Siegfried Pammer 6 years ago
parent
commit
b18876d087
  1. 19
      ICSharpCode.Decompiler/Xml/DocumentationElement.cs
  2. 4
      ILSpy/Languages/CSharpLanguage.cs
  3. 4
      ILSpy/MainWindow.xaml.cs
  4. 11
      ILSpy/TextView/DecompilerTextView.cs
  5. 8
      ILSpy/TextView/XmlDocRenderer.cs

19
ICSharpCode.Decompiler/Xml/DocumentationElement.cs

@ -21,6 +21,7 @@ using System.Collections.Generic; @@ -21,6 +21,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using ICSharpCode.Decompiler.Documentation;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.Util;
@ -184,17 +185,17 @@ namespace ICSharpCode.Decompiler.Xml @@ -184,17 +185,17 @@ namespace ICSharpCode.Decompiler.Xml
foreach (var text in childTag.Children.OfType<AXmlText>())
list.Add(new XmlDocumentationElement(text.Value, declaringEntity));
} else if (childElement != null) {
if (nestingLevel < 5 && childElement.Name == "inheritdoc") {
/*string cref = childElement.GetAttributeValue("cref");
/*if (nestingLevel < 5 && childElement.Name == "inheritdoc") {
string cref = childElement.GetAttributeValue("cref");
IEntity inheritedFrom = null;
DocumentationComment inheritedDocumentation = null;
string inheritedDocumentation = null;
if (cref != null) {
inheritedFrom = crefResolver(cref);
if (inheritedFrom != null)
inheritedDocumentation = inheritedFrom.Documentation;
inheritedDocumentation = inheritedFrom.GetDocumentation();
} else {
foreach (IMember baseMember in InheritanceHelper.GetBaseMembers((IMember)declaringEntity, includeImplementedInterfaces: true)) {
inheritedDocumentation = baseMember.Documentation;
inheritedDocumentation = baseMember.GetDocumentation();
if (inheritedDocumentation != null) {
inheritedFrom = baseMember;
break;
@ -203,7 +204,7 @@ namespace ICSharpCode.Decompiler.Xml @@ -203,7 +204,7 @@ namespace ICSharpCode.Decompiler.Xml
}
if (inheritedDocumentation != null) {
var doc = new AXmlParser().Parse(inheritedDocumentation.Xml);
var doc = new AXmlParser().Parse(inheritedDocumentation);
// XPath filter not yet implemented
if (childElement.Parent is AXmlDocument && childElement.GetAttributeValue("select") == null) {
@ -221,10 +222,10 @@ namespace ICSharpCode.Decompiler.Xml @@ -221,10 +222,10 @@ namespace ICSharpCode.Decompiler.Xml
list.AddRange(CreateElements(inheritedChildren, inheritedFrom, inheritedDocumentation.ResolveCref, nestingLevel + 1));
}
}*/
} else {
list.Add(new XmlDocumentationElement(childElement, declaringEntity, crefResolver) { nestingLevel = nestingLevel });
}
} else {*/
list.Add(new XmlDocumentationElement(childElement, declaringEntity, crefResolver) { nestingLevel = nestingLevel });
//}
}
}
if (list.Count > 0 && list[0].IsTextNode) {

4
ILSpy/Languages/CSharpLanguage.cs

@ -633,8 +633,8 @@ namespace ICSharpCode.ILSpy @@ -633,8 +633,8 @@ namespace ICSharpCode.ILSpy
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());
var writer = new CSharpHighlightingTokenWriter(new InsertRequiredSpacesDecorator(decoratedWriter), richTextOutput);
new CSharpAmbience() { ConversionFlags = flags }.ConvertSymbol(entity, writer, new DecompilerSettings().CSharpFormattingOptions);
return new RichText(output.ToString(), richTextOutput.Model);
}

4
ILSpy/MainWindow.xaml.cs

@ -373,7 +373,7 @@ namespace ICSharpCode.ILSpy @@ -373,7 +373,7 @@ namespace ICSharpCode.ILSpy
}
}
private IEntity FindEntityInRelevantAssemblies(string navigateTo, IEnumerable<LoadedAssembly> relevantAssemblies)
internal static IEntity FindEntityInRelevantAssemblies(string navigateTo, IEnumerable<LoadedAssembly> relevantAssemblies)
{
ITypeReference typeRef = null;
IMemberReference memberRef = null;
@ -397,7 +397,7 @@ namespace ICSharpCode.ILSpy @@ -397,7 +397,7 @@ namespace ICSharpCode.ILSpy
return null;
}
private bool CanResolveTypeInPEFile(PEFile module, ITypeReference typeRef, out EntityHandle typeHandle)
static bool CanResolveTypeInPEFile(PEFile module, ITypeReference typeRef, out EntityHandle typeHandle)
{
switch (typeRef) {
case GetPotentiallyNestedClassTypeReference topLevelType:

11
ILSpy/TextView/DecompilerTextView.cs

@ -340,7 +340,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -340,7 +340,7 @@ namespace ICSharpCode.ILSpy.TextView
if (docProvider != null) {
string documentation = docProvider.GetDocumentation("F:System.Reflection.Emit.OpCodes." + code.EncodedName);
if (documentation != null) {
renderer.AddXmlDocumentation(documentation);
renderer.AddXmlDocumentation(documentation, null, null);
}
}
return new FlowDocumentTooltip(renderer.CreateDocument());
@ -373,13 +373,18 @@ namespace ICSharpCode.ILSpy.TextView @@ -373,13 +373,18 @@ namespace ICSharpCode.ILSpy.TextView
if (docProvider != null) {
string documentation = docProvider.GetDocumentation(resolved.GetIdString());
if (documentation != null) {
renderer.AddXmlDocumentation(documentation);
renderer.AddXmlDocumentation(documentation, resolved, ResolveReference);
}
}
} catch (XmlException) {
// ignore
}
return renderer.CreateDocument();
IEntity ResolveReference(string idString)
{
return MainWindow.FindEntityInRelevantAssemblies(idString, MainWindow.Instance.CurrentAssemblyList.GetAssemblies());
}
}
sealed class FlowDocumentTooltip : Popup
@ -389,7 +394,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -389,7 +394,7 @@ namespace ICSharpCode.ILSpy.TextView
public FlowDocumentTooltip(FlowDocument document)
{
TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display);
viewer = new FlowDocumentScrollViewer();
viewer = new FlowDocumentScrollViewer() { HorizontalScrollBarVisibility = ScrollBarVisibility.Visible };
viewer.Document = document;
Border border = new Border {
Background = SystemColors.ControlBrush,

8
ILSpy/TextView/XmlDocRenderer.cs

@ -115,14 +115,14 @@ namespace ICSharpCode.ILSpy.TextView @@ -115,14 +115,14 @@ namespace ICSharpCode.ILSpy.TextView
AddBlock(block);
}
public void AddXmlDocumentation(string xmlDocumentation)
public void AddXmlDocumentation(string xmlDocumentation, IEntity declaringEntity, Func<string, IEntity> resolver)
{
if (xmlDocumentation == null)
return;
Debug.WriteLine(xmlDocumentation);
AXmlParser parser = new AXmlParser();
var doc = parser.Parse(new Decompiler.Xml.StringTextSource(xmlDocumentation));
AddDocumentationElement(new XmlDocumentationElement(doc, null, null));
AddDocumentationElement(new XmlDocumentationElement(doc, declaringEntity, resolver));
}
@ -319,7 +319,9 @@ namespace ICSharpCode.ILSpy.TextView @@ -319,7 +319,9 @@ namespace ICSharpCode.ILSpy.TextView
Inline ConvertReference(IEntity referencedEntity)
{
var h = new Hyperlink(new Run(ambience.ConvertSymbol(referencedEntity)));
//h.Click += CreateNavigateOnClickHandler(referencedEntity);
h.Click += (sender, e) => {
MainWindow.Instance.JumpToReference(referencedEntity);
};
return h;
}

Loading…
Cancel
Save