Commit 29d52abf authored by Jesse McGrew's avatar Jesse McGrew

Remove monaco, disable trimming

parent 6dfec6316b32
@page "/oldindex"
@using Zapf
@using Zilf.Compiler
@using Zilf.Diagnostics
@inject TemplateService Templates
<h1>ZIL Playground</h1>
<div>
<div style="margin:10px 0;">
<label for="theme">Theme:</label>
<select id="theme" @onchange="ChangeTheme">
<option value="vs">Visual Studio</option>
<option value="vs-dark">Visual Studio Dark</option>
<option value="hc-black">High Contrast Black</option>
</select>
</div>
<div style="margin:10px 0;">
<label for="project">Project:</label>
<select id="project" @onchange="ChangeProject">
@foreach (var name in AvailableTemplates)
{
<option value="@name">@name</option>
}
</select>
</div>
@*<FileSystemBrowser FileSystem="FileSystem"
OnChange="FileSystemBrowserOnChange"
/>*@
<div style="margin:10px 0;">
<button @onclick="Compile">Compile</button>
</div>
</div>
<MonacoEditor @ref="_editor"
Id="code-editor"
ConstructionOptions="EditorConstructionOptions"
OnDidInit="EditorOnDidInit"
OnContextMenu="EditorOnContextMenu"
/>
<CompilerOutput CompileResult="@CompileResult"
AssembleResult="@AssembleResult"
FileSystem="@FileSystem" />
@code {
private MonacoEditor _editor { get; set; }
private string ValueToSet { get; set; }
private FrontEndResult CompileResult { get; set; }
private AssemblyResult? AssembleResult { get; set; }
private InMemoryFileSystem FileSystem { get; } = new InMemoryFileSystem();
private IEnumerable<string> AvailableTemplates { get; set; } = Enumerable.Empty<string>();
protected override async Task OnInitializedAsync()
{
AvailableTemplates = await Templates.GetTemplateNamesAsync();
}
private StandaloneEditorConstructionOptions EditorConstructionOptions(MonacoEditor editor)
{
return new StandaloneEditorConstructionOptions
{
Language = "zil",
GlyphMargin = true,
Value = "<VERSION ZIP>\n" +
"\n" +
"<ROUTINE GO ()\n" +
" <TELL \"Hello world!\" CR>\n" +
" <QUIT>>",
};
}
private async Task EditorOnDidInit(MonacoEditorBase editor)
{
await _editor.AddCommand((int)KeyMode.CtrlCmd | (int)KeyCode.KEY_H, (editor, keyCode) =>
{
Console.WriteLine("Ctrl+H : Initial editor command is triggered.");
System.Diagnostics.Debugger.Break();
});
//var newDecorations = new ModelDeltaDecoration[]
//{
// new ModelDeltaDecoration
// {
// Range = new BlazorMonaco.Bridge.Range(3,1,3,1),
// Options = new ModelDecorationOptions
// {
// IsWholeLine = true,
// ClassName = "decorationContentClass",
// GlyphMarginClassName = "decorationGlyphMarginClass"
// }
// }
//};
//decorationIds = await _editor.DeltaDecorations(null, newDecorations);
// You can now use 'decorationIds' to change or remove the decorations
}
//private string[] decorationIds;
private void EditorOnContextMenu(EditorMouseEvent eventArg)
{
Console.WriteLine("OnContextMenu : " + System.Text.Json.JsonSerializer.Serialize(eventArg));
}
private async Task ChangeTheme(ChangeEventArgs e)
{
Console.WriteLine($"setting theme to: {e.Value.ToString()}");
await MonacoEditor.SetTheme(e.Value.ToString());
}
private async Task SetValue()
{
Console.WriteLine($"setting value to: {ValueToSet}");
await _editor.SetValue(ValueToSet);
}
private async Task GetValue()
{
var val = await _editor.GetValue();
Console.WriteLine($"value is: {val}");
}
private async Task AddCommand()
{
await _editor.AddCommand((int)KeyMode.CtrlCmd | (int)KeyCode.Enter, (editor, keyCode) =>
{
Console.WriteLine("Ctrl+Enter : Editor command is triggered.");
});
}
private async Task AddAction()
{
await _editor.AddAction("testAction", "Test Action", new int[] { (int)KeyMode.CtrlCmd | (int)KeyCode.KEY_D, (int)KeyMode.CtrlCmd | (int)KeyCode.KEY_B }, null, null, "navigation", 1.5, (editor, keyCodes) =>
{
Console.WriteLine("Ctrl+D : Editor action is triggered.");
});
}
private async Task Compile()
{
FileSystem.SetText("main.zil", await _editor.GetValue());
var compiler = new FrontEnd { FileSystem = FileSystem, Logger = NullDiagnosticLogger.Instance };
var compResult = compiler.Compile("main.zil", "main.zap", false);
CompileResult = compResult;
AssembleResult = null;
if (compResult.Success)
{
var assembler = new Zapf.ZapfAssembler { FileSystem = FileSystem };
AssembleResult = assembler.Assemble("main.zap", "main.z#");
}
}
private Task ChangeProject(ChangeEventArgs e)
{
return Task.CompletedTask;
//if (e.Value is string name)
//{
// var (template, fileContents) = await Templates.LoadTemplateAsync(name);
// FileSystem.Clear();
// foreach (var (path, content) in fileContents)
// FileSystem.SetText(path, content);
// await _editor.SetValue(fileContents[0].content);
//}
}
}
@inject JSInterop Interop
@using System.Text.RegularExpressions
@using Zapf
@using Zilf.Common
@using Zilf.Compiler
<h2>Compilation Results</h2>
@if (CompileResult == null)
{
<p>No compilation requested.</p>
}
else
{
@if (AssembleResult != null)
{
<h3>Story File</h3>
if (!AssembleResult.Value.Success)
{
<p>Assembly failed. See below.</p>
}
else
{
<button @onclick="DownloadStoryFile">Download @StoryFileName</button>
}
}
<h3>Details</h3>
<table>
<tr>
<th>Success?</th>
<td>@CompileResult.Success</td>
</tr>
<tr>
<th>Errors</th>
<td>@CompileResult.ErrorCount</td>
</tr>
<tr>
<th>Warnings</th>
<td>@CompileResult.WarningCount (@CompileResult.SuppressedWarningCount suppressed)</td>
</tr>
</table>
@if (CompileResult.Diagnostics.Count > 0)
{
<h3>Diagnostics</h3>
<table>
<tr>
<th>Severity</th>
<th>Code</th>
<th>Description</th>
<th>Location</th>
</tr>
@foreach (var diag in CompileResult.Diagnostics)
{
<tr>
<td>@diag.Severity</td>
<td>@diag.Code</td>
<td>@diag.GetFormattedMessage()</td>
<td>@diag.Location.SourceInfo</td>
</tr>
}
</table>
}
@if (CompileResult.Success)
{
<h3>Assembly Code</h3>
<table>
@foreach (var (path, text) in GetZapOutput())
{
<tr @key="@path">
<th style="vertical-align: top">@path</th>
<td><pre>@text</pre></td>
</tr>
}
</table>
}
}
@code {
[Parameter]
public FrontEndResult CompileResult { get; set; }
[Parameter]
public AssemblyResult? AssembleResult { get; set; }
[Parameter]
public InMemoryFileSystem FileSystem { get; set; }
private static Regex StoryFileRegExp = new Regex(@"\.z\d$", RegexOptions.IgnoreCase);
private string StoryFileName => FileSystem?.Paths.FirstOrDefault(StoryFileRegExp.IsMatch);
private IEnumerable<(string path, string text)> GetZapOutput()
{
if (CompileResult == null)
return Enumerable.Empty<(string, string)>();
return from path in FileSystem.Paths
where path.EndsWith(".zap")
select (path, FileSystem.GetText(path));
}
private void DownloadStoryFile()
{
var path = StoryFileName;
if (path != null)
{
var file = FileSystem.GetBytes(path);
string filename = System.IO.Path.GetFileName(path);
string contentType = "application/x-zmachine";
Interop.DownloadBytesAsFile(file, filename, contentType);
}
}
}
......@@ -2,10 +2,10 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BlazorMonaco" Version="1.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
......@@ -18,6 +18,10 @@
<ProjectReference Include="..\Zilf\Zilf.csproj" />
</ItemGroup>
<!--<ItemGroup>
<TrimmerRootAssembly Include="System.Private.DataContractSerialization" />
</ItemGroup>-->
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
</Project>
......@@ -13,5 +13,5 @@
@using Zilf.Playground.Services.Workspaces
@using Zilf.Playground.Services.Repl
@using Zilf.Playground.Services.Templates
@using BlazorMonaco
@using BlazorMonaco.Bridge
\ No newline at end of file
@*@using BlazorMonaco
@using BlazorMonaco.Bridge*@
\ No newline at end of file
......@@ -95,10 +95,10 @@ a, .btn-link {
}
}*/
.monaco-editor-container {
/*.monaco-editor-container {
height: 200px;
border: 1px solid gray;
}
}*/
.decorationGlyphMarginClass {
background: red;
......
......@@ -12,7 +12,7 @@
<link href="css/app.css" rel="stylesheet" />
<link href="Zilf.Playground.styles.css" rel="stylesheet" />
<link href="_content/BlazorMonaco/lib/monaco-editor/min/vs/editor/editor.main.css" rel="stylesheet" />
<!--<link href="_content/BlazorMonaco/lib/monaco-editor/min/vs/editor/editor.main.css" rel="stylesheet" />-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.0/css/all.css">
......@@ -35,10 +35,10 @@
<script src="./interop.js"></script>
<!-- Monaco -->
<script src="_content/BlazorMonaco/lib/monaco-editor/min/vs/loader.js"></script>
<!--<script src="_content/BlazorMonaco/lib/monaco-editor/min/vs/loader.js"></script>
<script>require.config({ paths: { 'vs': '_content/BlazorMonaco/lib/monaco-editor/min/vs' } });</script>
<script src="_content/BlazorMonaco/lib/monaco-editor/min/vs/editor/editor.main.js"></script>
<script src="_content/BlazorMonaco/jsInterop.js"></script>
<script src="_content/BlazorMonaco/jsInterop.js"></script>-->
<!-- Blazor framework -->
<script src="_framework/blazor.webassembly.js"></script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment