Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@ internal static class CompilationWorkspaceProvider
CancellationToken cancellationToken)
{
var taskCompletionSource = new TaskCompletionSource<(Solution, WatchHotReloadService)>(TaskCreationOptions.RunContinuationsAsynchronously);
try
{
CreateProject(taskCompletionSource, hotReloadCapabilitiesTask, projectPath, reporter, cancellationToken);
}
catch (Exception ex)
{
taskCompletionSource.TrySetException(ex);
}

CreateProject(taskCompletionSource, hotReloadCapabilitiesTask, projectPath, reporter, cancellationToken);
return taskCompletionSource.Task;
}

Expand All @@ -43,39 +35,46 @@ static async void CreateProject(
IReporter reporter,
CancellationToken cancellationToken)
{
var workspace = MSBuildWorkspace.Create();

workspace.WorkspaceFailed += (_sender, diag) =>
try
{
if (diag.Diagnostic.Kind == WorkspaceDiagnosticKind.Warning)
{
reporter.Verbose($"MSBuildWorkspace warning: {diag.Diagnostic}");
}
else
var workspace = MSBuildWorkspace.Create();

workspace.WorkspaceFailed += (_sender, diag) =>
{
taskCompletionSource.TrySetException(new InvalidOperationException($"Failed to create MSBuildWorkspace: {diag.Diagnostic}"));
}
};
if (diag.Diagnostic.Kind == WorkspaceDiagnosticKind.Warning)
{
reporter.Verbose($"MSBuildWorkspace warning: {diag.Diagnostic}");
}
else
{
taskCompletionSource.TrySetException(new InvalidOperationException($"Failed to create MSBuildWorkspace: {diag.Diagnostic}"));
}
};

await workspace.OpenProjectAsync(projectPath, cancellationToken: cancellationToken);
var currentSolution = workspace.CurrentSolution;
await workspace.OpenProjectAsync(projectPath, cancellationToken: cancellationToken);
var currentSolution = workspace.CurrentSolution;

var hotReloadCapabilities = await GetHotReloadCapabilitiesAsync(hotReloadCapabilitiesTask, reporter);
var hotReloadService = new WatchHotReloadService(workspace.Services, await hotReloadCapabilitiesTask);
var hotReloadCapabilities = await GetHotReloadCapabilitiesAsync(hotReloadCapabilitiesTask, reporter);
var hotReloadService = new WatchHotReloadService(workspace.Services, await hotReloadCapabilitiesTask);

await hotReloadService.StartSessionAsync(currentSolution, cancellationToken);
await hotReloadService.StartSessionAsync(currentSolution, cancellationToken);

// Read the documents to memory
await Task.WhenAll(
currentSolution.Projects.SelectMany(p => p.Documents.Concat(p.AdditionalDocuments)).Select(d => d.GetTextAsync(cancellationToken)));
// Read the documents to memory
await Task.WhenAll(
currentSolution.Projects.SelectMany(p => p.Documents.Concat(p.AdditionalDocuments)).Select(d => d.GetTextAsync(cancellationToken)));

// Warm up the compilation. This would help make the deltas for first edit appear much more quickly
foreach (var project in currentSolution.Projects)
{
await project.GetCompilationAsync(cancellationToken);
}

// Warm up the compilation. This would help make the deltas for first edit appear much more quickly
foreach (var project in currentSolution.Projects)
taskCompletionSource.TrySetResult((currentSolution, hotReloadService));
}
catch (Exception ex)
{
await project.GetCompilationAsync(cancellationToken);
taskCompletionSource.TrySetException(ex);
}

taskCompletionSource.TrySetResult((currentSolution, hotReloadService));
}

private static async Task<ImmutableArray<string>> GetHotReloadCapabilitiesAsync(Task<ImmutableArray<string>> hotReloadCapabilitiesTask, IReporter reporter)
Expand Down