From e2d8fdddb3fb70001485807710b6eba7f7aa7adf Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Wed, 27 Aug 2025 19:31:15 +1000 Subject: [PATCH] Fix concurrency --- .../Features/SolutionDiscovery/SharpIdeFile.cs | 5 +++-- .../SolutionDiscovery/SharpIdeFolder.cs | 5 +++-- .../Features/SolutionDiscovery/TreeMapperV2.cs | 8 ++++---- .../VsPersistence/SharpIdeModels.cs | 17 ++++++++++------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/SharpIDE.Application/Features/SolutionDiscovery/SharpIdeFile.cs b/src/SharpIDE.Application/Features/SolutionDiscovery/SharpIdeFile.cs index b4572ea..ff5083f 100644 --- a/src/SharpIDE.Application/Features/SolutionDiscovery/SharpIdeFile.cs +++ b/src/SharpIDE.Application/Features/SolutionDiscovery/SharpIdeFile.cs @@ -1,4 +1,5 @@ -using System.Diagnostics.CodeAnalysis; +using System.Collections.Concurrent; +using System.Diagnostics.CodeAnalysis; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; namespace SharpIDE.Application.Features.SolutionDiscovery; @@ -10,7 +11,7 @@ public class SharpIdeFile : ISharpIdeNode, IChildSharpIdeNode public required string Name { get; set; } [SetsRequiredMembers] - internal SharpIdeFile(string fullPath, string name, IExpandableSharpIdeNode parent, HashSet allFiles) + internal SharpIdeFile(string fullPath, string name, IExpandableSharpIdeNode parent, ConcurrentBag allFiles) { Path = fullPath; Name = name; diff --git a/src/SharpIDE.Application/Features/SolutionDiscovery/SharpIdeFolder.cs b/src/SharpIDE.Application/Features/SolutionDiscovery/SharpIdeFolder.cs index 5df4c59..a5a8a18 100644 --- a/src/SharpIDE.Application/Features/SolutionDiscovery/SharpIdeFolder.cs +++ b/src/SharpIDE.Application/Features/SolutionDiscovery/SharpIdeFolder.cs @@ -1,4 +1,5 @@ -using System.Diagnostics.CodeAnalysis; +using System.Collections.Concurrent; +using System.Diagnostics.CodeAnalysis; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; namespace SharpIDE.Application.Features.SolutionDiscovery; @@ -13,7 +14,7 @@ public class SharpIdeFolder : ISharpIdeNode, IExpandableSharpIdeNode, IChildShar public bool Expanded { get; set; } [SetsRequiredMembers] - public SharpIdeFolder(DirectoryInfo folderInfo, IExpandableSharpIdeNode parent, HashSet allFiles) + public SharpIdeFolder(DirectoryInfo folderInfo, IExpandableSharpIdeNode parent, ConcurrentBag allFiles) { Parent = parent; Path = folderInfo.FullName; diff --git a/src/SharpIDE.Application/Features/SolutionDiscovery/TreeMapperV2.cs b/src/SharpIDE.Application/Features/SolutionDiscovery/TreeMapperV2.cs index f50f945..b6e90d7 100644 --- a/src/SharpIDE.Application/Features/SolutionDiscovery/TreeMapperV2.cs +++ b/src/SharpIDE.Application/Features/SolutionDiscovery/TreeMapperV2.cs @@ -10,7 +10,7 @@ public static class TreeMapperV2 return folder.Files .Concat(folder.Folders.SelectMany(sub => sub.GetAllFiles())); } - public static List GetSubFolders(string csprojectPath, SharpIdeProjectModel sharpIdeProjectModel, HashSet allFiles) + public static List GetSubFolders(string csprojectPath, SharpIdeProjectModel sharpIdeProjectModel, ConcurrentBag allFiles) { var projectDirectory = Path.GetDirectoryName(csprojectPath)!; var rootFolder = new SharpIdeFolder @@ -26,7 +26,7 @@ public static class TreeMapperV2 } private static readonly string[] _excludedFolders = ["bin", "obj", "node_modules"]; - public static List GetSubFolders(this SharpIdeFolder folder, IExpandableSharpIdeNode parent, HashSet allFiles) + public static List GetSubFolders(this SharpIdeFolder folder, IExpandableSharpIdeNode parent, ConcurrentBag allFiles) { var directoryInfo = new DirectoryInfo(folder.Path); ConcurrentBag subFolders = []; @@ -54,13 +54,13 @@ public static class TreeMapperV2 return subFolders.ToList(); } - public static List GetFiles(string csprojectPath, SharpIdeProjectModel sharpIdeProjectModel, HashSet allFiles) + public static List GetFiles(string csprojectPath, SharpIdeProjectModel sharpIdeProjectModel, ConcurrentBag allFiles) { var projectDirectory = Path.GetDirectoryName(csprojectPath)!; var directoryInfo = new DirectoryInfo(projectDirectory); return GetFiles(directoryInfo, sharpIdeProjectModel, allFiles); } - public static List GetFiles(this DirectoryInfo directoryInfo, IExpandableSharpIdeNode parent, HashSet allFiles) + public static List GetFiles(this DirectoryInfo directoryInfo, IExpandableSharpIdeNode parent, ConcurrentBag allFiles) { List fileInfos; try diff --git a/src/SharpIDE.Application/Features/SolutionDiscovery/VsPersistence/SharpIdeModels.cs b/src/SharpIDE.Application/Features/SolutionDiscovery/VsPersistence/SharpIdeModels.cs index 8b59596..0920a2a 100644 --- a/src/SharpIDE.Application/Features/SolutionDiscovery/VsPersistence/SharpIdeModels.cs +++ b/src/SharpIDE.Application/Features/SolutionDiscovery/VsPersistence/SharpIdeModels.cs @@ -1,4 +1,5 @@ -using System.Diagnostics.CodeAnalysis; +using System.Collections.Concurrent; +using System.Diagnostics.CodeAnalysis; using System.Threading.Channels; using Microsoft.Build.Evaluation; using SharpIDE.Application.Features.Evaluation; @@ -41,12 +42,14 @@ public class SharpIdeSolutionModel : ISharpIdeNode, IExpandableSharpIdeNode internal SharpIdeSolutionModel(string solutionFilePath, IntermediateSolutionModel intermediateModel) { var solutionName = Path.GetFileName(solutionFilePath); - AllProjects = []; - AllFiles = []; + var allProjects = new ConcurrentBag(); + var allFiles = new ConcurrentBag(); Name = solutionName; FilePath = solutionFilePath; - Projects = intermediateModel.Projects.Select(s => new SharpIdeProjectModel(s, AllProjects, AllFiles, this)).ToList(); - Folders = intermediateModel.SolutionFolders.Select(s => new SharpIdeSolutionFolder(s, AllProjects, AllFiles, this)).ToList(); + Projects = intermediateModel.Projects.Select(s => new SharpIdeProjectModel(s, allProjects, allFiles, this)).ToList(); + Folders = intermediateModel.SolutionFolders.Select(s => new SharpIdeSolutionFolder(s, allProjects, allFiles, this)).ToList(); + AllProjects = allProjects.ToHashSet(); + AllFiles = allFiles.ToHashSet(); } } public class SharpIdeSolutionFolder : ISharpIdeNode, IExpandableSharpIdeNode, IChildSharpIdeNode @@ -59,7 +62,7 @@ public class SharpIdeSolutionFolder : ISharpIdeNode, IExpandableSharpIdeNode, IC public required IExpandableSharpIdeNode Parent { get; set; } [SetsRequiredMembers] - internal SharpIdeSolutionFolder(IntermediateSlnFolderModel intermediateModel, HashSet allProjects, HashSet allFiles, IExpandableSharpIdeNode parent) + internal SharpIdeSolutionFolder(IntermediateSlnFolderModel intermediateModel, ConcurrentBag allProjects, ConcurrentBag allFiles, IExpandableSharpIdeNode parent) { Name = intermediateModel.Model.Name; Parent = parent; @@ -81,7 +84,7 @@ public class SharpIdeProjectModel : ISharpIdeNode, IExpandableSharpIdeNode, IChi public required Task MsBuildEvaluationProjectTask { get; set; } [SetsRequiredMembers] - internal SharpIdeProjectModel(IntermediateProjectModel projectModel, HashSet allProjects, HashSet allFiles, IExpandableSharpIdeNode parent) + internal SharpIdeProjectModel(IntermediateProjectModel projectModel, ConcurrentBag allProjects, ConcurrentBag allFiles, IExpandableSharpIdeNode parent) { Parent = parent; Name = projectModel.Model.ActualDisplayName;