Is there an option to disable the automatic creation/save of workspace settings files?
Currently, if you go to File > Preferences > Settings, and if you accidentally click the Workspace Settings tab, it will automatically create a .json file in your working directory. This gets a bit annoying if the project directory is under some sort of source control (git) as it creates a file that you now need to manage (stage, ignore, delete)
I know I can just add this to my .gitignore, but its a bit cumbersome if I have many projects under git control, and I have to add this to every gitignore file
Is there a way to turn this off? Or only create the file on Save so im sure I want the file to exist? (files.autoSave is off)
Currently settings file is created if not exists. Otherwise user cannot write into that file from editor. I think we need an in memory file which is editable and is only saved/created when user saves it.
Just to add a work-around for git:
In your git project folder, edit .git/info/exclude and add .vscode
(See git ignoring file)
An alternative workaround is to setup a global ignore for .vscode: https://stackoverflow.com/questions/7335420/global-git-ignore.
That does not address the problem of having directories and files created across your file system. In many cases the config files being an empty JSON object:
{
}
Would anyone more familiar with the code base know where the settings file gets created?
Would anyone more familiar with the code base know where the settings file gets created?
Seems to be somewhere under src/vs/workbench/parts/preferences/browser.
From what I could gather, it seems like to implement the "only create the file on Save" behavior we'd need some way to set the file path of a buffer/editor prior to creating the file, and then let the user save the settings file explicitly (exactly how users have to save the global settings file).
I tried:
$ code foo/bar.txt
foo, with the file bar.txt with hello:
$ cat foo/bar.txt
hello
That shows that all the required pieces to edit and then save/create a file in a directory that doesn't exist are there.
The change to resolve this issue would involve replacing the usage of createSettingsIfNotExists in src/vs/workbench/services/preferences/browser/preferencesService.ts#L354-L357 with code to create a new editor at a given path (without pre-creating a file) and then populating the editor with {\n}.
Any hints on how to get that last part?
I think the flow here would be to
@bpasero Need your expertise here to shed some light on how to achieve this.
@sandy081 like
IEditorService.openEditor({ filePath: <path to settings.json>, language: 'json', contents: <default contents>})
?
@bpasero What does the above API do if the path to settings.json is not found on the disk?
@sandy081 that is actually the expected usage of this method (because untitled files never exist on disk). It will cause a file to show up as dirty that has the associated path you give it. As such when saving it the path is being used as location without prompting the user. In other regards it behaves like any other untitled file.
Cool. Thanks @bpasero
@rhcarvalho You can use the API Ben suggested.
Thanks @sandy081 and @bpasero. I'm mid-vacation now. Will try to take a look at it late next week.
Anyone interested in tackling this in a shorter timeframe feel free to jump in :-)
What's the status of this issue?
What's the status of this issue?
@fenhl in my testing the stub .vscode/settings.json doesn't get created when I merely click on the Workspace tab. I also have to click the Open Settings (JSON) command button in the upper right.
Is there another pathway that results in a stub .vscode/settings.json file?
Version: 1.46.1 (user setup)
Commit: cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
Date: 2020-06-17T21:13:20.174Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Windows_NT x64 10.0.18363
On macOS, simply opening Code for the first time created ~/.vscode. It appears that extensions are also being saved there.
On macOS, simply opening Code for the first time created
~/.vscode. It appears that extensions are also being saved there.
That isn't what this issue is about. In your case perhaps you need to use Portable Mode.
Apologies, I was directed here. What's the right issue for home pollution then? (It doesn't look like Portable mode is what I want, since it would require creating a data folder in /Applications, which is not how that's supposed to work.)
@fenhl is it a requirement of macOS that Visual Studio Code.app has to be in /Applications ? I'm asking from a position of ignorance as I'm not a macOS user.
I don't know whether it's a requirement (apps in /Applications get extra permissions but I don't know which ones or whether Code uses any of them) but in my case it should stay there regardless since I installed it via Homebrew Cask.
@fenhl Please open a new issue. That way you're more likely to get a response from macOS users.
This happens when you have configured split json UI for opening settings. Since our primary settings UI is not causing this issue, closing this as won't fix.
Most helpful comment
An alternative workaround is to setup a global ignore for
.vscode: https://stackoverflow.com/questions/7335420/global-git-ignore.That does not address the problem of having directories and files created across your file system. In many cases the config files being an empty JSON object: