Yin-Yang
Yin-Yang copied to clipboard
VSCode settings.json Completely Overwritten
I had set Yin-Yang to change the color scheme in VS Code based on time of day, and it appears that it completely overwrote my settings.json
file with just the color scheme.
Yin-Yang needs to either append to, or update the JSON -- not completely overwrite the file. I would have lost years worth of settings accumulating if I hadn't had another computer with my old settings.json
still intact.
Machine configuration: DE: plasmashell 5.21.5 OS: Manjaro 21.0.6
Well, that should not have happened. It's likely there was an error while trying to read your settings file, since only then an empty settings file gets created (see this line here). So you should probably check if it is well formed, e.g. no missing brackets.
Could you please replicate the issue by doing the following:
- Create another backup of your settings.json.
- Disable everything except VS Code in yin-yang.
- Run
yin-yang -t
from a terminal. - Paste the output here.
- (Re-enable the automatic theme change, if you had it enabled before).
> yin-yang -t
SETTINGS 1
Changing "Default" to "Atom One Dark" in <my home folder>/.config/Code/User/settings.json
open(): No such file or directory
This reproduces the issue and overwrites the file. But my settings.json
appears to not have any errors in it.
I have the dark theme set to "Atom One Dark" and the light theme set to "Atom One Light" in the VS Code section of Yin-Yang.
I'm also running on the AUR version of the app -- v2.1
Interesting. Seems like the inplace_change() function is the issue here.
Good news is that in my pull request, VS Code doesn't use this function anymore, bad news is that other plugins still use it. I'm going to investigate this further.
json.load
doesn't accept a final comma in src/plugins/vscode.py
, but vscode accepts it as valid for settings.json
. See this discussion on StackOverflow. So my settings file was considered invalid by the plugin.
There may be a safer function to read the json. The SO post above has a solution with ast
. Or maybe yin-yang
could clean up users' settings.json
so python can parse it.
I actually don't think that this a good idea, since ast
isn't really meant to do that. Checking the user's settings file would be a lot of work.
Instead, I think there should just be an exception if the file is malformed and do nothing else.
Does VS Code automatically form the JSON files in such a way or did you manually edit it? If VS Code created those, then it may actually be needed.
I don't think vscode created any JSON that way by default, but any plug-ins that edit the settings file can theoretically add an extra comma.
For example, my settings file's last line was setting my Python virtualenv location. This was added by the Python extension, and it had a comma at the end of it.