use extension members
This commit is contained in:
@@ -21,7 +21,7 @@ public partial class BuildPanel : Control
|
|||||||
await this.InvokeAsync(() => _terminal.Clear());
|
await this.InvokeAsync(() => _terminal.Clear());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_writeTask = GodotTask.Run(async () =>
|
_writeTask = Task.GodotRun(async () =>
|
||||||
{
|
{
|
||||||
await this.InvokeAsync(() => _terminal.Clear());
|
await this.InvokeAsync(() => _terminal.Clear());
|
||||||
await foreach (var str in Singletons.BuildService.BuildTextWriter.ConsoleChannel.Reader.ReadAllAsync().ConfigureAwait(false))
|
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.");
|
GD.PrintErr("Attempted to start writing from project output, but a write task is already running.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_writeTask = GodotTask.Run(async () =>
|
_writeTask = Task.GodotRun(async () =>
|
||||||
{
|
{
|
||||||
await foreach (var array in Project.RunningOutputChannel!.Reader.ReadAllAsync().ConfigureAwait(false))
|
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.");
|
GD.PrintErr("Attempted to start writing from project output, but a write task is already running.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_writeTask = GodotTask.Run(async () =>
|
_writeTask = Task.GodotRun(async () =>
|
||||||
{
|
{
|
||||||
await foreach (var array in Project.RunningOutputChannel!.Reader.ReadAllAsync().ConfigureAwait(false))
|
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)
|
private void OnFileSelected(string path)
|
||||||
{
|
{
|
||||||
_ = GodotTask.Run(async () =>
|
_ = Task.GodotRun(async () =>
|
||||||
{
|
{
|
||||||
GD.Print($"Selected: {path}");
|
GD.Print($"Selected: {path}");
|
||||||
var solutionModel = await VsPersistenceMapper.GetSolutionModel(path);
|
var solutionModel = await VsPersistenceMapper.GetSolutionModel(path);
|
||||||
|
|||||||
@@ -4,74 +4,80 @@ namespace SharpIDE.Godot;
|
|||||||
|
|
||||||
public static class NodeExtensions
|
public static class NodeExtensions
|
||||||
{
|
{
|
||||||
public static Task InvokeAsync(this Node node, Action workItem)
|
extension(Node node)
|
||||||
{
|
{
|
||||||
var taskCompletionSource = new TaskCompletionSource();
|
public Task InvokeAsync(Action workItem)
|
||||||
//WorkerThreadPool.AddTask();
|
|
||||||
Callable.From(() =>
|
|
||||||
{
|
{
|
||||||
try
|
var taskCompletionSource = new TaskCompletionSource();
|
||||||
|
//WorkerThreadPool.AddTask();
|
||||||
|
Callable.From(() =>
|
||||||
{
|
{
|
||||||
workItem();
|
try
|
||||||
taskCompletionSource.SetResult();
|
{
|
||||||
}
|
workItem();
|
||||||
catch (Exception ex)
|
taskCompletionSource.SetResult();
|
||||||
{
|
}
|
||||||
taskCompletionSource.SetException(ex);
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
}).CallDeferred();
|
taskCompletionSource.SetException(ex);
|
||||||
return taskCompletionSource.Task;
|
}
|
||||||
}
|
}).CallDeferred();
|
||||||
|
return taskCompletionSource.Task;
|
||||||
public static Task InvokeAsync(this Node node, Func<Task> workItem)
|
}
|
||||||
{
|
|
||||||
var taskCompletionSource = new TaskCompletionSource();
|
public Task InvokeAsync(Func<Task> workItem)
|
||||||
//WorkerThreadPool.AddTask();
|
|
||||||
Callable.From(async void () =>
|
|
||||||
{
|
{
|
||||||
try
|
var taskCompletionSource = new TaskCompletionSource();
|
||||||
|
//WorkerThreadPool.AddTask();
|
||||||
|
Callable.From(async void () =>
|
||||||
{
|
{
|
||||||
await workItem();
|
try
|
||||||
taskCompletionSource.SetResult();
|
{
|
||||||
}
|
await workItem();
|
||||||
catch (Exception ex)
|
taskCompletionSource.SetResult();
|
||||||
{
|
}
|
||||||
taskCompletionSource.SetException(ex);
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
}).CallDeferred();
|
taskCompletionSource.SetException(ex);
|
||||||
return taskCompletionSource.Task;
|
}
|
||||||
|
}).CallDeferred();
|
||||||
|
return taskCompletionSource.Task;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GodotTask
|
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();
|
try
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
action();
|
||||||
{
|
}
|
||||||
GD.PrintErr($"Error: {ex}");
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
});
|
GD.PrintErr($"Error: {ex}");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task Run(Func<Task> action)
|
public static async Task GodotRun(Func<Task> action)
|
||||||
{
|
|
||||||
await Task.Run(async () =>
|
|
||||||
{
|
{
|
||||||
try
|
await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await action();
|
try
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
await action();
|
||||||
{
|
}
|
||||||
GD.PrintErr($"Error: {ex}");
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
});
|
GD.PrintErr($"Error: {ex}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
|||||||
{
|
{
|
||||||
// update the MSBuildWorkspace
|
// update the MSBuildWorkspace
|
||||||
RoslynAnalysis.UpdateDocument(_currentFile, Text);
|
RoslynAnalysis.UpdateDocument(_currentFile, Text);
|
||||||
_ = GodotTask.Run(async () =>
|
_ = Task.GodotRun(async () =>
|
||||||
{
|
{
|
||||||
var syntaxHighlighting = await RoslynAnalysis.GetDocumentSyntaxHighlighting(_currentFile);
|
var syntaxHighlighting = await RoslynAnalysis.GetDocumentSyntaxHighlighting(_currentFile);
|
||||||
var diagnostics = await RoslynAnalysis.GetDocumentDiagnostics(_currentFile);
|
var diagnostics = await RoslynAnalysis.GetDocumentDiagnostics(_currentFile);
|
||||||
@@ -136,7 +136,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
|||||||
if (codeAction is null) return;
|
if (codeAction is null) return;
|
||||||
var currentCaretPosition = GetCaretPosition();
|
var currentCaretPosition = GetCaretPosition();
|
||||||
var vScroll = GetVScroll();
|
var vScroll = GetVScroll();
|
||||||
_ = GodotTask.Run(async () =>
|
_ = Task.GodotRun(async () =>
|
||||||
{
|
{
|
||||||
await RoslynAnalysis.ApplyCodeActionAsync(codeAction);
|
await RoslynAnalysis.ApplyCodeActionAsync(codeAction);
|
||||||
var fileContents = await File.ReadAllTextAsync(_currentFile.Path);
|
var fileContents = await File.ReadAllTextAsync(_currentFile.Path);
|
||||||
@@ -244,7 +244,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
|||||||
SetLineColour(godotLine);
|
SetLineColour(godotLine);
|
||||||
var threadId = _executionStopInfo.ThreadId;
|
var threadId = _executionStopInfo.ThreadId;
|
||||||
_executionStopInfo = null;
|
_executionStopInfo = null;
|
||||||
_ = GodotTask.Run(async () =>
|
_ = Task.GodotRun(async () =>
|
||||||
{
|
{
|
||||||
await Singletons.RunService.SendDebuggerStepOver(threadId);
|
await Singletons.RunService.SendDebuggerStepOver(threadId);
|
||||||
});
|
});
|
||||||
@@ -292,7 +292,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
|||||||
_popupMenu.AddItem("Getting Context Actions...", 0);
|
_popupMenu.AddItem("Getting Context Actions...", 0);
|
||||||
_popupMenu.Popup();
|
_popupMenu.Popup();
|
||||||
GD.Print($"Code fixes requested at line {caretLine}, column {caretColumn}");
|
GD.Print($"Code fixes requested at line {caretLine}, column {caretColumn}");
|
||||||
_ = GodotTask.Run(async () =>
|
_ = Task.GodotRun(async () =>
|
||||||
{
|
{
|
||||||
var linePos = new LinePosition(caretLine, caretColumn);
|
var linePos = new LinePosition(caretLine, caretColumn);
|
||||||
var codeActions = await RoslynAnalysis.GetCodeFixesForDocumentAtPosition(_currentFile, linePos);
|
var codeActions = await RoslynAnalysis.GetCodeFixesForDocumentAtPosition(_currentFile, linePos);
|
||||||
@@ -317,7 +317,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
|||||||
var (caretLine, caretColumn) = GetCaretPosition();
|
var (caretLine, caretColumn) = GetCaretPosition();
|
||||||
|
|
||||||
GD.Print($"Code completion requested at line {caretLine}, column {caretColumn}");
|
GD.Print($"Code completion requested at line {caretLine}, column {caretColumn}");
|
||||||
_ = GodotTask.Run(async () =>
|
_ = Task.GodotRun(async () =>
|
||||||
{
|
{
|
||||||
var linePos = new LinePosition(caretLine, caretColumn);
|
var linePos = new LinePosition(caretLine, caretColumn);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user