microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.71k stars 29.08k forks source link

Wrong user-data-dir assumed when started from CLI #210772

Closed FatalMerlin closed 6 months ago

FatalMerlin commented 6 months ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

  1. Ensure neither ~/Code nor ~/.config/Code exist.
  2. Install VS Code from latest .deb file
  3. Launch VS Code from UI
  4. Observe it creating ~/.config/Code
  5. Close VS Code
  6. Launch VS Code from Terminal: code
  7. Notice that new folder ~/Code was created, instead of under ~/.config/Code

Note: also works properly when run via Gnome's "Run a command" dialog (ALT + F2). Note: also tested on 1.87.2

The bug appears regardless of command line arguments supplied (e.g. code path/to/project/dir) but can be semi-circumvented with explicit --user-data-dir ~/.config/Code.

I also noticed that when ran from the terminal, it also creates the ibus directory in the home dir and also launches the wrong default browser, e.g. when logging in to settings sync. It's almost as if the app somehow thinks that my $HOME is $HOME/.config for some reason. This is reinforced by the config dir for the launched browser also appearing in my $HOME folder when launched from VS Code in this scenario (e.g. ~/google-chrome instead of ~/.config/google-chrome).

This is a pretty fresh install of Debian so I did not yet have time to implement too many oddities on the system, however I did recently install a similar machine but I do not remember this occurring there.

I have verified that it is neither my terminal emulator (tried both GNOME Terminal and Warp Terminal) nor my $SHELL (tried both bash and zsh.

Even when copying the launch command from the /usr/share/applications/code.desktop file, the same issue occurs.

When running with code --verbose the 2nd line already points to the wrong directory:

[main 2024-04-19T17:42:43.072Z] [File Watcher (node.js)] Request to start watching: /home/fatalmerlin/Code/User (excludes: <none>, includes: <all>, correlationId: <none>),/home/fatalmerlin/Code/User/settings.json (excludes: <none>, includes: <all>, correlationId: <none>)
[main 2024-04-19T17:42:43.081Z] Starting VS Code
[main 2024-04-19T17:42:43.081Z] from: /usr/share/code/resources/app
deepak1556 commented 6 months ago

Is $XDG_CONFIG_HOME set on your machine ? Based on the info it is very likely we are using it to create the user data folder https://github.com/microsoft/vscode/blob/2ce94ec26a00be22c2fa2fe8863794eded31a3c4/src/vs/platform/environment/node/userDataPath.js#L95 which is expected per https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html.

But it is a bug that the launch from desktop uses a different user data folder in this case.

FatalMerlin commented 6 months ago

omg that was it :D thanks @deepak1556 ! somehow ended up as my user home.