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
202 stars 28 forks source link

racket-langserver didn't work in a devcontainer, and a workaround #51

Closed SFurnace closed 2 years ago

SFurnace commented 3 years ago

Environment

Error message

I use xvfb-run racket in a devcontainer, but racket-langserver doesn't work. I only get error message like that:

[Error - 下午2:22:06] Starting client failed
Launching server using command xvfb-run racket failed.

Workaround

I tried many times, and finally found if I change the serverOptions in extension.js from

        const executable = {
            command: racket,
            args: ["--lib", "racket-langserver"],
        };

to

        const executable = {
            command: racket,
            args: ["--lib", "racket-langserver"],
            options: { shell: true }
        };

then racket-langserver can work correctly. I guess vscode can communicate with the xvfb-run racket process by stdin/out, only when wrapping in a shell.

By the way, I put my devcontainer.json at here.

sdjdd commented 3 years ago

Doesn't work for me. My solution:

create a bash script xvfb-racket:

#!/bin/bash

for i in $*;
do
    params=" $params $i"
done

xvfb-run racket $params

add to $PATH

change the Racket Path config to xvfb-racket.

SFurnace commented 3 years ago

Doesn't work for me. My solution:

create a bash script xvfb-racket:

#!/bin/bash

for i in $*;
do
    params=" $params $i"
done

xvfb-run racket $params

add to $PATH

change the Racket Path config to xvfb-racket.

Maybe "$@" is a better way?

rocketnia commented 2 years ago

Just as @SFurnace suggested, I got this working using:

#!/bin/bash

xvfb-run racket "$@"

I'm using VS Code with the Magic Racket extension in Windows 10, talking to racket-langserver in a VirtualBox VM running Linux Mint.

Eugleo commented 2 years ago

Hey guys, is there anything I can do to make this simpler for you? Assuming no, closing issue, will re-open if need be. I will also link to this issue from the readme so that others can follow your instructions to get it working.

Eugleo commented 2 years ago

In the v0.6.0 it is possible to configure the command and the args that are used to launch the langserver. It should be possible to set the command to xvfb-run and the args to racket, [...and the args that are there by default].

elmisback commented 2 years ago

Confirming xvfb-run + racket --lib racket-langserver works on Windows WSL on v0.6.1.

elmisback commented 2 years ago

Another note--if multiple VSCode windows are opened, I found the --auto-servernum / -a argument to xvfb-run was required to avoid xvfb failing due to the default server number already being in use.

brettgilio commented 2 years ago

Doesn't work for me. My solution: create a bash script xvfb-racket:

#!/bin/bash

for i in $*;
do
    params=" $params $i"
done

xvfb-run racket $params

add to $PATH change the Racket Path config to xvfb-racket.

Maybe "$@" is a better way?

@Eugleo It would be nice if this file were included in either the magic-racket distribution as an in-built fallback. If the server fails to initialize then the bash sugar could be executed. I tried to use magic-racket today using https://github.com/gitpod-io/openvscode-server on a headless server and found myself having to tweak all kinds of things until I found this issue.

Halkcyon commented 2 years ago

Just to put this all together since I was setting this up from a fresh WSL2 Ubuntu install, I needed to take the following steps.

Dependencies:

$ sudo apt install -y --no-install-recommends \
    racket \
    libjpeg62-dev \
    libgtk2.0-dev \
    xvfb
$ raco pkg install racket-langserver

Script wrapper:

$ cat << EOF > xvfb-racket
#!/usr/bin/env bash
xvfb-run --auto-servernum racket "$@"
EOF
$ chmod +x xvfb-racket

Then I needed to point my configuration at it:

{
  "magicRacket.languageServer.command": "/home/$USERNAME/xvfb-racket",
  "magicRacket.general.racketPath": "/home/$USERNAME/xvfb-racket"
}

This made the extension work on files saved to disk, but not anonymous files in the editor.

enricopolanski commented 1 year ago

I tried to follow all of the comments here, using WSL 2 + Ubuntu 22.04.

It doesn't work for me.

In VSCode I get:

[Info  - 4:37:16 PM] Connection to server got closed. Server will restart.
[Info  - 4:37:17 PM] Connection to server got closed. Server will restart.
[Info  - 4:37:17 PM] Connection to server got closed. Server will restart.
[Info  - 4:37:17 PM] Connection to server got closed. Server will restart.
[Error - 4:37:17 PM] Connection to server got closed. Server will not be restarted.

If I try to execute highlight in REPL I get:

➜ /home/aquazi/xvfb-racket --repl --eval '(enter! (file "/home/aquazi/bench/racket-experiments/foo.rkt"))'
racket: bad module path: '(file "") derived from command-line argument: 

➜  racket-experiments "hello world"
hello world: command not found
aidenstern commented 1 year ago

This worked for me on WSL2 + Ubuntu 22.04

Dependencies:

$ sudo apt install -y --no-install-recommends \
    racket \
    libjpeg62-dev \
    libgtk2.0-dev \
    xvfb
$ raco pkg install racket-langserver

VSCode configuration:

}
    "magicRacket.languageServer.command": "xvfb-run",
    "magicRacket.languageServer.arguments": [
        "--auto-servernum",
        "racket",
        "--lib",
        "racket-langserver"
    ],
}