diff --git a/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs b/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs index 91086c2..7080a03 100644 --- a/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs +++ b/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs @@ -288,4 +288,19 @@ public static class RoslynAnalysis // } } } + + // TODO: Use AdhocWorkspace or something else, to avoid writing to disk on every change + public static void UpdateDocument(SharpIdeFile fileModel, string newContent) + { + Guard.Against.Null(fileModel, nameof(fileModel)); + Guard.Against.NullOrEmpty(newContent, nameof(newContent)); + + var project = _workspace!.CurrentSolution.Projects.Single(s => s.FilePath == ((IChildSharpIdeNode)fileModel).GetNearestProjectNode()!.FilePath); + var document = project.Documents.Single(s => s.FilePath == fileModel.Path); + Guard.Against.Null(document, nameof(document)); + + //var updatedDocument = document.WithText(SourceText.From(newContent)); + var newSolution = _workspace.CurrentSolution.WithDocumentText(document.Id, SourceText.From(newContent)); + _workspace.TryApplyChanges(newSolution); + } } diff --git a/src/SharpIDE.Godot/IdeRoot.tscn b/src/SharpIDE.Godot/IdeRoot.tscn index b765e05..930e605 100644 --- a/src/SharpIDE.Godot/IdeRoot.tscn +++ b/src/SharpIDE.Godot/IdeRoot.tscn @@ -59,6 +59,7 @@ highlight_current_line = true gutters_draw_line_numbers = true code_completion_enabled = true auto_brace_completion_enabled = true +auto_brace_completion_highlight_matching = true script = ExtResource("2_qjf5e") [node name="CodeFixesMenu" type="PopupMenu" parent="VBoxContainer/HBoxContainer/HSplitContainer/SharpIdeCodeEdit"] diff --git a/src/SharpIDE.Godot/SharpIdeCodeEdit.cs b/src/SharpIDE.Godot/SharpIdeCodeEdit.cs index aef7358..04c10db 100644 --- a/src/SharpIDE.Godot/SharpIdeCodeEdit.cs +++ b/src/SharpIDE.Godot/SharpIdeCodeEdit.cs @@ -45,9 +45,33 @@ public partial class SharpIdeCodeEdit : CodeEdit _currentLine = GetCaretLine(); GD.Print($"Selection changed to line {_currentLine}, start {_selectionStartCol}, end {_selectionEndCol}"); }; + TextChanged += OnTextChanged; this.SyntaxHighlighter = _syntaxHighlighter; } + private void OnTextChanged() + { + // update the MSBuildWorkspace + RoslynAnalysis.UpdateDocument(_currentFile, Text); + _ = Task.Run(async () => + { + try + { + 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}"); + } + }); + } + private void OnCodeFixSelected(long id) { GD.Print($"Code fix selected: {id}");