-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
TryRegisterAlias
into BuildContext
and make it not static To…
… solve a bug * I Believe the bug was a some kind of race condition about what file got the alias first
- Loading branch information
1 parent
4eb1c02
commit fbc2414
Showing
8 changed files
with
43 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,34 @@ | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using TestsHelper.SourceGenerator.CodeBuilding.Types; | ||
|
||
namespace TestsHelper.SourceGenerator.CodeBuilding; | ||
|
||
public readonly record struct BuildContext(FileBuilder FileBuilder); | ||
public readonly record struct BuildContext(FileBuilder FileBuilder) | ||
{ | ||
private readonly ISet<string> _nameAliases = new HashSet<string>(); | ||
|
||
private bool TryRegisterAlias(IType type, [NotNullWhen(true)] out AliasType? aliasType) | ||
{ | ||
if (type.TryCreateAlias(out aliasType)) | ||
{ | ||
if (_nameAliases.Contains(aliasType.Name)) | ||
{ | ||
return true; | ||
} | ||
|
||
UsingDirectiveSyntax usingDirectiveSyntax = SyntaxFactory.UsingDirective(aliasType.AliasTo) | ||
.WithAlias(SyntaxFactory.NameEquals(SyntaxFactory.IdentifierName(aliasType.Name))); | ||
|
||
FileBuilder.AddUsing(usingDirectiveSyntax); | ||
_nameAliases.Add(aliasType.Name); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public IType TryRegisterAlias(IType type) => TryRegisterAlias(type, out AliasType? aliasType) ? aliasType : 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
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
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