Skip to content

Commit 1f7dc9b

Browse files
committed
Use IAsyncServiceProvider when available
1 parent 495d38e commit 1f7dc9b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/InProcess/InProcComponent2.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ namespace Tvl.VisualStudio.MouseFastScroll.IntegrationTests.InProcess
88
using System.Windows;
99
using System.Windows.Threading;
1010
using Microsoft.VisualStudio.Threading;
11+
using static Microsoft.VisualStudio.Shell.VsTaskLibraryHelper;
1112
using DTE = EnvDTE.DTE;
13+
using IAsyncServiceProvider = Microsoft.VisualStudio.Shell.Interop.IAsyncServiceProvider;
14+
using SAsyncServiceProvider = Microsoft.VisualStudio.Shell.Interop.SAsyncServiceProvider;
1215
using SDTE = Microsoft.VisualStudio.Shell.Interop.SDTE;
1316
using ServiceProvider = Microsoft.VisualStudio.Shell.ServiceProvider;
1417

@@ -29,7 +32,15 @@ protected async Task<TInterface> GetGlobalServiceAsync<TService, TInterface>()
2932
where TInterface : class
3033
{
3134
await JoinableTaskFactory.SwitchToMainThreadAsync();
32-
return (TInterface)ServiceProvider.GlobalProvider.GetService(typeof(TService));
35+
36+
if (ServiceProvider.GlobalProvider.GetService(typeof(SAsyncServiceProvider)) is IAsyncServiceProvider asyncServiceProvider)
37+
{
38+
return (TInterface)await asyncServiceProvider.QueryServiceAsync(typeof(TService).GUID);
39+
}
40+
else
41+
{
42+
return (TInterface)ServiceProvider.GlobalProvider.GetService(typeof(TService));
43+
}
3344
}
3445

3546
protected async Task<DTE> GetDTEAsync()

Tvl.VisualStudio.MouseFastScroll.IntegrationTests/Tvl.VisualStudio.MouseFastScroll.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<PackageReference Include="InputSimulatorPlus" Version="1.0.6" />
1717
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="12.0.0" />
1818
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.12.0" Version="12.0.30111" />
19+
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime" Version="14.3.26929" />
1920
<PackageReference Include="VSSDK.ComponentModelHost.11" Version="11.0.4" />
2021
<PackageReference Include="VSSDK.DTE.8" Version="8.0.4" />
2122
<PackageReference Include="VSSDK.Shell.11" Version="11.0.4" />

0 commit comments

Comments
 (0)