@@ -63,32 +63,33 @@ private async Task PackageInitializationMainThreadAsync(PackageLoadTasks package
6363
6464 private Task PackageInitializationBackgroundThreadAsync ( PackageLoadTasks packageInitializationTasks , CancellationToken cancellationToken )
6565 {
66- RegisterLanguageService ( typeof ( TLanguageService ) , async cancellationToken =>
67- {
68- // Ensure we're on the BG when creating the language service.
69- await TaskScheduler . Default ;
70-
71- var languageService = CreateLanguageService ( ) ;
72- languageService . Setup ( cancellationToken ) ;
73-
74- // DevDiv 753309:
75- // We've redefined some VS interfaces that had incorrect PIAs. When
76- // we interop with native parts of VS, they always QI, so everything
77- // works. However, Razor is now managed, but assumes that the C#
78- // language service is native. When setting breakpoints, they
79- // get the language service from its GUID and cast it to IVsLanguageDebugInfo.
80- // This would QI the native lang service. Since we're managed and
81- // we've redefined IVsLanguageDebugInfo, the cast
82- // fails. To work around this, we put the LS inside a ComAggregate object,
83- // which always force a QueryInterface and allow their cast to succeed.
84- //
85- // This also fixes 752331, which is a similar problem with the
86- // exception assistant.
87-
88- // Creating the com aggregate has to happen on the UI thread.
89- await this . JoinableTaskFactory . SwitchToMainThreadAsync ( cancellationToken ) ;
90- return Interop . ComAggregate . CreateAggregatedObject ( languageService ) ;
91- } ) ;
66+ AddService ( typeof ( TLanguageService ) , async ( _ , cancellationToken , _ ) =>
67+ {
68+ // Ensure we're on the BG when creating the language service.
69+ await TaskScheduler . Default ;
70+
71+ var languageService = CreateLanguageService ( ) ;
72+ languageService . Setup ( cancellationToken ) ;
73+
74+ // DevDiv 753309:
75+ // We've redefined some VS interfaces that had incorrect PIAs. When
76+ // we interop with native parts of VS, they always QI, so everything
77+ // works. However, Razor is now managed, but assumes that the C#
78+ // language service is native. When setting breakpoints, they
79+ // get the language service from its GUID and cast it to IVsLanguageDebugInfo.
80+ // This would QI the native lang service. Since we're managed and
81+ // we've redefined IVsLanguageDebugInfo, the cast
82+ // fails. To work around this, we put the LS inside a ComAggregate object,
83+ // which always force a QueryInterface and allow their cast to succeed.
84+ //
85+ // This also fixes 752331, which is a similar problem with the
86+ // exception assistant.
87+
88+ // Creating the com aggregate has to happen on the UI thread.
89+ await this . JoinableTaskFactory . SwitchToMainThreadAsync ( cancellationToken ) ;
90+ return Interop . ComAggregate . CreateAggregatedObject ( languageService ) ;
91+ } ,
92+ promote : true ) ;
9293
9394 // Misc workspace has to be up and running by the time our package is usable so that it can track running
9495 // doc events and appropriately map files to/from it and other relevant workspaces (like the
@@ -148,9 +149,6 @@ protected override async Task LoadComponentsAsync(CancellationToken cancellation
148149 protected abstract IEnumerable < IVsEditorFactory > CreateEditorFactories ( ) ;
149150 protected abstract TLanguageService CreateLanguageService ( ) ;
150151
151- protected void RegisterLanguageService ( Type t , Func < CancellationToken , Task < object > > serviceCreator )
152- => AddService ( t , async ( container , cancellationToken , type ) => await serviceCreator ( cancellationToken ) . ConfigureAwait ( true ) , promote : true ) ;
153-
154152 protected override void Dispose ( bool disposing )
155153 {
156154 if ( disposing )
0 commit comments