Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support XDG_CONFIG_HOME for the argv.json file #162712

Open
Tracked by #199688
lgarron opened this issue Oct 5, 2022 · 14 comments · May be fixed by #170364
Open
Tracked by #199688

Support XDG_CONFIG_HOME for the argv.json file #162712

lgarron opened this issue Oct 5, 2022 · 14 comments · May be fixed by #170364
Labels
feature-request Request for new features or functionality good first issue Issues identified as good for first-time contributors help wanted Issues identified as good community contribution opportunities linux Issues with VS Code on Linux workbench-os-integration Native OS integration issues
Milestone

Comments

@lgarron
Copy link

lgarron commented Oct 5, 2022

There are many of us who find it bad practice that VSCode creates a ~/.vscode/ folder instead of following the common XDG base directory structure, respected by a wide variety of programs. This issue has come up regularly, without a good permanent solution:

I would like to propose the following new behaviour:

  1. If ~/.config/vscode/argv.json1 is present at launch in non-portable mode, then VSCode uses this as the path for argv.json.
  2. argv.json supports setting the following arguments, which the user can set to XDG-compatible paths if they like:
  • user-data-dir
  • extensions-dir

As far as I can tell, this would be sufficient to avoid creating a ~/.vscode/ folder. It also reuses the existing structure of VSCode to do this without introducing significant hacks, edge cases, or race conditions.

Part 1 seems reasonably feasible to me, given that argv.json is hardcoded in delightfully few places at the moment: https://github.com/microsoft/vscode/search?q=%22argv.json%22&type=code

Part 2 would essentially involve adding those arguments to SUPPORTED_ELECTRON_SWITCHES.

I'd be happy to submit a PR if this kind of approach is amenable to the maintainers.

Footnotes

  1. If a non-branded or non-Insiders build is launched, this would generalize to ~/.config/[prefix]code[suffix]/argv.json, per https://github.com/microsoft/vscode/issues/3884 . This is deterministic for any given installed build.

@lgarron lgarron changed the title Proposal: minimal changes to allow XDG-compatible data storage. Proposal: minimal changes to allow XDG-compatible data storage (and avoid ~/.vscode/) Oct 5, 2022
@roblourens roblourens assigned deepak1556 and unassigned roblourens Oct 5, 2022
lgarron added a commit to lgarron/vscode that referenced this issue Oct 20, 2022
If it's not available, fall back to reading and/or creating `~/.[product-name]/argv.json`.

This addresses microsoft#162712

Unfortunately, there is an issue in that
`AbstractNativeEnvironmentService.argvResource()` does not have access
to the filesystem directly. It will need further work to fall back from
one location to another.
lgarron added a commit to lgarron/vscode that referenced this issue Oct 20, 2022
…vention).

If it's not available, fall back to reading and/or creating `~/.[product-name]/argv.json`.

See `$XDG_CONFIG_HOME` at https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
This will allow VSCode to avoid creating new dirs in the home folder, matching a large number of other programs: https://wiki.archlinux.org/index.php/XDG_Base_Directory_support

This addresses microsoft#162712

Unfortunately, there is an issue in that
`AbstractNativeEnvironmentService.argvResource()` does not have access
to the filesystem directly. It will need further work to fall back from
one location to another.
lgarron added a commit to lgarron/vscode that referenced this issue Oct 20, 2022
…vention).

If it's not available, fall back to reading and/or creating `~/.[product-name]/argv.json`.

See `$XDG_CONFIG_HOME` at https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
This will allow VSCode to avoid creating new dirs in the home folder, matching a large number of other programs: https://wiki.archlinux.org/index.php/XDG_Base_Directory_support

This addresses microsoft#162712

Unfortunately, there is an issue in that
`AbstractNativeEnvironmentService.argvResource()` does not have access
to the filesystem directly. It will need further work to fall back from
one location to another.
lgarron added a commit to lgarron/vscode that referenced this issue Oct 20, 2022
…vention).

If it's not available, fall back to reading and/or creating `~/.[product-name]/argv.json`.

See `$XDG_CONFIG_HOME` at https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
This will allow VSCode to avoid creating new dirs in the home folder, matching a large number of other programs: https://wiki.archlinux.org/index.php/XDG_Base_Directory_support

This addresses microsoft#162712

Unfortunately, there is an issue in that
`AbstractNativeEnvironmentService.argvResource()` does not have access
to the filesystem directly. It will need further work to fall back from
one location to another.
@bpasero bpasero assigned bpasero and unassigned deepak1556 Nov 7, 2022
@bpasero bpasero added linux Issues with VS Code on Linux workbench-os-integration Native OS integration issues portable-mode VS Code portable mode issues labels Nov 7, 2022
@bpasero bpasero removed their assignment Nov 23, 2022
@bpasero bpasero added the feature-request Request for new features or functionality label Nov 23, 2022
@bpasero bpasero added this to the Backlog milestone Nov 23, 2022
@bpasero bpasero self-assigned this Dec 7, 2022
@bpasero bpasero removed the portable-mode VS Code portable mode issues label Dec 7, 2022
@bpasero
Copy link
Member

bpasero commented Dec 7, 2022

I agree that we should respect the XDG_CONFIG_HOME variable as we do here:

appDataPath = process.env['XDG_CONFIG_HOME'] || path.join(os.homedir(), '.config');

Where we currently just use os.homedir().

I would leave out the part that allows to configure the user data dir, that seems like a separate request.

@bpasero bpasero added help wanted Issues identified as good community contribution opportunities good first issue Issues identified as good for first-time contributors labels Dec 7, 2022
@bpasero bpasero changed the title Proposal: minimal changes to allow XDG-compatible data storage (and avoid ~/.vscode/) Support XDG_CONFIG_HOME for the argv.json file Dec 7, 2022
@bpasero bpasero removed their assignment Dec 13, 2022
@Da-Viper
Copy link

@bpasero I want to try this issue as it is marked as good first issue,

From what I understand this is to make the argv.json file comply with platform specific appdata path. In extension the XDG paths for linux ?

@bpasero
Copy link
Member

bpasero commented Dec 30, 2022

Yes, basically instead of just using os.homedir, support to check for presence of XDG environment variable. We probably also need to migrate the file to not break existing users.

@Da-Viper
Copy link

Yes, basically instead of just using os.homedir, support to check for presence of XDG environment variable. We probably also need to migrate the file to not break existing users.

This is what I assume this would be the Migration style:

Scenario 1
Exists: oldpath, newpath.
Resolution: Delete the old file // not sure if i am to merge the two files together ??
return the new path

Scenario 2
Exists: oldpath.
Resolution: Move the old path to the new path
return the new path

Scenario 3
Exists: newpath
Resolution: Nothing
return the new path

Scenario 4
Exists: None
Resolution: Nothing //creating of new argv.json logic is handled else where
return the new path

Da-Viper added a commit to Da-Viper/vscode that referenced this issue Jan 1, 2023
@Da-Viper Da-Viper linked a pull request Jan 1, 2023 that will close this issue
@untainsYD
Copy link

Is there any solution for this ISSUE? Because I have been trying to create ~/.config/vscode folder with user-data-dir and extensions-dir paths configured in my ~/.config/code-flags.conf but ~/.vscode folder is still created by VSCode startup in my $HOME directory.

@gjsjohnmurray
Copy link
Contributor

@untainsYD the PR #170364 by @Da-Viper hasn't yet been merged. In fact it seems to have failed a CI action so may need attention by the author before it is ready for @bpasero or another member of the core team to review.

@Da-Viper
Copy link

@untainsYD the PR #170364 by @Da-Viper hasn't yet been merged. In fact it seems to have failed a CI action so may need attention by the author before it is ready for @bpasero or another member of the core team to review.

I tried to update the MR but it is requesting review before CI

@untainsYD
Copy link

Any updates on that ISSUE?

@ashutosh887
Copy link

I'm willing to work on this

@untainsYD
Copy link

VSCode also generates ~/.pki when the vanilla electron stops doing it.

@untainsYD
Copy link

@untainsYD the PR #170364 by @Da-Viper hasn't yet been merged. In fact it seems to have failed a CI action so may need attention by the author before it is ready for @bpasero or another member of the core team to review.

I tried to update the MR but it is requesting review before CI

In this issue ~/.pki folder should be also taken to the account.

VSCode also generates ~/.pki when the vanilla electron stops doing it.

@sdavids
Copy link

sdavids commented Nov 7, 2023

While you are at it, please do not forget about macOS:

case 'darwin':
appDataPath = path.join(os.homedir(), 'Library', 'Application Support');

@ispanos
Copy link

ispanos commented Nov 29, 2023

I don't know if this should be added in this issue, but the R extension also creates .vscode-R in the home directory. In total I have 3 hidden directories, .pki, .vscode, vscoode-R, just from code.

@whitemossyoak64 whitemossyoak64 mentioned this issue Nov 30, 2023
@nl8-gh
Copy link

nl8-gh commented Apr 27, 2024

Any news how this evolved? Related intel appears pretty cluttered and lacking of clear MSFT guidance on how to get vscode to respect XDG defaults - if / once set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality good first issue Issues identified as good for first-time contributors help wanted Issues identified as good community contribution opportunities linux Issues with VS Code on Linux workbench-os-integration Native OS integration issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.