diff --git a/ModData/About/About.xml b/ModData/About/About.xml index 4f3f624..b0025db 100644 --- a/ModData/About/About.xml +++ b/ModData/About/About.xml @@ -2,7 +2,7 @@ Slang JoeDiertay - 0.4.4 + 0.4.5 [h1]Slang: High-Level Programming for Stationeers[/h1] diff --git a/csharp_mod/Formatter.cs b/csharp_mod/Formatter.cs index 890b79c..2335013 100644 --- a/csharp_mod/Formatter.cs +++ b/csharp_mod/Formatter.cs @@ -165,18 +165,15 @@ public class SlangFormatter : ICodeFormatter return; } - var (compilationSuccess, compiled, sourceMap) = await Task.Run( - () => - { - var successful = Marshal.CompileFromString( - inputSrc, - out var compiled, - out var sourceMap - ); - return (successful, compiled, sourceMap); - }, - cancellationToken - ); + var (compilationSuccess, compiled, sourceMap) = await Task.Run(() => + { + var successful = Marshal.CompileFromString( + inputSrc, + out var compiled, + out var sourceMap + ); + return (successful, compiled, sourceMap); + }); if (compilationSuccess) { @@ -192,6 +189,7 @@ public class SlangFormatter : ICodeFormatter } } + // This runs on the main thread private void UpdateIc10Formatter() { var tab = Editor.ParentTab; @@ -215,14 +213,11 @@ public class SlangFormatter : ICodeFormatter entry.SlangSource.StartLine == caretPos || entry.SlangSource.EndLine == caretPos ); - // extract the current "context" of the ic10 compilation. The current Slang source line - // should be directly next to the compiled IC10 source line, and we should highlight the - // IC10 code that directly represents the Slang source - Ic10Editor.ResetCode(ic10CompilationResult); if (lines.Count() < 1) { + L.Debug($"SourceMap count: {ic10SourceMap.Count}"); Ic10Editor.Selection = new TextRange { End = new TextPosition { Col = 0, Line = 0 }, diff --git a/csharp_mod/Marshal.cs b/csharp_mod/Marshal.cs index d5fb834..84e1982 100644 --- a/csharp_mod/Marshal.cs +++ b/csharp_mod/Marshal.cs @@ -67,7 +67,9 @@ public static class Marshal try { _libraryHandle = LoadLibrary(ExtractNativeLibrary(Ffi.RustLib)); + L.Debug("Rust DLL loaded successfully. Enjoy native speed compilations!"); CodeFormatters.RegisterFormatter("Slang", typeof(SlangFormatter), true); + return true; } catch (Exception ex) @@ -91,8 +93,13 @@ public static class Marshal try { - FreeLibrary(_libraryHandle); + CodeFormatters.RegisterFormatter("Slang", typeof(PlainTextFormatter), true); + if (!FreeLibrary(_libraryHandle)) + { + L.Warning("Unable to free Rust library"); + } _libraryHandle = IntPtr.Zero; + L.Debug("Rust DLL library freed"); return true; } catch (Exception ex) diff --git a/csharp_mod/Plugin.cs b/csharp_mod/Plugin.cs index 8b5f08a..662a0fe 100644 --- a/csharp_mod/Plugin.cs +++ b/csharp_mod/Plugin.cs @@ -40,9 +40,9 @@ namespace Slang { public const string PluginGuid = "com.biddydev.slang"; public const string PluginName = "Slang"; - public const string PluginVersion = "0.4.4"; + public const string PluginVersion = "0.4.5"; - private Harmony? _harmony; + private static Harmony? _harmony; private static Regex? _slangSourceCheck = null; @@ -64,19 +64,28 @@ namespace Slang return SlangSourceCheck.IsMatch(input); } - private void Awake() + public void Awake() { L.SetLogger(Logger); - this._harmony = new Harmony(PluginGuid); + _harmony = new Harmony(PluginGuid); // If we failed to load the compiler, bail from the rest of the patches. It won't matter, // as the compiler itself has failed to load. if (!Marshal.Init()) { + L.Error("Marshal failed to init"); return; } - this._harmony.PatchAll(); + _harmony.PatchAll(); + L.Debug("Ran Harmony patches"); + } + + public void OnDestroy() + { + Marshal.Destroy(); + _harmony?.UnpatchSelf(); + L.Debug("Cleaned up Harmony patches"); } } } diff --git a/rust_compiler/Cargo.lock b/rust_compiler/Cargo.lock index b5bca3c..91769ce 100644 --- a/rust_compiler/Cargo.lock +++ b/rust_compiler/Cargo.lock @@ -930,7 +930,7 @@ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" [[package]] name = "slang" -version = "0.4.3" +version = "0.4.5" dependencies = [ "anyhow", "clap", diff --git a/rust_compiler/Cargo.toml b/rust_compiler/Cargo.toml index 41b30e7..94ee887 100644 --- a/rust_compiler/Cargo.toml +++ b/rust_compiler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "slang" -version = "0.4.3" +version = "0.4.5" edition = "2021" [workspace]