Skip to content

Commit

Permalink
fix(XmlToTooltip): fall back to manual file lookup for unfound types
Browse files Browse the repository at this point in the history
If a type doesn't contain any method with debug information in it
the file will be looked up by using the file path of another type in
the same module.
  • Loading branch information
Christopher - Marcel Böddecker committed Feb 3, 2019
1 parent b8fcef9 commit bbb327e
Showing 1 changed file with 55 additions and 7 deletions.
62 changes: 55 additions & 7 deletions Sources/XmlDocumentationAttribute.Fody/ModuleWeaver.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace Malimbe.XmlDocumentationAttribute.Fody
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using global::Fody;
using Malimbe.Shared;
using Mono.Cecil;
using Mono.Cecil.Cil;

// ReSharper disable once UnusedMember.Global
public sealed class ModuleWeaver : BaseModuleWeaver
Expand Down Expand Up @@ -148,16 +148,64 @@ private static IReadOnlyDictionary<string, List<string>> ParseSourceFileXmlDocum
TypeDefinition typeDefinition,
string identifierReplacementFormat)
{
SequencePoint sequencePoint = typeDefinition.Methods.Select(definition => definition.DebugInformation)
.SelectMany(information => information.SequencePoints)
.FirstOrDefault();
if (sequencePoint == null)
string GetDocumentFilePath(TypeDefinition definition) =>
definition.Methods.Select(methodDefinition => methodDefinition.DebugInformation)
.SelectMany(information => information.SequencePoints)
.FirstOrDefault()
?.Document.Url;

string documentFilePath = GetDocumentFilePath(typeDefinition);
if (!File.Exists(documentFilePath))
{
documentFilePath = typeDefinition.Module.Types.Select(
definition =>
{
string filePath = GetDocumentFilePath(definition);
if (filePath == null)
{
return (null, null);
}

string[] namespaceParts = definition.Namespace.Split('.');
DirectoryInfo directoryInfo = new FileInfo(filePath).Directory;

for (int index = namespaceParts.Length - 1; index >= 0; index--)
{
if (directoryInfo == null)
{
return (null, null);
}

string namespacePart = namespaceParts[index];
if (!string.Equals(
namespacePart,
directoryInfo.Name,
StringComparison.OrdinalIgnoreCase))
{
return (directoryInfo.FullName, namespacePart);
}

directoryInfo = directoryInfo.Parent;
}

return (null, null);
})
.Where(tuple => tuple.FullName != null)
.Select(
tuple => Path.Combine(
tuple.FullName,
typeDefinition.Namespace.Replace($"{tuple.namespacePart}.", string.Empty)
.Replace('.', Path.DirectorySeparatorChar),
$"{typeDefinition.Name}.cs"))
.FirstOrDefault(File.Exists);
}

if (documentFilePath == null || !File.Exists(documentFilePath))
{
return new Dictionary<string, List<string>>();
}

string documentUrl = sequencePoint.Document.Url;
string sourceCode = File.ReadAllText(documentUrl);
string sourceCode = File.ReadAllText(documentFilePath);
Dictionary<string, List<string>> summariesByIdentifierName = new Dictionary<string, List<string>>();

foreach (Match match in _documentedIdentifierRegex.Matches(sourceCode))
Expand Down

0 comments on commit bbb327e

Please sign in to comment.