Skip to content

Commit f31d317

Browse files
Remove RegisterLanguageServer helper
This isn't doing anything interesting.
1 parent b8eec28 commit f31d317

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

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

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
Imports System.ComponentModel.Design
66
Imports System.Runtime.InteropServices
7+
Imports System.Threading
78
Imports Microsoft.CodeAnalysis
89
Imports Microsoft.CodeAnalysis.ErrorReporting
910
Imports Microsoft.CodeAnalysis.Options
@@ -59,7 +60,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic
5960
Public Sub New()
6061
MyBase.New()
6162

62-
' This is a UI-affinitized operation. Currently this opeartion prevents setting AllowsBackgroundLoad for
63+
' This is a UI-affinitized operation. Currently this operation prevents setting AllowsBackgroundLoad for
6364
' VisualBasicPackage. The call should be removed from the constructor, and the package set back to allowing
6465
' background loads.
6566
_comAggregate = Implementation.Interop.ComAggregate.CreateAggregatedObject(Me)
@@ -73,7 +74,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic
7374
isMainThreadTask:=False,
7475
task:=Function() As Task
7576
Try
76-
RegisterLanguageService(GetType(IVbCompilerService), Function() Task.FromResult(_comAggregate))
77+
AddService(GetType(IVbCompilerService), Function(_1, cancellationToken, _2) Task.FromResult(_comAggregate), promote:=True)
7778

7879
DirectCast(Me, IServiceContainer).AddService(
7980
GetType(IVbTempPECompilerFactory),

0 commit comments

Comments
 (0)