update MSBuildWorkspace on doc change
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ highlight_current_line = true
|
|||||||
gutters_draw_line_numbers = true
|
gutters_draw_line_numbers = true
|
||||||
code_completion_enabled = true
|
code_completion_enabled = true
|
||||||
auto_brace_completion_enabled = true
|
auto_brace_completion_enabled = true
|
||||||
|
auto_brace_completion_highlight_matching = true
|
||||||
script = ExtResource("2_qjf5e")
|
script = ExtResource("2_qjf5e")
|
||||||
|
|
||||||
[node name="CodeFixesMenu" type="PopupMenu" parent="VBoxContainer/HBoxContainer/HSplitContainer/SharpIdeCodeEdit"]
|
[node name="CodeFixesMenu" type="PopupMenu" parent="VBoxContainer/HBoxContainer/HSplitContainer/SharpIdeCodeEdit"]
|
||||||
|
|||||||
@@ -45,9 +45,33 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
|||||||
_currentLine = GetCaretLine();
|
_currentLine = GetCaretLine();
|
||||||
GD.Print($"Selection changed to line {_currentLine}, start {_selectionStartCol}, end {_selectionEndCol}");
|
GD.Print($"Selection changed to line {_currentLine}, start {_selectionStartCol}, end {_selectionEndCol}");
|
||||||
};
|
};
|
||||||
|
TextChanged += OnTextChanged;
|
||||||
this.SyntaxHighlighter = _syntaxHighlighter;
|
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)
|
private void OnCodeFixSelected(long id)
|
||||||
{
|
{
|
||||||
GD.Print($"Code fix selected: {id}");
|
GD.Print($"Code fix selected: {id}");
|
||||||
|
|||||||
Reference in New Issue
Block a user