Type on mouseover
It would be really nice it type on evalulated cells could be shown on mouseover, similar to ide's such as atom.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
+1
Comments from IPython devs on this:
Me:
Get some info about an identifier from the kernel when I hover my mouse over that identifier, and display it as a popup. Idea: Use CodeMirror API and IPython comms to communicate with kernel.
Response:
I think CM.coorsChar is the relevant API.
You might not need to use comms for this one, if
inspect_requestis the right action. If the output should be distinguished from inspection via other means, then a custom comm would be appropriate.
I studied the API provided by codemirror, and these are the interesting functions:
-
cm.getTokenTypeAt: A function that does the job partially. i.e. it tells the type of a token in the syntax-tree sense (null for unstyled tokens, an array containing all applicable styles otherwise). (Good for a initial proof-of-concept) -
cm.getTokenAt: Retrieves information about the token in the current mode found before the given position. (includes the type, string, start-end positions, and the mode's parser state at end of this token).
Assuming that there is a way to extract the type of any token in a code fragment in IHaskell (using the GHC API), I am now thinking about building a proof-of-concept that just shows the type (AST sense type).
For displaying the type, I am thinking of using the display/panel.js addon from CodeMirror to show a thin panel at the bottom of the cell, which will automatically hide when inactive. The problem with it is that it might require frontend support. Another possible way is to provide a widget similar to parsec-widget, but that will look clumsy.
Also, I did not get the idea about inspect_request. There is no such function provided by CodeMirror. Is it a part of the IPython/Jupyter messaging specification?
@sumitsahrawat
That sounds promising. For inspect_request, check out that portion of the IPython messaging spec here.
I suggest as a starting point, just get it to show (as a tooltip) whatever symbol the mouse is hovering over at the time. One that works, then you can use javascript comms to talk to the backend.
The messaging spec seems to have changed. IHaskell implements object_info_request which has been renamed to inspect_request. I'll rename some constructors to make it match the latest spec.
Sounds good. The messaging spec did indeed change (from v3 to v4 to v5) and IHaskell switched to v5 when it was ported to IPython 3. The main messages were fixed to work, but there's a bunch of places where IHaskell doesn't quite do the right thing for the messaging spec and this looks like one of them.
Some updates
-
inspect_requestis triggered usingShift-Tab, not mouse-over. - The tooltip that shows is not what I had in mind. An IPython example:

- The code sent by the kernel during
inspect_requestis unreliable. For example, in the following code
print = putStrLn . show
If the cursor is placed at the end of show, the request sends back the whole code with correct position of cursor calculated from the starting of the cell. If the word show is highlighted, then only the word show is sent back, but the position is still calculated from the starting of the cell. A possible hacky solution is to check whether the code has only one word and proceed accordingly.
I'll try and see if I can use this to display hoogle results.
To clarify: the mention of inspect_request is as a tool. The idea is that on mouse over, the frontend will issue an inspect_request to the kernel. We have already implemented inspect_request (albeit perhaps not as well as it should be implemented). The challenge is to get the frontend to issue the request on mouse over as well as on shift tab!
On Thu, Apr 2, 2015 at 4:47 PM, Sumit Sahrawat [email protected] wrote:
Some updates
- inspect_request is triggered using Shift-Tab, not mouse-over.
- The tooltip that shows is not what I had in mind. An IPython example:
[image: Example] https://cloud.githubusercontent.com/assets/5645741/6975369/1bd56fbc-d9b9-11e4-80e2-135ed9944988.png
- The code sent by the kernel during inspect_request is unreliable. For example, in the following code
print = putStrLn . show
If the cursor is placed at the end of show, the request sends back the whole code with correct position of cursor calculated from the starting of the cell. If the word show is highlighted, then only the word show is sent back, but the position is still calculated from the starting of the cell. A possible hacky solution is to check whether the code has only one word and proceed accordingly.
I'll try and see if I can use this to display hoogle results.
— Reply to this email directly or view it on GitHub https://github.com/gibiansky/IHaskell/issues/347#issuecomment-89082323.
Seems reasonable. So what should the user see in this tooltip? Just the type, or formatted in a similar way as above? (without the 'String Form')
More or less, yes, just the type. On Apr 2, 2015 5:17 PM, "Sumit Sahrawat" [email protected] wrote:
Seems reasonable. So what should the user see in this tooltip? Just the type, or formatted in a similar way as above? (without the 'String Form')
— Reply to this email directly or view it on GitHub https://github.com/gibiansky/IHaskell/issues/347#issuecomment-89090629.
This would be a nice feature! Maybe intero helps too.