IC10Editor fix #9

Merged
dbidwell merged 3 commits from live-reload into master 2025-12-27 22:26:51 -07:00
6 changed files with 36 additions and 25 deletions
Showing only changes of commit 3543b87561 - Show all commits

View File

@@ -2,7 +2,7 @@
<ModMetadata xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ModMetadata xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>Slang</Name> <Name>Slang</Name>
<Author>JoeDiertay</Author> <Author>JoeDiertay</Author>
<Version>0.4.4</Version> <Version>0.4.5</Version>
<Description> <Description>
[h1]Slang: High-Level Programming for Stationeers[/h1] [h1]Slang: High-Level Programming for Stationeers[/h1]

View File

@@ -165,8 +165,7 @@ public class SlangFormatter : ICodeFormatter
return; return;
} }
var (compilationSuccess, compiled, sourceMap) = await Task.Run( var (compilationSuccess, compiled, sourceMap) = await Task.Run(() =>
() =>
{ {
var successful = Marshal.CompileFromString( var successful = Marshal.CompileFromString(
inputSrc, inputSrc,
@@ -174,9 +173,7 @@ public class SlangFormatter : ICodeFormatter
out var sourceMap out var sourceMap
); );
return (successful, compiled, sourceMap); return (successful, compiled, sourceMap);
}, });
cancellationToken
);
if (compilationSuccess) if (compilationSuccess)
{ {
@@ -192,6 +189,7 @@ public class SlangFormatter : ICodeFormatter
} }
} }
// This runs on the main thread
private void UpdateIc10Formatter() private void UpdateIc10Formatter()
{ {
var tab = Editor.ParentTab; var tab = Editor.ParentTab;
@@ -215,14 +213,11 @@ public class SlangFormatter : ICodeFormatter
entry.SlangSource.StartLine == caretPos || entry.SlangSource.EndLine == caretPos 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); Ic10Editor.ResetCode(ic10CompilationResult);
if (lines.Count() < 1) if (lines.Count() < 1)
{ {
L.Debug($"SourceMap count: {ic10SourceMap.Count}");
Ic10Editor.Selection = new TextRange Ic10Editor.Selection = new TextRange
{ {
End = new TextPosition { Col = 0, Line = 0 }, End = new TextPosition { Col = 0, Line = 0 },

View File

@@ -67,7 +67,9 @@ public static class Marshal
try try
{ {
_libraryHandle = LoadLibrary(ExtractNativeLibrary(Ffi.RustLib)); _libraryHandle = LoadLibrary(ExtractNativeLibrary(Ffi.RustLib));
L.Debug("Rust DLL loaded successfully. Enjoy native speed compilations!");
CodeFormatters.RegisterFormatter("Slang", typeof(SlangFormatter), true); CodeFormatters.RegisterFormatter("Slang", typeof(SlangFormatter), true);
return true; return true;
} }
catch (Exception ex) catch (Exception ex)
@@ -91,8 +93,13 @@ public static class Marshal
try try
{ {
FreeLibrary(_libraryHandle); CodeFormatters.RegisterFormatter("Slang", typeof(PlainTextFormatter), true);
if (!FreeLibrary(_libraryHandle))
{
L.Warning("Unable to free Rust library");
}
_libraryHandle = IntPtr.Zero; _libraryHandle = IntPtr.Zero;
L.Debug("Rust DLL library freed");
return true; return true;
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -40,9 +40,9 @@ namespace Slang
{ {
public const string PluginGuid = "com.biddydev.slang"; public const string PluginGuid = "com.biddydev.slang";
public const string PluginName = "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; private static Regex? _slangSourceCheck = null;
@@ -64,19 +64,28 @@ namespace Slang
return SlangSourceCheck.IsMatch(input); return SlangSourceCheck.IsMatch(input);
} }
private void Awake() public void Awake()
{ {
L.SetLogger(Logger); 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, // 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. // as the compiler itself has failed to load.
if (!Marshal.Init()) if (!Marshal.Init())
{ {
L.Error("Marshal failed to init");
return; return;
} }
this._harmony.PatchAll(); _harmony.PatchAll();
L.Debug("Ran Harmony patches");
}
public void OnDestroy()
{
Marshal.Destroy();
_harmony?.UnpatchSelf();
L.Debug("Cleaned up Harmony patches");
} }
} }
} }

View File

@@ -930,7 +930,7 @@ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
[[package]] [[package]]
name = "slang" name = "slang"
version = "0.4.3" version = "0.4.5"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "slang" name = "slang"
version = "0.4.3" version = "0.4.5"
edition = "2021" edition = "2021"
[workspace] [workspace]