Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finer grained determination of visibility for extension methods #58

Open
wants to merge 26 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
307b0fa
Bump dependencies to latest stable version
ProphetLamb Jun 20, 2023
3093850
Bump LangVersion to 11.0
ProphetLamb Jun 20, 2023
69902ef
Bump remaining dependencies
ProphetLamb Jun 20, 2023
60dd991
Migrate to IIncrementalSourceGenerator
ProphetLamb Jun 20, 2023
0c56caa
Downgrade Microsoft.CodeAnalysis.CSharp to 4.4.0 for compatibility
ProphetLamb Jun 20, 2023
881a7d9
Add Verify for SourceGenerator testing
ProphetLamb Jun 20, 2023
f381bb2
EnforceExtendedAnalyzerRules
ProphetLamb Jun 20, 2023
ba586f6
Use namespace qualitfied metadata name
ProphetLamb Jun 20, 2023
357a4c4
Migrate test solution to IIncrementalSourceGenerator
ProphetLamb Jun 20, 2023
316c316
Hack: metadata output for debug builds
ProphetLamb Jun 20, 2023
2287673
Suppress nullable warning
ProphetLamb Jun 21, 2023
f17045d
Bump test from net45 to net 452
ProphetLamb Jun 21, 2023
3be87c5
Make models ValueTypes
ProphetLamb Jun 21, 2023
a527984
Implement diagnosed result sum type
ProphetLamb Jun 21, 2023
5cf5bf7
IDisposable via runtime typename
ProphetLamb Jun 21, 2023
e453d22
Collect diagnostics into array
ProphetLamb Jun 21, 2023
dd8f463
Add Nullable struct extensions to value providers
ProphetLamb Jun 21, 2023
04dce5c
Use diagnosedresult type to carry diagnostics
ProphetLamb Jun 21, 2023
025bbbb
Fix HintName generation
ProphetLamb Jun 21, 2023
2a56501
Force DiagnosedResult value IEquatable
ProphetLamb Jun 21, 2023
72c2dd4
Apply rename HintName
ProphetLamb Jun 21, 2023
09d8830
Make models structs
ProphetLamb Jun 21, 2023
97f6a67
Compute VariantInfo.TypeParameterQualifiedName
ProphetLamb Jun 21, 2023
98b1758
Use TypeParameterQualifiedName for extension classes
ProphetLamb Jun 21, 2023
8913488
Update test cases
ProphetLamb Jun 21, 2023
d75d354
Add test case according to #44
ProphetLamb Jun 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="3.9.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions src/dotVariant.Generator.Test/GeneratorTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace dotVariant.Generator.Test
{
internal static class GeneratorTools
{
public static Dictionary<string, string> GetGeneratedOutput(IDictionary<string, string> sources, Func<ISourceGenerator> makeGenerator, bool failOnInvalidSource = false)
public static Dictionary<string, string> GetGeneratedOutput(IDictionary<string, string> sources, Func<IIncrementalGenerator> makeGenerator, bool failOnInvalidSource = false)
{
var compilation = Compile(sources);

Expand All @@ -41,10 +41,10 @@ public static Dictionary<string, string> GetGeneratedOutput(IDictionary<string,
}

public static Dictionary<string, string> GetGeneratedOutput<TGenerator>(IDictionary<string, string> sources, bool failOnInvalidSource = false)
where TGenerator : ISourceGenerator, new()
where TGenerator : IIncrementalGenerator, new()
=> GetGeneratedOutput(sources, () => new TGenerator(), failOnInvalidSource);

public static ImmutableArray<Diagnostic> GetGeneratorDiagnostics(IDictionary<string, string> sources, Func<ISourceGenerator> makeGenerator)
public static ImmutableArray<Diagnostic> GetGeneratorDiagnostics(IDictionary<string, string> sources, Func<IIncrementalGenerator> makeGenerator)
{
var compilation = Compile(sources);

Expand All @@ -57,7 +57,7 @@ public static ImmutableArray<Diagnostic> GetGeneratorDiagnostics(IDictionary<str
}

public static ImmutableArray<Diagnostic> GetGeneratorDiagnostics<TGenerator>(IDictionary<string, string> sources)
where TGenerator : ISourceGenerator, new()
where TGenerator : IIncrementalGenerator, new()
=> GetGeneratorDiagnostics(sources, () => new TGenerator());

public static CSharpCompilation Compile(
Expand Down
9 changes: 4 additions & 5 deletions src/dotVariant.Generator.Test/RenderInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ private static ImmutableArray<RenderInfo> GetRenderInfoFromCompilation(
{
var compilation = Compile(SupportSources.Add("input", source), version);
var generator = new SourceGenerator();
var driver = CSharpGeneratorDriver.Create(
new[] { generator },
optionsProvider: new AnalyzerConfigOptionsProvider(msBuildProperties),
parseOptions: new CSharpParseOptions(version));
var driver = CSharpGeneratorDriver.Create(generator)
.WithUpdatedAnalyzerConfigOptions(new AnalyzerConfigOptionsProvider(msBuildProperties))
.WithUpdatedParseOptions(new CSharpParseOptions(version));
_ = driver.RunGeneratorsAndUpdateCompilation(compilation, out var _, out var _);
return generator.RenderInfos;
return generator.RenderInfos.ToImmutableArray();
}
}
}
53 changes: 29 additions & 24 deletions src/dotVariant.Generator.Test/SourceGenerator.Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ namespace dotVariant.Generator.Test
internal static class SourceGenerator_Test
{
[TestCaseSource(nameof(TranslationCases))]
public static void Translation(string typeName, string fileName, string input, string expected)
public static void Translation(string[] typeNames, string fileName, string input, string expected)
{
var sources = SupportSources.Add("input", input);
var outputs = GetGeneratedOutput<SourceGenerator>(sources, true);
var file =
Path.Combine(
$"{typeof(SourceGenerator).Assembly.GetName().Name}",
$"{typeof(SourceGenerator).FullName}",
$"{typeName}.cs");
var output = outputs[file];
output = _copyrightHeader + output;

var output = _copyrightHeader;
foreach (var typeName in typeNames)
{
var file =
Path.Combine(
$"{typeof(SourceGenerator).Assembly.GetName().Name}",
$"{typeof(SourceGenerator).FullName}",
$"{typeName}.cs");
output += outputs[file];
}

if (output != expected)
{
Expand Down Expand Up @@ -69,23 +73,24 @@ private static void WriteSample(string name, string content)
}

public static IEnumerable<TestCaseData> TranslationCases()
=> new (string FileName, string TypeName)[]
=> new (string FileName, string[] TypeName)[]
{
("Variant-class-nullable-disable", "Foo.Variant_class_nullable_disable"),
("Variant-class-nullable-enable", "Foo.Variant_class_nullable_enable"),
("Variant-disposable", "Foo.Variant_disposable"),
("Variant-generic-class", "Foo.Variant{T}"),
("Variant-generic-class-nullable", "Foo.Variant{T}"),
("Variant-generic-multiple", "Foo.Variant{T1, T2, T3}"),
("Variant-generic-notnull", "Foo.Variant{T}"),
("Variant-generic-struct", "Foo.Variant{T}"),
("Variant-generic-T-as-nullable", "Foo.Variant{T1, T2, T3, T4, T5, T6}"),
("Variant-generic-unbounded", "Foo.Variant{T}"),
("Variant-nullable-value-type", "Foo.Variant_nullable_value_type"),
("Variant-public", "Foo.Variant_public"),
("Variant-no-implicit-conversion", "Foo.Variant_no_implicit_conversion"),
("Variant-struct-nullable-disable", "Foo.Variant_struct_nullable_disable"),
("Variant-struct-nullable-enable", "Foo.Variant_struct_nullable_enable"),
("Variant-class-nullable-disable",new[] { "Foo.Variant_class_nullable_disable" }),
("Variant-class-nullable-enable", new[] { "Foo.Variant_class_nullable_enable" }),
("Variant-disposable", new[] { "Foo.Variant_disposable" }),
("Variant-generic-class", new[] { "Foo.Variant{T}" }),
("Variant-generic-class-nullable", new[] { "Foo.Variant{T}" }),
("Variant-generic-multiple", new[] { "Foo.Variant{T1, T2, T3}" }),
("Variant-generic-notnull", new[] { "Foo.Variant{T}" }),
("Variant-generic-struct", new[] { "Foo.Variant{T}" }),
("Variant-generic-T-as-nullable", new[] { "Foo.Variant{T1, T2, T3, T4, T5, T6}" }),
("Variant-generic-unbounded", new[] { "Foo.Variant{T}" }),
("Variant-nullable-value-type", new[] { "Foo.Variant_nullable_value_type" }),
("Variant-public", new[] { "Foo.Variant_public" }),
("Variant-no-implicit-conversion", new[] { "Foo.Variant_no_implicit_conversion" }),
("Variant-struct-nullable-disable", new[] { "Foo.Variant_struct_nullable_disable" }),
("Variant-struct-nullable-enable", new[] { "Foo.Variant_struct_nullable_enable" }),
("Variant-generic-same-name", new[] { "Foo.Variant{T}", "Foo.Variant{T1, T2}" })
}
.Select(
test => new TestCaseData(
Expand Down
16 changes: 9 additions & 7 deletions src/dotVariant.Generator.Test/dotVariant.Generator.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IsExternalInit" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="System.Interactive" Version="5.0.0" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="IsExternalInit" Version="1.0.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="System.Interactive" Version="6.0.1" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="Verify.NUnit" Version="20.4.0" />
<PackageReference Include="Verify.SourceGenerators" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright Miro Knejp 2021.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -1702,7 +1702,7 @@ namespace Foo
/// Extensions which allow for easy and powerful integration into `System.Linq`-like queries
/// on <see cref="global::System.Collections.Generic.IEnumerable{T}" /> sequences, that let you manipulate a stream of variants based on the contained type.
/// </summary>
public static partial class VariantEx
public static partial class Variant_T1_T2_T3_T4_T5_T6_Ex
{
/// <summary>
/// Transform a Variant-based enumerable sequence by applying a selector function to those elements
Expand Down Expand Up @@ -2388,7 +2388,7 @@ namespace Foo
/// Extensions which allow for easy and powerful integration into `System.Reactive.Linq`-like queries
/// on <see cref="global::System.IObservable{T}" /> sequences, that let you manipulate an asynchronous stream of variants based on the contained type.
/// </summary>
public static partial class VariantEx
public static partial class Variant_T1_T2_T3_T4_T5_T6_Ex
{
/// <summary>
/// Projects each <see cref="T1?"/> element of an observable sequence
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright Miro Knejp 2021.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -518,7 +518,7 @@ namespace Foo
/// Extensions which allow for easy and powerful integration into `System.Linq`-like queries
/// on <see cref="global::System.Collections.Generic.IEnumerable{T}" /> sequences, that let you manipulate a stream of variants based on the contained type.
/// </summary>
public static partial class VariantEx
public static partial class Variant_T_Ex
{
/// <summary>
/// Transform a Variant-based enumerable sequence by applying a selector function to those elements
Expand Down Expand Up @@ -679,7 +679,7 @@ namespace Foo
/// Extensions which allow for easy and powerful integration into `System.Reactive.Linq`-like queries
/// on <see cref="global::System.IObservable{T}" /> sequences, that let you manipulate an asynchronous stream of variants based on the contained type.
/// </summary>
public static partial class VariantEx
public static partial class Variant_T_Ex
{
/// <summary>
/// Projects each <see cref="T"/> element of an observable sequence
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright Miro Knejp 2021.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -518,7 +518,7 @@ namespace Foo
/// Extensions which allow for easy and powerful integration into `System.Linq`-like queries
/// on <see cref="global::System.Collections.Generic.IEnumerable{T}" /> sequences, that let you manipulate a stream of variants based on the contained type.
/// </summary>
public static partial class VariantEx
public static partial class Variant_T_Ex
{
/// <summary>
/// Transform a Variant-based enumerable sequence by applying a selector function to those elements
Expand Down Expand Up @@ -679,7 +679,7 @@ namespace Foo
/// Extensions which allow for easy and powerful integration into `System.Reactive.Linq`-like queries
/// on <see cref="global::System.IObservable{T}" /> sequences, that let you manipulate an asynchronous stream of variants based on the contained type.
/// </summary>
public static partial class VariantEx
public static partial class Variant_T_Ex
{
/// <summary>
/// Projects each <see cref="T"/> element of an observable sequence
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright Miro Knejp 2021.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -1017,7 +1017,7 @@ namespace Foo
/// Extensions which allow for easy and powerful integration into `System.Linq`-like queries
/// on <see cref="global::System.Collections.Generic.IEnumerable{T}" /> sequences, that let you manipulate a stream of variants based on the contained type.
/// </summary>
public static partial class VariantEx
public static partial class Variant_T1_T2_T3_Ex
{
/// <summary>
/// Transform a Variant-based enumerable sequence by applying a selector function to those elements
Expand Down Expand Up @@ -1378,7 +1378,7 @@ namespace Foo
/// Extensions which allow for easy and powerful integration into `System.Reactive.Linq`-like queries
/// on <see cref="global::System.IObservable{T}" /> sequences, that let you manipulate an asynchronous stream of variants based on the contained type.
/// </summary>
public static partial class VariantEx
public static partial class Variant_T1_T2_T3_Ex
{
/// <summary>
/// Projects each <see cref="T1"/> element of an observable sequence
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright Miro Knejp 2021.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -518,7 +518,7 @@ namespace Foo
/// Extensions which allow for easy and powerful integration into `System.Linq`-like queries
/// on <see cref="global::System.Collections.Generic.IEnumerable{T}" /> sequences, that let you manipulate a stream of variants based on the contained type.
/// </summary>
public static partial class VariantEx
public static partial class Variant_T_Ex
{
/// <summary>
/// Transform a Variant-based enumerable sequence by applying a selector function to those elements
Expand Down Expand Up @@ -679,7 +679,7 @@ namespace Foo
/// Extensions which allow for easy and powerful integration into `System.Reactive.Linq`-like queries
/// on <see cref="global::System.IObservable{T}" /> sequences, that let you manipulate an asynchronous stream of variants based on the contained type.
/// </summary>
public static partial class VariantEx
public static partial class Variant_T_Ex
{
/// <summary>
/// Projects each <see cref="T"/> element of an observable sequence
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Copyright Miro Knejp 2021.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
//

#nullable enable
namespace Foo
{
[dotVariant.Variant]
public partial class Variant<T>
{
static partial void VariantOf(T value);
}


[dotVariant.Variant]
internal partial class Variant<T1, T2>
{
static partial void VariantOf(T1 value1, T2 value2);
}
}
Loading