diff --git a/src/SharpIDE.Godot/Features/Build/BuildPanel.cs b/src/SharpIDE.Godot/Features/Build/BuildPanel.cs index 179acd3..8e0c0b6 100644 --- a/src/SharpIDE.Godot/Features/Build/BuildPanel.cs +++ b/src/SharpIDE.Godot/Features/Build/BuildPanel.cs @@ -21,7 +21,7 @@ public partial class BuildPanel : Control await this.InvokeAsync(() => _terminal.Clear()); return; } - _writeTask = GodotTask.Run(async () => + _writeTask = Task.GodotRun(async () => { await this.InvokeAsync(() => _terminal.Clear()); await foreach (var str in Singletons.BuildService.BuildTextWriter.ConsoleChannel.Reader.ReadAllAsync().ConfigureAwait(false)) diff --git a/src/SharpIDE.Godot/Features/Debug_/Tab/DebugPanelTab.cs b/src/SharpIDE.Godot/Features/Debug_/Tab/DebugPanelTab.cs index fc43471..0870a9b 100644 --- a/src/SharpIDE.Godot/Features/Debug_/Tab/DebugPanelTab.cs +++ b/src/SharpIDE.Godot/Features/Debug_/Tab/DebugPanelTab.cs @@ -33,7 +33,7 @@ public partial class DebugPanelTab : Control GD.PrintErr("Attempted to start writing from project output, but a write task is already running."); return; } - _writeTask = GodotTask.Run(async () => + _writeTask = Task.GodotRun(async () => { await foreach (var array in Project.RunningOutputChannel!.Reader.ReadAllAsync().ConfigureAwait(false)) { diff --git a/src/SharpIDE.Godot/Features/Run/RunPanelTab.cs b/src/SharpIDE.Godot/Features/Run/RunPanelTab.cs index d2faa61..100e3cb 100644 --- a/src/SharpIDE.Godot/Features/Run/RunPanelTab.cs +++ b/src/SharpIDE.Godot/Features/Run/RunPanelTab.cs @@ -25,7 +25,7 @@ public partial class RunPanelTab : Control GD.PrintErr("Attempted to start writing from project output, but a write task is already running."); return; } - _writeTask = GodotTask.Run(async () => + _writeTask = Task.GodotRun(async () => { await foreach (var array in Project.RunningOutputChannel!.Reader.ReadAllAsync().ConfigureAwait(false)) { diff --git a/src/SharpIDE.Godot/GlobalUsings.cs b/src/SharpIDE.Godot/GlobalUsings.cs index 769e515..5f28270 100644 --- a/src/SharpIDE.Godot/GlobalUsings.cs +++ b/src/SharpIDE.Godot/GlobalUsings.cs @@ -1 +1 @@ -global using static SharpIDE.Godot.NodeExtensions; \ No newline at end of file + \ No newline at end of file diff --git a/src/SharpIDE.Godot/IdeRoot.cs b/src/SharpIDE.Godot/IdeRoot.cs index 8dca4d9..a736bbc 100644 --- a/src/SharpIDE.Godot/IdeRoot.cs +++ b/src/SharpIDE.Godot/IdeRoot.cs @@ -65,7 +65,7 @@ public partial class IdeRoot : Control private void OnFileSelected(string path) { - _ = GodotTask.Run(async () => + _ = Task.GodotRun(async () => { GD.Print($"Selected: {path}"); var solutionModel = await VsPersistenceMapper.GetSolutionModel(path); diff --git a/src/SharpIDE.Godot/NodeExtensions.cs b/src/SharpIDE.Godot/NodeExtensions.cs index 29cc846..7a743c1 100644 --- a/src/SharpIDE.Godot/NodeExtensions.cs +++ b/src/SharpIDE.Godot/NodeExtensions.cs @@ -4,74 +4,80 @@ namespace SharpIDE.Godot; public static class NodeExtensions { - public static Task InvokeAsync(this Node node, Action workItem) + extension(Node node) { - var taskCompletionSource = new TaskCompletionSource(); - //WorkerThreadPool.AddTask(); - Callable.From(() => + public Task InvokeAsync(Action workItem) { - try + var taskCompletionSource = new TaskCompletionSource(); + //WorkerThreadPool.AddTask(); + Callable.From(() => { - workItem(); - taskCompletionSource.SetResult(); - } - catch (Exception ex) - { - taskCompletionSource.SetException(ex); - } - }).CallDeferred(); - return taskCompletionSource.Task; - } - - public static Task InvokeAsync(this Node node, Func workItem) - { - var taskCompletionSource = new TaskCompletionSource(); - //WorkerThreadPool.AddTask(); - Callable.From(async void () => + try + { + workItem(); + taskCompletionSource.SetResult(); + } + catch (Exception ex) + { + taskCompletionSource.SetException(ex); + } + }).CallDeferred(); + return taskCompletionSource.Task; + } + + public Task InvokeAsync(Func workItem) { - try + var taskCompletionSource = new TaskCompletionSource(); + //WorkerThreadPool.AddTask(); + Callable.From(async void () => { - await workItem(); - taskCompletionSource.SetResult(); - } - catch (Exception ex) - { - taskCompletionSource.SetException(ex); - } - }).CallDeferred(); - return taskCompletionSource.Task; + try + { + await workItem(); + taskCompletionSource.SetResult(); + } + catch (Exception ex) + { + taskCompletionSource.SetException(ex); + } + }).CallDeferred(); + return taskCompletionSource.Task; + } } } public static class GodotTask { - public static async Task Run(Action action) + extension(Task task) { - await Task.Run(() => + public static async Task GodotRun(Action action) { - try + await Task.Run(() => { - action(); - } - catch (Exception ex) - { - GD.PrintErr($"Error: {ex}"); - } - }); - } + try + { + action(); + } + catch (Exception ex) + { + GD.PrintErr($"Error: {ex}"); + } + }); + } - public static async Task Run(Func action) - { - await Task.Run(async () => + public static async Task GodotRun(Func action) { - try + await Task.Run(async () => { - await action(); - } - catch (Exception ex) - { - GD.PrintErr($"Error: {ex}"); - } - }); + try + { + await action(); + } + catch (Exception ex) + { + GD.PrintErr($"Error: {ex}"); + } + }); + } } } \ No newline at end of file diff --git a/src/SharpIDE.Godot/SharpIdeCodeEdit.cs b/src/SharpIDE.Godot/SharpIdeCodeEdit.cs index b470a42..078fe12 100644 --- a/src/SharpIDE.Godot/SharpIdeCodeEdit.cs +++ b/src/SharpIDE.Godot/SharpIdeCodeEdit.cs @@ -117,7 +117,7 @@ public partial class SharpIdeCodeEdit : CodeEdit { // update the MSBuildWorkspace RoslynAnalysis.UpdateDocument(_currentFile, Text); - _ = GodotTask.Run(async () => + _ = Task.GodotRun(async () => { var syntaxHighlighting = await RoslynAnalysis.GetDocumentSyntaxHighlighting(_currentFile); var diagnostics = await RoslynAnalysis.GetDocumentDiagnostics(_currentFile); @@ -136,7 +136,7 @@ public partial class SharpIdeCodeEdit : CodeEdit if (codeAction is null) return; var currentCaretPosition = GetCaretPosition(); var vScroll = GetVScroll(); - _ = GodotTask.Run(async () => + _ = Task.GodotRun(async () => { await RoslynAnalysis.ApplyCodeActionAsync(codeAction); var fileContents = await File.ReadAllTextAsync(_currentFile.Path); @@ -244,7 +244,7 @@ public partial class SharpIdeCodeEdit : CodeEdit SetLineColour(godotLine); var threadId = _executionStopInfo.ThreadId; _executionStopInfo = null; - _ = GodotTask.Run(async () => + _ = Task.GodotRun(async () => { await Singletons.RunService.SendDebuggerStepOver(threadId); }); @@ -292,7 +292,7 @@ public partial class SharpIdeCodeEdit : CodeEdit _popupMenu.AddItem("Getting Context Actions...", 0); _popupMenu.Popup(); GD.Print($"Code fixes requested at line {caretLine}, column {caretColumn}"); - _ = GodotTask.Run(async () => + _ = Task.GodotRun(async () => { var linePos = new LinePosition(caretLine, caretColumn); var codeActions = await RoslynAnalysis.GetCodeFixesForDocumentAtPosition(_currentFile, linePos); @@ -317,7 +317,7 @@ public partial class SharpIdeCodeEdit : CodeEdit var (caretLine, caretColumn) = GetCaretPosition(); GD.Print($"Code completion requested at line {caretLine}, column {caretColumn}"); - _ = GodotTask.Run(async () => + _ = Task.GodotRun(async () => { var linePos = new LinePosition(caretLine, caretColumn);