dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.82k stars 773 forks source link

I'm getting unwanted navigation when holding `Ctrl` and hovering over operators like `&&` or `>`. Not sure if caused by this PR or a bug in VS. #17230

Open vzarytovskii opened 1 month ago

vzarytovskii commented 1 month ago

I'm getting unwanted navigation when holding Ctrl and hovering over operators like && or >. Not sure if caused by this PR or a bug in VS.

Originally posted by @kerams in https://github.com/dotnet/fsharp/pull/17047#issuecomment-2068051467

majocha commented 1 month ago

Just hovering over external symbol, (not just operators) while holding Ctrl causes VS (Roslyn?) to call IFSharpGoToDefinitionService.FindDefinitionsAsync.

Which in turn calls NavigateToExternalDeclarationAsync:

https://github.com/dotnet/fsharp/blob/6420e36b89d05c54f49d8fa81f9b4922dd0a8fa0/vsintegration/src/FSharp.Editor/Navigation/GoToDefinition.fs#L775-L789

Somehow this doesn't happen that often with vsix built from main, but I can repro this in debug mode each time.

vzarytovskii commented 1 month ago

Yeah, that's definitely either VS or Roslyn. @CyrusNajmabadi is it something you can control?

CyrusNajmabadi commented 1 month ago

Are they clicking while holding Ctrl? If so, this is by design. Ctrl-click navigates you to the thing under the caret.

I believe there is a setting for this in vs if the user doesn't like that behavior.

vzarytovskii commented 1 month ago

Are they clicking while holding Ctrl? If so, this is by design. Ctrl-click navigates you to the thing under the caret.

I believe there is a setting for this in vs if the user doesn't like that behavior.

I believe it's just hovering, @majocha may confirm/deny it.

majocha commented 1 month ago

Yes, it's just hover.

More interestingly, if you enable "View > Code Definition Window", the unwanted navigation can happen just with typing.

For example:

Type Console.Out. Move the cursor back with left-arrow, and bam, navigation to metadata.

I suspect the problem is that our code path for external symbols ends up calling NavigateToExternalDeclarationAsync instead of just returning a FSharpNavigableItem array.

VS calls IFSharpGoToDefinitionService.FindDefinitionsAsync -> the symbol is external -> we end up here:

https://github.com/dotnet/fsharp/blob/6420e36b89d05c54f49d8fa81f9b4922dd0a8fa0/vsintegration/src/FSharp.Editor/Navigation/GoToDefinition.fs#L784