Skip to content

Commit 5baa92e

Browse files
committed
refactor LoadSolution
1 parent af81460 commit 5baa92e

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

src/SharpIDE.Application/Features/SolutionDiscovery/VsPersistence/VsPersistenceSolutionService.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,33 @@ public class VsPersistenceSolutionService
1212
private ISolutionSerializer? _solutionSerializer;
1313
private string? _solutionFilePath;
1414

15-
public async Task<SharpIdeSolutionModel> LoadSolution(string solutionFilePath, CancellationToken cancellationToken = default)
15+
public async Task LoadSolution(string solutionFilePath, SolutionModel vsSln, ISolutionSerializer slnSerializer, CancellationToken cancellationToken = default)
1616
{
17-
using var _ = SharpIdeOtel.Source.StartActivity();
17+
_vsSolution = vsSln;
18+
_solutionSerializer = slnSerializer;
1819
_solutionFilePath = solutionFilePath;
20+
}
21+
// Weird separation between ReadSolution and LoadSolution is so we can call the static ReadSolution in IdeRoot before all the UI Nodes are ready and DI services injected
22+
public static async Task<(SharpIdeSolutionModel, SolutionModel, ISolutionSerializer)> ReadSolution(string solutionFilePath, CancellationToken cancellationToken = default)
23+
{
24+
using var _ = SharpIdeOtel.Source.StartActivity();
1925

26+
ISolutionSerializer? solutionSerializer;
27+
SolutionModel vsSolution;
2028
using (SharpIdeOtel.Source.StartActivity("VsPersistence.OpenSolution"))
2129
{
22-
_solutionSerializer = SolutionSerializers.GetSerializerByMoniker(solutionFilePath);
23-
Guard.Against.Null(_solutionSerializer);
24-
_vsSolution = await _solutionSerializer.OpenAsync(solutionFilePath, cancellationToken);
30+
solutionSerializer = SolutionSerializers.GetSerializerByMoniker(solutionFilePath);
31+
Guard.Against.Null(solutionSerializer);
32+
vsSolution = await solutionSerializer.OpenAsync(solutionFilePath, cancellationToken);
2533
}
2634

2735
// This intermediate model is pretty much useless, but I have left it around as we grab the project nodes with it, which we might use later.
28-
var intermediateModel = await IntermediateMapper.GetIntermediateModel(solutionFilePath, _vsSolution, cancellationToken);
36+
var intermediateModel = await IntermediateMapper.GetIntermediateModel(solutionFilePath, vsSolution, cancellationToken);
2937

3038
var solutionModel = new SharpIdeSolutionModel(solutionFilePath, intermediateModel);
3139

3240
var gitFolderPath = Repository.Discover(solutionFilePath);
33-
if (gitFolderPath is null) return solutionModel;
41+
if (gitFolderPath is null) return (solutionModel, vsSolution, solutionSerializer);
3442
using var repo = new Repository(gitFolderPath);
3543
var status = repo.RetrieveStatus(new StatusOptions());
3644

@@ -52,7 +60,7 @@ public async Task<SharpIdeSolutionModel> LoadSolution(string solutionFilePath, C
5260
fileInSolution.GitStatus = mappedGitStatus;
5361
}
5462

55-
return solutionModel;
63+
return (solutionModel, vsSolution, solutionSerializer);
5664
}
5765

5866
public async Task AddProject(IExpandableSharpIdeNode parentNode, string projectName, string projectFilePath, CancellationToken cancellationToken = default)

src/SharpIDE.Godot/IdeRoot.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ public void SetSlnFilePath(string path)
152152
_ = Task.GodotRun(async () =>
153153
{
154154
GD.Print($"Selected: {path}");
155-
await _nodeReadyTcs.Task;
156-
// Do not use injected services until after _nodeReadyTcs - Services aren't injected until _Ready
157155
var timer = Stopwatch.StartNew();
158-
var solutionModel = await _vsPersistenceSolutionService.LoadSolution(path);
156+
var (solutionModel, vsSln, solutionSerializer) = await VsPersistenceSolutionService.ReadSolution(path);
159157
timer.Stop();
160158
_logger.LogInformation("Solution model fully created in {ElapsedMilliseconds} ms", timer.ElapsedMilliseconds);
159+
await _nodeReadyTcs.Task;
160+
// Do not use injected services until after _nodeReadyTcs - Services aren't injected until _Ready
161+
await _vsPersistenceSolutionService.LoadSolution(path, vsSln, solutionSerializer);
161162
_sharpIdeSolutionAccessor.SolutionModel = solutionModel;
162163
_sharpIdeSolutionAccessor.SolutionReadyTcs.SetResult();
163164
_solutionExplorerPanel.SolutionModel = solutionModel;

src/SharpIDE.Photino/Layout/MainLayout.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
var solutionFilePath = (string)result.Data!;
185185
_solutionFilePath = solutionFilePath;
186186

187-
var solutionModel = await VsPersistenceSolutionService.LoadSolution(_solutionFilePath);
187+
var (solutionModel, _, _) = await VsPersistenceSolutionService.ReadSolution(_solutionFilePath);
188188
_solutionModel = solutionModel;
189189
RoslynAnalysis.StartLoadingSolutionInWorkspace(solutionModel);
190190
}

tests/SharpIDE.Application.IntegrationTests/Features/Analysis/RoslynAnalysisTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public async Task GetProjectDiagnostics_NoSolutionChanges_IsSubsequentlyCheaper(
3737

3838
var roslynAnalysis = new RoslynAnalysis(logger, buildService, analyzerFileWatcher);
3939

40-
var solutionModel = await vsPersistenceSolutionService.LoadSolution(@"C:\Users\Matthew\Documents\Git\SharpIDE\SharpIDE.slnx", TestContext.Current.CancellationToken);
40+
var (solutionModel, _, _) = await VsPersistenceSolutionService.ReadSolution(@"C:\Users\Matthew\Documents\Git\SharpIDE\SharpIDE.slnx", TestContext.Current.CancellationToken);
4141
var sharpIdeApplicationProject = solutionModel.AllProjects.Single(p => p.Name.Value == "SharpIDE.Application");
4242

4343
var timer = Stopwatch.StartNew();

0 commit comments

Comments
 (0)