Skip to content

Commit 3f9e8a7

Browse files
Remove usage of WaitAndGetResult from debugger paths
1 parent 5befcf9 commit 3f9e8a7

File tree

3 files changed

+36
-43
lines changed

3 files changed

+36
-43
lines changed

src/VisualStudio/Core/Def/LanguageService/AbstractLanguageService`2.IVsLanguageContextProvider.cs

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,54 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable disable
6-
75
using System.Threading;
86
using Microsoft.CodeAnalysis.Shared.Extensions;
97
using Microsoft.CodeAnalysis.Text;
108
using Microsoft.VisualStudio.LanguageServices.Implementation.F1Help;
119
using Microsoft.VisualStudio.Shell.Interop;
1210
using Microsoft.VisualStudio.TextManager.Interop;
13-
using Roslyn.Utilities;
1411

1512
namespace Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService;
1613

1714
internal abstract partial class AbstractLanguageService<TPackage, TLanguageService> : IVsLanguageContextProvider
1815
{
1916
public int UpdateLanguageContext(uint dwHint, IVsTextLines pBuffer, Microsoft.VisualStudio.TextManager.Interop.TextSpan[] ptsSelection, object pUC)
2017
{
21-
var textBuffer = EditorAdaptersFactoryService.GetDataBuffer(pBuffer);
22-
var context = (IVsUserContext)pUC;
23-
24-
if (textBuffer == null || context == null)
18+
return this.ThreadingContext.JoinableTaskFactory.Run(async () =>
2519
{
26-
return VSConstants.E_UNEXPECTED;
27-
}
20+
var textBuffer = EditorAdaptersFactoryService.GetDataBuffer(pBuffer);
21+
var context = (IVsUserContext)pUC;
2822

29-
var document = textBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
30-
if (document == null)
31-
{
32-
return VSConstants.E_FAIL;
33-
}
23+
if (textBuffer == null || context == null)
24+
return VSConstants.E_UNEXPECTED;
3425

35-
var start = textBuffer.CurrentSnapshot.GetLineFromLineNumber(ptsSelection[0].iStartLine).Start + ptsSelection[0].iStartIndex;
36-
var end = textBuffer.CurrentSnapshot.GetLineFromLineNumber(ptsSelection[0].iEndLine).Start + ptsSelection[0].iEndIndex;
37-
var span = Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(start, end);
26+
var document = textBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
27+
if (document == null)
28+
return VSConstants.E_FAIL;
3829

39-
var helpService = document.GetLanguageService<IHelpContextService>();
40-
if (helpService == null)
41-
{
42-
return VSConstants.E_NOTIMPL;
43-
}
30+
var start = textBuffer.CurrentSnapshot.GetLineFromLineNumber(ptsSelection[0].iStartLine).Start + ptsSelection[0].iStartIndex;
31+
var end = textBuffer.CurrentSnapshot.GetLineFromLineNumber(ptsSelection[0].iEndLine).Start + ptsSelection[0].iEndIndex;
32+
var span = Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(start, end);
4433

45-
// VS help is not cancellable.
46-
var cancellationToken = CancellationToken.None;
47-
var helpTerm = helpService.GetHelpTermAsync(document, span, cancellationToken).WaitAndGetResult(cancellationToken);
34+
var helpService = document.GetLanguageService<IHelpContextService>();
35+
if (helpService == null)
36+
return VSConstants.E_NOTIMPL;
4837

49-
if (string.IsNullOrWhiteSpace(helpTerm))
50-
{
51-
return VSConstants.S_FALSE;
52-
}
38+
// VS help is not cancellable.
39+
var cancellationToken = CancellationToken.None;
40+
var helpTerm = await helpService.GetHelpTermAsync(
41+
document, span, cancellationToken).ConfigureAwait(true);
42+
43+
if (string.IsNullOrWhiteSpace(helpTerm))
44+
return VSConstants.S_FALSE;
5345

54-
context.RemoveAttribute("keyword", null);
55-
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "devlang", helpService.Language);
56-
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "product", helpService.Product);
57-
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "product", "VS");
58-
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1_CaseSensitive, "keyword", helpTerm);
46+
context.RemoveAttribute("keyword", null);
47+
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "devlang", helpService.Language);
48+
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "product", helpService.Product);
49+
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "product", "VS");
50+
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1_CaseSensitive, "keyword", helpTerm);
5951

60-
return VSConstants.S_OK;
52+
return VSConstants.S_OK;
53+
});
6154
}
6255
}

src/VisualStudio/Core/Def/LanguageService/AbstractLanguageService`2.VsLanguageDebugInfo.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ internal sealed class VsLanguageDebugInfo : IVsLanguageDebugInfo
3131
{
3232
private readonly Guid _languageId;
3333
private readonly TLanguageService _languageService;
34-
private readonly IThreadingContext _threadingContext;
3534
private readonly ILanguageDebugInfoService? _languageDebugInfo;
3635
private readonly IBreakpointResolutionService? _breakpointService;
3736
private readonly IProximityExpressionsService? _proximityExpressionsService;
@@ -41,21 +40,21 @@ public VsLanguageDebugInfo(
4140
Guid languageId,
4241
TLanguageService languageService,
4342
HostLanguageServices languageServiceProvider,
44-
IThreadingContext threadingContext,
4543
IUIThreadOperationExecutor uiThreadOperationExecutor)
4644
{
4745
Contract.ThrowIfNull(languageService);
4846
Contract.ThrowIfNull(languageServiceProvider);
4947

5048
_languageId = languageId;
5149
_languageService = languageService;
52-
_threadingContext = threadingContext;
5350
_languageDebugInfo = languageServiceProvider.GetService<ILanguageDebugInfoService>();
5451
_breakpointService = languageServiceProvider.GetService<IBreakpointResolutionService>();
5552
_proximityExpressionsService = languageServiceProvider.GetService<IProximityExpressionsService>();
5653
_uiThreadOperationExecutor = uiThreadOperationExecutor;
5754
}
5855

56+
private IThreadingContext ThreadingContext => _languageService.ThreadingContext;
57+
5958
public int GetLanguageID(IVsTextBuffer pBuffer, int iLine, int iCol, out Guid pguidLanguageID)
6059
{
6160
pguidLanguageID = _languageId;
@@ -100,7 +99,7 @@ public int GetNameOfLocation(IVsTextBuffer pBuffer, int iLine, int iCol, out str
10099
// NOTE(cyrusn): We have to wait here because the debuggers'
101100
// GetNameOfLocation is a blocking call. In the future, it
102101
// would be nice if they could make it async.
103-
_threadingContext.JoinableTaskFactory.Run(async () =>
102+
this.ThreadingContext.JoinableTaskFactory.Run(async () =>
104103
{
105104
var debugLocationInfo = await _languageDebugInfo.GetLocationInfoAsync(document, point, cancellationToken).ConfigureAwait(false);
106105

@@ -133,7 +132,7 @@ public int GetNameOfLocation(IVsTextBuffer pBuffer, int iLine, int iCol, out str
133132

134133
public int GetProximityExpressions(IVsTextBuffer pBuffer, int iLine, int iCol, int cLines, out IVsEnumBSTR? ppEnum)
135134
{
136-
ppEnum = _threadingContext.JoinableTaskFactory.Run(async () =>
135+
ppEnum = this.ThreadingContext.JoinableTaskFactory.Run(async () =>
137136
{
138137
// NOTE(cyrusn): cLines is ignored. This is to match existing dev10 behavior.
139138
using (Logger.LogBlock(FunctionId.Debugging_VsLanguageDebugInfo_GetProximityExpressions, CancellationToken.None))
@@ -199,7 +198,7 @@ public int ResolveName(string pszName, uint dwFlags, out IVsEnumDebugName? ppNam
199198
showProgress: false,
200199
action: waitContext =>
201200
{
202-
_threadingContext.JoinableTaskFactory.Run(async () =>
201+
this.ThreadingContext.JoinableTaskFactory.Run(async () =>
203202
{
204203
var cancellationToken = waitContext.UserCancellationToken;
205204
if (dwFlags == (uint)RESOLVENAMEFLAGS.RNF_BREAKPOINT)
@@ -236,7 +235,7 @@ private async ValueTask<IVsDebugName> CreateDebugNameAsync(
236235
// If we're inside an Venus code nugget, we need to map the span to the surface buffer.
237236
// Otherwise, we'll just use the original span.
238237
var mappedSpan = await span.MapSpanFromSecondaryBufferToPrimaryBufferAsync(
239-
_threadingContext, document.Id, cancellationToken).ConfigureAwait(false);
238+
this.ThreadingContext, document.Id, cancellationToken).ConfigureAwait(false);
240239
if (mappedSpan != null)
241240
span = mappedSpan.Value;
242241

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ protected AbstractLanguageService(TPackage package)
8787
this._languageDebugInfo = CreateLanguageDebugInfo();
8888
}
8989

90+
private IThreadingContext ThreadingContext => this.Package.ComponentModel.GetService<IThreadingContext>();
91+
9092
public override IServiceProvider SystemServiceProvider
9193
=> Package;
9294

@@ -223,7 +225,6 @@ private VsLanguageDebugInfo CreateLanguageDebugInfo()
223225
this.DebuggerLanguageId,
224226
(TLanguageService)this,
225227
languageServices,
226-
this.Package.ComponentModel.GetService<IThreadingContext>(),
227228
this.Package.ComponentModel.GetService<IUIThreadOperationExecutor>());
228229
}
229230

0 commit comments

Comments
 (0)