Skip to content

Commit 4ae36eb

Browse files
committed
Merge branch 'main' into niels9001/titlebar-improvements
2 parents 83207c7 + 5490aac commit 4ae36eb

27 files changed

+847
-649
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
workflow_dispatch:
1717

1818
env:
19-
DOTNET_VERSION: ${{ '6.0.x' }}
19+
DOTNET_VERSION: ${{ '7.0.x' }}
2020
ENABLE_DIAGNOSTICS: false
2121
#COREHOST_TRACE: 1
2222
COREHOST_TRACEFILE: corehosttrace.log
@@ -64,7 +64,7 @@ jobs:
6464

6565
- name: dotnet build
6666
working-directory: ./
67-
run: dotnet build /bl CommunityToolkit.Tooling.sln
67+
run: dotnet build /bl CommunityToolkit.Tooling.sln -p:Configuration=Release
6868

6969
# Run tests
7070
- name: Install Testspace Module
@@ -73,7 +73,7 @@ jobs:
7373
domain: ${{ github.repository_owner }}
7474

7575
- name: Run tests against Source Generators
76-
run: dotnet test --logger "trx;LogFileName=sourceGeneratorTestResults.trx"
76+
run: dotnet test --logger "trx;LogFileName=sourceGeneratorTestResults.trx" -p:Configuration=Release
7777

7878
- name: Create test reports
7979
run: |

CommunityToolkit.App.Shared/Renderers/GeneratedSampleOptionsRenderer.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
1+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
22
<UserControl x:Class="CommunityToolkit.App.Shared.Renderers.GeneratedSampleOptionsRenderer"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

CommunityToolkit.App.Shared/Renderers/ToolkitDocumentationRenderer.xaml

Lines changed: 79 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:behaviors="using:CommunityToolkit.App.Shared.Behaviors"
6+
xmlns:converters="using:CommunityToolkit.WinUI.Converters"
67
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
78
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
89
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
@@ -34,6 +35,11 @@
3435
<local:DocOrSampleTemplateSelector x:Key="DocOrSampleTemplateSelector"
3536
Document="{StaticResource DocumentTemplate}"
3637
Sample="{StaticResource SampleTemplate}" />
38+
<converters:DoubleToVisibilityConverter x:Name="doubleToVisibilityConverter"
39+
FalseValue="Collapsed"
40+
GreaterThan="1"
41+
NullValue="Collapsed"
42+
TrueValue="Visible" />
3743
</Page.Resources>
3844

3945
<Grid>
@@ -89,8 +95,13 @@
8995

9096
<!-- Header grid -->
9197
<Grid x:Name="HeaderGrid"
92-
Margin="40,24,40,40"
93-
VerticalAlignment="Top">
98+
Margin="40,24,40,24"
99+
VerticalAlignment="Top"
100+
ColumnSpacing="8">
101+
<Grid.ColumnDefinitions>
102+
<ColumnDefinition Width="*" />
103+
<ColumnDefinition Width="Auto" />
104+
</Grid.ColumnDefinitions>
94105
<Grid.RowDefinitions>
95106
<RowDefinition Height="Auto" />
96107
<RowDefinition Height="Auto" />
@@ -106,78 +117,79 @@
106117
<TextBlock Grid.Row="1"
107118
Margin="0,8,0,0"
108119
HorizontalAlignment="Left"
120+
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
109121
Text="{x:Bind Metadata.Description, Mode=OneWay}"
110122
TextWrapping="WrapWholeWords" />
111123

112-
<Grid Grid.Row="2"
113-
Margin="0,16,0,0"
114-
ColumnSpacing="8">
115-
116-
<StackPanel x:Name="ButtonPanel"
117-
x:Load="{x:Bind renderer:ToolkitDocumentationRenderer.IsProjectPathValid()}"
118-
Orientation="Horizontal"
119-
Spacing="8">
120-
<Button Visibility="{x:Bind renderer:ToolkitDocumentationRenderer.IsIdValid(Metadata.DiscussionId), Mode=OneWay}">
121-
<StackPanel Orientation="Horizontal">
122-
<FontIcon FontSize="14"
123-
Glyph="&#xE8F2;" />
124-
<TextBlock Margin="8,0,0,0"
125-
Text="Discussion" />
126-
</StackPanel>
127-
<interactivity:Interaction.Behaviors>
128-
<interactions:EventTriggerBehavior EventName="Click">
129-
<behaviors:NavigateToUriAction NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToGitHubUri('discussions', Metadata.DiscussionId), Mode=OneWay}" />
130-
</interactions:EventTriggerBehavior>
131-
</interactivity:Interaction.Behaviors>
132-
</Button>
133-
<Button Visibility="{x:Bind renderer:ToolkitDocumentationRenderer.IsIdValid(Metadata.IssueId), Mode=OneWay}">
134-
<StackPanel Orientation="Horizontal">
135-
<PathIcon Margin="-3"
136-
VerticalAlignment="Center"
137-
Data="{StaticResource GithubIcon}">
138-
<PathIcon.RenderTransform>
139-
<CompositeTransform ScaleX="0.65"
140-
ScaleY="0.65"
141-
TranslateX="-5"
142-
TranslateY="5" />
143-
</PathIcon.RenderTransform>
144-
</PathIcon>
145-
<TextBlock Margin="-4,0,0,0"
146-
Text="Tracking Issue" />
147-
</StackPanel>
148-
<interactivity:Interaction.Behaviors>
149-
<interactions:EventTriggerBehavior EventName="Click">
150-
<behaviors:NavigateToUriAction NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToGitHubUri('issues', Metadata.IssueId), Mode=OneWay}" />
151-
</interactions:EventTriggerBehavior>
152-
</interactivity:Interaction.Behaviors>
153-
</Button>
154-
</StackPanel>
155-
156-
<StackPanel HorizontalAlignment="Right"
157-
VerticalAlignment="Center"
158-
Orientation="Horizontal"
159-
Spacing="8">
160-
<TextBlock VerticalAlignment="Center"
124+
<StackPanel x:Name="ButtonPanel"
125+
Grid.Row="2"
126+
Margin="0,16,0,0"
127+
x:Load="{x:Bind renderer:ToolkitDocumentationRenderer.IsProjectPathValid()}"
128+
Orientation="Horizontal"
129+
Spacing="8">
130+
<Button Visibility="{x:Bind renderer:ToolkitDocumentationRenderer.IsIdValid(Metadata.DiscussionId), Mode=OneWay}">
131+
<StackPanel Orientation="Horizontal">
132+
<FontIcon FontSize="14"
133+
Glyph="&#xE8F2;" />
134+
<TextBlock Margin="8,0,0,0"
135+
Text="Discussion" />
136+
</StackPanel>
137+
<interactivity:Interaction.Behaviors>
138+
<interactions:EventTriggerBehavior EventName="Click">
139+
<behaviors:NavigateToUriAction NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToGitHubUri('discussions', Metadata.DiscussionId), Mode=OneWay}" />
140+
</interactions:EventTriggerBehavior>
141+
</interactivity:Interaction.Behaviors>
142+
</Button>
143+
<Button Visibility="{x:Bind renderer:ToolkitDocumentationRenderer.IsIdValid(Metadata.IssueId), Mode=OneWay}">
144+
<StackPanel Orientation="Horizontal">
145+
<PathIcon Margin="-3"
146+
VerticalAlignment="Center"
147+
Data="{StaticResource GithubIcon}">
148+
<PathIcon.RenderTransform>
149+
<CompositeTransform ScaleX="0.65"
150+
ScaleY="0.65"
151+
TranslateX="-5"
152+
TranslateY="5" />
153+
</PathIcon.RenderTransform>
154+
</PathIcon>
155+
<TextBlock Margin="-4,0,0,0"
156+
Text="Tracking Issue" />
157+
</StackPanel>
158+
<interactivity:Interaction.Behaviors>
159+
<interactions:EventTriggerBehavior EventName="Click">
160+
<behaviors:NavigateToUriAction NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToGitHubUri('issues', Metadata.IssueId), Mode=OneWay}" />
161+
</interactions:EventTriggerBehavior>
162+
</interactivity:Interaction.Behaviors>
163+
</Button>
164+
</StackPanel>
165+
<ComboBox x:Name="SampleSelectionBox"
166+
Grid.RowSpan="2"
167+
Grid.Column="1"
168+
MinWidth="160"
169+
HorizontalAlignment="Right"
170+
VerticalAlignment="Bottom"
171+
ItemsSource="{x:Bind Samples, Mode=OneWay}"
172+
SelectedIndex="0"
173+
SelectionChanged="SampleSelectionBox_SelectionChanged"
174+
Visibility="{x:Bind Samples.Count, Converter={StaticResource doubleToVisibilityConverter}}">
175+
<ComboBox.Header>
176+
<TextBlock Foreground="{ThemeResource TextFillColorSecondaryBrush}"
161177
Style="{StaticResource CaptionTextBlockStyle}"
162-
Text="Sample:" />
163-
<ComboBox x:Name="SampleSelectionBox"
164-
MinWidth="160"
165-
ItemsSource="{x:Bind Samples, Mode=OneWay}"
166-
SelectedIndex="0"
167-
SelectionChanged="SampleSelectionBox_SelectionChanged">
168-
<ComboBox.ItemTemplate>
169-
<DataTemplate x:DataType="metadata:ToolkitSampleMetadata">
170-
<TextBlock Text="{Binding DisplayName, Mode=OneWay}" />
171-
</DataTemplate>
172-
</ComboBox.ItemTemplate>
173-
</ComboBox>
174-
</StackPanel>
175-
</Grid>
178+
Text="Go to sample:" />
179+
</ComboBox.Header>
180+
<ComboBox.ItemTemplate>
181+
<DataTemplate x:DataType="metadata:ToolkitSampleMetadata">
182+
<TextBlock Text="{Binding DisplayName, Mode=OneWay}" />
183+
</DataTemplate>
184+
</ComboBox.ItemTemplate>
185+
</ComboBox>
186+
176187
<muxc:InfoBar Title="Experimental"
177188
Grid.Row="3"
189+
Grid.ColumnSpan="2"
178190
Margin="0,16,0,0"
179191
IsClosable="False"
180-
IsOpen="True">
192+
Visibility="Collapsed">
181193
<muxc:InfoBar.ActionButton>
182194
<HyperlinkButton Content="Learn how you can use this experiment in your app"
183195
NavigateUri="https://aka.ms/wct/wiki/previewpackages" />
@@ -186,3 +198,4 @@
186198
</Grid>
187199
</Grid>
188200
</Page>
201+

CommunityToolkit.App.Shared/Renderers/ToolkitSampleRenderer.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@
9797
<ScrollViewer x:Name="OptionsScrollViewer"
9898
Grid.Row="0"
9999
Grid.Column="0"
100-
MinWidth="256"
100+
MinWidth="286"
101101
Padding="16">
102102
<ContentControl x:Name="OptionsControl"
103+
HorizontalContentAlignment="Stretch"
103104
Content="{x:Bind SampleOptionsPaneInstance, Mode=OneWay}" />
104105
</ScrollViewer>
105106
<Grid x:Name="FixedOptionsBar"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.CodeAnalysis;
6+
using Microsoft.CodeAnalysis.Text;
7+
8+
namespace CommunityToolkit.Tooling.SampleGen.Tests.Helpers;
9+
10+
internal class InMemoryAdditionalText : AdditionalText
11+
{
12+
private readonly SourceText _content;
13+
14+
public InMemoryAdditionalText(string path, string content)
15+
{
16+
Path = path;
17+
_content = SourceText.From(content, Encoding.UTF8);
18+
}
19+
20+
public override string Path { get; }
21+
22+
public override SourceText GetText(CancellationToken cancellationToken = default) => _content;
23+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.CodeAnalysis;
6+
using System.Collections.Immutable;
7+
8+
namespace CommunityToolkit.Tooling.SampleGen.Tests.Helpers;
9+
10+
public record SourceGeneratorRunResult(Compilation Compilation, ImmutableArray<Diagnostic> Diagnostics);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.CodeAnalysis;
6+
using Microsoft.CodeAnalysis.CSharp;
7+
using System.Collections.Immutable;
8+
9+
namespace CommunityToolkit.Tooling.SampleGen.Tests.Helpers;
10+
11+
public static partial class TestHelpers
12+
{
13+
internal static IEnumerable<MetadataReference> GetAllReferencedAssemblies()
14+
{
15+
return from assembly in AppDomain.CurrentDomain.GetAssemblies()
16+
where !assembly.IsDynamic
17+
let reference = MetadataReference.CreateFromFile(assembly.Location)
18+
select reference;
19+
}
20+
21+
internal static SyntaxTree ToSyntaxTree(this string source)
22+
{
23+
return CSharpSyntaxTree.ParseText(source,
24+
CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10));
25+
}
26+
27+
internal static CSharpCompilation CreateCompilation(this SyntaxTree syntaxTree, string assemblyName, IEnumerable<MetadataReference>? references = null)
28+
{
29+
return CSharpCompilation.Create(assemblyName, new[] { syntaxTree }, references ?? GetAllReferencedAssemblies(), new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
30+
}
31+
32+
internal static CSharpCompilation CreateCompilation(this IEnumerable<SyntaxTree> syntaxTree, string assemblyName, IEnumerable<MetadataReference>? references = null)
33+
{
34+
return CSharpCompilation.Create(assemblyName, syntaxTree, references ?? GetAllReferencedAssemblies(), new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
35+
}
36+
37+
internal static GeneratorDriver CreateSourceGeneratorDriver(this SyntaxTree syntaxTree, params IIncrementalGenerator[] generators)
38+
{
39+
return CSharpGeneratorDriver.Create(generators).WithUpdatedParseOptions((CSharpParseOptions)syntaxTree.Options);
40+
}
41+
42+
internal static GeneratorDriver CreateSourceGeneratorDriver(this Compilation compilation, params IIncrementalGenerator[] generators)
43+
{
44+
return CSharpGeneratorDriver.Create(generators).WithUpdatedParseOptions((CSharpParseOptions)compilation.SyntaxTrees.First().Options);
45+
}
46+
47+
internal static GeneratorDriver WithMarkdown(this GeneratorDriver driver, params string[] markdownFilesToCreate)
48+
{
49+
foreach (var markdown in markdownFilesToCreate)
50+
{
51+
if (!string.IsNullOrWhiteSpace(markdown))
52+
{
53+
var text = new InMemoryAdditionalText(@"C:\pathtorepo\components\experiment\samples\experiment.Samples\documentation.md", markdown);
54+
driver = driver.AddAdditionalTexts(ImmutableArray.Create<AdditionalText>(text));
55+
}
56+
}
57+
58+
return driver;
59+
}
60+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.CodeAnalysis;
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
using System.Collections.Immutable;
8+
9+
namespace CommunityToolkit.Tooling.SampleGen.Tests.Helpers;
10+
11+
public static partial class TestHelpers
12+
{
13+
internal static SourceGeneratorRunResult RunSourceGenerator<TGenerator>(this string source, string assemblyName, string markdown = "") where TGenerator : class, IIncrementalGenerator, new() => RunSourceGenerator<TGenerator>(source.ToSyntaxTree(), assemblyName, markdown);
14+
15+
internal static SourceGeneratorRunResult RunSourceGenerator<TGenerator>(this SyntaxTree syntaxTree, string assemblyName, string markdown = "")
16+
where TGenerator : class, IIncrementalGenerator, new()
17+
{
18+
var compilation = syntaxTree.CreateCompilation(assemblyName); // assembly name should always be supplied in param
19+
return RunSourceGenerator<TGenerator>(compilation, markdown);
20+
}
21+
22+
internal static SourceGeneratorRunResult RunSourceGenerator<TGenerator>(this Compilation compilation, string markdown = "")
23+
where TGenerator : class, IIncrementalGenerator, new()
24+
{
25+
// Create a driver for the source generator
26+
var driver = compilation
27+
.CreateSourceGeneratorDriver(new TGenerator())
28+
.WithMarkdown(markdown);
29+
30+
// Update the original compilation using the source generator
31+
_ = driver.RunGeneratorsAndUpdateCompilation(compilation, out Compilation generatorCompilation, out ImmutableArray<Diagnostic> postGeneratorCompilationDiagnostics);
32+
33+
return new(generatorCompilation, postGeneratorCompilationDiagnostics);
34+
}
35+
36+
internal static void AssertDiagnosticsAre(this IEnumerable<Diagnostic> diagnostics, params DiagnosticDescriptor[] expectedDiagnosticDescriptors)
37+
{
38+
var expectedIds = expectedDiagnosticDescriptors.Select(x => x.Id).ToHashSet();
39+
var resultingIds = diagnostics.Select(diagnostic => diagnostic.Id).ToHashSet();
40+
41+
Assert.IsTrue(resultingIds.SetEquals(expectedIds), $"Expected [{string.Join(", ", expectedIds)}] diagnostic Ids. Got [{string.Join(", ", resultingIds)}]");
42+
}
43+
44+
internal static void AssertNoCompilationErrors(this Compilation outputCompilation)
45+
{
46+
var generatedCompilationDiagnostics = outputCompilation.GetDiagnostics();
47+
Assert.IsTrue(generatedCompilationDiagnostics.All(x => x.Severity != DiagnosticSeverity.Error), $"Expected no generated compilation errors. Got: \n{string.Join("\n", generatedCompilationDiagnostics.Where(x => x.Severity == DiagnosticSeverity.Error).Select(x => $"[{x.Id}: {x.GetMessage()}]"))}");
48+
}
49+
50+
internal static string GetFileContentsByName(this Compilation compilation, string filename)
51+
{
52+
var generatedTree = compilation.SyntaxTrees.SingleOrDefault(tree => Path.GetFileName(tree.FilePath) == filename);
53+
Assert.IsNotNull(generatedTree, $"No file named {filename} was generated");
54+
55+
return generatedTree.ToString();
56+
}
57+
58+
internal static void AssertSourceGenerated(this Compilation compilation, string filename, string expectedContents)
59+
{
60+
}
61+
62+
internal static void AssertDiagnosticsAre(this SourceGeneratorRunResult result, params DiagnosticDescriptor[] expectedDiagnosticDescriptors) => AssertDiagnosticsAre(result.Diagnostics, expectedDiagnosticDescriptors);
63+
64+
internal static void AssertNoCompilationErrors(this SourceGeneratorRunResult result) => AssertNoCompilationErrors(result.Compilation);
65+
}

0 commit comments

Comments
 (0)