set file colour in sln explorer based on git status
This commit is contained in:
@@ -17,6 +17,7 @@ public class SharpIdeFile : ISharpIdeNode, IChildSharpIdeNode, IFileOrFolder
|
||||
public bool IsCshtmlFile => Path.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase);
|
||||
public bool IsCsharpFile => Path.EndsWith(".cs", StringComparison.OrdinalIgnoreCase);
|
||||
public bool IsRoslynWorkspaceFile => IsCsharpFile || IsRazorFile || IsCshtmlFile;
|
||||
public GitStatus GitStatus { get; set; } = GitStatus.Unaltered;
|
||||
public required ReactiveProperty<bool> IsDirty { get; init; }
|
||||
public required bool SuppressDiskChangeEvents { get; set; } // probably has concurrency issues
|
||||
public required DateTimeOffset? LastIdeWriteTime { get; set; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using LibGit2Sharp;
|
||||
|
||||
namespace SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
|
||||
@@ -11,7 +12,34 @@ public static class VsPersistenceMapper
|
||||
var intermediateModel = await IntermediateMapper.GetIntermediateModel(solutionFilePath, cancellationToken);
|
||||
|
||||
var solutionModel = new SharpIdeSolutionModel(solutionFilePath, intermediateModel);
|
||||
using var repo = new Repository(solutionModel.DirectoryPath);
|
||||
var status = repo.RetrieveStatus(new StatusOptions());
|
||||
|
||||
foreach (var entry in status.Where(s => s.State is not FileStatus.Ignored))
|
||||
{
|
||||
// Assumes solution file is at git repo root
|
||||
var filePath = new FileInfo(Path.Combine(solutionModel.DirectoryPath, entry.FilePath)).FullName; // used to normalise path separators
|
||||
var fileInSolution = solutionModel.AllFiles.SingleOrDefault(f => f.Path.Equals(filePath, StringComparison.OrdinalIgnoreCase));
|
||||
if (fileInSolution is null) continue;
|
||||
|
||||
var mappedGitStatus = entry.State switch
|
||||
{
|
||||
FileStatus.NewInIndex | FileStatus.ModifiedInWorkdir => GitStatus.Added, // I've seen these appear together
|
||||
FileStatus.NewInIndex or FileStatus.NewInWorkdir => GitStatus.Added,
|
||||
FileStatus.ModifiedInIndex or FileStatus.ModifiedInWorkdir => GitStatus.Modified,
|
||||
_ => GitStatus.Unaltered // TODO: handle other kinds?
|
||||
};
|
||||
|
||||
fileInSolution.GitStatus = mappedGitStatus;
|
||||
}
|
||||
|
||||
return solutionModel;
|
||||
}
|
||||
}
|
||||
|
||||
public enum GitStatus
|
||||
{
|
||||
Unaltered,
|
||||
Modified,
|
||||
Added
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user