Eugleo / magic-racket

The best coding experience for Racket in VS Code
https://marketplace.visualstudio.com/items?itemName=evzen-wybitul.magic-racket
GNU General Public License v3.0
199 stars 29 forks source link

LSP not connecting to Racket installed via Snap #109

Closed madkins23 closed 1 year ago

madkins23 commented 1 year ago

Environment

OS

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:    22.04
Codename:   jammy

VSCode

Version: 1.79.2
Commit: 695af097c7bd098fbf017ce3ac85e09bbc5dda06
Date: 2023-06-14T08:59:55.818Z
Electron: 22.5.7
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Linux x64 5.15.0-75-generic snap

Racket

Welcome to Racket v8.9 [cs].

Magic Racket v0.6.5 Racket LSP 570b19570db40647c5ae69c73a67d3a05466a465

Error message

Output > Racket Language Client

[Info  - 6:36:12 AM] Connection to server got closed. Server will restart.
[Info  - 6:36:12 AM] Connection to server got closed. Server will restart.
[Info  - 6:36:12 AM] Connection to server got closed. Server will restart.
[Info  - 6:36:12 AM] Connection to server got closed. Server will restart.
[Error - 6:36:12 AM] Connection to server got closed. Server will not be restarted.

Output > Extension Host

2023-06-23 06:38:09.916 [info] ExtensionService#_doActivateExtension evzen-wybitul.magic-racket, startup: false, activationEvent: 'onLanguage:racket'
2023-06-23 06:38:11.255 [error] Error: Connection to server got closed. Server will not be restarted.
    at LanguageClient.handleConnectionClosed (/home/marc/.vscode/extensions/evzen-wybitul.magic-racket-0.6.5/node_modules/vscode-languageclient/lib/common/client.js:2442:47)
    at LanguageClient.handleConnectionClosed (/home/marc/.vscode/extensions/evzen-wybitul.magic-racket-0.6.5/node_modules/vscode-languageclient/lib/node/main.js:155:15)
    at closeHandler (/home/marc/.vscode/extensions/evzen-wybitul.magic-racket-0.6.5/node_modules/vscode-languageclient/lib/common/client.js:2411:18)
    at CallbackList.invoke (/home/marc/.vscode/extensions/evzen-wybitul.magic-racket-0.6.5/node_modules/vscode-jsonrpc/lib/common/events.js:55:39)
    at Emitter.fire (/home/marc/.vscode/extensions/evzen-wybitul.magic-racket-0.6.5/node_modules/vscode-jsonrpc/lib/common/events.js:117:36)
    at closeHandler (/home/marc/.vscode/extensions/evzen-wybitul.magic-racket-0.6.5/node_modules/vscode-jsonrpc/lib/common/connection.js:256:26)
    at CallbackList.invoke (/home/marc/.vscode/extensions/evzen-wybitul.magic-racket-0.6.5/node_modules/vscode-jsonrpc/lib/common/events.js:55:39)
    at Emitter.fire (/home/marc/.vscode/extensions/evzen-wybitul.magic-racket-0.6.5/node_modules/vscode-jsonrpc/lib/common/events.js:117:36)
    at StreamMessageReader.fireClose (/home/marc/.vscode/extensions/evzen-wybitul.magic-racket-0.6.5/node_modules/vscode-jsonrpc/lib/common/messageReader.js:40:27)
    at Socket.<anonymous> (/home/marc/.vscode/extensions/evzen-wybitul.magic-racket-0.6.5/node_modules/vscode-jsonrpc/lib/common/messageReader.js:125:42)
    at Socket.emit (node:events:525:35)
    at Pipe.<anonymous> (node:net:757:14)

Output > Pty Host

2023-06-23 06:38:12.466 [warning] Persistent process "1": Process had no disconnect runners but was an orphan
2023-06-23 06:38:12.470 [info] Persistent process reconnection "1"
2023-06-23 06:38:12.473 [warning] Persistent process "2": Process had no disconnect runners but was an orphan
2023-06-23 06:38:12.474 [info] Persistent process reconnection "2"
2023-06-23 06:38:12.477 [warning] Persistent process "3": Process had no disconnect runners but was an orphan
2023-06-23 06:38:12.478 [info] Persistent process reconnection "3"
2023-06-23 06:38:12.478 [warning] Persistent process "4": Process had no disconnect runners but was an orphan
2023-06-23 06:38:12.478 [info] Persistent process reconnection "4"
2023-06-23 06:38:12.480 [warning] Persistent process "5": Process had no disconnect runners but was an orphan
2023-06-23 06:38:12.480 [info] Persistent process reconnection "5"
2023-06-23 06:38:12.526 [info] Persistent process "1": Replaying 1661 chars and 1 size events
2023-06-23 06:38:12.557 [info] Persistent process "2": Replaying 834 chars and 1 size events
2023-06-23 06:38:12.572 [info] Persistent process "3": Replaying 1387 chars and 1 size events
2023-06-23 06:38:12.583 [info] Persistent process "4": Replaying 794 chars and 1 size events
2023-06-23 06:38:12.593 [info] Persistent process "5": Replaying 1046 chars and 1 size events

Output > Racket Language Server

None. Doesn't get that far.

Additional context

Triggers when I edit a .rkt file. If I start in that file it happens immediately. If I start in another type of file it doesn't happen until I switch to a .rkt file.

I have a Go program that was able to connect to the Racket LSP. It takes 4 seconds when I hit the raco-installed library and 8 seconds when I use racket to bring the source for the LSP up from scratch. I am able to send the initialization request and get an appropriate response back so the LSP is properly configured.

I tried various commands and command paths for the LSP, thinking that perhaps the extension couldn't find stuff. Nothing made any difference.

I forked and downloaded both Magic Racket and the Racket LSP so that I could try to debug through them. I didn't get very far. The VSCode Language Extension code is large and gnarly and I am not able to find a lot of detailed documentation on it, just examples online. I can step though the code in extension.ts but whatever is breaking is happening in the "background" and since it's all single threaded with futures it doesn't happen anywhere I can easily step through. Check out the stack trace above, there's none of the Magic Racket code in there.

At one point when I was attempting to put breakpoints in VSCode Language Extension code I was able to get some message about exceeding a one second timeout. Not sure where that really was happening and I can't find any documentation on setting up the LanguageClient that mentions any timeouts. Reference my comment earlier on 4 second startup of the LSP but also note from the Output > Racket Language Client output that all attempts occurred in the same second.

Note: Racket is installed via snap and "lives" at /snap/bin/racket which is a symbolic link to /usr/bin/snap which apparently knows how to run the actual program. The /snap/bin directory is on my PATH. I tracked down the actual binary file in /snap/racket/current/usr/bin/racket and tried that for the path in the extension settings but it failed the same way. I even copied the binary out so that I could reference it directly instead of via the weird /snap/bin pseudo-directory but still no dice.

I can't remember all of the other stuff I've tried, so it's time to file this issue.

madkins23 commented 1 year ago

OK, I just removed the snap-installed version of racket and installed from the download site. Now it works. So I guess the problem is snap. I doubt that it's your problem. It's probably the VSCode Language Extension code.

AFAIK things are working. I'm getting useful warnings (e.g. require not used in this file) and popups with doc about specific functions. That looks like the stuff that the LSP is supposed to provide.

As a side note, the only error message I'm getting now is:

/snap/core20/current/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /lib/x86_64-linux-gnu/libproxy.so.1)
Failed to load module: /home/marc/snap/code/common/.cache/gio-modules/libgiolibproxy.so

So still snap-related, I guess, though it doesn't seem to be hurting anything thus far. Sigh.

madkins23 commented 1 year ago

I can now verify that all is working correctly. I have a log file of message traffic between magic-racket and racket-langserver (attached). This issue can be closed, I'm leaving it open for now so that you will know what happened. Might be worth a mention in the README.md file.

jryans commented 1 year ago

Thanks for filing this issue! I'm glad you were at least able to get things working, even if you did have to change how Racket is installed.

The lang server requires some of the same graphical components that DrRacket uses, and perhaps the Snap version is quite packaged correctly for all those to work...? In any case, it does seem to be an issue with Snap packaging as you deduced.

I'll add a note about this to README pointing to this issue. Hopefully that will help others as well.