Skip to content

Commit

Permalink
Properly fix formatting error by switching to href
Browse files Browse the repository at this point in the history
We were using cref, which is for API members, which is what was causing the formatting error in the first place.

Fixes 408
  • Loading branch information
kzu committed Sep 30, 2024
1 parent fae4e05 commit 06cef3f
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/ThisAssembly.Constants/CSharp.sbntxt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{{ func remarks }}
{{~ if Remarks ~}}
{{ Remarks }}
/// <see cref="{{ Url }}"/>
/// <see href="{{ Url }}"/>
{{~ end ~}}
{{ end }}
{{ func render }}
Expand Down
10 changes: 2 additions & 8 deletions src/ThisAssembly.Constants/ConstantsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Devlooped.Sponsors;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
Expand All @@ -17,8 +16,6 @@ namespace ThisAssembly;
[Generator(LanguageNames.CSharp)]
public class ConstantsGenerator : IIncrementalGenerator
{
static readonly Regex SeeExpr = new("<see.+sponsorlink\"/>", RegexOptions.Compiled);

public void Initialize(IncrementalGeneratorInitializationContext context)
{
var files = context.AdditionalTextsProvider
Expand Down Expand Up @@ -124,16 +121,13 @@ void GenerateConstant(SourceProductionContext spc,
// structures via functions.
if (parse.Language == LanguageNames.CSharp)
{
output = SeeExpr.Replace(SyntaxFactory
output = SyntaxFactory
.ParseCompilationUnit(output, options: cs)
.NormalizeWhitespace()
.GetText()
.ToString(),
$"<see cref=\"{Funding.HelpUrl}\"/>");
.ToString();
}

spc.AddSource($"{root}.{name}.g.cs", SourceText.From(output, Encoding.UTF8));
}


}
2 changes: 1 addition & 1 deletion src/ThisAssembly.Resources/CSharp.sbntxt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// </summary>
{{~ if Remarks ~}}
{{ Remarks }}
/// <see cref="{{ Url }}"/>
/// <see href="{{ Url }}"/>
{{~ end ~}}
{{~ if Warn ~}}
[Obsolete("{{ Warn }}", false
Expand Down
8 changes: 2 additions & 6 deletions src/ThisAssembly.Resources/ResourcesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Devlooped.Sponsors;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
Expand All @@ -17,8 +16,6 @@ namespace ThisAssembly;
[Generator(LanguageNames.CSharp)]
public class ResourcesGenerator : IIncrementalGenerator
{
static readonly Regex SeeExpr = new("<see.+sponsorlink\"/>", RegexOptions.Compiled);

public void Initialize(IncrementalGeneratorInitializationContext context)
{
context.RegisterPostInitializationOutput(
Expand Down Expand Up @@ -124,12 +121,11 @@ static void GenerateSource(SourceProductionContext spc,
};
var output = template.Render(model, member => member.Name);

output = SeeExpr.Replace(SyntaxFactory
output = SyntaxFactory
.ParseCompilationUnit(output, options: parse as CSharpParseOptions)
.NormalizeWhitespace()
.GetText()
.ToString(),
$"<see cref=\"{Funding.HelpUrl}\"/>");
.ToString();

spc.AddSource(
$"{basePath.Replace('\\', '.').Replace('/', '.')}.g.cs",
Expand Down
2 changes: 1 addition & 1 deletion src/ThisAssembly.Strings/CSharp.sbntxt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// </summary>
{{~ if Remarks ~}}
{{ Remarks }}
/// <see cref="{{ Url }}"/>
/// <see href="{{ Url }}"/>
{{~ end ~}}
{{~ if Warn ~}}
[Obsolete("{{ Warn }}", false
Expand Down
8 changes: 2 additions & 6 deletions src/ThisAssembly.Strings/StringsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Devlooped.Sponsors;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
Expand All @@ -16,8 +15,6 @@ namespace ThisAssembly;
[Generator(LanguageNames.CSharp)]
public class StringsGenerator : IIncrementalGenerator
{
static readonly Regex SeeExpr = new("<see.+sponsorlink\"/>", RegexOptions.Compiled);

public void Initialize(IncrementalGeneratorInitializationContext context)
{
// Read the ThisAssemblyNamespace property or default to null
Expand Down Expand Up @@ -85,12 +82,11 @@ static void GenerateSource(SourceProductionContext spc,

var output = template.Render(model, member => member.Name);

output = SeeExpr.Replace(SyntaxFactory
output = SyntaxFactory
.ParseCompilationUnit(output, options: parse as CSharpParseOptions)
.NormalizeWhitespace()
.GetText()
.ToString(),
$"<see cref=\"{Funding.HelpUrl}\"/>");
.ToString();

spc.AddSource(resourceName, SourceText.From(output, Encoding.UTF8));
}
Expand Down

0 comments on commit 06cef3f

Please sign in to comment.