use extension members
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -1 +1 @@
|
||||
global using static SharpIDE.Godot.NodeExtensions;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Task> 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<Task> 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<Task> action)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
public static async Task GodotRun(Func<Task> 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}");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user