Skip to content

Commit 46e6634

Browse files
authored
Merge pull request #21703 from rchande/restoreChanges
Restore changes intended for 15.4 P2
2 parents a194462 + 0cad0ba commit 46e6634

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

src/VisualStudio/Core/Def/Implementation/PreviewPane/PreviewPane.xaml.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
using System.Windows.Controls;
88
using System.Windows.Documents;
99
using System.Windows.Navigation;
10-
using EnvDTE;
1110
using Microsoft.CodeAnalysis.Diagnostics.Log;
1211
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
1312
using Roslyn.Utilities;
1413
using Microsoft.CodeAnalysis.Editor.Implementation.Preview;
14+
using IVsUIShell = Microsoft.VisualStudio.Shell.Interop.IVsUIShell;
15+
using OLECMDEXECOPT = Microsoft.VisualStudio.OLE.Interop.OLECMDEXECOPT;
1516

1617
namespace Microsoft.VisualStudio.LanguageServices.Implementation.PreviewPane
1718
{
@@ -24,7 +25,7 @@ internal partial class PreviewPane : UserControl, IDisposable
2425

2526
private readonly string _id;
2627
private readonly bool _logIdVerbatimInTelemetry;
27-
private readonly DTE _dte;
28+
private readonly IVsUIShell _uiShell;
2829

2930
private bool _isExpanded;
3031
private double _heightForThreeLineTitle;
@@ -39,14 +40,14 @@ public PreviewPane(
3940
string helpLinkToolTipText,
4041
IReadOnlyList<object> previewContent,
4142
bool logIdVerbatimInTelemetry,
42-
DTE dte,
43+
IVsUIShell uiShell,
4344
Guid optionPageGuid = default(Guid))
4445
{
4546
InitializeComponent();
4647

4748
_id = id;
4849
_logIdVerbatimInTelemetry = logIdVerbatimInTelemetry;
49-
_dte = dte;
50+
_uiShell = uiShell;
5051

5152
// Initialize header portion.
5253
if ((severityIcon != null) && !string.IsNullOrWhiteSpace(id) && !string.IsNullOrWhiteSpace(title))
@@ -358,7 +359,11 @@ private void OptionsButton_Click(object sender, RoutedEventArgs e)
358359
{
359360
if (_optionPageGuid != default(Guid))
360361
{
361-
_dte.ExecuteCommand("Tools.Options", _optionPageGuid.ToString());
362+
ErrorHandler.ThrowOnFailure(_uiShell.PostExecCommand(
363+
VSConstants.GUID_VSStandardCommandSet97,
364+
(uint)VSConstants.VSStd97CmdID.ToolsOptions,
365+
(uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT,
366+
_optionPageGuid.ToString()));
362367
}
363368
}
364369
}

src/VisualStudio/Core/Def/Implementation/PreviewPane/PreviewPaneService.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@
1818
using Microsoft.VisualStudio.Imaging.Interop;
1919
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
2020
using Microsoft.VisualStudio.Shell;
21+
using IVsUIShell = Microsoft.VisualStudio.Shell.Interop.IVsUIShell;
22+
using SVsUIShell = Microsoft.VisualStudio.Shell.Interop.SVsUIShell;
2123

2224
namespace Microsoft.VisualStudio.LanguageServices.Implementation.PreviewPane
2325
{
2426
[ExportWorkspaceServiceFactory(typeof(IPreviewPaneService), ServiceLayer.Host), Shared]
2527
internal class PreviewPaneService : ForegroundThreadAffinitizedObject, IPreviewPaneService, IWorkspaceServiceFactory
2628
{
27-
private readonly EnvDTE.DTE _dte;
29+
private readonly IVsUIShell _uiShell;
2830

2931
[ImportingConstructor]
3032
public PreviewPaneService(SVsServiceProvider serviceProvider)
3133
{
32-
_dte = serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
34+
_uiShell = serviceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;
3335
}
3436

3537
IWorkspaceService IWorkspaceServiceFactory.CreateService(HostWorkspaceServices workspaceServices)
@@ -107,7 +109,7 @@ object IPreviewPaneService.GetPreviewPane(
107109

108110
return new PreviewPane(
109111
severityIcon: null, id: null, title: null, description: null, helpLink: null, helpLinkToolTipText: null,
110-
previewContent: previewContent, logIdVerbatimInTelemetry: false, dte: _dte);
112+
previewContent: previewContent, logIdVerbatimInTelemetry: false, uiShell: _uiShell);
111113
}
112114

113115
var helpLinkToolTipText = string.Empty;
@@ -128,7 +130,7 @@ object IPreviewPaneService.GetPreviewPane(
128130
helpLinkToolTipText: helpLinkToolTipText,
129131
previewContent: previewContent,
130132
logIdVerbatimInTelemetry: diagnostic.CustomTags.Contains(WellKnownDiagnosticTags.Telemetry),
131-
dte: _dte,
133+
uiShell: _uiShell,
132134
optionPageGuid: optionPageGuid);
133135
}
134136

src/Workspaces/Core/Portable/Utilities/TaskExtensions.cs

+20
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public static Task SafeContinueWith(
9090
TaskContinuationOptions continuationOptions,
9191
TaskScheduler scheduler)
9292
{
93+
Contract.ThrowIfNull(continuationAction, nameof(continuationAction));
94+
9395
Func<Task, bool> continuationFunction = antecedent =>
9496
{
9597
continuationAction(antecedent);
@@ -116,6 +118,8 @@ public static Task<TResult> SafeContinueWith<TInput, TResult>(
116118
TaskContinuationOptions continuationOptions,
117119
TaskScheduler scheduler)
118120
{
121+
Contract.ThrowIfNull(continuationFunction, nameof(continuationFunction));
122+
119123
return task.SafeContinueWith<TResult>(
120124
(Task antecedent) => continuationFunction((Task<TInput>)antecedent), cancellationToken, continuationOptions, scheduler);
121125
}
@@ -127,6 +131,8 @@ public static Task SafeContinueWith<TInput>(
127131
TaskContinuationOptions continuationOptions,
128132
TaskScheduler scheduler)
129133
{
134+
Contract.ThrowIfNull(continuationAction, nameof(continuationAction));
135+
130136
return task.SafeContinueWith(
131137
(Task antecedent) => continuationAction((Task<TInput>)antecedent), cancellationToken, continuationOptions, scheduler);
132138
}
@@ -156,6 +162,8 @@ public static Task<TResult> SafeContinueWith<TResult>(
156162
// We do not want this, so we pass the LazyCancellation flag to the TPL which implements
157163
// the behavior we want.
158164

165+
Contract.ThrowIfNull(continuationFunction, nameof(continuationFunction));
166+
159167
Func<Task, TResult> outerFunction = t =>
160168
{
161169
try
@@ -223,6 +231,8 @@ public static Task<TResult> ContinueWithAfterDelay<TInput, TResult>(
223231
TaskContinuationOptions taskContinuationOptions,
224232
TaskScheduler scheduler)
225233
{
234+
Contract.ThrowIfNull(continuationFunction, nameof(continuationFunction));
235+
226236
return task.SafeContinueWith(t =>
227237
Task.Delay(millisecondsDelay, cancellationToken).SafeContinueWith(
228238
_ => continuationFunction(t), cancellationToken, TaskContinuationOptions.None, scheduler),
@@ -237,6 +247,8 @@ public static Task<TNResult> ContinueWithAfterDelay<TNResult>(
237247
TaskContinuationOptions taskContinuationOptions,
238248
TaskScheduler scheduler)
239249
{
250+
Contract.ThrowIfNull(continuationFunction, nameof(continuationFunction));
251+
240252
return task.SafeContinueWith(t =>
241253
Task.Delay(millisecondsDelay, cancellationToken).SafeContinueWith(
242254
_ => continuationFunction(t), cancellationToken, TaskContinuationOptions.None, scheduler),
@@ -251,6 +263,8 @@ public static Task ContinueWithAfterDelay(
251263
TaskContinuationOptions taskContinuationOptions,
252264
TaskScheduler scheduler)
253265
{
266+
Contract.ThrowIfNull(continuationAction, nameof(continuationAction));
267+
254268
return task.SafeContinueWith(t =>
255269
Task.Delay(millisecondsDelay, cancellationToken).SafeContinueWith(
256270
_ => continuationAction(), cancellationToken, TaskContinuationOptions.None, scheduler),
@@ -264,6 +278,8 @@ public static Task<TResult> SafeContinueWithFromAsync<TInput, TResult>(
264278
TaskContinuationOptions continuationOptions,
265279
TaskScheduler scheduler)
266280
{
281+
Contract.ThrowIfNull(continuationFunction, nameof(continuationFunction));
282+
267283
return task.SafeContinueWithFromAsync<TResult>(
268284
(Task antecedent) => continuationFunction((Task<TInput>)antecedent), cancellationToken, continuationOptions, scheduler);
269285
}
@@ -350,6 +366,8 @@ public static Task<TNResult> ContinueWithAfterDelayFromAsync<TNResult>(
350366
TaskContinuationOptions taskContinuationOptions,
351367
TaskScheduler scheduler)
352368
{
369+
Contract.ThrowIfNull(continuationFunction, nameof(continuationFunction));
370+
353371
return task.SafeContinueWith(t =>
354372
Task.Delay(millisecondsDelay, cancellationToken).SafeContinueWithFromAsync(
355373
_ => continuationFunction(t), cancellationToken, TaskContinuationOptions.None, scheduler),
@@ -364,6 +382,8 @@ public static Task ContinueWithAfterDelayFromAsync(
364382
TaskContinuationOptions taskContinuationOptions,
365383
TaskScheduler scheduler)
366384
{
385+
Contract.ThrowIfNull(continuationFunction, nameof(continuationFunction));
386+
367387
return task.SafeContinueWith(t =>
368388
Task.Delay(millisecondsDelay, cancellationToken).SafeContinueWithFromAsync(
369389
_ => continuationFunction(t), cancellationToken, TaskContinuationOptions.None, scheduler),

0 commit comments

Comments
 (0)