diff --git a/csharp_mod/Formatter.cs b/csharp_mod/Formatter.cs index 24ba823..486ca5f 100644 --- a/csharp_mod/Formatter.cs +++ b/csharp_mod/Formatter.cs @@ -12,16 +12,15 @@ using UnityEngine; public class SlangFormatter : ICodeFormatter { - protected static Editor? Ic10Editor = null; - private CancellationTokenSource? _lspCancellationToken; private object _tokenLock = new(); + protected static Editor? Ic10Editor = null; private IC10CodeFormatter iC10CodeFormatter = new IC10CodeFormatter(); private string ic10CompilationResult = ""; private List ic10SourceMap = new(); - // VS Code Dark Theme Palette + #region Colors 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 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 ColorIdentifier = ColorFromHTML("#9CDCFE"); // Light Blue (variables) 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"); + #endregion private HashSet _linesWithErrors = new(); private int _lastLineCount = -1; @@ -160,15 +157,7 @@ public class SlangFormatter : ICodeFormatter { ic10CompilationResult = compiled; ic10SourceMap = sourceMap; - try - { - UpdateIc10Formatter(); - } - catch (Exception ex) - { - L.Error(ex.Message); - L.Error(ex.StackTrace); - } + UpdateIc10Formatter(); } } catch (OperationCanceledException) { } diff --git a/csharp_mod/GlobalCode.cs b/csharp_mod/GlobalCode.cs index 88286df..786c5ce 100644 --- a/csharp_mod/GlobalCode.cs +++ b/csharp_mod/GlobalCode.cs @@ -1,15 +1,12 @@ using System; using System.Collections.Generic; -using System.IO; -using System.IO.Compression; -using System.Text; namespace Slang; public static class GlobalCode { 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 // so that save file data is smaller @@ -110,43 +107,11 @@ public static class GlobalCode private static string EncodeSource(string source) { - if (string.IsNullOrEmpty(source)) - { - 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()); - } + return SlangFormatter.EncodeSource(source, SLANG_SRC); } private static string DecodeSource(string source) { - if (string.IsNullOrEmpty(source)) - { - 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()); - } - } - } + return SlangFormatter.DecodeSource(source, SLANG_SRC); } }