sveltejs / vite-plugin-svelte

Svelte plugin for http://vitejs.dev/
MIT License
864 stars 105 forks source link

Inspector fails to open if vscode path has spaces or accented characters. #608

Closed olafurw closed 1 year ago

olafurw commented 1 year ago

Describe the bug

On a Windows machine and using the inspector, hitting Shift+Ctrl, I get the svelte selection but when I click on a component, I get this error.

Could not open +page.svelte in the editor.
The editor process exited with an error: (code 1).      

'C:\Users\Olafur' is not recognized as an internal or external command,
operable program or batch file.

VSCode is inside of this path C:\Users\Ólafur Waage\AppData\Local\Programs\Microsoft VS Code.

It's both missing the accent above the Ó and it doesn't show my last name, which has spaces after the first name.

Reproduction URL

http://example.com

Reproduction

I can't show a reproduction URL because I can't change the paths of where vscode and the project is within StackBlitz.

Using Windows 10, happens both if I run it through Powershell or the windows cmd.

Logs

The logs are the same regardless of if I run it with --debug or not.

Could not open +page.svelte in the editor.
The editor process exited with an error: (code 1).      

'C:\Users\Olafur' is not recognized as an internal or external command,
operable program or batch file.

### System Info

```shell
npx envinfo --system --binaries --browsers --npmPackages "{svelte,svelte-hmr,@sveltejs/*,vite}"

  System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 
3.00GHz
    Memory: 4.50 GB / 31.73 GB
  Binaries:
    Node: 18.12.1 - C:\Program Files\nodejs\node.EXE    
    npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD       
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (111.0.1661.44)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.0.0
    @sveltejs/kit: ^1.13.0 => 1.13.0
    svelte: ^3.57.0 => 3.57.0
    vite: ^4.2.1 => 4.2.1
dominikg commented 1 year ago

known issue with launch-editor, used via vite's openInEditor middleware: https://github.com/yyx990803/launch-editor/issues/35

dominikg commented 1 year ago

I don't expect this to get fixed soon, would recommend using a home directory without spaces or other special characters in it, or if that doesn't work, maybe you can create C:\develop and put your projects there .

Yes, the situation is unfortunate, but problems with non-ascii characters and spaces in paths are still common in even in 2023.

dominikg commented 1 year ago

For the launch command you may be able to use the LAUNCH_EDITOR environment variable, put a script without spaces in there and call the properly quoted path from that script

olafurw commented 1 year ago

My project is in c:\work it's the location of vscode that's messing this up.

Thanks for the suggestions and the link to the other bug. Cheers.

olafurw commented 1 year ago

Here's a Windows .bat file that people can repurpose as they wish if anyone finds this bug report.

You save this in a location with no spaces or accented characters and point to it using the LAUNCH_EDITOR environment variable.

@echo off
set filename=%1
set line=%2
set column=%3
"%appdata%\..\Local\Programs\Microsoft VS Code\Code.exe" -r -g "%filename%":%lineNumber%:%columnNumber%
henrikvilhelmberglund commented 1 year ago

For me filename already included the quotation marks so the extra ones caused it to go a bit haywire with file names containing spaces. If that's the case for someone else try this:

@echo off
set filename=%1
set lineNumber=%2
set columnNumber=%3
"%appdata%\..\Local\Programs\Microsoft VS Code\Code.exe" -r -g %filename%:%lineNumber%:%columnNumber%

Thanks for the .bat! 😄