Skip to content

Commit 27bc8ea

Browse files
committed
refactor more TryApplyChanges
1 parent 502ba20 commit 27bc8ea

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -996,16 +996,22 @@ public async Task RemoveDocument(SharpIdeFile fileModel)
996996

997997
public async Task MoveDocument(SharpIdeFile sharpIdeFile, string oldFilePath)
998998
{
999-
var document = _workspace!.CurrentSolution.GetDocumentIdsWithFilePath(oldFilePath).Single();
1000-
var updatedSolution = _workspace.CurrentSolution.WithDocumentFilePath(document, sharpIdeFile.Path);
1001-
_workspace.TryApplyChanges(updatedSolution);
999+
var documentId = _workspace!.CurrentSolution.GetDocumentIdsWithFilePath(oldFilePath).Single();
1000+
_workspace.SetCurrentSolution(oldSolution =>
1001+
{
1002+
var newSolution = oldSolution.WithDocumentFilePath(documentId, sharpIdeFile.Path);
1003+
return newSolution;
1004+
}, WorkspaceChangeKind.DocumentInfoChanged, documentId: documentId);
10021005
}
10031006

10041007
public async Task RenameDocument(SharpIdeFile sharpIdeFile, string oldFilePath)
10051008
{
10061009
var documentId = _workspace!.CurrentSolution.GetDocumentIdsWithFilePath(oldFilePath).Single();
1007-
var updatedSolution = _workspace.CurrentSolution.WithDocumentName(documentId, sharpIdeFile.Name);
1008-
_workspace.TryApplyChanges(updatedSolution);
1010+
_workspace.SetCurrentSolution(oldSolution =>
1011+
{
1012+
var newSolution = oldSolution.WithDocumentName(documentId, sharpIdeFile.Name);
1013+
return newSolution;
1014+
}, WorkspaceChangeKind.DocumentInfoChanged, documentId: documentId);
10091015
}
10101016

10111017
public async Task<string> GetOutputDllPathForProject(SharpIdeProjectModel projectModel)

0 commit comments

Comments
 (0)