-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
47 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters