|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 | // See the LICENSE file in the project root for more information. |
4 | 4 |
|
5 | | -#nullable disable |
6 | | - |
7 | 5 | using System.Threading; |
8 | 6 | using Microsoft.CodeAnalysis.Shared.Extensions; |
9 | 7 | using Microsoft.CodeAnalysis.Text; |
10 | 8 | using Microsoft.VisualStudio.LanguageServices.Implementation.F1Help; |
11 | 9 | using Microsoft.VisualStudio.Shell.Interop; |
12 | 10 | using Microsoft.VisualStudio.TextManager.Interop; |
13 | | -using Roslyn.Utilities; |
14 | 11 |
|
15 | 12 | namespace Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService; |
16 | 13 |
|
17 | 14 | internal abstract partial class AbstractLanguageService<TPackage, TLanguageService> : IVsLanguageContextProvider |
18 | 15 | { |
19 | 16 | public int UpdateLanguageContext(uint dwHint, IVsTextLines pBuffer, Microsoft.VisualStudio.TextManager.Interop.TextSpan[] ptsSelection, object pUC) |
20 | 17 | { |
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 () => |
25 | 19 | { |
26 | | - return VSConstants.E_UNEXPECTED; |
27 | | - } |
| 20 | + var textBuffer = EditorAdaptersFactoryService.GetDataBuffer(pBuffer); |
| 21 | + var context = (IVsUserContext)pUC; |
28 | 22 |
|
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; |
34 | 25 |
|
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; |
38 | 29 |
|
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); |
44 | 33 |
|
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; |
48 | 37 |
|
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; |
53 | 45 |
|
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); |
59 | 51 |
|
60 | | - return VSConstants.S_OK; |
| 52 | + return VSConstants.S_OK; |
| 53 | + }); |
61 | 54 | } |
62 | 55 | } |
0 commit comments