Fix concurrency

This commit is contained in:
Matt Parker
2025-08-27 19:31:15 +10:00
parent b5d80204e9
commit e2d8fdddb3
4 changed files with 20 additions and 15 deletions

View File

@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis; using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
namespace SharpIDE.Application.Features.SolutionDiscovery; namespace SharpIDE.Application.Features.SolutionDiscovery;
@@ -10,7 +11,7 @@ public class SharpIdeFile : ISharpIdeNode, IChildSharpIdeNode
public required string Name { get; set; } public required string Name { get; set; }
[SetsRequiredMembers] [SetsRequiredMembers]
internal SharpIdeFile(string fullPath, string name, IExpandableSharpIdeNode parent, HashSet<SharpIdeFile> allFiles) internal SharpIdeFile(string fullPath, string name, IExpandableSharpIdeNode parent, ConcurrentBag<SharpIdeFile> allFiles)
{ {
Path = fullPath; Path = fullPath;
Name = name; Name = name;

View File

@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis; using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
namespace SharpIDE.Application.Features.SolutionDiscovery; namespace SharpIDE.Application.Features.SolutionDiscovery;
@@ -13,7 +14,7 @@ public class SharpIdeFolder : ISharpIdeNode, IExpandableSharpIdeNode, IChildShar
public bool Expanded { get; set; } public bool Expanded { get; set; }
[SetsRequiredMembers] [SetsRequiredMembers]
public SharpIdeFolder(DirectoryInfo folderInfo, IExpandableSharpIdeNode parent, HashSet<SharpIdeFile> allFiles) public SharpIdeFolder(DirectoryInfo folderInfo, IExpandableSharpIdeNode parent, ConcurrentBag<SharpIdeFile> allFiles)
{ {
Parent = parent; Parent = parent;
Path = folderInfo.FullName; Path = folderInfo.FullName;

View File

@@ -10,7 +10,7 @@ public static class TreeMapperV2
return folder.Files return folder.Files
.Concat(folder.Folders.SelectMany(sub => sub.GetAllFiles())); .Concat(folder.Folders.SelectMany(sub => sub.GetAllFiles()));
} }
public static List<SharpIdeFolder> GetSubFolders(string csprojectPath, SharpIdeProjectModel sharpIdeProjectModel, HashSet<SharpIdeFile> allFiles) public static List<SharpIdeFolder> GetSubFolders(string csprojectPath, SharpIdeProjectModel sharpIdeProjectModel, ConcurrentBag<SharpIdeFile> allFiles)
{ {
var projectDirectory = Path.GetDirectoryName(csprojectPath)!; var projectDirectory = Path.GetDirectoryName(csprojectPath)!;
var rootFolder = new SharpIdeFolder var rootFolder = new SharpIdeFolder
@@ -26,7 +26,7 @@ public static class TreeMapperV2
} }
private static readonly string[] _excludedFolders = ["bin", "obj", "node_modules"]; private static readonly string[] _excludedFolders = ["bin", "obj", "node_modules"];
public static List<SharpIdeFolder> GetSubFolders(this SharpIdeFolder folder, IExpandableSharpIdeNode parent, HashSet<SharpIdeFile> allFiles) public static List<SharpIdeFolder> GetSubFolders(this SharpIdeFolder folder, IExpandableSharpIdeNode parent, ConcurrentBag<SharpIdeFile> allFiles)
{ {
var directoryInfo = new DirectoryInfo(folder.Path); var directoryInfo = new DirectoryInfo(folder.Path);
ConcurrentBag<SharpIdeFolder> subFolders = []; ConcurrentBag<SharpIdeFolder> subFolders = [];
@@ -54,13 +54,13 @@ public static class TreeMapperV2
return subFolders.ToList(); return subFolders.ToList();
} }
public static List<SharpIdeFile> GetFiles(string csprojectPath, SharpIdeProjectModel sharpIdeProjectModel, HashSet<SharpIdeFile> allFiles) public static List<SharpIdeFile> GetFiles(string csprojectPath, SharpIdeProjectModel sharpIdeProjectModel, ConcurrentBag<SharpIdeFile> allFiles)
{ {
var projectDirectory = Path.GetDirectoryName(csprojectPath)!; var projectDirectory = Path.GetDirectoryName(csprojectPath)!;
var directoryInfo = new DirectoryInfo(projectDirectory); var directoryInfo = new DirectoryInfo(projectDirectory);
return GetFiles(directoryInfo, sharpIdeProjectModel, allFiles); return GetFiles(directoryInfo, sharpIdeProjectModel, allFiles);
} }
public static List<SharpIdeFile> GetFiles(this DirectoryInfo directoryInfo, IExpandableSharpIdeNode parent, HashSet<SharpIdeFile> allFiles) public static List<SharpIdeFile> GetFiles(this DirectoryInfo directoryInfo, IExpandableSharpIdeNode parent, ConcurrentBag<SharpIdeFile> allFiles)
{ {
List<FileInfo> fileInfos; List<FileInfo> fileInfos;
try try

View File

@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis; using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Channels; using System.Threading.Channels;
using Microsoft.Build.Evaluation; using Microsoft.Build.Evaluation;
using SharpIDE.Application.Features.Evaluation; using SharpIDE.Application.Features.Evaluation;
@@ -41,12 +42,14 @@ public class SharpIdeSolutionModel : ISharpIdeNode, IExpandableSharpIdeNode
internal SharpIdeSolutionModel(string solutionFilePath, IntermediateSolutionModel intermediateModel) internal SharpIdeSolutionModel(string solutionFilePath, IntermediateSolutionModel intermediateModel)
{ {
var solutionName = Path.GetFileName(solutionFilePath); var solutionName = Path.GetFileName(solutionFilePath);
AllProjects = []; var allProjects = new ConcurrentBag<SharpIdeProjectModel>();
AllFiles = []; var allFiles = new ConcurrentBag<SharpIdeFile>();
Name = solutionName; Name = solutionName;
FilePath = solutionFilePath; FilePath = solutionFilePath;
Projects = intermediateModel.Projects.Select(s => new SharpIdeProjectModel(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(); Folders = intermediateModel.SolutionFolders.Select(s => new SharpIdeSolutionFolder(s, allProjects, allFiles, this)).ToList();
AllProjects = allProjects.ToHashSet();
AllFiles = allFiles.ToHashSet();
} }
} }
public class SharpIdeSolutionFolder : ISharpIdeNode, IExpandableSharpIdeNode, IChildSharpIdeNode public class SharpIdeSolutionFolder : ISharpIdeNode, IExpandableSharpIdeNode, IChildSharpIdeNode
@@ -59,7 +62,7 @@ public class SharpIdeSolutionFolder : ISharpIdeNode, IExpandableSharpIdeNode, IC
public required IExpandableSharpIdeNode Parent { get; set; } public required IExpandableSharpIdeNode Parent { get; set; }
[SetsRequiredMembers] [SetsRequiredMembers]
internal SharpIdeSolutionFolder(IntermediateSlnFolderModel intermediateModel, HashSet<SharpIdeProjectModel> allProjects, HashSet<SharpIdeFile> allFiles, IExpandableSharpIdeNode parent) internal SharpIdeSolutionFolder(IntermediateSlnFolderModel intermediateModel, ConcurrentBag<SharpIdeProjectModel> allProjects, ConcurrentBag<SharpIdeFile> allFiles, IExpandableSharpIdeNode parent)
{ {
Name = intermediateModel.Model.Name; Name = intermediateModel.Model.Name;
Parent = parent; Parent = parent;
@@ -81,7 +84,7 @@ public class SharpIdeProjectModel : ISharpIdeNode, IExpandableSharpIdeNode, IChi
public required Task<Project> MsBuildEvaluationProjectTask { get; set; } public required Task<Project> MsBuildEvaluationProjectTask { get; set; }
[SetsRequiredMembers] [SetsRequiredMembers]
internal SharpIdeProjectModel(IntermediateProjectModel projectModel, HashSet<SharpIdeProjectModel> allProjects, HashSet<SharpIdeFile> allFiles, IExpandableSharpIdeNode parent) internal SharpIdeProjectModel(IntermediateProjectModel projectModel, ConcurrentBag<SharpIdeProjectModel> allProjects, ConcurrentBag<SharpIdeFile> allFiles, IExpandableSharpIdeNode parent)
{ {
Parent = parent; Parent = parent;
Name = projectModel.Model.ActualDisplayName; Name = projectModel.Model.ActualDisplayName;