Skip to content
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

F# HoverText #714

Merged
merged 8 commits into from
Sep 16, 2020
Merged

F# HoverText #714

merged 8 commits into from
Sep 16, 2020

Conversation

krauthaufen
Copy link
Contributor

Hey interactive people, I added support for RequestHoverText in FSharpKernel via adding (a very reduced variant) of FsAutoComplete.

image

I'm aware that this is not really pretty, since changes in FsAutoComplete won't be easy to integrate (some files are modified slightly) but nonetheless hover-texts are really useful (escpecially for F#).

Maybe you have a better idea how to integrate FsAutoComplete's hover-text.
Cheers

@dnfadmin
Copy link

dnfadmin commented Aug 15, 2020

CLA assistant check
All CLA requirements met.

@brettfo
Copy link
Member

brettfo commented Aug 17, 2020

This looks wonderful! Can you add the appropriate tests to the src/Microsoft.DotNet.Interactive.Tests/LanguageServices/HoverTextTests.cs file?

Long term we'd likely want this code migrated to the dotnet/fsharp repo, but for now I think we're ok with it existing here, especially if we have tests that we can use to confirm if/when the code is moved.

@@ -0,0 +1,39 @@
// --------------------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this file can be removed.

@jonsequitur
Copy link
Contributor

An interesting enhancement here to traditional hover text is that we can also inspect the current value of the variable using FSharpKernel.TryGetVariable. Might be worth including?

@krauthaufen
Copy link
Contributor Author

I'll add some basic tests and remove more unnecessary code. @jonsequitur awesome idea, I will definetly look into that...

@krauthaufen
Copy link
Contributor Author

Hey, I just added a few tests and improved the layouting a little.

Btw. I also included the current-value when available:
image

@jonsequitur
Copy link
Contributor

That is very cool!

@brettfo brettfo changed the base branch from master to main August 19, 2020 19:56
@dsyme
Copy link
Contributor

dsyme commented Aug 19, 2020

This is great work and I think we will be able to take this after an iteration or too

I'm aware that this is not really pretty, since changes in FsAutoComplete won't be easy to integrate (some files are modified slightly) but nonetheless hover-texts are really useful (escpecially for F#).

We do need to be consolidating here.

Referencing ionide/FsAutoComplete#645 which covers the ground

@dsyme
Copy link
Contributor

dsyme commented Aug 19, 2020

@krauthaufen Did you consider calling the FCS method GetStructuredToolTipText directly?

These tooltips are the ones used in Visual Studio, which are not too bad though Ionide has its own point of view on the content to show

newFooter
]

FormattedValue("text/markdown", stdinRx.Replace(fsiModuleRx.Replace(markdown, ""), ""))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we producing text/markdown? Does HoverTextProduced require it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically what ionide does and the tooltip-text contains markdown for e.g. generic arguments. Furthermore the F# syntax highlighting works with markdown code-blocks...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore the F# syntax highlighting works with markdown code-blocks...

Right, though that's a non-standard interpretation of F# code comments only really supported by F# tooling based off the ionide toolchain.

We're talking about standardizing it but it's a long way off, I don't think we should adopt it in F# notebooks

return None
}

match! res.TryGetToolTipEnhanced (FSharp.Compiler.Range.mkPos line col) lineContent with
Copy link
Contributor

@dsyme dsyme Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'm wondering why we need FsAutoComplete tooltips here, why not the tooltips provided by FCS. That might greatly reduce the amount of code copied across (and leave us to possibly incorporate the FsAutoComplete tooltips into FCS later).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I first tried to use the plain tooltips from FCS but they don't incorporate types/modules etc. (at least when used with overlapping names).
When hovering the type int i got the tooltip for the int : ^T -> int function, so i figured FsAutoComplete could be a way to go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I first tried to use the plain tooltips from FCS but they don't incorporate types/modules etc. (at least when used with overlapping names).

You're right that the FsAutoComplete tooltips make improvements (though it's not yet clear to me if they also regress other things).

But in any case, for .NET Interactive we would take the approach that we build on FSharp.Compiler.Service and just have to accept the tooling possibilities that gives. If we need to improve those tooltips, let's do it in FCS (e.g. by incorporating and aligning the tooltips code with Ionide)

match fullName with
| Some name ->
let expr = if name.StartsWith "Stdin." then name.Substring 6 else name
try return script.Value.Fsi.EvalExpression(expr) |> Some
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to understand more about how "safe" this evaluation is (i.e. not have side-effects)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it just runs for module-bindings I figured they were already evaluated in the FSI-semantics?

@dsyme
Copy link
Contributor

dsyme commented Aug 19, 2020

Note to self: the static checking in this PR (from which the tooltips are driven) appears to be based on the current type-check state of FSI, plus the checking of the cell contents of the cell being examined (but not of prior cell contents). This differs from iFSharp etc. where the static checking concatenates all cell contents and then splits them out again.

This means executing cells (especially definitions and package loads) will light up more accurate tooling in subsequent cells

@jonsequitur
Copy link
Contributor

the static checking in this PR (from which the tooltips are driven) appears to be based on the current type-check state of FSI, plus the checking of the cell contents of the cell being examined (but not of prior cell contents)

We've considered the possibility of doing a compile for language services evaluation when the notebook starts up. This would make the assumption that the cells should be evaluated in order, which I think is intuitive. It would present some challenges for polyglot scenarios where a submission in one languages influences the state of another, e.g. variable sharing.

@brettfo
Copy link
Member

brettfo commented Aug 26, 2020

@krauthaufen Can you update each test in the file src/Microsoft.DotNet.Interactive.Tests/LanguageServices/HoverTextTests.cs by adding the appropriate [InlineData(Language.FSharp...)] attributes and removing the Skip = "not implemented in fsharp" parameter? There are some oddities in how the hover text request gets forwarded to the underlying kernel that these tests can enforce.

Once that file's updated (and a merge or rebase to fix conflicts) I'm ready to pull it.

@krauthaufen
Copy link
Contributor Author

Hey, sorry for the delay, I addressed all your requests however I have no idea how useful these tests are since they're very strict in the Hover-Texts. They all succeed atm. but minor format changes would immediately break them.

@brettfo
Copy link
Member

brettfo commented Sep 9, 2020

Thanks for adding those F# tests. Yes, they're very strict, but they test that the F# kernel is setup to receive those commands, which is subtly different than directly testing the kernel itself.

The CI failure appears to be a refactoring that's causing problems with your merge from main.

@brettfo brettfo merged commit 741215f into dotnet:main Sep 16, 2020
@brettfo
Copy link
Member

brettfo commented Sep 16, 2020

@krauthaufen Thank you again for porting over F# hover text. I was eager to use it so I've published a new version of the VS Code extension. Version 1.0.146603 has F# hover text and it's beautiful.

@krauthaufen
Copy link
Contributor Author

Cool, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants