Skip to content

Commit 8bcbd05

Browse files
authored
Move various bits of code to the after package load code in RoslynPackage (#77745)
1) Move the *very expensive* color schema applier initialization code to occur after package load. I talked with Joey about this and he indicated this could (quite infrequently) cause a recolorization in the editor upon open, but only when the user had previously changed themes or the very first open of a C# file after install. 2) Move the global notification service construction to happen on a bg thread, bright before it's use. 3) Move the SolutionEventMonitor construction and bulk file notification registration to occur after solution load. The bulk notification for the solution open would have already been initiated if the package load occurs during solution load, so this shouldn't affect that notification. 4) A bit of cleanup from earlier PRs: (VB lambda param cleanup, removing duplicated MiscellaneousFilesWorkspace service retrieval)
1 parent a48562d commit 8bcbd05

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

src/VisualStudio/Core/Def/ColorSchemes/ColorSchemeApplier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ public void RegisterInitializationWork(PackageLoadTasks packageInitializationTas
6767
_isInitialized = true;
6868
}
6969

70-
packageInitializationTasks.AddTask(isMainThreadTask: false, task: PackageInitializationBackgroundThreadAsync);
70+
packageInitializationTasks.AddTask(isMainThreadTask: false, task: AfterPackageLoadedBackgroundThreadAsync);
7171
}
7272

73-
private async Task PackageInitializationBackgroundThreadAsync(PackageLoadTasks packageInitializationTasks, CancellationToken cancellationToken)
73+
private async Task AfterPackageLoadedBackgroundThreadAsync(PackageLoadTasks afterPackageLoadedTasks, CancellationToken cancellationToken)
7474
{
7575
var settingsManager = await _asyncServiceProvider.GetServiceAsync<SVsSettingsPersistenceManager, ISettingsManager>(_threadingContext.JoinableTaskFactory).ConfigureAwait(false);
7676

src/VisualStudio/Core/Def/LanguageService/AbstractPackage`2.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ private async Task PackageInitializationMainThreadAsync(PackageLoadTasks package
5858
RegisterEditorFactory(editorFactory);
5959
}
6060

61+
// Misc workspace has to be up and running by the time our package is usable so that it can track running
62+
// doc events and appropriately map files to/from it and other relevant workspaces (like the
63+
// metadata-as-source workspace).
6164
var miscellaneousFilesWorkspace = this.ComponentModel.GetService<MiscellaneousFilesWorkspace>();
6265

6366
// awaiting an IVsTask guarantees to return on the captured context

src/VisualStudio/Core/Def/RoslynPackage.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System;
66
using System.Collections.Immutable;
77
using System.ComponentModel.Design;
8-
using System.IO;
98
using System.Runtime.InteropServices;
109
using System.Threading;
1110
using System.Threading.Tasks;
@@ -20,7 +19,6 @@
2019
using Microsoft.CodeAnalysis.Options;
2120
using Microsoft.CodeAnalysis.Remote.ProjectSystem;
2221
using Microsoft.CodeAnalysis.Shared.TestHooks;
23-
using Microsoft.CodeAnalysis.SolutionCrawler;
2422
using Microsoft.VisualStudio.ComponentModelHost;
2523
using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings;
2624
using Microsoft.VisualStudio.LanguageServices.Implementation.Diagnostics;
@@ -32,7 +30,6 @@
3230
using Microsoft.VisualStudio.LanguageServices.Implementation.TableDataSource;
3331
using Microsoft.VisualStudio.LanguageServices.Implementation.UnusedReferences;
3432
using Microsoft.VisualStudio.LanguageServices.InheritanceMargin;
35-
using Microsoft.VisualStudio.LanguageServices.Options;
3633
using Microsoft.VisualStudio.LanguageServices.ProjectSystem;
3734
using Microsoft.VisualStudio.LanguageServices.ProjectSystem.BrokeredService;
3835
using Microsoft.VisualStudio.LanguageServices.StackTraceExplorer;
@@ -54,7 +51,6 @@ internal sealed class RoslynPackage : AbstractPackage
5451
private static RoslynPackage? s_lazyInstance;
5552

5653
private RuleSetEventHandler? _ruleSetEventHandler;
57-
private ColorSchemeApplier? _colorSchemeApplier;
5854
private SolutionEventMonitor? _solutionEventMonitor;
5955

6056
internal static async ValueTask<RoslynPackage?> GetOrLoadAsync(IThreadingContext threadingContext, IAsyncServiceProvider serviceProvider, CancellationToken cancellationToken)
@@ -85,13 +81,6 @@ protected override void RegisterInitializeAsyncWork(PackageLoadTasks packageInit
8581

8682
private async Task PackageInitializationBackgroundThreadAsync(PackageLoadTasks packageInitializationTasks, CancellationToken cancellationToken)
8783
{
88-
_colorSchemeApplier = ComponentModel.GetService<ColorSchemeApplier>();
89-
_colorSchemeApplier.RegisterInitializationWork(packageInitializationTasks);
90-
91-
// We are at the VS layer, so we know we must be able to get the IGlobalOperationNotificationService here.
92-
var globalNotificationService = this.ComponentModel.GetService<IGlobalOperationNotificationService>();
93-
Assumes.Present(globalNotificationService);
94-
9584
await ProfferServiceBrokerServicesAsync().ConfigureAwait(true);
9685

9786
var settingsEditorFactory = this.ComponentModel.GetService<SettingsEditorFactory>();
@@ -100,16 +89,8 @@ private async Task PackageInitializationBackgroundThreadAsync(PackageLoadTasks p
10089
isMainThreadTask: true,
10190
task: (packageInitializationTasks, cancellationToken) =>
10291
{
103-
_solutionEventMonitor = new SolutionEventMonitor(globalNotificationService);
104-
TrackBulkFileOperations(globalNotificationService);
105-
10692
RegisterEditorFactory(settingsEditorFactory);
10793

108-
// Misc workspace has to be up and running by the time our package is usable so that it can track running
109-
// doc events and appropriately map files to/from it and other relevant workspaces (like the
110-
// metadata-as-source workspace).
111-
var miscellaneousFilesWorkspace = this.ComponentModel.GetService<MiscellaneousFilesWorkspace>();
112-
11394
return Task.CompletedTask;
11495
});
11596
}
@@ -125,6 +106,16 @@ protected override void RegisterOnAfterPackageLoadedAsyncWork(PackageLoadTasks a
125106

126107
Task OnAfterPackageLoadedBackgroundThreadAsync(PackageLoadTasks afterPackageLoadedTasks, CancellationToken cancellationToken)
127108
{
109+
var colorSchemeApplier = ComponentModel.GetService<ColorSchemeApplier>();
110+
colorSchemeApplier.RegisterInitializationWork(afterPackageLoadedTasks);
111+
112+
// We are at the VS layer, so we know we must be able to get the IGlobalOperationNotificationService here.
113+
var globalNotificationService = this.ComponentModel.GetService<IGlobalOperationNotificationService>();
114+
Assumes.Present(globalNotificationService);
115+
116+
_solutionEventMonitor = new SolutionEventMonitor(globalNotificationService);
117+
TrackBulkFileOperations(globalNotificationService);
118+
128119
// Ensure the options persisters are loaded since we have to fetch options from the shell
129120
LoadOptionPersistersAsync(this.ComponentModel, cancellationToken).Forget();
130121

src/VisualStudio/VisualBasic/Impl/LanguageService/VisualBasicPackage.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic
6969

7070
packageInitializationTasks.AddTask(
7171
isMainThreadTask:=False,
72-
task:=Function(packageInitializationTasks2, cancellationToken) As Task
72+
task:=Function() As Task
7373
Try
7474
RegisterLanguageService(GetType(IVbCompilerService), Function() Task.FromResult(_comAggregate))
7575

0 commit comments

Comments
 (0)