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

VSCodium Error: `string::2: read: expected a ')' to close '('` #114

Closed EdThePro101 closed 1 year ago

EdThePro101 commented 1 year ago

Environment

Error message

string::2: read: expected a `)` to close `(`

Additional context

When using the normal command prompt (cmd.exe) as my terminal in VS Codium, this error occurs. But when I switch to Powershell, this error doesn't occur. The reason this error occurs is because single quotes don't function as pairs like double quotes do.

Let's say that running the REPL executes the following command:

racket --repl --eval '(enter! (file "/path/to/hello-world.rkt"))'

In Powershell, this works fine because it knows how to use single quotes. But in Command Prompt, it does not work because it reads:

racket --repl --eval '(enter! (file "/path/to/hello-world.rkt"))'

command: racket
`---- argument: --repl
`---- argument: --eval
`---- argument: '(enter!
`---- argument: (file
`---- argument/string: "/path/to/hello-world.rkt"))'

Idea 1: Detect which terminal the user is using.

If the user is using Command Prompt, run the specific command that will work for the terminal. Otherwise, run the Powershell or Bash friendly command.

Idea 2: Provide the --eval string using double quotes.

racket --repl --eval "(enter! (file \"/path/to/hello-world.rkt\"))"

Here, we replaced the single quotes with double quotes and escaped the embedded double quotes via \".

EdThePro101 commented 1 year ago

Another error (both Powershell and Command Prompt):

When clicking the run button to run the Racket file, Magic Racket runs the following:

racket c\:/Users/USER/OneDrive/Documents/Projects/hello-world.rkt

Note the c\:/Users part. This causes some whacky bugs in one of my projects:

open-input-file: cannot open module file
  module path: #<path:C:\Users\USER\OneDrive\Documents\Projects\wordle-rkt\c\:\Users\USER\OneDrive\Documents\Projects\wordle-rkt\make-5-letter-word-list.rkt>
  path: C:\Users\USER\OneDrive\Documents\Projects\wordle-rkt\c\:\Users\USER\OneDrive\Documents\Projects\wordle-rkt\make-5-letter-word-list.rkt
  system error: The filename, directory name, or volume label syntax is incorrect.; win_err=123

Here's the function where the file is read:

(define (read-word-list filename)
  (with-input-from-file filename
    (lambda ()
      (for/list ([word (in-lines)]
                 #:when (has-5-letters word))
        word))))

The proper formation for Windows paths is either using only back slashes (\) or forward slashes (/). However, there is a simpler option (may work for other platforms also):

racket "C:/Users/USER/OneDrive/Documents/Projects/hello-world.rkt"

By using double quotes, we also take note that some users might have spaces in their directory names. And by using forward slashes, we avoid the need for escaping the backslash (\\).

jryans commented 1 year ago

Thanks for reporting these issues!

Magic Racket version: 0.6.2

The latest version is 0.6.5. Have you tried updating to 0.6.5 to see if there's any change?

Quoting for cmd

I am a bit confused about the first cmd quoting issue because the extension is trying to produce the following for cmd:

https://github.com/Eugleo/magic-racket/blob/ae19c951607a824f26330db2ee5cbff8fb5b44c0/src/repl.ts#L91

...but that's not what you are seeing. It feels like the cmd shell detection is failing for some reason... Currently the extension tries to detect with vscode.env.shell.endsWith("cmd.exe"). Does that fail for your case? Perhaps it would be good to know the value of vscode.env.shell when you use cmd.

File paths

Similarly for this part, I am also a bit confused... The extension tries to change all slashes:

https://github.com/Eugleo/magic-racket/blob/ae19c951607a824f26330db2ee5cbff8fb5b44c0/src/utils.ts#L24-L29

...so I wonder why that would be missing one of them in your case.

EdThePro101 commented 1 year ago

Have you tried updating to 0.6.5 to see if there's any change?

Both VS Codium and Open VSX Registry shows only up to version 0.6.2...

image

image

Regarding vscode.env.shell, I am not so sure how to view it as I have tried searching Google and it only told me about OS environment variables. Also asked Bing chat, but it said that terminal.integrated.shell is the same as vscode.env.shell. Perhaps my VS Codium settings.json file might help?

{
    "python.defaultInterpreterPath": "C:\\Users\\USER\\AppData\\Local\\Programs\\Python\\Python311\\python.exe",
    "window.zoomLevel": 1,
    "editor.fontSize": 16,
    "editor.fontFamily": "\"Fira Code\", \"Source Code Pro\", \"Noto Mono\", Consolas, 'Courier New', monospace",
    "editor.minimap.renderCharacters": false,
    "editor.minimap.scale": 3,
    "editor.minimap.autohide": true,
    "explorer.confirmDelete": false,
    "files.autoSave": "afterDelay",
    "files.autoSaveDelay": 10000,
    "workbench.iconTheme": "material-icon-theme",
    "workbench.colorTheme": "GitHub Dark",
    "python.linting.pylintEnabled": true,
    "editor.formatOnSave": true,
    "python.formatting.provider": "black",
    "terminal.integrated.defaultProfile.windows": "Command Prompt",
    "editor.fontLigatures": true,
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash"
        },
        "Windows PowerShell": {
            "path": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
        }
    },
}
jryans commented 1 year ago

Both VS Codium and Open VSX Registry shows only up to version 0.6.2...

Ah indeed, it seems the last few versions weren't published to Open VSX unfortunately. I'll investigate this and see what we can do to fix it going forward.

Regarding vscode.env.shell, I am not so sure how to view it as I have tried searching Google and it only told me about OS environment variables. Also asked Bing chat, but it said that terminal.integrated.shell is the same as vscode.env.shell. Perhaps my VS Codium settings.json file might help?

    "terminal.integrated.defaultProfile.windows": "Command Prompt",
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash"
        },
        "Windows PowerShell": {
            "path": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
        }
    },
}

Hmm, your "Command Prompt" profile there seems a bit odd: why is path defined as array with two programs in it? https://code.visualstudio.com/docs/terminal/profiles suggests path should be a single value, not an array. (It's possible there's some advanced feature I don't know about here, if so please pass along a link so I can read more about it.)

EdThePro101 commented 1 year ago

Hmm... I did a bit of Googling and came across this: Sysnative folder in Windows 64-bit explained.

Apparently, it is a virtual folder that just points to System32? It's the first time I'm hearing about this 😵

I removed the first option that points to Sysnative, so path only has one string assigned to it:

"Command Prompt": {
    "path": "${env:windir}\\System32\\cmd.exe",
    "args": [],
    "icon": "terminal-cmd"
},

Apart from speed improvement in terminal creation, everything looks the same:

image

image

(Does Magic Racket attempt to clear the terminal before running the program? I am noticing that clear is entered into the terminal when I click the run button. In Command Prompt cls is used instead.)

The extension seems to work perfectly in Git Bash :smile:

jryans commented 1 year ago

I removed the first option that points to Sysnative, so path only has one string assigned to it:

"Command Prompt": {
    "path": "${env:windir}\\System32\\cmd.exe",
    "args": [],
    "icon": "terminal-cmd"
},

Apart from speed improvement in terminal creation, everything looks the same:

Hmm, curious, so it's still not being detected correctly... Would you be open to trying a test build of the extension? I'd like to add some extra logging to see what value the extension is seeing for your shell.

(Does Magic Racket attempt to clear the terminal before running the program? I am noticing that clear is entered into the terminal when I click the run button. In Command Prompt cls is used instead.)

It does know to use cls in certain cases, but this also depends on detecting the appropriate shell.

EdThePro101 commented 1 year ago

Hmm, curious, so it's still not being detected correctly... Would you be open to trying a test build of the extension? I'd like to add some extra logging to see what value the extension is seeing for your shell.

Sure! I'd be happy to help! 😄

How would I go about setting up the test build?

jryans commented 1 year ago

I've added some logging of the extension environment that should help us work out what's happening here.

I have attached a development build of the extension with this new code below.

magic-racket.vsix.zip

To test this out, try something like the following:

  1. Download and unzip the file above
  2. Run codium --install-extension magic-racket.vsix or some other means of installing from the file
  3. Reload a window with a Racket file in it
  4. Look for an output channel called "Racket"
  5. Copy the environment info shown there into this issue (should say "Magic Racket environment info" at the top)
EdThePro101 commented 1 year ago

It is installed! :smiley:

It appears to be working as expected now (In the Extensions tab it shows that the installed extension is version 0.6.5, previously 0.6.2). This is the output that I see for cmd.exe:

image

When I click the Run button, it runs perfectly:

image

When I click the Run in REPL button, it runs perfectly in cmd.exe as well:

image

Also tried running in Powershell. Both the Run and Run in REPL buttons work as expected as well. The vscode.env.shell points to C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe.

Also tried Git Bash, works perfectly. The vscode.env.shell points to C:\Program Files\Git\bin\bash.exe.

VSCodium verssion:

1.80.0
9d3b0fa210fb4535589e8296483a5b43fe5e660a
x64

Thanks for making this extension devs 😁 Have an amazing weekend :heart:

jryans commented 1 year ago

Aha, that's great to hear! It looks like existing changes after 0.6.2 were enough to resolve the issues you saw, so really the main problem was the outdated version on Open VSX.

I have opened a separate issue (https://github.com/Eugleo/magic-racket/issues/116) for the Open VSX publishing part, so please follow that for updates so you can switch back to that version once it's available and receive updates in the future.