Skip to content

Commit 1a8bd58

Browse files
committed
AnalyzeCSharp now generates shorter symbol document source paths (#244)
1 parent 2f019b2 commit 1a8bd58

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

RELEASE.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.0-beta.63
2+
3+
- 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).
4+
15
# 1.0.0-beta.62
26

37
- Changed `Statiq.App.props` to `Statiq.App.targets` to resolve some import ordering bugs.

src/extensions/Statiq.CodeAnalysis/Analysis/AnalyzeSymbolVisitor.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.CodeAnalysis;
1212
using Microsoft.CodeAnalysis.CSharp;
1313
using Microsoft.CodeAnalysis.Text;
14+
using Microsoft.Extensions.Logging;
1415
using Statiq.Common;
1516

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

25+
private static readonly SymbolDisplayFormat _documentSourceFormat = new SymbolDisplayFormat(
26+
memberOptions: SymbolDisplayMemberOptions.IncludeContainingType,
27+
parameterOptions: SymbolDisplayParameterOptions.None,
28+
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
29+
genericsOptions: SymbolDisplayGenericsOptions.None);
30+
2431
private readonly ConcurrentCache<string, IDocument> _namespaceDisplayNameToDocument =
2532
new ConcurrentCache<string, IDocument>(false);
2633
private readonly ConcurrentCache<string, ConcurrentHashSet<INamespaceSymbol>> _namespaceDisplayNameToSymbols =
@@ -476,9 +483,16 @@ private IDocument AddDocumentCommon(ISymbol symbol, bool xmlDocumentation, Metad
476483

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

0 commit comments

Comments
 (0)