Skip to content

Commit

Permalink
Merge 47f249d into 3c87326
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih authored Apr 3, 2023
2 parents 3c87326 + 47f249d commit 2c01f38
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ await LoadCompilationFromProject(project.AbsolutePath) is { } compilation)
var projectMetadataList = new List<MetadataItem>();
var extensionMethods = assemblies.SelectMany(assembly => assembly.Item1.FindExtensionMethods()).ToArray();
var filter = new SymbolFilter(_config, _options);
var allAssemblies = new HashSet<IAssemblySymbol>(assemblies.Select(a => a.Item1), SymbolEqualityComparer.Default);

foreach (var (assembly, compilation) in assemblies)
{
Logger.LogInfo($"Processing {assembly.Name}");
var projectMetadata = assembly.Accept(new SymbolVisitorAdapter(compilation, new(compilation), _config, filter, extensionMethods));
var projectMetadata = assembly.Accept(new SymbolVisitorAdapter(
compilation, new(compilation, _config.MemberLayout, allAssemblies), _config, filter, extensionMethods));

if (projectMetadata != null)
projectMetadataList.Add(projectMetadata);
Expand Down
5 changes: 3 additions & 2 deletions src/Microsoft.DocAsCode.Dotnet/SymbolFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public static ImmutableArray<SymbolDisplayPart> GetSyntaxParts(ISymbol symbol, S
}
}

public static List<LinkItem> ToLinkItems(this ImmutableArray<SymbolDisplayPart> parts, Compilation compilation, SyntaxLanguage language, bool overload)
public static List<LinkItem> ToLinkItems(this ImmutableArray<SymbolDisplayPart> parts,
Compilation compilation, MemberLayout memberLayout, HashSet<IAssemblySymbol> allAssemblies, bool overload)
{
var result = new List<LinkItem>();
foreach (var part in parts)
Expand All @@ -133,7 +134,7 @@ LinkItem ToLinkItem(SymbolDisplayPart part)
{
Name = overload ? VisitorHelper.GetOverloadId(symbol) : VisitorHelper.GetId(symbol),
DisplayName = part.ToString(),
Href = SymbolUrlResolver.GetSymbolUrl(symbol, compilation),
Href = SymbolUrlResolver.GetSymbolUrl(symbol, compilation, memberLayout, allAssemblies),
IsExternalPath = symbol.IsExtern || symbol.DeclaringSyntaxReferences.Length == 0,
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.DocAsCode.Dotnet/SymbolHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static class SymbolHelper
public static MetadataItem? GenerateMetadataItem(this IAssemblySymbol assembly, Compilation compilation, ExtractMetadataConfig? config = null, DotnetApiOptions? options = null, IMethodSymbol[]? extensionMethods = null)
{
config ??= new();
return assembly.Accept(new SymbolVisitorAdapter(compilation, new(compilation), config, new(config, options ?? new()), extensionMethods));
return assembly.Accept(new SymbolVisitorAdapter(compilation, new(compilation, MemberLayout.SamePage, new(new[] { assembly }, SymbolEqualityComparer.Default)), config, new(config, options ?? new()), extensionMethods));
}

public static bool IsInstanceInterfaceMember(this ISymbol symbol)
Expand Down
32 changes: 29 additions & 3 deletions src/Microsoft.DocAsCode.Dotnet/SymbolUrlResolver.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
using Microsoft.CodeAnalysis;
using System.Text.RegularExpressions;
using Microsoft.CodeAnalysis;

#nullable enable

namespace Microsoft.DocAsCode.Dotnet;

internal static partial class SymbolUrlResolver
{
public static string? GetSymbolUrl(ISymbol symbol, Compilation compilation)
public static string? GetSymbolUrl(ISymbol symbol, Compilation compilation, MemberLayout memberLayout, HashSet<IAssemblySymbol> allAssemblies)
{
return GetMicrosoftLearnUrl(symbol)
return GetDocfxUrl(symbol, memberLayout, allAssemblies)
?? GetMicrosoftLearnUrl(symbol)
?? GetPdbSourceLinkUrl(compilation, symbol);
}

internal static string? GetDocfxUrl(ISymbol symbol, MemberLayout memberLayout, HashSet<IAssemblySymbol> allAssemblies)
{
if (symbol.ContainingAssembly is null || !allAssemblies.Contains(symbol.ContainingAssembly))
return null;

var commentId = symbol.GetDocumentationCommentId();
if (commentId is null)
return null;

var parts = commentId.Split(':');
var type = parts[0];
var uid = parts[1];

return type switch
{
"!" => null,
"N" or "T" => $"{uid.Replace('`', '-')}.html",
"M" or "F" or "P" or "E" => memberLayout is MemberLayout.SeparatePages && !symbol.IsEnumMember()
? $"{VisitorHelper.GetId(symbol).Replace('`', '-')}.html"
: $"{VisitorHelper.GetId(symbol.ContainingType).Replace('`', '-')}.html#{Regex.Replace(uid, @"/\W/", "_")}",
_ => throw new NotSupportedException($"Unknown comment ID format '{type}"),
};
}
}
18 changes: 11 additions & 7 deletions src/Microsoft.DocAsCode.Dotnet/Visitors/YamlModelGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ namespace Microsoft.DocAsCode.Dotnet;
internal class YamlModelGenerator
{
private readonly Compilation _compilation;
private readonly MemberLayout _memberLayout;
private readonly HashSet<IAssemblySymbol> _allAssemblies;

public YamlModelGenerator(Compilation compilation)
public YamlModelGenerator(Compilation compilation, MemberLayout memberLayout, HashSet<IAssemblySymbol> allAssemblies)
{
_compilation = compilation;
_memberLayout = memberLayout;
_allAssemblies = allAssemblies;
}

public void DefaultVisit(ISymbol symbol, MetadataItem item)
Expand All @@ -35,9 +39,9 @@ public void GenerateReference(ISymbol symbol, ReferenceItem reference, bool asOv
if (!reference.QualifiedNameParts.ContainsKey(SyntaxLanguage.CSharp))
reference.QualifiedNameParts.Add(SyntaxLanguage.CSharp, new());

reference.NameParts[SyntaxLanguage.CSharp] = SymbolFormatter.GetNameParts(symbol, SyntaxLanguage.CSharp, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, SyntaxLanguage.CSharp, asOverload);
reference.NameWithTypeParts[SyntaxLanguage.CSharp] = SymbolFormatter.GetNameWithTypeParts(symbol, SyntaxLanguage.CSharp, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, SyntaxLanguage.CSharp, asOverload);
reference.QualifiedNameParts[SyntaxLanguage.CSharp] = SymbolFormatter.GetQualifiedNameParts(symbol, SyntaxLanguage.CSharp, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, SyntaxLanguage.CSharp, asOverload);
reference.NameParts[SyntaxLanguage.CSharp] = SymbolFormatter.GetNameParts(symbol, SyntaxLanguage.CSharp, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, _memberLayout, _allAssemblies, asOverload);
reference.NameWithTypeParts[SyntaxLanguage.CSharp] = SymbolFormatter.GetNameWithTypeParts(symbol, SyntaxLanguage.CSharp, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, _memberLayout, _allAssemblies, asOverload);
reference.QualifiedNameParts[SyntaxLanguage.CSharp] = SymbolFormatter.GetQualifiedNameParts(symbol, SyntaxLanguage.CSharp, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, _memberLayout, _allAssemblies, asOverload);

if (!reference.NameParts.ContainsKey(SyntaxLanguage.VB))
reference.NameParts.Add(SyntaxLanguage.VB, new());
Expand All @@ -46,9 +50,9 @@ public void GenerateReference(ISymbol symbol, ReferenceItem reference, bool asOv
if (!reference.QualifiedNameParts.ContainsKey(SyntaxLanguage.VB))
reference.QualifiedNameParts.Add(SyntaxLanguage.VB, new());

reference.NameParts[SyntaxLanguage.VB] = SymbolFormatter.GetNameParts(symbol, SyntaxLanguage.VB, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, SyntaxLanguage.VB, asOverload);
reference.NameWithTypeParts[SyntaxLanguage.VB] = SymbolFormatter.GetNameWithTypeParts(symbol, SyntaxLanguage.VB, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, SyntaxLanguage.VB, asOverload);
reference.QualifiedNameParts[SyntaxLanguage.VB] = SymbolFormatter.GetQualifiedNameParts(symbol, SyntaxLanguage.VB, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, SyntaxLanguage.VB, asOverload);
reference.NameParts[SyntaxLanguage.VB] = SymbolFormatter.GetNameParts(symbol, SyntaxLanguage.VB, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, _memberLayout, _allAssemblies, asOverload);
reference.NameWithTypeParts[SyntaxLanguage.VB] = SymbolFormatter.GetNameWithTypeParts(symbol, SyntaxLanguage.VB, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, _memberLayout, _allAssemblies, asOverload);
reference.QualifiedNameParts[SyntaxLanguage.VB] = SymbolFormatter.GetQualifiedNameParts(symbol, SyntaxLanguage.VB, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, _memberLayout, _allAssemblies, asOverload);
}

public void GenerateSyntax(ISymbol symbol, SyntaxDetail syntax, SymbolFilter filter)
Expand Down

0 comments on commit 2c01f38

Please sign in to comment.