mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-07-31 01:59:59 -06:00
Use a single parser execution per text box update
Before it would: parse, compile, then execute for getting the formatted result, then run the suggestions function which did parsing on its own. It has now been moved to the new ParseAndGetCompletions function which returns the used ParserResult, saving some work.
This commit is contained in:
@ -55,7 +55,7 @@
|
||||
<PackageVersion Include="SkiaSharp" Version="2.88.9" />
|
||||
<PackageVersion Include="SkiaSharp.NativeAssets.Linux" Version="2.88.9" />
|
||||
<PackageVersion Include="SPB" Version="0.0.4-build32" />
|
||||
<PackageVersion Include="Starscript.Net" Version="1.0.35" />
|
||||
<PackageVersion Include="Starscript.Net" Version="1.0.36" />
|
||||
<PackageVersion Include="System.IO.Hashing" Version="9.0.2" />
|
||||
<PackageVersion Include="System.Management" Version="9.0.2" />
|
||||
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />
|
||||
|
@ -1,6 +1,5 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Styling;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using Humanizer;
|
||||
@ -8,6 +7,7 @@ using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Ava.UI.Controls;
|
||||
using Ryujinx.Ava.UI.Helpers;
|
||||
using Starscript;
|
||||
using Starscript.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
@ -20,7 +20,7 @@ namespace Ryujinx.Ava.Systems.Starscript
|
||||
{
|
||||
public IReadOnlyList<string> CurrentSuggestions => ViewModel.CurrentSuggestions;
|
||||
|
||||
public string CurrentScriptSource => ViewModel.CurrentScriptSource;
|
||||
public ParserResult CurrentScriptSource => ViewModel.CurrentScriptSource;
|
||||
public Exception Exception => ViewModel.Exception;
|
||||
public Script CurrentScript => ViewModel.CurrentScript;
|
||||
public StringSegment CurrentScriptResult => ViewModel.CurrentScriptResult;
|
||||
@ -28,8 +28,6 @@ namespace Ryujinx.Ava.Systems.Starscript
|
||||
public StarscriptTextBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
InputBox.TextInput += HandleTextChanged;
|
||||
|
||||
InputBox.AsyncPopulator = GetSuggestionsAsync;
|
||||
InputBox.MinimumPopulateDelay = 0.Seconds();
|
||||
@ -70,12 +68,6 @@ namespace Ryujinx.Ava.Systems.Starscript
|
||||
private Task<IEnumerable<object>> GetSuggestionsAsync(string input, CancellationToken token)
|
||||
=> Task.FromResult(ViewModel.GetSuggestions(input, token));
|
||||
|
||||
private void HandleTextChanged(object sender, TextInputEventArgs eventArgs)
|
||||
{
|
||||
if (sender is AutoCompleteBox)
|
||||
ViewModel.CurrentScriptSource = eventArgs.Text;
|
||||
}
|
||||
|
||||
public static StarscriptTextBox Create(StarscriptHypervisor hv)
|
||||
=> new() { ViewModel = new StarscriptTextBoxViewModel(hv) };
|
||||
|
||||
|
@ -5,6 +5,7 @@ using Starscript.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ryujinx.Ava.Systems.Starscript
|
||||
@ -24,7 +25,7 @@ namespace Ryujinx.Ava.Systems.Starscript
|
||||
[ObservableProperty] private StringSegment _currentScriptResult;
|
||||
[ObservableProperty] private string _errorMessage;
|
||||
private Exception _exception;
|
||||
private string _currentScriptSource;
|
||||
private ParserResult _currentScriptSource;
|
||||
private Script _currentScript;
|
||||
|
||||
public Exception Exception
|
||||
@ -38,12 +39,14 @@ namespace Ryujinx.Ava.Systems.Starscript
|
||||
StarscriptException se => se.Message,
|
||||
_ => string.Empty
|
||||
};
|
||||
|
||||
HasError = value is not null;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string CurrentScriptSource
|
||||
public ParserResult CurrentScriptSource
|
||||
{
|
||||
get => _currentScriptSource;
|
||||
set
|
||||
@ -55,23 +58,11 @@ namespace Ryujinx.Ava.Systems.Starscript
|
||||
CurrentScript = null;
|
||||
CurrentScriptResult = null;
|
||||
Exception = null;
|
||||
HasError = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CurrentScript = Compiler.DirectCompile(CurrentScriptSource);
|
||||
Exception = null;
|
||||
HasError = false;
|
||||
}
|
||||
catch (ParseException pe)
|
||||
{
|
||||
CurrentScript = null;
|
||||
CurrentScriptResult = null;
|
||||
Exception = pe;
|
||||
HasError = true;
|
||||
}
|
||||
|
||||
CurrentScript = Compiler.SingleCompile(value);
|
||||
Exception = null;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
@ -87,25 +78,41 @@ namespace Ryujinx.Ava.Systems.Starscript
|
||||
CurrentScriptResult = value?.Execute(_hv)!;
|
||||
_currentScript = value;
|
||||
Exception = null;
|
||||
HasError = false;
|
||||
}
|
||||
catch (StarscriptException se)
|
||||
{
|
||||
_currentScript = null;
|
||||
CurrentScriptResult = null;
|
||||
Exception = se;
|
||||
HasError = true;
|
||||
}
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void ReExecuteScript()
|
||||
{
|
||||
if (_currentScript is null) return;
|
||||
|
||||
try
|
||||
{
|
||||
CurrentScriptResult = _currentScript.Execute(_hv)!;
|
||||
}
|
||||
catch (StarscriptException se)
|
||||
{
|
||||
CurrentScriptResult = null;
|
||||
Exception = se;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<object> GetSuggestions(string input, CancellationToken token)
|
||||
{
|
||||
CurrentScriptSource = input;
|
||||
|
||||
_hv.GetCompletions(CurrentScriptSource, CurrentScriptSource.Length, CreateCallback(), token);
|
||||
CurrentScriptSource = _hv.ParseAndGetCompletions(input, input.Length, CreateCallback(), token);
|
||||
|
||||
if (CurrentScriptSource.HasErrors)
|
||||
{
|
||||
Exception = new ParseException(CurrentScriptSource.Errors.First());
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(CurrentSuggestions));
|
||||
|
||||
|
Reference in New Issue
Block a user