From f4b1e9c1c079e346d8994215f1cf8477f8bad964 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Fri, 28 Nov 2025 18:08:18 +1000 Subject: [PATCH] Fix source generator updates using additional files --- .../Features/Analysis/RoslynAnalysis.cs | 9 ++------- .../Features/FileWatching/FileChangedService.cs | 6 +++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs b/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs index e887ee7..53bb41e 100644 --- a/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs +++ b/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs @@ -919,15 +919,10 @@ public class RoslynAnalysis(ILogger logger, BuildService buildSe Guard.Against.NullOrEmpty(newContent, nameof(newContent)); 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 - }; + var documentId = documentIdsWithFilePath.FirstOrDefault(); // Linked files should take care of the rest of the documents with the same path if (documentId is null) { - _logger.LogWarning("UpdateDocument failed: Document '{DocumentPath}' not found in workspace", fileModel.Path); + _logger.LogTrace("UpdateDocument failed: Document '{DocumentPath}' not found in workspace", fileModel.Path); return false; } diff --git a/src/SharpIDE.Application/Features/FileWatching/FileChangedService.cs b/src/SharpIDE.Application/Features/FileWatching/FileChangedService.cs index 908ff18..5d09642 100644 --- a/src/SharpIDE.Application/Features/FileWatching/FileChangedService.cs +++ b/src/SharpIDE.Application/Features/FileWatching/FileChangedService.cs @@ -107,10 +107,9 @@ public class FileChangedService } var afterSaveTask = (file, changeType) switch { - ({ IsRoslynWorkspaceFile: true }, _) => HandleWorkspaceFileChanged(file, newContents), ({ IsCsprojFile: true }, FileChangeType.IdeSaveToDisk or FileChangeType.ExternalChange) => HandleCsprojChanged(file), ({ IsCsprojFile: true }, _) => Task.CompletedTask, - _ => throw new InvalidOperationException("Unknown file change type.") + (_, _) => HandlePotentialWorkspaceFile_Changed(file, newContents) }; await afterSaveTask; } @@ -130,7 +129,8 @@ public class FileChangedService _updateSolutionDiagnosticsQueue.AddWork(); } - private async Task HandleWorkspaceFileChanged(SharpIdeFile file, string newContents) + /// AdditionalFiles such as txt files may have changed, so we need to attempt to update the workspace regardless of extension + private async Task HandlePotentialWorkspaceFile_Changed(SharpIdeFile file, string newContents) { var fileUpdatedInWorkspace = await _roslynAnalysis.UpdateDocument(file, newContents); if (fileUpdatedInWorkspace is false) return;