diff --git a/src/SharpIDE.Godot/IdeRoot.cs b/src/SharpIDE.Godot/IdeRoot.cs index 1938a32..cd73c2d 100644 --- a/src/SharpIDE.Godot/IdeRoot.cs +++ b/src/SharpIDE.Godot/IdeRoot.cs @@ -47,43 +47,35 @@ public partial class IdeRoot : Control private void OnFileSelected(string path) { - _ = Task.Run(async () => + _ = GodotTask.Run(async () => { - try - { - GD.Print($"Selected: {path}"); - var solutionModel = await VsPersistenceMapper.GetSolutionModel(path); - _solutionExplorerPanel.SolutionModel = solutionModel; - Callable.From(_solutionExplorerPanel.RepopulateTree).CallDeferred(); - RoslynAnalysis.StartSolutionAnalysis(path); + GD.Print($"Selected: {path}"); + var solutionModel = await VsPersistenceMapper.GetSolutionModel(path); + _solutionExplorerPanel.SolutionModel = solutionModel; + Callable.From(_solutionExplorerPanel.RepopulateTree).CallDeferred(); + RoslynAnalysis.StartSolutionAnalysis(path); - var tasks = solutionModel.AllProjects.Select(p => p.MsBuildEvaluationProjectTask).ToList(); - await Task.WhenAll(tasks).ConfigureAwait(false); - var runnableProjects = solutionModel.AllProjects.Where(p => p.IsRunnable).ToList(); - await this.InvokeAsync(() => + var tasks = solutionModel.AllProjects.Select(p => p.MsBuildEvaluationProjectTask).ToList(); + await Task.WhenAll(tasks).ConfigureAwait(false); + var runnableProjects = solutionModel.AllProjects.Where(p => p.IsRunnable).ToList(); + await this.InvokeAsync(() => + { + var runMenuPopupVbox = _runMenuPopup.GetNode("MarginContainer/VBoxContainer"); + foreach (var project in runnableProjects) { - var runMenuPopupVbox = _runMenuPopup.GetNode("MarginContainer/VBoxContainer"); - foreach (var project in runnableProjects) - { - var runMenuItem = _runMenuItemScene.Instantiate(); - runMenuItem.Project = project; - runMenuPopupVbox.AddChild(runMenuItem); - } - _runMenuButton.Disabled = false; - }); + var runMenuItem = _runMenuItemScene.Instantiate(); + runMenuItem.Project = project; + runMenuPopupVbox.AddChild(runMenuItem); + } + _runMenuButton.Disabled = false; + }); - var infraProject = solutionModel.AllProjects.Single(s => s.Name == "Infrastructure"); - var diFile = infraProject.Files.Single(s => s.Name == "DependencyInjection.cs"); - await this.InvokeAsync(async () => await _sharpIdeCodeEdit.SetSharpIdeFile(diFile)); + var infraProject = solutionModel.AllProjects.Single(s => s.Name == "Infrastructure"); + var diFile = infraProject.Files.Single(s => s.Name == "DependencyInjection.cs"); + await this.InvokeAsync(async () => await _sharpIdeCodeEdit.SetSharpIdeFile(diFile)); - //var runnableProject = solutionModel.AllProjects.First(s => s.IsRunnable); - //await this.InvokeAsync(() => _runPanel.NewRunStarted(runnableProject)); - } - catch (Exception e) - { - GD.PrintErr($"Error loading solution: {e.Message}"); - GD.PrintErr(e.StackTrace); - } + //var runnableProject = solutionModel.AllProjects.First(s => s.IsRunnable); + //await this.InvokeAsync(() => _runPanel.NewRunStarted(runnableProject)); }); } } \ No newline at end of file diff --git a/src/SharpIDE.Godot/SharpIdeCodeEdit.cs b/src/SharpIDE.Godot/SharpIdeCodeEdit.cs index 6bacb2c..5574862 100644 --- a/src/SharpIDE.Godot/SharpIdeCodeEdit.cs +++ b/src/SharpIDE.Godot/SharpIdeCodeEdit.cs @@ -114,22 +114,15 @@ public partial class SharpIdeCodeEdit : CodeEdit { // update the MSBuildWorkspace RoslynAnalysis.UpdateDocument(_currentFile, Text); - _ = Task.Run(async () => + _ = GodotTask.Run(async () => { - try + var syntaxHighlighting = await RoslynAnalysis.GetDocumentSyntaxHighlighting(_currentFile); + var diagnostics = await RoslynAnalysis.GetDocumentDiagnostics(_currentFile); + Callable.From(() => { - var syntaxHighlighting = await RoslynAnalysis.GetDocumentSyntaxHighlighting(_currentFile); - var diagnostics = await RoslynAnalysis.GetDocumentDiagnostics(_currentFile); - Callable.From(() => - { - SetSyntaxHighlightingModel(syntaxHighlighting); - SetDiagnosticsModel(diagnostics); - }).CallDeferred(); - } - catch (Exception ex) - { - GD.PrintErr($"Error Calling OnTextChanged: {ex.Message}"); - } + SetSyntaxHighlightingModel(syntaxHighlighting); + SetDiagnosticsModel(diagnostics); + }).CallDeferred(); }); } @@ -140,30 +133,23 @@ public partial class SharpIdeCodeEdit : CodeEdit if (codeAction is null) return; var currentCaretPosition = GetCaretPosition(); var vScroll = GetVScroll(); - _ = Task.Run(async () => + _ = GodotTask.Run(async () => { - try + await RoslynAnalysis.ApplyCodeActionAsync(codeAction); + var fileContents = await File.ReadAllTextAsync(_currentFile.Path); + var syntaxHighlighting = await RoslynAnalysis.GetDocumentSyntaxHighlighting(_currentFile); + var diagnostics = await RoslynAnalysis.GetDocumentDiagnostics(_currentFile); + Callable.From(() => { - await RoslynAnalysis.ApplyCodeActionAsync(codeAction); - var fileContents = await File.ReadAllTextAsync(_currentFile.Path); - var syntaxHighlighting = await RoslynAnalysis.GetDocumentSyntaxHighlighting(_currentFile); - var diagnostics = await RoslynAnalysis.GetDocumentDiagnostics(_currentFile); - Callable.From(() => - { - BeginComplexOperation(); - SetText(fileContents); - SetSyntaxHighlightingModel(syntaxHighlighting); - SetDiagnosticsModel(diagnostics); - SetCaretLine(currentCaretPosition.line); - SetCaretColumn(currentCaretPosition.col); - SetVScroll(vScroll); - EndComplexOperation(); - }).CallDeferred(); - } - catch (Exception ex) - { - GD.PrintErr($"Error applying code fix: {ex.Message}"); - } + BeginComplexOperation(); + SetText(fileContents); + SetSyntaxHighlightingModel(syntaxHighlighting); + SetDiagnosticsModel(diagnostics); + SetCaretLine(currentCaretPosition.line); + SetCaretColumn(currentCaretPosition.col); + SetVScroll(vScroll); + EndComplexOperation(); + }).CallDeferred(); }); } @@ -301,30 +287,23 @@ public partial class SharpIdeCodeEdit : CodeEdit _popupMenu.AddItem("Getting Context Actions...", 0); _popupMenu.Popup(); GD.Print($"Code fixes requested at line {caretLine}, column {caretColumn}"); - _ = Task.Run(async () => + _ = GodotTask.Run(async () => { - try + var linePos = new LinePosition(caretLine, caretColumn); + var codeActions = await RoslynAnalysis.GetCodeFixesForDocumentAtPosition(_currentFile, linePos); + Callable.From(() => { - var linePos = new LinePosition(caretLine, caretColumn); - var codeActions = await RoslynAnalysis.GetCodeFixesForDocumentAtPosition(_currentFile, linePos); - Callable.From(() => + _popupMenu.Clear(); + foreach (var (index, codeAction) in codeActions.Index()) { - _popupMenu.Clear(); - foreach (var (index, codeAction) in codeActions.Index()) - { - _currentCodeActionsInPopup = codeActions; - _popupMenu.AddItem(codeAction.Title, index); - //_popupMenu.SetItemMetadata(menuItem, codeAction); - } + _currentCodeActionsInPopup = codeActions; + _popupMenu.AddItem(codeAction.Title, index); + //_popupMenu.SetItemMetadata(menuItem, codeAction); + } - if (codeActions.Length is not 0) _popupMenu.SetFocusedItem(0); - GD.Print($"Code fixes found: {codeActions.Length}, displaying menu"); - }).CallDeferred(); - } - catch (Exception ex) - { - GD.Print(ex); - } + if (codeActions.Length is not 0) _popupMenu.SetFocusedItem(0); + GD.Print($"Code fixes found: {codeActions.Length}, displaying menu"); + }).CallDeferred(); }); } @@ -333,29 +312,22 @@ public partial class SharpIdeCodeEdit : CodeEdit var (caretLine, caretColumn) = GetCaretPosition(); GD.Print($"Code completion requested at line {caretLine}, column {caretColumn}"); - _ = Task.Run(async () => + _ = GodotTask.Run(async () => { - try - { - var linePos = new LinePosition(caretLine, caretColumn); + var linePos = new LinePosition(caretLine, caretColumn); - var completions = await RoslynAnalysis.GetCodeCompletionsForDocumentAtPosition(_currentFile, linePos); - Callable.From(() => - { - foreach (var completionItem in completions.ItemsList) - { - AddCodeCompletionOption(CodeCompletionKind.Class, completionItem.DisplayText, completionItem.DisplayText); - } - // partially working - displays menu only when caret is what CodeEdit determines as valid - UpdateCodeCompletionOptions(true); - //RequestCodeCompletion(true); - GD.Print($"Found {completions.ItemsList.Count} completions, displaying menu"); - }).CallDeferred(); - } - catch (Exception ex) + var completions = await RoslynAnalysis.GetCodeCompletionsForDocumentAtPosition(_currentFile, linePos); + Callable.From(() => { - GD.Print(ex); - } + foreach (var completionItem in completions.ItemsList) + { + AddCodeCompletionOption(CodeCompletionKind.Class, completionItem.DisplayText, completionItem.DisplayText); + } + // partially working - displays menu only when caret is what CodeEdit determines as valid + UpdateCodeCompletionOptions(true); + //RequestCodeCompletion(true); + GD.Print($"Found {completions.ItemsList.Count} completions, displaying menu"); + }).CallDeferred(); }); }