提交 aede7867 编写于 作者: J Jason Malinowski

Ensure we load the Roslyn package before we push projects down

Our package load does a bunch of specific things like setting up static
state and ensuring we have certain components loaded on the UI thread.
The InitOptionsAsync was doing just a small part of that, and missing
other things that had undefined behavior. This just loads the package
which is a bit heavy handed but at least ensures we won't have
differing behavior which is probably for the best until we delete all of
this.
上级 f7d2311e
......@@ -13,6 +13,7 @@
using Microsoft.VisualStudio.LanguageServices.Setup;
using Microsoft.VisualStudio.LiveShare;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Threading;
using Task = System.Threading.Tasks.Task;
......@@ -62,7 +63,7 @@ public async Task<ICollaborationService> CreateServiceAsync(CollaborationSession
{
await _remoteLanguageServiceWorkspace.SetSession(collaborationSession).ConfigureAwait(false);
await InitOptionsAsync(cancellationToken).ConfigureAwait(false);
await LoadRoslynPackage(cancellationToken).ConfigureAwait(false);
_remoteLanguageServiceWorkspace.Init();
// Kick off loading the projects in the background.
......@@ -95,19 +96,16 @@ public async Task EnsureProjectsLoadedAsync(CancellationToken cancellationToken)
}
}
/// <summary>
/// Initialize the options. This must be done on the UI thread because
/// multiple <see cref="IOptionPersister"/> are required to be initialized on the UI thread.
/// Typically this is done by <see cref="RoslynPackage"/> but this is not to guaranteed
/// to precede liveshare initialization.
/// TODO - https://github.com/dotnet/roslyn/issues/37377
/// </summary>
private async Task InitOptionsAsync(CancellationToken cancellationToken)
private async Task LoadRoslynPackage(CancellationToken cancellationToken)
{
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
var componentModel = (IComponentModel)_serviceProvider.GetService(typeof(SComponentModel));
// Ensure the options persisters are loaded since we have to fetch options from the shell
componentModel.GetExtensions<IOptionPersister>();
cancellationToken.ThrowIfCancellationRequested();
// Explicitly trigger the load of the Roslyn package. This ensures that UI-bound services are appropriately prefetched,
// that FatalError is correctly wired up, etc. Ideally once the things happening in the package initialize are cleaned up with
// better patterns, this would go away.
var shellService = (IVsShell7)_serviceProvider.GetService(typeof(SVsShell));
await shellService.LoadPackageAsync(Guids.RoslynPackageId);
}
/// <summary>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册