Skip to content

Commit b5b87f4

Browse files
authored
Improve some output displaying (#136)
2 parents 933130e + 0fde0b0 commit b5b87f4

13 files changed

Lines changed: 264 additions & 185 deletions

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<NoWarn>$(NoWarn);NU1507</NoWarn>
77
<NetCoreVersion>11.0.0-preview.1.26104.118</NetCoreVersion>
88
<AspNetCoreVersion>$(NetCoreVersion)</AspNetCoreVersion>
9-
<RoslynVersion>5.5.0-2.26110.7</RoslynVersion>
10-
<RazorVersion>10.0.0-preview.26109.1</RazorVersion>
9+
<RoslynVersion>5.6.0-2.26127.8</RoslynVersion>
10+
<RazorVersion>10.0.0-preview.26127.2</RazorVersion>
1111
<FluentUIVersion>4.14.0</FluentUIVersion>
1212
<NuGetVersion>7.3.0</NuGetVersion>
1313
</PropertyGroup>

src/App/Lab/Page.razor

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
{
205205
<FluentMessageBar Title="Compiler worker failed." Intent="MessageIntent.Error" AllowDismiss="false">
206206
<div style="white-space-collapse: preserve">@workerError</div>
207-
<FluentButton Appearance="Appearance.Accent" Style="width: 100%; margin-top: 0.5em" OnClick="ReloadWorker"
207+
<FluentButton Appearance="Appearance.Accent" Style="width: 100%; margin-top: 0.5em" OnClick="ReloadWorkerAsync"
208208
IconStart="@(new Icons.Regular.Size16.ArrowClockwise())">Re-create the worker</FluentButton>
209209
</FluentMessageBar>
210210
}
@@ -243,7 +243,7 @@
243243
</FluentTabs>
244244

245245
@* Output toolbar *@
246-
@if (OutputHasToolbar)
246+
@if (OutputHasToolbar && GetOutput(DisplayOutputType) != null)
247247
{
248248
<FluentToolbar>
249249
@switch (DisplayOutputType)
@@ -252,13 +252,16 @@
252252
{
253253
<FluentCheckbox @bind-Value:get="savedState.ShowSymbols"
254254
@bind-Value:set="(v) => ChangePreferencesAsync((s) => s with { ShowSymbols = v })"
255-
Label="Symbols" />
255+
Label="Symbols"
256+
title="Displays symbol nodes in the tree - look for `.GetSymbolInfo()` and `.GetDeclaredSymbol()` under syntax nodes" />
256257
<FluentCheckbox @bind-Value:get="savedState.ShowOperations"
257258
@bind-Value:set="(v) => ChangePreferencesAsync((s) => s with { ShowOperations = v })"
258-
Label="Operations" />
259+
Label="Operations"
260+
title="Displays IOperation nodes in the tree - look for `.GetOperation()` under syntax nodes" />
259261
<FluentCheckbox @bind-Value:get="savedState.ShowBoundNodes"
260262
@bind-Value:set="(v) => ChangePreferencesAsync((s) => s with { ShowBoundNodes = v })"
261-
Label="Bound nodes" />
263+
Label="Bound nodes"
264+
title="Displays bound nodes in the tree - look for `.GetBoundRoot()` under syntax nodes" />
262265
<FluentButton OnClick="FoldAllOutputAsync" Title="Collapse all">@*
263266
*@<FluentIcon Value="@(new Icons.Regular.Size20.ArrowCollapseAll())" Color="Color.Neutral" /></FluentButton>
264267
}
@@ -357,6 +360,8 @@
357360
public required DateTimeOffset Start { get; init; }
358361
public required DateTimeOffset End { get; init; }
359362

363+
public required bool AutoLoadLazyOutputs { get; init; }
364+
360365
/// <summary>
361366
/// Only set if this <see cref="CompiledState"/> instance represents compiled (not cached) state
362367
/// but we also have cached output loaded for it.
@@ -1019,6 +1024,7 @@
10191024
CacheInfo = cacheInfo,
10201025
Start = startTime,
10211026
End = DateTimeOffset.Now,
1027+
AutoLoadLazyOutputs = true,
10221028
};
10231029

10241030
await DisplaySquigglesAsync();
@@ -1187,6 +1193,8 @@
11871193

11881194
var text = CompilerOutputPlugin.GetText(outputInfo, result, out outputDisclaimer, ref language);
11891195

1196+
string? previousLanguage;
1197+
11901198
if (!outputStates.TryGetValue(outputType, out var state))
11911199
{
11921200
state = new(await BlazorMonaco.Editor.Global.CreateModel(
@@ -1195,10 +1203,12 @@
11951203
language: language,
11961204
uri: CompiledAssembly.GetOutputModelUri(outputInfo?.File, outputType)));
11971205
outputStates[outputType] = state;
1206+
previousLanguage = null;
11981207
}
11991208
else
12001209
{
12011210
await state.Model.SetValue(text);
1211+
previousLanguage = await state.Model.GetLanguageId();
12021212
await BlazorMonaco.Editor.Global.SetModelLanguage(JSRuntime, state.Model, language);
12031213
}
12041214

@@ -1216,14 +1226,20 @@
12161226

12171227
await outputEditor.SetModel(state.Model);
12181228

1219-
if (saveViewState && !state.ViewState.IsEmpty)
1229+
if (saveViewState && !state.ViewState.IsEmpty &&
1230+
// Avoid restoring state (and instead perform folding) when state changes drastically
1231+
// (currently we only detect language change - e.g., from error to normal output).
1232+
previousLanguage == language)
12201233
{
12211234
await outputEditor.RestoreViewStateAsync(state.ViewState, module);
12221235
}
12231236
else if (isOutputLanguage)
12241237
{
12251238
await FoldAllOutputAsync();
1239+
}
12261240

1241+
if (isOutputLanguage)
1242+
{
12271243
// Underline links.
12281244
if (result.Metadata != null &&
12291245
LanguageServices.TryGetOutputToOutputMapping(result.Metadata, out var mapping))
@@ -1251,8 +1267,13 @@
12511267
await BlazorMonacoInterop.ExecuteActionAsync(outputEditor.Id, "editor.unfold");
12521268
}
12531269

1254-
private OutputInfo? GetOutput(string type)
1270+
private OutputInfo? GetOutput(string? type)
12551271
{
1272+
if (type is null)
1273+
{
1274+
return null;
1275+
}
1276+
12561277
if (CurrentCompiledFile is { } currentCompiledFile)
12571278
{
12581279
if (currentCompiledFile.GetOutput(type) is { } output)
@@ -1323,7 +1344,7 @@
13231344

13241345
// If we are currently displaying cached outputs, but this specific output type is not cached,
13251346
// avoid resolving it and hence starting compilation implicitly.
1326-
if (compiled is { CacheInfo: not null, CachedOutput: null })
1347+
if (compiled?.AutoLoadLazyOutputs != true)
13271348
{
13281349
return (new() { Text = "(not cached, press Compile to load this)", Metadata = CompiledFileOutputMetadata.SpecialMessage }, false);
13291350
}
@@ -1429,6 +1450,12 @@
14291450
await TrySetCompiledFromCacheAsync(state.GetCompilerConfiguration(), state.ToCompilationInput(), output, new(timestamp), updateOutput: updateOutput);
14301451
StateHasChanged();
14311452
}
1453+
else if (updateOutput)
1454+
{
1455+
await AutoSelectOutputAsync(
1456+
updateTimestampMode: OutputActionMode.Never,
1457+
storeInCacheMode: OutputActionMode.Never);
1458+
}
14321459
}
14331460

14341461
private async Task TrySetCompiledFromCacheAsync(CompilerConfiguration config, CompilationInput input, CompiledAssembly output, CacheInfo info, bool updateOutput)
@@ -1452,7 +1479,8 @@
14521479
Output = output,
14531480
CacheInfo = info,
14541481
Start = timestamp,
1455-
End = timestamp
1482+
End = timestamp,
1483+
AutoLoadLazyOutputs = false,
14561484
};
14571485
StateHasChanged();
14581486

@@ -1570,10 +1598,9 @@
15701598
StateHasChanged();
15711599
}
15721600

1573-
private void ReloadWorker()
1601+
internal async Task ReloadWorkerAsync()
15741602
{
1603+
await Worker.RecreateWorkerAsync();
15751604
workerError = null;
1576-
StateHasChanged();
1577-
_ = Worker.RecreateWorkerAsync();
15781605
}
15791606
}

src/App/Lab/Settings.razor

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@
166166
</FluentSwitch>
167167
</ActionContent>
168168
</SettingsCard>
169+
170+
<SettingsCard Class="default-setting-expander-item settings-nowarp">
171+
<Header>
172+
<h5 class="unset">Worker stuck?</h5>
173+
</Header>
174+
<ActionContent>
175+
<FluentButton OnClick="Page.ReloadWorkerAsync"
176+
IconStart="@(new Icons.Regular.Size16.ArrowClockwise())">Restart the worker</FluentButton>
177+
</ActionContent>
178+
</SettingsCard>
169179
}
170180

171181
@* Caching check box *@

0 commit comments

Comments
 (0)