-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathAbstractLanguageService`2.IVsLanguageContextProvider.cs
60 lines (50 loc) · 2.71 KB
/
AbstractLanguageService`2.IVsLanguageContextProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServices.Implementation.F1Help;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TextManager.Interop;
using Roslyn.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService
{
internal abstract partial class AbstractLanguageService<TPackage, TLanguageService> : IVsLanguageContextProvider
{
public int UpdateLanguageContext(uint dwHint, IVsTextLines pBuffer, Microsoft.VisualStudio.TextManager.Interop.TextSpan[] ptsSelection, object pUC)
{
var textBuffer = EditorAdaptersFactoryService.GetDataBuffer(pBuffer);
var context = (IVsUserContext)pUC;
if (textBuffer == null || context == null)
{
return VSConstants.E_UNEXPECTED;
}
var document = textBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document == null)
{
return VSConstants.E_FAIL;
}
var start = textBuffer.CurrentSnapshot.GetLineFromLineNumber(ptsSelection[0].iStartLine).Start + ptsSelection[0].iStartIndex;
var end = textBuffer.CurrentSnapshot.GetLineFromLineNumber(ptsSelection[0].iEndLine).Start + ptsSelection[0].iEndIndex;
var span = Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(start, end);
var helpService = document.GetLanguageService<IHelpContextService>();
if (helpService == null)
{
return VSConstants.E_NOTIMPL;
}
// VS help is not cancellable.
var cancellationToken = CancellationToken.None;
var helpTerm = helpService.GetHelpTermAsync(document, span, cancellationToken).WaitAndGetResult(cancellationToken);
if (string.IsNullOrWhiteSpace(helpTerm))
{
return VSConstants.S_FALSE;
}
context.RemoveAttribute("keyword", null);
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "devlang", helpService.Language);
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "product", helpService.Product);
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "product", "VS");
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1_CaseSensitive, "keyword", helpTerm);
return VSConstants.S_OK;
}
}
}