From 06cd3a0357f9cbe81efe4f5cfc075ea6f08ed87a Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Sun, 23 Nov 2025 18:18:31 +1000 Subject: [PATCH] handle updating and removing document in multiple projects --- .../Features/Analysis/RoslynAnalysis.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs b/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs index 4016c46..ac20934 100644 --- a/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs +++ b/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs @@ -927,7 +927,13 @@ public class RoslynAnalysis(ILogger logger, BuildService buildSe Guard.Against.Null(fileModel, nameof(fileModel)); Guard.Against.NullOrEmpty(newContent, nameof(newContent)); - var documentId = _workspace!.CurrentSolution.GetDocumentIdsWithFilePath(fileModel.Path).SingleOrDefault(); + var documentIdsWithFilePath = _workspace!.CurrentSolution.GetDocumentIdsWithFilePath(fileModel.Path); + var documentId = documentIdsWithFilePath switch + { + {Length: 1} => documentIdsWithFilePath[0], + {Length: > 1} => documentIdsWithFilePath.SingleOrDefault(d => d.ProjectId == GetProjectForSharpIdeFile(fileModel).Id), + _ => null + }; if (documentId is null) { _logger.LogWarning("UpdateDocument failed: Document '{DocumentPath}' not found in workspace", fileModel.Path); @@ -1022,7 +1028,13 @@ public class RoslynAnalysis(ILogger logger, BuildService buildSe await _solutionLoadedTcs.Task; Guard.Against.Null(fileModel, nameof(fileModel)); - var documentId = _workspace!.CurrentSolution.GetDocumentIdsWithFilePath(fileModel.Path).SingleOrDefault(); + var documentIdsWithFilePath = _workspace!.CurrentSolution.GetDocumentIdsWithFilePath(fileModel.Path); + var documentId = documentIdsWithFilePath switch + { + {Length: 1} => documentIdsWithFilePath[0], + {Length: > 1} => documentIdsWithFilePath.SingleOrDefault(d => d.ProjectId == GetProjectForSharpIdeFile(fileModel).Id), + _ => null + }; if (documentId is null) { _logger.LogWarning("RemoveDocument failed: Document '{DocumentPath}' not found in workspace", fileModel.Path);