-
Notifications
You must be signed in to change notification settings - Fork 789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
f1 key on type does not query reference documentation. #1938
Comments
This is the interface which should be implemented: https://github.com/dotnet/roslyn/blob/master/src/VisualStudio/Core/Def/Implementation/F1Help/IHelpContextService.cs Spoke with @CyrusNajmabadi and he said that |
@CyrusNajmabadi @cartermp And I presume
Which was previously called in this code:
which was in turn used by this code:
|
@dsyme Yep, that's correct. |
That interface is marked |
@rojepp that's not a problem, everything there is internal and we use it. I've no idea how it works though. |
@vasily-kirichenko How do you get it to compile? I don't know much about Roslyn I'm afraid. |
You cannot compile it? Strange. Make a WIP PR, we'll look at it. |
It seems I can. I was doing something wrong. I'd be happy to do some work on this if no-one else is working on it? |
What about me, I'm not going to work on it. |
@rojepp pro tip: run |
To get the latest fixes? Thanks, I'll do that! |
Yes. Without it even tooltips don't work. |
FSharp.Editor is listed as InternalsVisibleTo for Roslyn. |
BTW I've pushed a branch "bleeding-edge" which you can use to get the combination of features @vasily-kirichenko has been working on. PRs should of course be based on master. https://github.com/Microsoft/visualfsharp/tree/bleeding-edge |
@dsyme I'm afraid I've stuck with Inline Rename unless somebody from Roslyn/TS team helps. |
@vasily-kirichenko Ah yes :) Bleeding indeed :) |
@rojepp I just have some basic code that implements the interface, but it doesn't seem to be intercepting the f1 key hit. Have you had success getting it to hit a breakpoint? I noticed that the old language service implementation isn't even called anymore, so that isn't overriding this. namespace Microsoft.VisualStudio.FSharp.Editor
open System
open System.Composition
open System.Collections.Generic
open System.Collections.Immutable
open System.Linq
open System.Threading
open System.Threading.Tasks
open System.Runtime.CompilerServices
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Classification
open Microsoft.CodeAnalysis.Editor
open Microsoft.CodeAnalysis.Editor.Host
open Microsoft.CodeAnalysis.Navigation
open Microsoft.CodeAnalysis.Editor.Shared.Utilities
open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.CodeAnalysis.Text
open Microsoft.VisualStudio.LanguageServices.Implementation.F1Help
open Microsoft.VisualStudio.FSharp.LanguageService
open Microsoft.VisualStudio.Text
open Microsoft.VisualStudio.Text.Tagging
open Microsoft.FSharp.Compiler.Range
open Microsoft.FSharp.Compiler.SourceCodeServices
[<Shared>]
[<ExportLanguageService(typeof<IHelpContextService>, FSharpCommonConstants.FSharpLanguageName)>]
type internal FSharpF1HelpProvider =
static member internal GetKeywordAsync(document: Document, textSpan: TextSpan, cancellationToken: CancellationToken) =
async {
document |> ignore
textSpan |> ignore
cancellationToken |> ignore
return Some("hello")
}
interface IHelpContextService with
member this.GetHelpTermAsync(document: Document, textSpan: TextSpan, cancellationToken: CancellationToken) =
async {
let! res = FSharpF1HelpProvider.GetKeywordAsync(document, textSpan, cancellationToken)
match res with
| Some keyword -> return keyword
| None -> return String.Empty
} |> CommonRoslynHelpers.StartAsyncAsTask cancellationToken
// The current interface has this member which is not applicable to F#.
// We can just return 'null' here, as it won't affect the behavior for us.
member this.FormatSymbol(symbol: ISymbol) = symbol |> ignore; null
// This is what C# does. See here:
//
// https://github.com/dotnet/roslyn/blob/84bc7eea2e05e9d9d7e1b53c2a107c0ac9857a72/src/VisualStudio/CSharp/Impl/LanguageService/CSharpHelpContextService.cs#L23
member this.Language = "fsharp"
member this.Product = "fsharp" |
@cartermp I'm having the same issue. My code isn't getting called. I also tried inheriting from [<Shared>]
[<ExportLanguageService(typeof<IHelpContextService>, FSharpCommonConstants.FSharpLanguageName)>] ? |
Check (twice) that Shared attribute is the right one. |
definitely don't derive from the Abtract guys. They're there to share VB/C# logic. |
You'll have to debug through AbstractLanguageService`2.UpdateLanguageContext You guys do have a derivation of AbstractLanguageService`2 in F# land, right? |
Okay, thanks @CyrusNajmabadi for pointing me in the right direction. In our subclass of AbstractLanguageService`2 here, we'll need to do something similar to this, which will get the IHelpContextService service, which we implement as above, and then pass the result into the VS API. |
no no... you shouldn't need ot do that. we already do that for you :) |
We need to figure out why it's not working. can you add a BP to that method and see what happens when F1 is hit in an F# scenario? |
@CyrusNajmabadi I don't have Roslyn set up for debugging, but I reimplemented interface IVsLanguageContextProvider with
member this.UpdateLanguageContext(_dwHint, pBuffer, ptsSelection, pUC) =
let textViewAdapter = this.Package.ComponentModel.GetService<IVsEditorAdaptersFactoryService>()
let textBuffer = textViewAdapter.GetDataBuffer(pBuffer)
let context = pUC :?> IVsUserContext
match textBuffer = null, context = null with
| true,_
| _,true -> VSConstants.E_UNEXPECTED;
| _ ->
let snapshot = textBuffer.CurrentSnapshot
match snapshot.GetOpenDocumentInCurrentContextWithChanges() with
| null -> VSConstants.E_FAIL
| document ->
match document.Project.LanguageServices.GetService<IHelpContextService>() with
| null -> VSConstants.E_NOTIMPL
| helpService ->
let selectionStart = textBuffer.CurrentSnapshot.GetLineFromLineNumber(ptsSelection.[0].iStartLine).Start + ptsSelection.[0].iStartIndex
let selectionEnd = textBuffer.CurrentSnapshot.GetLineFromLineNumber(ptsSelection.[0].iEndLine).Start + ptsSelection.[0].iEndIndex
let _span = Microsoft.CodeAnalysis.Text.TextSpan.FromBounds(unbox selectionStart, unbox selectionEnd)
// VS help is not cancellable.
let _cancellationToken = System.Threading.CancellationToken.None;
let helpTerm = "DummyKeyword" // helpService.GetHelpTermAsync(document, span, cancellationToken).WaitAndGetResult(cancellationToken);
match String.IsNullOrWhiteSpace(helpTerm) with
| true -> VSConstants.S_FALSE
| _ ->
context.RemoveAttribute("keyword", null) |> ignore
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "devlang", helpService.Language) |> ignore
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "product", helpService.Product) |> ignore
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "product", "VS") |> ignore
context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1_CaseSensitive, "keyword", helpTerm) |> ignore
VSConstants.S_OK |
Is the document correct? does it have the right language? |
It's the right document. It also has |
We'll have to debug to figure out why |
Those shouldn't matter here, since we're not even getting to that point. That's something to do with how the help system works. Honestly, if you weren't setting those values before, they likely don't matter at all now. |
@vasily-kirichenko |
@OmarTawfik Is there anything special we might need to do to export |
@cartermp first thing I noticed is that you should use
|
@OmarTawfik I used |
OK, problem solved at my end! I had |
@rojepp Awesome! Looking forward to seeing this working. Interesting that removing that |
Great! |
This is the exact problem I've met twice. I was sure it's about the wrong Shared attribute. |
Seems like the kind of thing that a compile error or warning should be generated from. |
* WIP: implement F1 HelpContextService Implements #1938 * Small cleanup * Enable context help tests for provided types * Delete old tests * Rebase against master
Fixed by #1966. |
* WIP: implement F1 HelpContextService Implements dotnet#1938 * Small cleanup * Enable context help tests for provided types * Delete old tests * Rebase against master
Assuming the following code:
Hit the
f1
key onConcat
.Expected: Browser tab (en-us) open with this link: https://msdn.microsoft.com/en-us/library/0wkb0y3w(v=vs.110).aspx
Actual: This link is opened instead: https://docs.microsoft.com/en-us/visualstudio/ide/creating-solutions-and-projects
The text was updated successfully, but these errors were encountered: