This commit is contained in:
Matt Parker
2025-08-13 19:27:49 +10:00
parent 0b30611aa7
commit 8ca6c5f38c
6 changed files with 9 additions and 160 deletions

View File

@@ -1,22 +0,0 @@
using System.Text.Json.Serialization;
namespace SharpIDE.Application.Features.SolutionDiscovery;
public class Folder
{
public required string Path { get; set; }
public string Name { get; set; } = null!;
public List<Folder> Folders { get; set; } = [];
public List<TreeMapFile> Files { get; set; } = [];
public bool IsPseudoFolder { get; set; }
public int Depth { get; set; }
[JsonIgnore]
public bool Expanded { get; set; }
}
public class TreeMapFile
{
public required string Path { get; set; }
public required string Name { get; set; }
}

View File

@@ -1,60 +0,0 @@
using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Globbing;
namespace SharpIDE.Application.Features.SolutionDiscovery;
public static class GetNodesInSolution
{
private static readonly ProjectCollection _projectCollection = new();
public static SolutionFile? ParseSolutionFileFromPath(string solutionFilePath)
{
var solutionFile = SolutionFile.Parse(solutionFilePath);
return solutionFile;
}
public static List<ProjectRootElement> GetCSharpProjectObjectsFromSolutionFile(SolutionFile solutionFile)
{
var projectList = solutionFile
.ProjectsByGuid.Where(x => x.Value.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat)
.Select(s => ProjectRootElement.Open(s.Value.AbsolutePath))
.ToList();
return projectList;
}
public static List<FileInfo> GetFilesInProject(string projectPath)
{
var project = _projectCollection.LoadProject(projectPath);
var compositeGlob = new CompositeGlob(project.GetAllGlobs().Select(s => s.MsBuildGlob));
var directory = new DirectoryInfo(Path.GetDirectoryName(projectPath)!);
var files = directory.EnumerateFiles("*", SearchOption.AllDirectories)
.Where(f =>
{
var relativeDirectory = Path.GetRelativePath(directory.FullName, f.FullName);
return compositeGlob.IsMatch(relativeDirectory);
})
.ToList();
return files;
}
}

View File

@@ -0,0 +1,9 @@
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
namespace SharpIDE.Application.Features.SolutionDiscovery;
public class SharpIdeFile : ISharpIdeNode
{
public required string Path { get; set; }
public required string Name { get; set; }
}

View File

@@ -2,19 +2,11 @@
namespace SharpIDE.Application.Features.SolutionDiscovery;
public class SharpIdeFile : ISharpIdeNode
{
public required string Path { get; set; }
public required string Name { get; set; }
}
public class SharpIdeFolder : ISharpIdeNode
{
public required string Path { get; set; }
public required string Name { get; set; }
public required List<SharpIdeFile> Files { get; set; }
public required List<SharpIdeFolder> Folders { get; set; }
// public required int Depth { get; set; }
public bool Expanded { get; set; }
}

View File

@@ -1,69 +0,0 @@
using System.Collections.Concurrent;
namespace SharpIDE.Application.Features.SolutionDiscovery;
public static class TreeMapper
{
public static List<Folder> GetSubFolders(this Folder folder)
{
var directoryInfo = new DirectoryInfo(folder.Path);
ConcurrentBag<Folder> subFolders = [];
var files = GetFiles(directoryInfo);
if (files.Count is not 0)
{
var pseudoFolder = new Folder
{
Path = folder.Path,
Name = "<Files>",
IsPseudoFolder = true,
Files = files,
Depth = folder.Depth + 1
};
subFolders.Add(pseudoFolder);
}
List<DirectoryInfo> subFolderInfos;
try
{
subFolderInfos = directoryInfo.EnumerateDirectories("*", new EnumerationOptions { IgnoreInaccessible = false, AttributesToSkip = FileAttributes.ReparsePoint}).ToList();
}
catch (UnauthorizedAccessException)
{
return subFolders.ToList();
}
Parallel.ForEach(subFolderInfos, subFolderInfo =>
{
var subFolder = new Folder
{
Path = subFolderInfo.FullName,
Name = subFolderInfo.Name,
Depth = folder.Depth + 1
};
subFolder.Folders = subFolder.GetSubFolders();
subFolders.Add(subFolder);
});
return subFolders.ToList();
}
public static List<TreeMapFile> GetFiles(DirectoryInfo directoryInfo)
{
List<FileInfo> fileInfos;
try
{
fileInfos = directoryInfo.EnumerateFiles().ToList();
}
catch (UnauthorizedAccessException)
{
return [];
}
var files = fileInfos.Select(s => new TreeMapFile
{
Path = s.FullName,
Name = s.Name
}).ToList();
return files;
}
}

View File

@@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
namespace SharpIDE.Application.Features.SolutionDiscovery;