janpfeifer / gonb

GoNB, a Go Notebook Kernel for Jupyter
https://github.com/janpfeifer/gonb
MIT License
631 stars 35 forks source link

Contextual help not activating in VsCode #100

Open Michael-F-Ellis opened 6 months ago

Michael-F-Ellis commented 6 months ago

Latest VsCode and Jupyter extension running on MacOS.

Can't get mouseover contextual help in gonb notebooks. Shift-Tab and Ctrl-I have no effect. Context help works fine in normal go files.

Screen Shot 2024-03-21 at 1 40 49 PM
janpfeifer commented 6 months ago

hi @Michael-F-Ellis , thanks for the report.

I quickly checked that Jupyter notebook on a normal browser works:

image

I'll try to figure out what is (not?) happening in VSCode later next week -- apologies, i'm out of town this week, and it's harder for me to test.

Michael-F-Ellis commented 6 months ago

@janpfeifer Thanks. No hurry. I can try to dig into it a bit further if you have any suggestions about where to begin looking.

janpfeifer commented 6 months ago

Yes, so to debug it, clone gonb, go its root directory and do:

go run . --install --logtostderr --vmodule=goplsclient=2,exec=2,conn=2

Then restart jupyter-lab. This will make Jupyter execute it with debugging messages enabled for the files listed in vmodule. The logging level 2 are most debug messages. Maybe it will be too verbose, or some of the files messages doesn't matter, you'll have to experiment.

That and peeking at the code under gonb/internal/goexec/goplsclient should give you a picture of what is going on.

Michael-F-Ellis commented 6 months ago

Cloned and ran per your instructions. Restarted kernel in VsCode notebook window. No errors reported at startup, and everything runs fine but there's no log output in the terminal.

Running ps ax | grep gonb shows

14316   ??  S      0:00.08 /Users/mellis/Library/Jupyter/kernels/gonb/gonb --kernel /Users/mellis/Library/Jupyter/runtime/kernel-v2-14086GREYoI1fW6m5.json --vmodule=goplsclient=2,exec=2,conn=2 --logtostderr

along with some socket connections to gopls.

It's clearly communicating with gopls because I'm getting syntax highlighting and completion suggestions when I type. Just no help when I mouse over a symbol.

As a sanity check, I created a Python notebook and ran it under the Jupyter Python kernel in VsCode. Mouse over help works as expected there.

janpfeifer commented 6 months ago

Ok, I don't have VSCode here now (the following weekend I'll have), so I'm guessing blindly here ...

In my laptop I run jupyter-lab manually, and the logs show up in the terminal where I run jupyter-lab. I'm assuming VSCode runs jupyter-lab (or jupyter-server) directly and redirects the logs somewhere else.

gonb has another flag that may be helpful here, --extra_log. If you can, try:

go run . --install --logtostderr --vmodule=goplsclient=2,exec=2,conn=2 --extra_log=/tmp/gonb.log

And you should see the logs going on in /tmp/gonb.log (or change it to whatever you want).

You'll need to restart jupyter, so it re-reads the configuration for the kernel...

Notice it won't fix the issue, but maybe you will see if requests to gopls are happening.

Btw, just for sanity sake, it may be worth updating gopls: go install golang.org/x/tools/gopls@latest.

Michael-F-Ellis commented 6 months ago

That's more like it! Thanks. So when I tail -f /tmp/gonb.log, it shows startup messages and messages whenever I execute a cell, e.g.,

I0322 14:40:59.313398   19464 jpyexec.go:153] [13ddd5e7] Executing: /var/folders/qg/3yynzg3n0cn43w9x9bpd5c0c0000gn/T/gonb_13ddd5e7/gonb_13ddd5e7 []

for cells that execute without error. Cells with errors produce a trace that looks pretty standard.

What I don't see is any traffic with gopls no matter what I do within the cell with mouse or keyboard.

Which is funny, because there's clearly communication with a language server since I'm getting highlighting and autocomplete. (BTW, I did upgrade gopls to latest)

janpfeifer commented 6 months ago

Thanks for checking it @Michael-F-Ellis !

So, in that case, the next thing I would look for is what is transpiring in the protocol between JupyterServer and gonb. If you add --vmodule=...,messages=2,kernel=2 to your gonb configuration, it will print it out.

It should display the requests for auto-complete/context help there. The protocol is described here. Inside gonb all the protocols going on are described in the FrontEnd Communication document -- it has a diagram in the bottom.

I mean, I was hoping it would be something simpler than having to dive into all these ... but just in case you are curious or need to understand something.

Michael-F-Ellis commented 6 months ago

So here's the message stream from a successful cell execution with the new build.

I0322 15:40:48.821401   23497 jpyexec.go:153] [825a1ae0] Executing: /var/folders/qg/3yynzg3n0cn43w9x9bpd5c0c0000gn/T/gonb_825a1ae0/gonb_825a1ae0 []
I0322 15:40:48.829601   23497 messages.go:268] [825a1ae0] [IOPub] Publish message "stream" -- parent msg_id="0392cadf-5ea1-4a75-a2f2-a5f7d57e7c9d"
I0322 15:40:48.830067   23497 messages.go:340] [825a1ae0] [Shell] Reply message "execute_reply", parent msg_id="0392cadf-5ea1-4a75-a2f2-a5f7d57e7c9d"
I0322 15:40:48.830297   23497 messages.go:268] [825a1ae0] [IOPub] Publish message "status" -- parent msg_id="0392cadf-5ea1-4a75-a2f2-a5f7d57e7c9d"

I0322 15:42:19.182319   23497 messages.go:268] [825a1ae0] [IOPub] Publish message "status" -- parent msg_id="7e1cc54b-4acf-4bc1-8e6a-42dc0371311c"
I0322 15:42:19.182807   23497 messages.go:268] [825a1ae0] [IOPub] Publish message "execute_input" -- parent msg_id="7e1cc54b-4acf-4bc1-8e6a-42dc0371311c"
I0322 15:42:20.026027   23497 jpyexec.go:153] [825a1ae0] Executing: /var/folders/qg/3yynzg3n0cn43w9x9bpd5c0c0000gn/T/gonb_825a1ae0/gonb_825a1ae0 []
I0322 15:42:20.031926   23497 messages.go:268] [825a1ae0] [IOPub] Publish message "stream" -- parent msg_id="7e1cc54b-4acf-4bc1-8e6a-42dc0371311c"
I0322 15:42:20.032228   23497 messages.go:340] [825a1ae0] [Shell] Reply message "execute_reply", parent msg_id="7e1cc54b-4acf-4bc1-8e6a-42dc0371311c"
I0322 15:42:20.032402   23497 messages.go:268] [825a1ae0] [IOPub] Publish message "status" -- parent msg_id="7e1cc54b-4acf-4bc1-8e6a-42dc0371311c"

Still seeing no traffic in response to any mouse or kbd action.

janpfeifer commented 6 months ago

Sorry for the delay @Michael-F-Ellis, I was on a business trip, and didn't have an opportunity to investigate it earlier.

So vanilla VSCode won't talk Jupyter's Completion protocol. It relies on IntelliSense (according to this at least) for Python.

Let me see if there are any plugins that will make it work ... in the mean time I'm adding a document on the limitations/information on VSCode.

Pls, let me know if you have any hints/tricks on that so I can add there. I'm going to take a look at Polyglot next.

ps.: I also confirmed that VSCode won't allow any javascript in its output, so Plotly and Widgets won't work there :( I figure it must be the same with Python.

janpfeifer commented 6 months ago

I intalled VSCode+Polyglot locally, but indeed it doesn't work with Go, they state that in their homepage.

I created a https://github.com/dotnet/interactive/issues/3511, check it out/subscribe to it ?