From 27bc8eab836da56b96c0e3603df13af54fe96c97 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Sun, 23 Nov 2025 00:58:41 +1000 Subject: [PATCH] refactor more TryApplyChanges --- .../Features/Analysis/RoslynAnalysis.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs b/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs index 558de57..9f075e1 100644 --- a/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs +++ b/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs @@ -996,16 +996,22 @@ public class RoslynAnalysis(ILogger logger, BuildService buildSe public async Task MoveDocument(SharpIdeFile sharpIdeFile, string oldFilePath) { - var document = _workspace!.CurrentSolution.GetDocumentIdsWithFilePath(oldFilePath).Single(); - var updatedSolution = _workspace.CurrentSolution.WithDocumentFilePath(document, sharpIdeFile.Path); - _workspace.TryApplyChanges(updatedSolution); + var documentId = _workspace!.CurrentSolution.GetDocumentIdsWithFilePath(oldFilePath).Single(); + _workspace.SetCurrentSolution(oldSolution => + { + var newSolution = oldSolution.WithDocumentFilePath(documentId, sharpIdeFile.Path); + return newSolution; + }, WorkspaceChangeKind.DocumentInfoChanged, documentId: documentId); } public async Task RenameDocument(SharpIdeFile sharpIdeFile, string oldFilePath) { var documentId = _workspace!.CurrentSolution.GetDocumentIdsWithFilePath(oldFilePath).Single(); - var updatedSolution = _workspace.CurrentSolution.WithDocumentName(documentId, sharpIdeFile.Name); - _workspace.TryApplyChanges(updatedSolution); + _workspace.SetCurrentSolution(oldSolution => + { + var newSolution = oldSolution.WithDocumentName(documentId, sharpIdeFile.Name); + return newSolution; + }, WorkspaceChangeKind.DocumentInfoChanged, documentId: documentId); } public async Task GetOutputDllPathForProject(SharpIdeProjectModel projectModel)