ic10editor-update #4
@@ -12,16 +12,15 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class SlangFormatter : ICodeFormatter
|
public class SlangFormatter : ICodeFormatter
|
||||||
{
|
{
|
||||||
protected static Editor? Ic10Editor = null;
|
|
||||||
|
|
||||||
private CancellationTokenSource? _lspCancellationToken;
|
private CancellationTokenSource? _lspCancellationToken;
|
||||||
private object _tokenLock = new();
|
private object _tokenLock = new();
|
||||||
|
|
||||||
|
protected static Editor? Ic10Editor = null;
|
||||||
private IC10CodeFormatter iC10CodeFormatter = new IC10CodeFormatter();
|
private IC10CodeFormatter iC10CodeFormatter = new IC10CodeFormatter();
|
||||||
private string ic10CompilationResult = "";
|
private string ic10CompilationResult = "";
|
||||||
private List<SourceMapEntry> ic10SourceMap = new();
|
private List<SourceMapEntry> ic10SourceMap = new();
|
||||||
|
|
||||||
// VS Code Dark Theme Palette
|
#region Colors
|
||||||
public static readonly uint ColorControl = ColorFromHTML("#C586C0"); // Pink (if, return, loop)
|
public static readonly uint ColorControl = ColorFromHTML("#C586C0"); // Pink (if, return, loop)
|
||||||
public static readonly uint ColorDeclaration = ColorFromHTML("#569CD6"); // Blue (let, device, fn)
|
public static readonly uint ColorDeclaration = ColorFromHTML("#569CD6"); // Blue (let, device, fn)
|
||||||
public static readonly uint ColorFunction = ColorFromHTML("#DCDCAA"); // Yellow (syscalls)
|
public static readonly uint ColorFunction = ColorFromHTML("#DCDCAA"); // Yellow (syscalls)
|
||||||
@@ -30,10 +29,8 @@ public class SlangFormatter : ICodeFormatter
|
|||||||
public static readonly uint ColorBoolean = ColorFromHTML("#569CD6"); // Blue (true/false)
|
public static readonly uint ColorBoolean = ColorFromHTML("#569CD6"); // Blue (true/false)
|
||||||
public static readonly uint ColorIdentifier = ColorFromHTML("#9CDCFE"); // Light Blue (variables)
|
public static readonly uint ColorIdentifier = ColorFromHTML("#9CDCFE"); // Light Blue (variables)
|
||||||
public static new readonly uint ColorDefault = ColorFromHTML("#D4D4D4"); // White (punctuation ; { } )
|
public static new readonly uint ColorDefault = ColorFromHTML("#D4D4D4"); // White (punctuation ; { } )
|
||||||
|
|
||||||
// Operators are often the same color as default text in VS Code Dark,
|
|
||||||
// but having a separate definition lets you tweak it (e.g. make them slightly darker or distinct)
|
|
||||||
public static readonly uint ColorOperator = ColorFromHTML("#D4D4D4");
|
public static readonly uint ColorOperator = ColorFromHTML("#D4D4D4");
|
||||||
|
#endregion
|
||||||
|
|
||||||
private HashSet<uint> _linesWithErrors = new();
|
private HashSet<uint> _linesWithErrors = new();
|
||||||
private int _lastLineCount = -1;
|
private int _lastLineCount = -1;
|
||||||
@@ -160,16 +157,8 @@ public class SlangFormatter : ICodeFormatter
|
|||||||
{
|
{
|
||||||
ic10CompilationResult = compiled;
|
ic10CompilationResult = compiled;
|
||||||
ic10SourceMap = sourceMap;
|
ic10SourceMap = sourceMap;
|
||||||
try
|
|
||||||
{
|
|
||||||
UpdateIc10Formatter();
|
UpdateIc10Formatter();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
L.Error(ex.Message);
|
|
||||||
L.Error(ex.StackTrace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException) { }
|
catch (OperationCanceledException) { }
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.IO.Compression;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Slang;
|
namespace Slang;
|
||||||
|
|
||||||
public static class GlobalCode
|
public static class GlobalCode
|
||||||
{
|
{
|
||||||
public const string SLANG_REF = "#SLANG_REF:";
|
public const string SLANG_REF = "#SLANG_REF:";
|
||||||
public const string SLANG_SRC = "#SLANG_SRC:";
|
public const string SLANG_SRC = "SLANG_SRC";
|
||||||
|
|
||||||
// This is a Dictionary of ENCODED source code, compressed
|
// This is a Dictionary of ENCODED source code, compressed
|
||||||
// so that save file data is smaller
|
// so that save file data is smaller
|
||||||
@@ -110,43 +107,11 @@ public static class GlobalCode
|
|||||||
|
|
||||||
private static string EncodeSource(string source)
|
private static string EncodeSource(string source)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(source))
|
return SlangFormatter.EncodeSource(source, SLANG_SRC);
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] bytes = Encoding.UTF8.GetBytes(source);
|
|
||||||
|
|
||||||
using (var memoryStream = new MemoryStream())
|
|
||||||
{
|
|
||||||
using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress))
|
|
||||||
{
|
|
||||||
gzipStream.Write(bytes, 0, bytes.Length);
|
|
||||||
}
|
|
||||||
return Convert.ToBase64String(memoryStream.ToArray());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string DecodeSource(string source)
|
private static string DecodeSource(string source)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(source))
|
return SlangFormatter.DecodeSource(source, SLANG_SRC);
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] compressedBytes = Convert.FromBase64String(source);
|
|
||||||
|
|
||||||
using (var memoryStream = new MemoryStream(compressedBytes))
|
|
||||||
{
|
|
||||||
using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
|
|
||||||
{
|
|
||||||
using (var outputStream = new MemoryStream())
|
|
||||||
{
|
|
||||||
gzipStream.CopyTo(outputStream);
|
|
||||||
|
|
||||||
return Encoding.UTF8.GetString(outputStream.ToArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user