Skip to content

Commit

Permalink
AnalyzeCSharp now generates shorter symbol document source paths (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
daveaglick committed Aug 1, 2022
1 parent 2f019b2 commit 1a8bd58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.0-beta.63

- Fixed generation of document source paths for symbols in `AnalyzeCSharp` to use the symbol ID and generate shorter names so very long symbols don't create paths that are too long (#244).

# 1.0.0-beta.62

- Changed `Statiq.App.props` to `Statiq.App.targets` to resolve some import ordering bugs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.Logging;
using Statiq.Common;

namespace Statiq.CodeAnalysis.Analysis
Expand All @@ -21,6 +22,12 @@ internal class AnalyzeSymbolVisitor : SymbolVisitor
{
private static readonly object XmlDocLock = new object();

private static readonly SymbolDisplayFormat _documentSourceFormat = new SymbolDisplayFormat(
memberOptions: SymbolDisplayMemberOptions.IncludeContainingType,
parameterOptions: SymbolDisplayParameterOptions.None,
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
genericsOptions: SymbolDisplayGenericsOptions.None);

private readonly ConcurrentCache<string, IDocument> _namespaceDisplayNameToDocument =
new ConcurrentCache<string, IDocument>(false);
private readonly ConcurrentCache<string, ConcurrentHashSet<INamespaceSymbol>> _namespaceDisplayNameToSymbols =
Expand Down Expand Up @@ -476,9 +483,16 @@ private IDocument AddDocumentCommon(ISymbol symbol, bool xmlDocumentation, Metad

// Create the document and add it to caches
// Use a special ".symbol" extension for the source so we don't conflict with other known file types when consuming
// We also need to use a special symbol display format to make sure the document sources are short enough,
// then hash and combine the full display string to get a unique name
return _symbolToDocument.GetOrAdd(
symbol,
(key, args) => args._context.CreateDocument(new NormalizedPath(key.ToDisplayString() + ".symbol", PathKind.Absolute), args.destination, args.items),
(key, args) => args._context.CreateDocument(
new NormalizedPath(
$"{key.ToDisplayString(_documentSourceFormat)}_{key.GetId()}.symbol",
PathKind.Absolute),
args.destination,
args.items),
(destination, items, _context));
}

Expand Down

0 comments on commit 1a8bd58

Please sign in to comment.