1

edit - nov 2022 - I didn't need this anymore, I've switched to Linux & Docker, no more coding under Windows

Does someone knows how to refer to my APPDATA folder in my vscode settings.json file?

I'm trying to set the path to my php-cs-fixer like below so, on all my development computer, the path can be retrieved.

"php-cs-fixer.executablePathWindows": "$env:APPDATA/Composer/vendor/bin/php-cs-fixer.bat",

To be clear: $env:APPDATA seems to be unsupported.

I'm using the latest version of vscode.

Version: 1.52.1 (user setup)
Commit: ea3859d4ba2f3e577a159bc91e3074c5d85c0523
Date: 2020-12-16T16:34:46.910Z
Electron: 9.3.5
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Windows_NT x64 10.0.19041
cavo789
  • 185
  • 1
  • 13
  • I don't remember the exact syntax but i think you could do something like this: `C:\Users\%USER%\AppData` – Nikolai Dec 29 '20 at 21:30
  • Thanks @boiski! Nice try but not working... I've tried `dir C:\Users\%USERNAME%\AppData\Roaming\Composer\vendor\bin\php-cs-fixer.bat` under a Dos Prompt and I get my file ==> it's %USERNAME% **but not working in vscode** I've set my variable like this: `"php-cs-fixer.executablePathWindows": "C:\\Users\\%USERNAME%\\AppData\\Roaming\\Composer\\vendor\\bin\\php-cs-fixer.bat",` and I get this error in vscode Developer window: `[Extension Host] Error: spawn C:\Users\%USERNAME%\AppData\Roaming\Composer\vendor\bin\php-cs-fixer.bat ENOENT`. So, in short, nice try but not working. Thanks! – cavo789 Dec 29 '20 at 21:51
  • In Linux, you can use `${USERNAME}` ... I know that vscode was made to work mostly interchangeably, on both platforms. can you give that a go and see if it helps? – Jad Dec 29 '20 at 23:26
  • Thanks @jad but `C:\Users\${USERNAME}\AppData\Roaming\Composer\vendor\bin\php-cs-fixer.bat` is not working. Here is the error message in my Developer window: `PHP CS Fixer: executablePath not found, please check your settings. It will set to built-in php-cs-fixer.phar. Try again! [Extension Host] Error: spawn C:\Users\${USERNAME}\AppData\Roaming\Composer\vendor\bin\php-cs-fixer.bat ENOENT` – cavo789 Dec 30 '20 at 19:18
  • Just a quick check, does it work if you hard code in the current user? – Jad Dec 30 '20 at 19:23
  • Yes, it works with hardcoded value. I've found an issue on the vscode github page; I've added a comment. https://github.com/microsoft/vscode/issues/2809#issuecomment-752733101. Many thanks everyone; such variable (appdata, username, ...) seems to not be supported for settings. – cavo789 Dec 30 '20 at 19:32
  • How about creating a "bootstrap" type of command, or script, that you call in order to then run the user specific code/version? – Jad Dec 30 '20 at 19:36
  • I've already think about a "workaround": create on each computer a folder with each username (the ones I've on my three computers) so, on my private computer, create a folder with my two username that I use at work. And then, use symlinks to link the global vendor/bin folder in each. Should works but it's a dirty workaround I think ;) – cavo789 Dec 30 '20 at 19:40
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/226631/discussion-between-jad-and-cavo789). – Jad Dec 30 '20 at 22:35

2 Answers2

1

I tried this on VSCode Insiders 1.53, was able to set using ~:

{
  "php-cs-fixer.executablePathWindows": "~\\AppData\\Roaming\\Composer\\vendor\\bin\\php-cs-fixer.bat"
}

Seems that the ~ is transformed to match C:\Users\[you].

mitch
  • 985
  • 10
  • 12
  • Hey, that's cool! Thanks for the info. I'll wait; I don't have the insider version and will wait that it's included in the standard vesion. Actually, I've changed how I work with such tools: I'm downloading the `.phar` file of php-cs-fixer, phan, ... and put them in a `.bin/` folder inside my project. So, the path is always relative to my project. – cavo789 Jan 19 '21 at 21:51
0

I know for sure that ${env:APPDATA} works because I use it in the setting : "emmet.extensionsPath": "${env:APPDATA}\\Code\\User\\Emmet Settings",

Check this documentation section. Unfortunately, this issue complains that it is not supported in every settings and extensions. I strongly suggest that every one upvote this issue so we have better chance MS takes care of it.

Fred Eric
  • 135
  • 1
  • 1
  • 10