wip -- lsp mappings to various types
This commit is contained in:
@@ -88,6 +88,53 @@ namespace Slang
|
||||
public static extern unsafe Vec_uint8_t compile_from_string(slice_ref_uint16_t input);
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Size = 16)]
|
||||
public unsafe struct FfiRange_t
|
||||
{
|
||||
public UInt32 start_col;
|
||||
|
||||
public UInt32 end_col;
|
||||
|
||||
public UInt32 start_line;
|
||||
|
||||
public UInt32 end_line;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Size = 48)]
|
||||
public unsafe struct FfiDiagnostic_t
|
||||
{
|
||||
public Vec_uint8_t message;
|
||||
|
||||
public Int32 severity;
|
||||
|
||||
public FfiRange_t range;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Same as [<c>Vec<T></c>][<c>rust::Vec</c>], but with guaranteed <c>#[repr(C)]</c> layout
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Size = 24)]
|
||||
public unsafe struct Vec_FfiDiagnostic_t
|
||||
{
|
||||
public FfiDiagnostic_t* ptr;
|
||||
|
||||
public UIntPtr len;
|
||||
|
||||
public UIntPtr cap;
|
||||
}
|
||||
|
||||
public unsafe partial class Ffi
|
||||
{
|
||||
[DllImport(RustLib, ExactSpelling = true)]
|
||||
public static extern unsafe Vec_FfiDiagnostic_t diagnose_source();
|
||||
}
|
||||
|
||||
public unsafe partial class Ffi
|
||||
{
|
||||
[DllImport(RustLib, ExactSpelling = true)]
|
||||
public static extern unsafe void free_ffi_diagnostic_vec(Vec_FfiDiagnostic_t v);
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Size = 64)]
|
||||
public unsafe struct FfiToken_t
|
||||
{
|
||||
@@ -126,16 +173,4 @@ namespace Slang
|
||||
[DllImport(RustLib, ExactSpelling = true)]
|
||||
public static extern unsafe void free_string(Vec_uint8_t s);
|
||||
}
|
||||
|
||||
public unsafe partial class Ffi
|
||||
{
|
||||
/// <summary>
|
||||
/// C# handles strings as UTF16. We do NOT want to allocate that memory in C# because
|
||||
/// we want to avoid GC. So we pass it to Rust to handle all the memory allocations.
|
||||
/// This should result in the ability to tokenize many times without triggering frame drops
|
||||
/// from the GC from a <c>GetBytes()</c> call on a string in C#.
|
||||
/// </summary>
|
||||
[DllImport(RustLib, ExactSpelling = true)]
|
||||
public static extern unsafe Vec_FfiToken_t tokenize_line(slice_ref_uint16_t input);
|
||||
}
|
||||
} /* Slang */
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
namespace Slang;
|
||||
|
||||
using System.Timers;
|
||||
using StationeersIC10Editor;
|
||||
|
||||
public class SlangFormatter : ICodeFormatter
|
||||
{
|
||||
private Timer _timer;
|
||||
|
||||
public static readonly uint ColorInstruction = ColorFromHTML("#ffff00");
|
||||
public static readonly uint ColorString = ColorFromHTML("#ce9178");
|
||||
|
||||
public override Line ParseLine(string line)
|
||||
public SlangFormatter()
|
||||
{
|
||||
return Marshal.TokenizeLine(line);
|
||||
_timer = new Timer(250);
|
||||
|
||||
this.OnCodeChanged += HandleCodeChanged;
|
||||
}
|
||||
|
||||
public override string Compile()
|
||||
@@ -17,4 +22,19 @@ public class SlangFormatter : ICodeFormatter
|
||||
L.Info("ICodeFormatter attempted to compile source code.");
|
||||
return this.Lines.RawText;
|
||||
}
|
||||
|
||||
public override Line ParseLine(string line)
|
||||
{
|
||||
return new Line(line);
|
||||
}
|
||||
|
||||
private void HandleCodeChanged()
|
||||
{
|
||||
_timer.Stop();
|
||||
_timer.Dispose();
|
||||
_timer = new Timer(250);
|
||||
_timer.Elapsed += (_, _) => HandleLsp();
|
||||
}
|
||||
|
||||
private void HandleLsp() { }
|
||||
}
|
||||
|
||||
@@ -61,29 +61,6 @@ public static class Marshal
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe Line TokenizeLine(string source)
|
||||
{
|
||||
if (String.IsNullOrEmpty(source))
|
||||
{
|
||||
return new Line(source);
|
||||
}
|
||||
|
||||
if (!EnsureLibLoaded())
|
||||
{
|
||||
return new Line(source);
|
||||
}
|
||||
|
||||
fixed (char* ptrString = source)
|
||||
{
|
||||
var input = new slice_ref_uint16_t
|
||||
{
|
||||
ptr = (ushort*)ptrString,
|
||||
len = (UIntPtr)source.Length,
|
||||
};
|
||||
return Ffi.tokenize_line(input).ToLine(source);
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe bool CompileFromString(string inputString, out string compiledString)
|
||||
{
|
||||
if (String.IsNullOrEmpty(inputString))
|
||||
|
||||
Reference in New Issue
Block a user