Modify IC10 view logic to conform to the new IC10Editor update

This commit is contained in:
2025-12-22 17:45:42 -07:00
parent 73e08b9896
commit 06a0ec28eb
2 changed files with 25 additions and 34 deletions

View File

@@ -12,6 +12,8 @@ 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();
@@ -78,34 +80,6 @@ public class SlangFormatter : ICodeFormatter
return this.Lines.RawText; return this.Lines.RawText;
} }
public override void DrawLine(int lineIndex, TextRange selection, bool drawLineNumber = true)
{
Vector2 cursorPos = ImGui.GetCursorScreenPos();
Vector2 space = ImGui.GetContentRegionAvail();
base.DrawLine(lineIndex, selection, drawLineNumber);
var charWidth = Settings.CharWidth;
var width = Mathf.Max(Lines.Width + 10.0f + LineNumberOffset * charWidth, space.x / 2);
ImGui
.GetWindowDrawList()
.AddLine(
new Vector2(cursorPos.x + width + 4.5f * charWidth, cursorPos.y),
new Vector2(
cursorPos.x + width + 4.5f * charWidth,
cursorPos.y + space.y + Settings.LineHeight
),
ColorLineNumber,
1.0f
);
cursorPos.x += width;
ImGui.SetCursorScreenPos(cursorPos);
if (lineIndex < iC10CodeFormatter.Lines.Count)
iC10CodeFormatter.DrawLine(lineIndex, new TextRange(), true);
}
public override StyledLine ParseLine(string line) public override StyledLine ParseLine(string line)
{ {
// We create the line first // We create the line first
@@ -186,7 +160,15 @@ public class SlangFormatter : ICodeFormatter
{ {
ic10CompilationResult = compiled; ic10CompilationResult = compiled;
ic10SourceMap = sourceMap; ic10SourceMap = sourceMap;
UpdateIc10Formatter(); try
{
UpdateIc10Formatter();
}
catch (Exception ex)
{
L.Error(ex.Message);
L.Error(ex.StackTrace);
}
} }
} }
catch (OperationCanceledException) { } catch (OperationCanceledException) { }
@@ -198,7 +180,16 @@ public class SlangFormatter : ICodeFormatter
private void UpdateIc10Formatter() private void UpdateIc10Formatter()
{ {
iC10CodeFormatter.Editor = Editor; if (Ic10Editor is null)
{
var tab = Editor.ParentTab;
iC10CodeFormatter = new IC10CodeFormatter();
Ic10Editor = new Editor(Editor.KeyHandler);
Ic10Editor.IsReadOnly = true;
iC10CodeFormatter.Editor = Ic10Editor;
tab.AddEditor(Ic10Editor);
}
var caretPos = Editor.CaretPos.Line; var caretPos = Editor.CaretPos.Line;
// get the slang sourceMap at the current editor line // get the slang sourceMap at the current editor line
@@ -210,7 +201,7 @@ public class SlangFormatter : ICodeFormatter
// should be directly next to the compiled IC10 source line, and we should highlight the // should be directly next to the compiled IC10 source line, and we should highlight the
// IC10 code that directly represents the Slang source // IC10 code that directly represents the Slang source
iC10CodeFormatter.ResetCode(ic10CompilationResult); Ic10Editor.ResetCode(ic10CompilationResult);
if (lines.Count() < 1) if (lines.Count() < 1)
{ {
@@ -223,7 +214,7 @@ public class SlangFormatter : ICodeFormatter
// highlight all the IC10 lines that are within the specified range // highlight all the IC10 lines that are within the specified range
foreach (var index in Enumerable.Range((int)min, (int)(max - min) + 1)) foreach (var index in Enumerable.Range((int)min, (int)(max - min) + 1))
{ {
var lineText = iC10CodeFormatter.Lines[index].Text; var lineText = Ic10Editor.Lines[index].Text;
var newLine = new StyledLine( var newLine = new StyledLine(
lineText, lineText,
@@ -239,7 +230,7 @@ public class SlangFormatter : ICodeFormatter
] ]
); );
iC10CodeFormatter.Lines[index] = newLine; Ic10Editor.Lines[index] = newLine;
} }
} }

View File

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