Skip to content

Commit 5a23df0

Browse files
Remove usage of WaitAndGetResult from debugger paths (#76479)
2 parents 58e0ac1 + 5638aed commit 5a23df0

File tree

3 files changed

+156
-181
lines changed

3 files changed

+156
-181
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
}

0 commit comments

Comments
 (0)